Displaying 1 result from an estimated 1 matches for "saddo_portable2".
Did you mean:
saddo_portable
2018 Nov 20
2
A pattern for portable __builtin_add_overflow()
...o easy. I tried 2 versions, but the result
is quite far away from the optimal assembly.
int saddo_native(int a, int b, int* s)
{
return __builtin_add_overflow(a, b, s);
}
int saddo_portable(int a, int b, int* s)
{
*s = (unsigned)a + (unsigned)b;
return (a > 0) ? *s <= b : *s > b;
}
int saddo_portable2(int a, int b, int* s)
{
*s = (unsigned)a + (unsigned)b;
int cond = a > 0;
int check = *s > b;
return (cond & !check) | (!cond & check);
}
Assembly:
saddo_native: # @saddo_native
xor eax, eax
add edi, esi
seto al
mov dword ptr [rdx], edi
ret
saddo_portable: # @saddo_portable
lea eax,...