Subject: Re: [boost] [atomic] (op)_and_test naming
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2018-01-26 09:34:45
On 01/26/18 03:08, Peter Dimov via Boost wrote:
>> Â Â Â if (a.sub_and_test(1))
>> Also, the generated code for these operations can potentially be more
> While we're on the subject, on what architectures would opaque_sub be
> more efficient than sub_and_test?
On x86 and gcc < 7 opaque_sub allows to use "lock sub" or "lock dec"
without setting the bool according to the zero flag, i.e. it saves a
register and an instruction. Gcc 7 introduced the ability to return
flags from the asm statement, so the code can be written the same way.
Although I noticed that the compiler tends to save the flag into a
register early unless it is tested immediately, so in some cases
opaque_sub might still be preferable where it suits. AFAIK, other
compilers, including clang, don't support this feature.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk