... > Going the other way is similar: > > all_bits = low_bits + ((u64) high_bits << 16) << 16); > > and again, the compiler will recognize this idiom and do the right > thing (and if 'all_bits' is only 32-bit, the compiler will optimize > the high bit noise away).
On a 32bit system the compiler might not do the expected thing. I had terrible trouble with the 32bit div_u64_u32() code I was playing with getting the compiler to do 'something sensible' for that. I just couldn't get it to stop generating two 64bit values (in two register pairs) and then oring them together. I didn't try using a union - that might work. On x64 the asm "A" (edx:eax) and "a" and "d" constraints will DTRT but force the values into edx:eax which is ok if you are doing divides. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)