This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
128-bit inline assembly addition
- From: Marcel Keller <mks dot keller at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 16 Jul 2018 21:52:12 +0200
- Subject: 128-bit inline assembly addition
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?
Best regards,
Marcel
#include <immintrin.h>
#include <iostream>
using namespace std;
int main()
{
long res[2] = { 0, 0 };
long x[2] = { 1, 0 };
__asm__ volatile (
"add %2, %0 \n"
"adc %3, %1 \n"
: "+r"(res[0]), "+r"(res[1])
: "rm"(x[0]), "rm"(x[1])
: "cc"
);
cout << "res " << hex << res[0] << " " << res[1] << endl;
}