[discuss] 128bit integer arithmetic

Jan Beulich JBeulich at novell.com
Thu Aug 18 15:37:17 CEST 2005

>>> "H. Peter Anvin" <hpa at zytor.com> 11.08.05 01:50:28 >>>
>Gunnar wrote:
>> Hi.
>> I'd like to multiply two 64 bit integers and run it on a Athlon64
>> That means the result will be 128 bits.
>> Is there any 128 bit integer arithmetic instructions that I could
use or do I 
>> have to find other ways of doing it?
>> Any illustrative code in C/C++ could also help a lot.
>I don't think __int128 is implemented in the current gcc, but in 
>assembly this is simply done with the mulq (or, if signed, imulq) 

gcc supports double-machine-word operations generically for all
targets, so 128-bit integer support (using the custom __int128_t and
__uint128_t types, or using __attribute__((__mode__(__TI__)))) is
available for all 64-bit machines. Additionally I recently committed a
patch to actually provide some backend support for x86-64, so 4.1 will
hopefully produce somewhat better code than that resulting from the
(architecture independent) splitting into machine word quantities.


More information about the discuss mailing list