Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Operations on 64 bits operands in 32 bit architectures?

how does most compilers implement operations on 64 bit operands (e.g long int) in 32 bit environments ? in other words, is there a way to implement these operations in a single step or we need to access multiple memory locations to implement these operations ?

like image 282
Ibrahim Najjar Avatar asked Oct 15 '11 22:10

Ibrahim Najjar


1 Answers

They use two registers to hold a 64-bit value. One for the lower 32-bits and one for the upper 32-bits.

For x86, 64-bit Addition/subtraction is done using add-with-carry and subtract-with-borrow instructions:

add   %eax, (lower 32-bits of operand)
adc   %edx, (upper 32-bits of operand)

64-bit multiplication is much more complicated, but also done using a combination of 32-bit multiplies and 32-bit add-with-carry instructions. (in a way similar to long-multiplication with 2 digits)

For loads and stores, yes, two 32-bit values need to be loaded/stored into/from two registers.

Similarly, 128-bit integers can be implemented on 64-bit hardware. GCC supports this as an extension.

like image 110
Mysticial Avatar answered Oct 12 '22 01:10

Mysticial