The MASM Forum

General => The Campus => Topic started by: daydreamer on January 17, 2021, 08:08:18 PM

Title: What is best alternative?
Post by: daydreamer on January 17, 2021, 08:08:18 PM
If I have x and Y coordinates.  variables Stored in fixed point 16:16 so I get smooth movement, final fetch upper half for drawing? What is best?
Mov zx?
Mov +shift?
Push /pop?
Packed expand words to dwords?
Title: Re: What is best alternative?
Post by: hutch-- on January 17, 2021, 09:17:14 PM
Depends on how fast you want to access the data, 2 x 16 bit is smaller but you have to extract the data but 2 x 32 bit are faster access in the decoding. Effectively splitting a single value into 2 parts is expensive time wise. If you want them as 16 bit values, store them sequentially as 16 bit values in an array.
Title: Re: What is best alternative?
Post by: daydreamer on January 18, 2021, 01:53:17 AM
Quote from: hutch-- on January 17, 2021, 09:17:14 PM
Depends on how fast you want to access the data, 2 x 16 bit is smaller but you have to extract the data but 2 x 32 bit are faster access in the decoding. Effectively splitting a single value into 2 parts is expensive time wise. If you want them as 16 bit values, store them sequentially as 16 bit values in an array.
could as well go 64bit 32:32 must be most effective with many physics+control code ending in cache xpos,ypos in registers and use only upper 32bit part right before invoke imagedrawing?

Title: Re: What is best alternative?
Post by: felipe on January 18, 2021, 05:36:24 AM
I belive that in a game you would be updating the position of a game player a lot, so putting those coordinates in registers will be wise. Now, if you code in 64 bits, you have more registers to use, you can still use a 16 bit register part, even in those registers that couldn't do that before, as esi o edi.  :icon_idea:
Title: Re: What is best alternative?
Post by: jj2007 on January 18, 2021, 09:02:52 AM
Quote from: felipe on January 18, 2021, 05:36:24 AMyou can still use a 16 bit register part, even in those registers that couldn't do that before, as esi o edi.  :icon_idea:

include \masm32\MasmBasic\MasmBasic.inc
  Init
  mov edi, 11111111h
  mov di, 2222h
  deb 4, "Test", x:edi
EndOfCode


Output: Test    x:edi           11112222
Title: Re: What is best alternative?
Post by: daydreamer on January 18, 2021, 06:59:28 PM
Quote from: felipe on January 18, 2021, 05:36:24 AM
I belive that in a game you would be updating the position of a game player a lot, so putting those coordinates in registers will be wise. Now, if you code in 64 bits, you have more registers to use, you can still use a 16 bit register part, even in those registers that couldn't do that before, as esi o edi.  :icon_idea:
place everything in the same PROC with GetDC/ReleaseDC,64bit registers would have advantage of fast 32:32 bit physics together with invokes takes arguments from registers

actually I update coordinates inside fast timer that has freqency so it fits ca 30fps,a secondary slow timer that spawns/respawns objects that been destroyed
dont know how much faster it would go,if I do packed physics
Title: Re: What is best alternative?
Post by: TouEnMasm on January 18, 2021, 07:49:51 PM
Quote
If I have x and Y coordinates.  variables Stored in fixed point 16:16 so I get smooth movement, final fetch upper half for drawing? What is best?
Mov zx?
Mov +shift?
Push /pop?
Packed expand words to dwords?

Best way to solve this is to put it in a c program ,use /Ox and /FA,you get an asm who give you the best soluce.
Title: Re: What is best alternative?
Post by: felipe on January 19, 2021, 09:59:26 AM
Quote from: jj2007 on January 18, 2021, 09:02:52 AM
Quote from: felipe on January 18, 2021, 05:36:24 AMyou can still use a 16 bit register part, even in those registers that couldn't do that before, as esi o edi.  :icon_idea:

include \masm32\MasmBasic\MasmBasic.inc
  Init
  mov edi, 11111111h
  mov di, 2222h
  deb 4, "Test", x:edi
EndOfCode


Output: Test    x:edi           11112222

You are absolutly right, how can the memory trick me after so much time without coding anything...My statement above should say 8 bit register part, which is not even in the question-topic... :sad:

