http://d.puremagic.com/issues/show_bug.cgi?id=6829
--- Comment #24 from [email protected] 2013-07-12 01:59:52 PDT --- (In reply to comment #23) > and 5. Make sure that you use bearophiles last implementation example. ;) Updated code, lacks unittests: import std.traits: isIntegral, isUnsigned; /// Left-shift x by n bits. T rol(T)(in T x, in uint nBits) @safe pure nothrow if (isIntegral!T && isUnsigned!T) in { assert(nBits < (T.sizeof * 8)); } body { return cast(T)((x << nBits) | (x >> ((T.sizeof * 8) - nBits))); } /// Right-shift x by n bits. T ror(T)(in T x, in uint nBits) @safe pure nothrow if (isIntegral!T && isUnsigned!T) in { assert(nBits < (T.sizeof * 8)); } body { return cast(T)((x >> nBits) | (x << ((T.sizeof * 8) - nBits))); } void main() { // Tests to check for assembly output. { __gshared static ubyte xb; __gshared static ushort xs; __gshared static uint xi; __gshared static ulong xl; __gshared static uint yi; rol(xb, yi); // rolb ror(xb, yi); // rorb rol(xs, yi); // rolw ror(xs, yi); // rorw rol(xi, yi); // roll ror(xi, yi); // rorl rol(xl, yi); // version(X86_64) rolq ror(xl, yi); // version(X86_64) rorq } } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
