What is a correct implementation that uses btr to reset a bit in an integer in C++ with the extended assembly (asm volatile
) syntax? I need to return the value in the bit before the reset.
This is the implementation I have, is this correct for a 16 bit integer?
std::uint16_t reset(std::uint16_t& integer, std::uint32_t bit) {
auto success = false;
asm volatile("lock btrw %1, (%2); setnc %0"
: "=r"(success)
: "i"(bit), "r"(&integer)
: "memory", "flags");
return !success;
}
Is this implementation correct? Have I missed any detail? I am not very familiar with the asm()
syntax or with x86 assembly.