gcc
4.4 seems to be the first version when they added int128_t
. I need to use bit shifting and I have run out of room for some bit fields.
Edit: It might be because I'm on a 32-bit computer, there's no way to have it for a 32-bit computer (Intel Atom), is there? I wouldn't care if it generated tricky slow machine code if I would work as expected with bit shifting.
You could use two 64-bit ints, but then you need to keep track of the bits moving between.
Bit shifting is very easy in any arbitrary number of bits. Just remember to shift the overflowed bits to the next limb. That's all
Similar for shift right
You could also use a library. This would have the advantage that it is portable (regarding platform and compiler) and you could easily switch to even bigger datatype. One I could recommend is gmp (even if its intention is not to handle bitwidth x, but variable as big as you want).
I'm pretty sure that
__int128_t
is available on earlier versions of gcc. Just checked on 4.2.1 and FreeBSD andsizeof(__int128_t)
gives 16.