(* ROL and ROR at every width, by constants and by variables, negative and past the width; CLZ, CTZ and POPCOUNT at every width, as x86-64 gives them *) module Rotate; import Out; proc show(n: U64); begin Out.hex(n, 1); Out.str(" "); end; proc main*; var b: U8; h: U16; w: U32; q: U64; n, i: INT; counts: [6]INT; begin counts := [0, 1, 3, 8, 13, -1]; b := 81H; h := 8001H; w := 80000001H; q := 8000000000000001H; for i := 0 to 5 do n := counts[i]; show(U64(ROL(b, n))); show(U64(ROR(b, n))); show(U64(ROL(h, n))); show(U64(ROR(h, n))); show(U64(ROL(w, n))); show(U64(ROR(w, n))); show(U64(ROL(q, n))); show(U64(ROR(q, n))); Out.ln; end; show(U64(ROL(b, 3))); show(U64(ROR(b, 3))); show(U64(ROL(h, 9))); show(U64(ROR(h, 9))); show(U64(ROL(w, 33))); show(U64(ROR(w, -1))); show(U64(ROL(q, 65))); show(U64(ROR(q, 0))); Out.ln; b := 0B4H; h := 0B4B4H; w := 0F0000H; q := 0; 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; b := 0; h := 0; w := 0; q := 0; for i := 0 to 2 do Out.int(CLZ(b)); Out.str(" "); Out.int(CTZ(b)); Out.str(" "); Out.int(POPCOUNT(b)); Out.str(" "); Out.int(CLZ(h)); Out.str(" "); Out.int(CTZ(h)); Out.str(" "); Out.int(POPCOUNT(h)); Out.str(" "); Out.int(CLZ(w)); Out.str(" "); Out.int(CTZ(w)); Out.str(" "); Out.int(POPCOUNT(w)); Out.str(" "); Out.int(CLZ(q)); Out.str(" "); Out.int(CTZ(q)); Out.str(" "); Out.int(POPCOUNT(q)); Out.ln; b := b + 18H; h := h + 1800H; w := w + 180000H; q := q + 1800000000H; if i = 1 then b := 0FFH; h := 0FFFFH; w := 0FFFFFFFFH; q := MAX(U64); end; end; end; end Rotate.