raz / test / mac / Rotate.raz

40 lines · 1.6 KiB · raw · history · last change e99cab9b

1(* ROL and ROR at every width, by constants and by variables, negative
2 and past the width; CLZ, CTZ and POPCOUNT at every width, as x86-64
3 gives them *)
4module Rotate;
5import Out;
6
7proc show(n: U64);
8begin
9 Out.hex(n, 1); Out.str(" ");
10end;
11
12proc main*;
13var
14 b: U8; h: U16; w: U32; q: U64; n, i: INT;
15 counts: [6]INT;
16begin
17 counts := [0, 1, 3, 8, 13, -1];
18 b := 81H; h := 8001H; w := 80000001H; q := 8000000000000001H;
19 for i := 0 to 5 do
20 n := counts[i];
21 show(U64(ROL(b, n))); show(U64(ROR(b, n))); show(U64(ROL(h, n))); show(U64(ROR(h, n)));
22 show(U64(ROL(w, n))); show(U64(ROR(w, n))); show(U64(ROL(q, n))); show(U64(ROR(q, n)));
23 Out.ln;
24 end;
25 show(U64(ROL(b, 3))); show(U64(ROR(b, 3))); show(U64(ROL(h, 9))); show(U64(ROR(h, 9)));
26 show(U64(ROL(w, 33))); show(U64(ROR(w, -1))); show(U64(ROL(q, 65))); show(U64(ROR(q, 0))); Out.ln;
27 b := 0B4H; h := 0B4B4H; w := 0F0000H; q := 0;
28 show(U64(ROL(b, 4) | ROR(b, 4))); show(U64(ROL(h, 12))); show(U64(ROR(w, 16))); show(U64(ROL(q, 5))); Out.ln;
29 b := 0; h := 0; w := 0; q := 0;
30 for i := 0 to 2 do
31 Out.int(CLZ(b)); Out.str(" "); Out.int(CTZ(b)); Out.str(" "); Out.int(POPCOUNT(b)); Out.str(" ");
32 Out.int(CLZ(h)); Out.str(" "); Out.int(CTZ(h)); Out.str(" "); Out.int(POPCOUNT(h)); Out.str(" ");
33 Out.int(CLZ(w)); Out.str(" "); Out.int(CTZ(w)); Out.str(" "); Out.int(POPCOUNT(w)); Out.str(" ");
34 Out.int(CLZ(q)); Out.str(" "); Out.int(CTZ(q)); Out.str(" "); Out.int(POPCOUNT(q)); Out.ln;
35 b := b + 18H; h := h + 1800H; w := w + 180000H; q := q + 1800000000H;
36 if i = 1 then b := 0FFH; h := 0FFFFH; w := 0FFFFFFFFH; q := MAX(U64); end;
37 end;
38end;
39
40end Rotate.