Author Topic: Avoiding dependencies  (Read 212 times)

felipe

  • Member
  • ***
  • Posts: 419
  • Asssssssembly language...said the snake.
Avoiding dependencies
« on: December 19, 2017, 10:27:51 AM »
When you want to avoid dependencies (to optimize code speed, parallel processing) in usage of registers, to execute instructions in parallel (32 bits, integer arithmetic instructions) but for some reason you can't do it in some places: It would be a good idea to interleave in these places some nops intructions? If not (for some reason) what other instruction would be a good idea to place there? As an example:
Code: [Select]
mov    eax,memlocation1
mov    ebx,memlocation2
add     eax,ebx
xor     edx,edx
mul    ebx
Can be written (to avoid register dependecies):
Code: [Select]
mov     eax,memlocation1
mov     ebx,memlocation2
xor      edx,edx
add     eax,ebx
mul     ebx
But you can't avoid all the dependencies yet. Of course here you have to assume (for the purpose of the question) than there aren't other registers available or it could be difficult to keep trace of all them when pushing and popping them from the stack). So it would be a good idea to do somenthing like this (using nops)?:
Code: [Select]
mov    eax,memlocation1
mov   ebx,memlocation2
xor    edx,edx
add   eax,ebx
nop
mul   ebx

 :idea:
Felipe.

felipe

  • Member
  • ***
  • Posts: 419
  • Asssssssembly language...said the snake.
Re: Avoiding dependencies
« Reply #1 on: December 19, 2017, 12:58:14 PM »
Or i'm absolutely wrong with this and also not too much uptodate?  :redface:
Felipe.

felipe

  • Member
  • ***
  • Posts: 419
  • Asssssssembly language...said the snake.
Re: Avoiding dependencies
« Reply #2 on: December 19, 2017, 01:02:56 PM »
Maybe this question should go in the campus.  :redface:  :P
Felipe.

LordAdef

  • Member
  • ***
  • Posts: 287
Re: Avoiding dependencies
« Reply #3 on: December 19, 2017, 01:50:22 PM »
Hey Felipe,

Interesting question!
My gut feeling is "nop" wont do the job. But let´s wait for the masters.

aw27

  • Member
  • ****
  • Posts: 966
  • Let's Make ASM Great Again!
Re: Avoiding dependencies
« Reply #4 on: December 19, 2017, 04:21:12 PM »
CPUs will notice that and reorder the instructions for us. Except, with vector instructions.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5040
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Avoiding dependencies
« Reply #5 on: December 19, 2017, 07:45:26 PM »
The general drift is to kick the guts out of a single thread algo then work out how to run the algo in parallel with multithreading. It requires a multicore processor but they have been around for years now so it should not be a problem. It always helps to write the control integer instructions is an efficient manner which means in modern terms "instruction scheduling" that avoids old style junk that only lives in micro-code for backwards compatibility reasons but the gains here are small alongside what you can do with AVX and to a lesser degree SSE instructions. Get the later instructions right and multithread them where real speed matters and you will see big gains in performance.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

felipe

  • Member
  • ***
  • Posts: 419
  • Asssssssembly language...said the snake.
Re: Avoiding dependencies
« Reply #6 on: December 20, 2017, 04:44:23 AM »
Clear as clean water, thanks.  :icon14:
I will peak the newest instructions and intel manuals soon as i can.  :greensml:
Felipe.