Page 1 of 1

ASMCODE: IF / ELSE EXAMPLE - DWB~2014

Posted: Sun Apr 27, 2014 3:12 am
by digitalwhitebyte
I wanted to share this code,
to discuss further possibilities to execute a function IF / ELSE for the individual channels.

I found this very useful code to bypass or switch other pieces of code very complex and heavy for a single channel,
so as to have a single process and not only mask the result,
also a partner in poly section to always use the bypass / switch possibility.

Code: Select all

/* ## ASMCODE: IF / ELSE EXAMPLE - DWB~2014 ## */
streamin in1;streamin in2;
streamout out;

//>> ** TEMP VAR FOR IF / ELSE ROUTINE
float TmpCompare=0;
//<< ** TEMP VAR FOR IF / ELSE ROUTINE

//>> ** STORE EAX,EBX REGISTER
push eax;
push ebx;
//<< ** STORE EAX,EBX REGISTER

//>> ** ASSIGN VAR TO XMM REGISTER
movaps xmm0,in1;
movaps xmm1,in2;
//>> ** ASSIGN VAR TO XMM REGISTER

//>> ** COMPARE TWO XMM REGISTER
cmpps  xmm0,xmm1,5;
//   ** STORE RESULT IN TEMP VAR
movaps TmpCompare,xmm0;
//<< ** COMPARE TWO XMM REGISTER

//>> ** IF / ELSE ROUTINE >>>>>>>>>>>>>>>>>>>>>>>>>>
//   ** Move the 1° CH Compared State to EAX Register
mov   eax,TmpCompare[0];
//   ** Compare the state mode (cmmps xmm,xmm,mode;)
//   ** this set the FLAG for jump opcode     
cmp   eax,0;
jz   if0;
   //>> ** Your IF code here
   // mov ebx,in1[0]; //Test Output
   
   //<< ** Your IF code here
   if0:
jnz else0;
   //>> ** Your ELSE code here
   //mov ebx,in2[0]; //Test Output
   
   //<< ** Your ELSE code here
   else0:
   //>> ** Your THEN code here
   //mov out[0],ebx; //Test Output
   
   //<< ** Your THEN code here
//<< ** IF ELSE ROUTINE <<<<<<<<<<<<<<<<<<<<<<<<<<<<

//>> ** IF / ELSE ROUTINE >>>>>>>>>>>>>>>>>>>>>>>>>>
//   ** Move the 2° CH Compared State to EAX Register
mov   eax,TmpCompare[1];
//   ** Compare the state mode (cmmps xmm,xmm,mode;)
//   ** this set the FLAG for jump opcode     
cmp   eax,0;
jz   if1;
   //>> ** Your IF code here
   // mov ebx,in1[1]; //Test Output
   
   //<< ** Your IF code here
   if1:
jnz else1;
   //>> ** Your ELSE code here
   //mov ebx,in2[1]; //Test Output
   
   //<< ** Your ELSE code here
   else1:
   //>> ** Your THEN code here
   //mov out[1],ebx; //Test Output
   
   //<< ** Your THEN code here
//<< ** IF ELSE ROUTINE <<<<<<<<<<<<<<<<<<<<<<<<<<<<

//>> ** IF / ELSE ROUTINE >>>>>>>>>>>>>>>>>>>>>>>>>>
//   ** Move the 3° CH Compared State to EAX Register
mov   eax,TmpCompare[2];
//   ** Compare the state mode (cmmps xmm,xmm,mode;)
//   ** this set the FLAG for jump opcode     
cmp   eax,0;
jz   if2;
   //>> ** Your IF code here
   // mov ebx,in1[2]; //Test Output
   
   //<< ** Your IF code here
   if2:
jnz else2;
   //>> ** Your ELSE code here
   //mov ebx,in2[2]; //Test Output
   
   //<< ** Your ELSE code here
   else2:
   //>> ** Your THEN code here
   //mov out[2],ebx; //Test Output
   
   //<< ** Your THEN code here
//<< ** IF ELSE ROUTINE <<<<<<<<<<<<<<<<<<<<<<<<<<<<

//>> ** IF / ELSE ROUTINE >>>>>>>>>>>>>>>>>>>>>>>>>>
//   ** Move the 4° CH Compared State to EAX Register
mov   eax,TmpCompare[3];
//   ** Compare the state mode (cmmps xmm,xmm,mode;)
//   ** this set the FLAG for jump opcode     
cmp   eax,0;
jz   if3;
   //>> ** Your IF code here
   // mov ebx,in1[3]; //Test Output
   
   //<< ** Your IF code here
   if3:
jnz else3;
   //>> ** Your ELSE code here
   //mov ebx,in2[3]; //Test Output
   
   //<< ** Your ELSE code here
   else3:
   //>> ** Your THEN code here
   //mov out[3],ebx; //Test Output
   
   //<< ** Your THEN code here
//<< ** IF ELSE ROUTINE <<<<<<<<<<<<<<<<<<<<<<<<<<<<

//>> ** RESTORE EAX,EBX REGISTER
pop ebx;
pop eax;
//<< ** RESTORE EAX,EBX REGISTER

Re: ASMCODE: IF / ELSE EXAMPLE - DWB~2014

Posted: Mon Apr 28, 2014 12:06 am
by Nubeat7
thx DWB this seems to be a very useful template, still not very used to with the jump opcodes after i use it very rarely, anyway right into my toolbox :)

Re: ASMCODE: IF / ELSE EXAMPLE - DWB~2014

Posted: Thu May 01, 2014 4:08 pm
by KG_is_back
with SSE all 4 channels are computed all at once, so it doesn't really matter to bypass all of them individually. You may bypass the code execution if all channels are in off-state. If not simply apply mask to output.

note that bypass variable has to be a false/true mask, otherwise the output mask apply will not work correctly (although the bypassing will)

Code: Select all

streamin in;
streamboolin bypass;
streamout out;

movaps eax,bypass[0];
add eax,bypass[1];
add eax,bypass[2];
add eax,bypass[3];
cmp eax,0;
jz skipcode;
//your code
//example
movaps xmm0,in;
//
skipcode:
andps xmm0,bypass;
movaps out,xmm0;




this might be very useful in poly sections in situations where you what to execute specific code for specific channel based on parameter. For example looping mode in sampler, you can now have all looping modes (one shot, forward loop, forward-backward loop etc.) without having to execute all of them.