I've been studying inline-assembly for almost 1 month now, and as another practice problem, I'm trying to add up two uint512
using inline-assembly, at first I got what I wanted, the code compiles and I was able to get the correct result with my code below. Though until this time I'm only compiling my program with optimization flags; -O2 and -O3.
But when I tried to remove -O1, -O2 or -O3 in my compilation flag it produces a compilation error error: 'asm' operand has impossible constraints
, what could be the reason for this?
I'm assuming because the optimizations is disabled, the program is actually trying to use more registers than my CPU have?. Still I'm just using 8 registers (or maybe not anymore?), is my input being stored in another 8 registers instead?
// uint512 += uint512
void uint512_add(unsigned long *sum, unsigned long *add) {
asm volatile(
"add %[adn0], %[sum0]\n\t"
"adc %[adn1], %[sum1]\n\t"
"adc %[adn2], %[sum2]\n\t"
"adc %[adn3], %[sum3]\n\t"
"adc %[adn4], %[sum4]\n\t"
"adc %[adn5], %[sum5]\n\t"
"adc %[adn6], %[sum6]\n\t"
"adc %[adn7], %[sum7]"
:
[sum0]"+r"(sum[0]), [sum1]"+r"(sum[1]),
[sum2]"+r"(sum[2]), [sum3]"+r"(sum[3]),
[sum4]"+r"(sum[4]), [sum5]"+r"(sum[5]),
[sum6]"+r"(sum[6]), [sum7]"+r"(sum[7])
:
[adn0]"m"(add[0]), [adn1]"m"(add[1]),
[adn2]"m"(add[2]), [adn3]"m"(add[3]),
[adn4]"m"(add[4]), [adn5]"m"(add[5]),
[adn6]"m"(add[6]), [adn7]"m"(add[7])
: "memory", "cc"
);
}