I'm trying to understand what this testb instruction (x86-64) will do.
testb $1, %al
What is the value of $1 here. is it all ones (0xFF
) or a single 1 (0x1
)?
The assembly is produced by clang for the following program:
#include <atomic>
std::atomic<bool> flag_atomic{false};
extern void f1();
extern void f2();
void foo() {
bool b = flag_atomic.load(std::memory_order_relaxed);
if (b == false) {
f1();
} else {
f2();
}
}
The relevant assembly with (clang++ -s test.cpp -O3) is the following:
Lcfi2:
.cfi_def_cfa_register %rbp
movb _flag_atomic(%rip), %al
testb $1, %al ; <<<<------------
jne LBB0_2