Author Topic: If you developed your own CPU...  (Read 1270 times)

jj2007

  • Member
  • *****
  • Posts: 13932
  • Assembly is fun ;-)
    • MasmBasic
Re: If you developed your own CPU...
« Reply #15 on: February 27, 2023, 08:59:15 PM »
Now I wonder if sub and Cmp difference is Cmp is sub without results

If you don't test it, it will always remain a mystery :cool:

daydreamer

  • Member
  • *****
  • Posts: 2393
  • my kind of REAL10 Blonde
Re: If you developed your own CPU...
« Reply #16 on: March 01, 2023, 03:33:20 PM »
Jochen
Intel recommend add and sub, instead of inc and dec
Got SSE ideas now

Mov ecx,-count
Lea ebx, adress+count
Movaps xmm0, values
L1:
Movaps [ebx+ecx], xmm0
Add ecx, 16
Jne L1
-------------------or
Mov ecx, count
Lea ebx, adress
Movaps xmm0, values
L2: movaps [ebx+ecx], xmm0
Sub ecx, 16
Jne L2

Instead of the usual add ecx, 1 and sub ecx, 1
my none asm creations
http://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

jj2007

  • Member
  • *****
  • Posts: 13932
  • Assembly is fun ;-)
    • MasmBasic
Re: If you developed your own CPU...
« Reply #17 on: March 01, 2023, 07:07:56 PM »
Jochen
Intel recommend add and sub, instead of inc and dec

I know that they recommend it, but my measurements show that there is absolutely no difference, except that add and sub pollute the cpu instruction cache with two useless extra bytes.

Quote
Cache read misses from an instruction cache generally cause the largest delay, because the processor, or at least the thread of execution, has to wait (stall) until the instruction is fetched from main memory.

Quote
Got SSE ideas now

Great :thumbsup:

daydreamer

  • Member
  • *****
  • Posts: 2393
  • my kind of REAL10 Blonde
Re: If you developed your own CPU...
« Reply #18 on: March 02, 2023, 07:17:07 PM »
Jochen I still want to time the above vs having two add/sub =
add ebx,16
Sub ecx,1 or Dec ecx

I also believe in outer loop or loop containing api call that takes milliseconds it might be better to use
Dec variable
Vs register preservation + sub reg,1 or Dec reg
I already written the way of use in game
Dec lives
Jne Mainloop

Invoke MessageBox "game over"
my none asm creations
http://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

jj2007

  • Member
  • *****
  • Posts: 13932
  • Assembly is fun ;-)
    • MasmBasic
Re: If you developed your own CPU...
« Reply #19 on: March 02, 2023, 09:34:30 PM »
Jochen I still want to time the above vs having two add/sub =

We've tried that pretty often in The Lab, see e.g. http://masm32.com/board/index.php?topic=5900.msg62727#msg62727

InfiniteLoop

  • Regular Member
  • *
  • Posts: 44
Re: If you developed your own CPU...
« Reply #20 on: March 20, 2023, 11:29:51 AM »
Jochen I still want to time the above vs having two add/sub =
add ebx,16
Sub ecx,1 or Dec ecx

I also believe in outer loop or loop containing api call that takes milliseconds it might be better to use
Dec variable
Vs register preservation + sub reg,1 or Dec reg
I already written the way of use in game
Dec lives
Jne Mainloop

Invoke MessageBox "game over"

I believe inc and dec are old, obsolete instructions
Add and sub have the same speed.
On Golden Cove, add reg,byte constant is eliminated.

jj2007

  • Member
  • *****
  • Posts: 13932
  • Assembly is fun ;-)
    • MasmBasic
Re: If you developed your own CPU...
« Reply #21 on: March 20, 2023, 12:37:54 PM »
I believe inc and dec are old, obsolete instructions

I'm not a religious person - I know that inc/dec are exactly as fast as add/sub, and 66% shorter (I measured it).

daydreamer

  • Member
  • *****
  • Posts: 2393
  • my kind of REAL10 Blonde
Re: If you developed your own CPU...
« Reply #22 on: March 20, 2023, 08:43:40 PM »
I believe inc and dec are old, obsolete instructions
Add and sub have the same speed.
It's convenient to instead of in non critical innerloop do this
Mov reg,variable
Sub variable, 1
Mov variable, reg
Jne label
Might need additional register preservation in 32bit for the above code
Replace with
Dec variable
Jne label

my none asm creations
http://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

zedd151

  • Member
  • *****
  • Posts: 1942
Re: If you developed your own CPU...
« Reply #23 on: March 22, 2023, 10:09:10 AM »
I believe inc and dec are old, obsolete instructions

I'm not a religious person - I know that inc/dec are exactly as fast as add/sub, and 66% shorter (I measured it).
'inc eax'/'dec eax' is also a little less typing than 'add eax, 1'/'sub eax, 1'  :tongue:
Regards, zedd.
:tongue:

daydreamer

  • Member
  • *****
  • Posts: 2393
  • my kind of REAL10 Blonde
Re: If you developed your own CPU...
« Reply #24 on: March 23, 2023, 08:38:09 PM »
I believe inc and dec are old, obsolete instructions

I'm not a religious person - I know that inc/dec are exactly as fast as add/sub, and 66% shorter (I measured it).
'inc eax'/'dec eax' is also a little less typing than 'add eax, 1'/'sub eax, 1'  :tongue:
Code productivity is also good for hobby coders,instead of waste time to optimize MessageBox and end up with unfinished program
Dec var ;more shorter than :mov eax,var/sub var,1/mov var,eax
Neg var ;is also available as shorter alternative to change sign

Inspired by old hardware had vertical blank interrupt that started working every time the cathode ray went back to top left screen, 30 fps it was called 30 times /second
So i did similar with Wm_timer, put a loop that changes all x y coordinates, check for out of screen and invaliderect
Collision detection I put in paint
Inspired by games that spawn enemies from a portal,I used a second slow timer that respawned enemies

my none asm creations
http://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding