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?
3 replies to this topic
#1
Posted 19 May 2011 - 10:23 PM
|
|
|
#2
Posted 19 May 2011 - 10:46 PM
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:
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 -0x4And 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.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 20 May 2011 - 05:41 PM
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?
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
Posted 20 May 2011 - 05:58 PM
Fighter said:
A question though, edit: two, would accessing it as a pointer work as any other?
Quote
Also, would arithmetic on the value require the processor to work on both halves as it is stored?
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.
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


Sign In
Create Account


Back to top









