[Issue 6829] Unsigned rotate standard function in Phobos
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jul 10 03:49:51 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=6829
--- Comment #9 from Iain Buclaw <ibuclaw at ubuntu.com> 2013-07-10 03:49:49 PDT ---
(In reply to comment #8)
> (In reply to comment #6)
> > (In reply to comment #5)
> > > I think this should be a recognizable rotate left function:
> > >
> > > private static uint rol(in uint x, in uint y) pure nothrow {
> > > return (x << y) | (x >> (32 - y));
> > > }
> >
> > It is (in gdc with -O :)
> >
> > _D3rol3rolFNaNbxkxkZk:
> > mov x, %eax
> > mov y, %ecx
> > rol %cl, %eax
> > ret
>
>
> Both dmd and ldc2 recognize the patterns:
>
Excellent, so could put these as templates then. :)
T rol (T)(in T x, in uint y) pure nothrow
{
return cast(T)((x << y) | (x >> ((T.sizeof * 8) - y)));
}
T ror (T)(in T x, in uint y) pure nothrow
{
return cast(T)((x >> y) | (x << ((T.sizeof * 8) - y)));
}
// Tests to check for assembly output.
extern ubyte xb;
extern ushort xs;
extern uint xi;
extern ulong xl;
extern 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: -------
More information about the Digitalmars-d-bugs
mailing list