Shame on me, btw thanks jj you have been very instructive as in other times.  :thup:
Title: Re: What is best alternative?
Post by: jj2007 on January 19, 2021, 10:15:37 AM
Quote from: felipe on January 19, 2021, 09:59:26 AMYou are absolutly right, how can the memory trick me after so much time without coding anything...My statement above should say 8 bit register part, which is not even in the question-topic... :sad:

Shame on me, btw thanks jj you have been very instructive as in other times.  :thup:

My pleasure, Felipe. Actually, I wasn't sure myself, as I have never used mov di, ... - so I tested it and it works :cool:
Title: Re: What is best alternative?
Post by: daydreamer on January 20, 2021, 05:13:17 AM
Quote from: jj2007 on January 19, 2021, 10:15:37 AM
Quote from: felipe on January 19, 2021, 09:59:26 AMYou are absolutly right, how can the memory trick me after so much time without coding anything...My statement above should say 8 bit register part, which is not even in the question-topic... :sad:

Shame on me, btw thanks jj you have been very instructive as in other times.  :thup:

My pleasure, Felipe. Actually, I wasn't sure myself, as I have never used mov di, ... - so I tested it and it works :cool:
would be nice to know 64bit choose of register usage,why do my compiler choose R9D(32bit) to use in a loop?
@Toutenmasm
offcourse I try that,but I doubt C compiler know the intention of use fixed point optimizations

Title: Re: What is best alternative?
Post by: hutch-- on January 20, 2021, 05:22:11 AM
Magnus,

The Microsoft ABI (application binary interface) controls the registers that are used for different purposes. I think from memory that there is a list in the 64 bit MASM sub forum.
Title: Re: What is best alternative?
Post by: jj2007 on January 20, 2021, 05:58:17 AM
Hutch,

I tried searching for it with abi rax rcx rdx r8 r9 scratch registers - 0 hits. So I took away the "abi" and tried again but was greeted with Your last search was less than 30 seconds ago. Please try again later.

Is that a setting against bots? For human search it makes little sense...
Title: Re: What is best alternative?
Post by: hutch-- on January 20, 2021, 05:59:44 AM
> Is that a setting against bots?

Yes.

http://masm32.com/board/index.php?topic=6177.0
Title: Re: What is best alternative?
Post by: jj2007 on January 20, 2021, 06:01:43 AM
Can you switch it off for members?

P.S.: I waited long enough and found your post titled Ray Chen on Win64 (http://masm32.com/board/index.php?topic=5455.0), which explains register use in detail
Title: Re: What is best alternative?
Post by: hutch-- on January 20, 2021, 06:03:52 AM
No, its there to stop bot floods.
Title: Re: What is best alternative?
Post by: felipe on January 20, 2021, 09:47:02 AM
Quote from: daydreamer on January 20, 2021, 05:13:17 AM
why do my compiler choose R9D(32bit) to use in a loop?

Probably because the r9 register is one of the volatile on function call registers (as ecx in 32 bit abi), so the compiler won't use a non-volatile register in loops... :icon_idea:
Title: Re: What is best alternative?
Post by: felipe on January 20, 2021, 09:50:37 AM
of course this in the context of the windows 64 bit abi, as mentioned by hutch...
Title: Re: What is best alternative?
Post by: hutch-- on January 20, 2021, 10:55:09 AM
felipe is correct here, if you get the register list in the masm 64 bit reference section, transient registers are used differently from system or fixed registers and it works in much the same way as the Intel 32 bit ABI, some registers are reserved by the OS and the others are transient.

Win64 is a lot easier to use as you have a lot more registers and rarely need locals to make up for registers so the OS has enough to make the OS faster while leaving more transient registers available.
Title: Re: What is best alternative?
Post by: daydreamer on January 21, 2021, 03:08:32 AM
Quote from: hutch-- on January 20, 2021, 10:55:09 AM
felipe is correct here, if you get the register list in the masm 64 bit reference section, transient registers are used differently from system or fixed registers and it works in much the same way as the Intel 32 bit ABI, some registers are reserved by the OS and the others are transient.
thanks Hutch
so 32bit use free registers used to change X and Y first avoids 3push/3pops,its push,push,push,push,call bitblt or other imagedrawing call,question if fixed point 16:16 shift to get only integer part

64bit use the right 4 registers to change X,xlow and Y,ylow and shift and call bitblt,few cycles faster!!!