Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

ASMCODE: IF / ELSE EXAMPLE - DWB~2014

Post any examples or modules that you want to share here

ASMCODE: IF / ELSE EXAMPLE - DWB~2014

Postby digitalwhitebyte » Sun Apr 27, 2014 3:12 am

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
User avatar
digitalwhitebyte
 
Posts: 106
Joined: Sat Jul 31, 2010 10:20 am

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

Postby Nubeat7 » Mon Apr 28, 2014 12:06 am

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 :)
User avatar
Nubeat7
 
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna

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

Postby KG_is_back » Thu May 01, 2014 4:08 pm

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.
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia


Return to User Examples

Who is online

Users browsing this forum: No registered users and 99 guests