HiWord/LoWord

Forum for discussion about the documentation project.
Post Reply
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

HiWord/LoWord

Post by Imortis »

I made some changes to the Hiword and Loword wiki pages because they were using UInteger whose size depends on the CPU size. The C code in the RTLib is using CUINT to force the numbers to be 32bit, so I changed the code to show use of ULong instead so it will always be 32bit.

Let me know if there are any problems there.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: HiWord/LoWord

Post by fxm »

OK, but I have not seen the corresponding commit in github yet ?
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: HiWord/LoWord

Post by Imortis »

fxm wrote: Nov 04, 2022 15:11 OK, but I have not seen the corresponding commit in github yet ?
What do you mean? All I did was change the text to reflect what is actually happening. There were no changes needed in the compiler itself.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: HiWord/LoWord

Post by fxm »

When I compile the following (in 64-bit), I always see UINTEGER type variables:

Code: Select all

#print typeof(HiByte(0))
#print typeof(LoByte(0))
#print typeof(HiWord(0))
#print typeof(LoWord(0))
Must we wait for a new fbc build ?
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: HiWord/LoWord

Post by Imortis »

The code converts what ever you pass to it into a C UInteger: 32bits. It then masks out 16 of those bits. Even if you pass in an 64bits it is converting to 32. Even if it is returning 64 bits, it is still only working with 32. The Docs should then be changed to say it Expands to an Integer, not long, The description of the Macro at the top of the page was incorrect, still.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: HiWord/LoWord

Post by fxm »

And for LOBYTE and HIBYTE ?

For LOWORD and HIWORD documentation pages, maybe we can define the macros as:

Code: Select all

#define Hiword( expr ) Cuint((Cast(Ulong, expr) and &hFFFF0000) shr 16)
#define Loword( expr ) Cuint(Cast(Ulong, expr) and &h0000FFFF)
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: HiWord/LoWord

Post by Imortis »

Upon further reflection, the initial text of the doc is literally correct. The Cast to UInteger is what is happening behind the scenes in the compiler.

However, the macros only ever touch the bottom (most significant) 32bits of any number passed in, regardless of size. If you pass it a 64bit integer, the top 32bits are completely ignored.

It might as well be Casting to ULong because all other data is ignored. Is that what is intended? I am unsure how I feel about that, if it is. I will change to document back to reflect the original, but I think there might be grounds for discussion on what those macros should be doing.
Post Reply