Re: 128-bit inline assembly addition

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 16/07/18 21:52, Marcel Keller wrote:
> Hi,
> 
> I've found that the attached program, which supposedly adds 1 and 0 as
> 128-bit numbers using inline assembly, outputs 2^64 + 1 instead when
> compiled with g++ 7 or 8 and at least -O1. Am I doing something wrong,
> or is this a compiler bug?
> 

If you just want to use 128-bit integers, rather than learning inline
assembly, then you might be easier using gcc's __int128 or unsigned
__int128 types.  If your particular target does not support __int128,
then another option is the builtin overflow functions.  With a little
care (and optimisation enabled), these will give you at least as good
code, and sometimes better, as your inline assembly.  (It can be better
because the compiler knows what they do for optimisation, and may be
able to improve instruction scheduling.)

<https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html>




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux