www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - core.bitop.bt semantics

reply "David Nadlinger" <code klickverbot.at> writes:
The documentation [1] for core.bitop.bt just says "Tests the bit."

With the function returning an int, the question is whether the 
return value is guaranteed to be 0 or 1, as ensured by the 
current implementation, or whether it can be any non-zero integer 
if the bit is set (as documented for the related bts function).

The std.bitmanip.BitArray formatting functions in 2.064 assume 
the former, and are thus currently broken with LDC. LDC will 
probably end up switching to simply using the D implementation 
anyway as LLVM recognizes the pattern just fine, but I'd like to 
know what to fix first.

David


[1] http://dlang.org/phobos/core_bitop.html
Oct 20 2013
parent Lionello Lunesu <lionello lunesu.remove.com> writes:
On 10/20/13 21:23, David Nadlinger wrote:
 The documentation [1] for core.bitop.bt just says "Tests the bit."

 With the function returning an int, the question is whether the return
 value is guaranteed to be 0 or 1, as ensured by the current
 implementation, or whether it can be any non-zero integer if the bit is
 set (as documented for the related bts function).

 The std.bitmanip.BitArray formatting functions in 2.064 assume the
 former, and are thus currently broken with LDC. LDC will probably end up
 switching to simply using the D implementation anyway as LLVM recognizes
 the pattern just fine, but I'd like to know what to fix first.

 David


 [1] http://dlang.org/phobos/core_bitop.html
bt, bts, btr, btc all have the same return value. They only differ in what happens with the tested bit. The fact that they return "int" amplifies the zero / non-zero pattern. I think BitArray should get fixed to support that definition. But you might want to keep "bt" on LDC the same as on DMD, just to prevent similar bugs in user's code. L.
Oct 21 2013