[Issue 6686] New: bitmanip bitfields are broken at 64 bits
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Sep 17 13:13:18 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6686
Summary: bitmanip bitfields are broken at 64 bits
Product: D
Version: D2
Platform: Other
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: paul.d.anderson at comcast.net
--- Comment #0 from Paul D. Anderson <paul.d.anderson at comcast.net> 2011-09-17 13:12:53 PDT ---
The bitfields setters give incorrect results if the bitfield is 64 bits long
and the first field is <= 32.
The following program returns the correct result:
import std.bitmanip;
import std.string;
public static void main() {
union S {
// entire 64-bit unsigned integer
ulong bits = ulong.max;
// split in two
mixin (bitfields!(
ulong, "back", 31,
ulong, "front", 33)
);
const string toHex() { return format("0x%016X", bits); }
}
S num;
num.bits = ulong.max;
writeln("num1 = ", num.toHex);
num.back = 1;
writeln("num2 = ", num.toHex);
}
Output:
num1 = 0xFFFFFFFFFFFFFFFF
num2 = 0xFFFFFFFE00000001
But if you change the bitfields to this:
mixin (bitfields!(
ulong, "back", 32,
ulong, "front", 32)
);
Output:
num1 = 0xFFFFFFFFFFFFFFFF
num2 = 0x0000000000000001
The front half, which shouldn't be changed, is converted to zeros.
Or:
mixin (bitfields!(
ulong, "back", 31,
ulong, "front", 33)
);
Output:
num1 = 0xFFFFFFFFFFFFFFFF
num2 = 0x0000000080000001
I experimented a little bit.
1) The sizes of the fields (ubyte, ushort, etc.) don't seem to matter as long
as they are long enough to hold the value.
2) It's only the first field that is broken, as far as I can tell.
3) Additional fields don't solve the problem.
I looked at the code for std.bitmanip but it's beyond my ability to modify. So
I'll have to rely on the kindness of strangers for a fix.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list