Cfish
Cfish copied to clipboard
Have you tried juggling those flags?
Did you see https://developers.redhat.com/blog/2016/02/25/new-asm-flags-feature-for-x86-in-gcc-6/ ? If I had known about this earlier, I might not have tried to write asmfish in asm. It really does work, and I have tried it myself for overflow https://github.com/tthsqe12/cas/blob/master/types.h#L182
Interesting! I did not know about this. Last time I looked the closest one could get to directly using the condition flags was with "asm goto".
I should add that the register-memory form of bt is exceedingly slow compared to the register-register version. Took forever to track down that bottleneck
Unfortunately gcc isn't always being clever.
#include <inttypes.h>
#include <stdio.h>
static __inline__ int test_sq(uint64_t b, uint64_t s)
{
int bit;
__asm__("btq\t%2, %1" : "=@ccc" (bit) : "r" (b), "Ir" ((uint64_t)s));
return bit;
}
int f(uint64_t b, uint64_t s)
{
if (!test_sq(b, s))
return 0;
printf("test\n");
return 1;
}
compiles to (AT&T notation):
f:
btq %rsi, %rdi
jc .L13
setc %al
movzbl %al, %eax
ret
.L13:
subq $8, %rsp
movl $.LC0, %edi
call puts
movl $1, %eax
addq $8, %rsp
ret
If I return 1 instead, the setc and movzbl instructions are replaced with "movl $1, %eax".
Do you have a bool type? I suppose gcc is getting confused by booleans https://godbolt.org/g/SZwmPb