Jump to content

GCC: Simple 64 bit integers on 32 bit system?

- - - - -

  • Please log in to reply
3 replies to this topic

#1
Fighter

Fighter

    Newbie

  • Members
  • PipPip
  • 28 posts
My processor supports 64 bit instructions, however I am unfortunately on a 32 bit operating system, x86 Arch Linux. I am attempting to implement a method to work with 64 bit integers in my program, that are at a reasonable speed when accessing many of them for the fact I am using them for light media purposes, or mathematical applications which I generally found 8 bytes to successfully hold the data I am using.

I had thought out using an arbitrary precision libraries, I am not quite sure the benefits are there in speed over maybe a silly struct (and the problems I face testing with it) to store a high and low 32 bit integer, and integrate over and under flow protection.

Do you guys have a method that is fairly safe, as in the method would use native integers on the 64 bit native architectures yet still be usable on my 32?

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
This is actually not as hard, Windows has the __int64 type and C99 has (u)int64_t type inside stdint.h. This may be synonymous to long long on your platform.

i.e. A valid constant representation: 0xff000000000000ffLLU

Could very well be represented to the stack as the following for you:
move long 255 in to -8(%ebp) # (0xff) in to EBP offset of -0x8
move long -16777216 in to -4(%ebp)  # (unsigned overflow of ff00...) in to EBP with offset of -0x4
And as such, your struct with high and low integers would not be far off, however you would be correct to assume the integers may not be even near each other in some situations.

Edited by Alexander, 21 May 2011 - 08:32 AM.

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
Fighter

Fighter

    Newbie

  • Members
  • PipPip
  • 28 posts
Ah perfect, the compiler was throwing me off by saying my integers were invalid however it compiled, adding the hints worked perfectly (LL), this makes me much more comfortable working with them.

A question though, edit: two, would accessing it as a pointer work as any other? Also, would arithmetic on the value require the processor to work on both halves as it is stored?

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200

Fighter said:

A question though, edit: two, would accessing it as a pointer work as any other?
Sure it will, as long as the compiler knows its type it will provide the operations to perform on it.

Quote

Also, would arithmetic on the value require the processor to work on both halves as it is stored?
It will, I would envision ADC and SBB operations which would carry the result to the other halves to sum. I am unsure of how intensive the operations are however, it should be a lot less than custom methods however of which use more cycles no matter how fast they are.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users