raz / test / run / AsmSimd.raz

127 lines · 2.9 KiB · raw · history · last change 013c05d6

1module AsmSimd;
2(* The packed, shuffle and SHA instructions of the assembler: each one's bytes,
3 read back from the procedure they are made in. Each was checked against
4 GNU as (Intel syntax, objdump). *)
5import Out;
6import SYSTEM;
7
8const
9 Count = 31;
10 Names: [Count][]const U8 = [
11 "paddd xmm1, xmm2",
12 "paddd xmm9, xmm14",
13 "paddd xmm0, [rdi]",
14 "paddd xmm10, [r12 + rcx * 8 + 400]",
15 "punpcklqdq xmm1, xmm2",
16 "punpcklqdq xmm8, xmm3",
17 "punpcklqdq xmm2, [rax + 16]",
18 "punpckhqdq xmm1, xmm2",
19 "punpckhqdq xmm3, xmm15",
20 "punpckhqdq xmm7, [r9]",
21 "pshufb xmm1, xmm2",
22 "pshufb xmm8, xmm9",
23 "pshufb xmm0, [rdi]",
24 "pshufb xmm12, [rsp + 32]",
25 "pshufb xmm3, [r13 + 8]",
26 "palignr xmm1, xmm2, 8",
27 "palignr xmm9, xmm0, 0",
28 "palignr xmm2, [rdi + 16], 4",
29 "palignr xmm11, [r12], 15",
30 "sha256rnds2 xmm1, xmm2, xmm0",
31 "sha256rnds2 xmm9, xmm3, xmm0",
32 "sha256rnds2 xmm1, [rdi], xmm0",
33 "sha256rnds2 xmm2, [r9 + rbx * 4 + 64], xmm0",
34 "sha256rnds2 xmm1, xmm2",
35 "sha256rnds2 xmm1, [rdi]",
36 "sha256msg1 xmm1, xmm2",
37 "sha256msg1 xmm8, xmm15",
38 "sha256msg1 xmm3, [rsi + 32]",
39 "sha256msg2 xmm1, xmm2",
40 "sha256msg2 xmm0, xmm9",
41 "sha256msg2 xmm4, [r10 + 8]"];
42 Sizes: [Count]INT = [
43 4,
44 5,
45 4,
46 10,
47 4,
48 5,
49 5,
50 4,
51 5,
52 5,
53 5,
54 6,
55 5,
56 8,
57 7,
58 6,
59 7,
60 7,
61 8,
62 4,
63 5,
64 4,
65 7,
66 4,
67 4,
68 4,
69 5,
70 5,
71 4,
72 5,
73 6];
74
75proc simd;
76code
77 paddd xmm1, xmm2;
78 paddd xmm9, xmm14;
79 paddd xmm0, [rdi];
80 paddd xmm10, [r12 + rcx * 8 + 400];
81 punpcklqdq xmm1, xmm2;
82 punpcklqdq xmm8, xmm3;
83 punpcklqdq xmm2, [rax + 16];
84 punpckhqdq xmm1, xmm2;
85 punpckhqdq xmm3, xmm15;
86 punpckhqdq xmm7, [r9];
87 pshufb xmm1, xmm2;
88 pshufb xmm8, xmm9;
89 pshufb xmm0, [rdi];
90 pshufb xmm12, [rsp + 32];
91 pshufb xmm3, [r13 + 8];
92 palignr xmm1, xmm2, 8;
93 palignr xmm9, xmm0, 0;
94 palignr xmm2, [rdi + 16], 4;
95 palignr xmm11, [r12], 15;
96 sha256rnds2 xmm1, xmm2, xmm0;
97 sha256rnds2 xmm9, xmm3, xmm0;
98 sha256rnds2 xmm1, [rdi], xmm0;
99 sha256rnds2 xmm2, [r9 + rbx * 4 + 64], xmm0;
100 sha256rnds2 xmm1, xmm2;
101 sha256rnds2 xmm1, [rdi];
102 sha256msg1 xmm1, xmm2;
103 sha256msg1 xmm8, xmm15;
104 sha256msg1 xmm3, [rsi + 32];
105 sha256msg2 xmm1, xmm2;
106 sha256msg2 xmm0, xmm9;
107 sha256msg2 xmm4, [r10 + 8];
108 ret;
109end simd;
110
111proc main*;
112var p: proc; b: ^U8; i, j, at: INT;
113begin
114 p := simd;
115 b := ^U8(p);
116 at := 0;
117 for i := 0 to Count - 1 do
118 Out.str(Names[i]); Out.str(":");
119 for j := 0 to Sizes[i] - 1 do
120 Out.str(" "); Out.hex(U64(b[at + j]), 2);
121 end;
122 Out.ln;
123 at := at + Sizes[i];
124 end;
125end;
126
127end AsmSimd.