1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
#define SimdImm
using NUnit.Framework;
using System.Collections.Generic;
using System.Runtime.Intrinsics;
namespace Ryujinx.Tests.Cpu
{
[Category("SimdImm")]
public sealed class CpuTestSimdImm : CpuTest
{
#if SimdImm
#region "Helper methods"
// abcdefgh -> aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffffgggggggghhhhhhhh
private static ulong ExpandImm8(byte imm8)
{
ulong imm64 = 0ul;
for (int i = 0, j = 0; i < 8; i++, j += 8)
{
if (((imm8 >> i) & 0b1) != 0)
{
imm64 |= 0b11111111ul << j;
}
}
return imm64;
}
// aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffffgggggggghhhhhhhh -> abcdefgh
private static byte ShrinkImm64(ulong imm64)
{
byte imm8 = 0;
for (int i = 0, j = 0; i < 8; i++, j += 8)
{
if (((imm64 >> j) & 0b11111111ul) != 0ul) // Note: no format check.
{
imm8 |= (byte)(0b1 << i);
}
}
return imm8;
}
#endregion
#region "ValueSource (Types)"
private static IEnumerable<byte> _8BIT_IMM_()
{
yield return 0x00;
yield return 0x7F;
yield return 0x80;
yield return 0xFF;
for (int cnt = 1; cnt <= RndCntImm8; cnt++)
{
byte imm8 = TestContext.CurrentContext.Random.NextByte();
yield return imm8;
}
}
private static IEnumerable<ulong> _64BIT_IMM_()
{
yield return ExpandImm8(0x00);
yield return ExpandImm8(0x7F);
yield return ExpandImm8(0x80);
yield return ExpandImm8(0xFF);
for (int cnt = 1; cnt <= RndCntImm64; cnt++)
{
byte imm8 = TestContext.CurrentContext.Random.NextByte();
yield return ExpandImm8(imm8);
}
}
#endregion
#region "ValueSource (Opcodes)"
private static uint[] _Movi_V_8bit_()
{
return new uint[]
{
0x0F00E400u // MOVI V0.8B, #0
};
}
private static uint[] _Movi_Mvni_V_16bit_shifted_imm_()
{
return new uint[]
{
0x0F008400u, // MOVI V0.4H, #0
0x2F008400u // MVNI V0.4H, #0
};
}
private static uint[] _Movi_Mvni_V_32bit_shifted_imm_()
{
return new uint[]
{
0x0F000400u, // MOVI V0.2S, #0
0x2F000400u // MVNI V0.2S, #0
};
}
private static uint[] _Movi_Mvni_V_32bit_shifting_ones_()
{
return new uint[]
{
0x0F00C400u, // MOVI V0.2S, #0, MSL #8
0x2F00C400u // MVNI V0.2S, #0, MSL #8
};
}
private static uint[] _Movi_V_64bit_scalar_()
{
return new uint[]
{
0x2F00E400u // MOVI D0, #0
};
}
private static uint[] _Movi_V_64bit_vector_()
{
return new uint[]
{
0x6F00E400u // MOVI V0.2D, #0
};
}
#endregion
private const int RndCntImm8 = 2;
private const int RndCntImm64 = 2;
[Test, Pairwise]
public void Movi_V_8bit([ValueSource("_Movi_V_8bit_")] uint opcodes,
[Values(0u)] uint rd,
[ValueSource("_8BIT_IMM_")] byte imm8,
[Values(0b0u, 0b1u)] uint q) // <8B, 16B>
{
uint abc = (imm8 & 0xE0u) >> 5;
uint defgh = (imm8 & 0x1Fu);
opcodes |= ((rd & 31) << 0);
opcodes |= (abc << 16) | (defgh << 5);
opcodes |= ((q & 1) << 30);
ulong z = TestContext.CurrentContext.Random.NextULong();
Vector128<float> v0 = MakeVectorE1(q == 0u ? z : 0ul);
SingleOpcode(opcodes, v0: v0);
CompareAgainstUnicorn();
}
[Test, Pairwise]
public void Movi_Mvni_V_16bit_shifted_imm([ValueSource("_Movi_Mvni_V_16bit_shifted_imm_")] uint opcodes,
[Values(0u)] uint rd,
[ValueSource("_8BIT_IMM_")] byte imm8,
[Values(0b0u, 0b1u)] uint amount, // <0, 8>
[Values(0b0u, 0b1u)] uint q) // <4H, 8H>
{
uint abc = (imm8 & 0xE0u) >> 5;
uint defgh = (imm8 & 0x1Fu);
opcodes |= ((rd & 31) << 0);
opcodes |= (abc << 16) | (defgh << 5);
opcodes |= ((amount & 1) << 13);
opcodes |= ((q & 1) << 30);
ulong z = TestContext.CurrentContext.Random.NextULong();
Vector128<float> v0 = MakeVectorE1(q == 0u ? z : 0ul);
SingleOpcode(opcodes, v0: v0);
CompareAgainstUnicorn();
}
[Test, Pairwise]
public void Movi_Mvni_V_32bit_shifted_imm([ValueSource("_Movi_Mvni_V_32bit_shifted_imm_")] uint opcodes,
[Values(0u)] uint rd,
[ValueSource("_8BIT_IMM_")] byte imm8,
[Values(0b00u, 0b01u, 0b10u, 0b11u)] uint amount, // <0, 8, 16, 24>
[Values(0b0u, 0b1u)] uint q) // <2S, 4S>
{
uint abc = (imm8 & 0xE0u) >> 5;
uint defgh = (imm8 & 0x1Fu);
opcodes |= ((rd & 31) << 0);
opcodes |= (abc << 16) | (defgh << 5);
opcodes |= ((amount & 3) << 13);
opcodes |= ((q & 1) << 30);
ulong z = TestContext.CurrentContext.Random.NextULong();
Vector128<float> v0 = MakeVectorE1(q == 0u ? z : 0ul);
SingleOpcode(opcodes, v0: v0);
CompareAgainstUnicorn();
}
[Test, Pairwise]
public void Movi_Mvni_V_32bit_shifting_ones([ValueSource("_Movi_Mvni_V_32bit_shifting_ones_")] uint opcodes,
[Values(0u)] uint rd,
[ValueSource("_8BIT_IMM_")] byte imm8,
[Values(0b0u, 0b1u)] uint amount, // <8, 16>
[Values(0b0u, 0b1u)] uint q) // <2S, 4S>
{
uint abc = (imm8 & 0xE0u) >> 5;
uint defgh = (imm8 & 0x1Fu);
opcodes |= ((rd & 31) << 0);
opcodes |= (abc << 16) | (defgh << 5);
opcodes |= ((amount & 1) << 12);
opcodes |= ((q & 1) << 30);
ulong z = TestContext.CurrentContext.Random.NextULong();
Vector128<float> v0 = MakeVectorE1(q == 0u ? z : 0ul);
SingleOpcode(opcodes, v0: v0);
CompareAgainstUnicorn();
}
[Test, Pairwise]
public void Movi_V_64bit_scalar([ValueSource("_Movi_V_64bit_scalar_")] uint opcodes,
[Values(0u)] uint rd,
[ValueSource("_64BIT_IMM_")] ulong imm)
{
byte imm8 = ShrinkImm64(imm);
uint abc = (imm8 & 0xE0u) >> 5;
uint defgh = (imm8 & 0x1Fu);
opcodes |= ((rd & 31) << 0);
opcodes |= (abc << 16) | (defgh << 5);
ulong z = TestContext.CurrentContext.Random.NextULong();
Vector128<float> v0 = MakeVectorE1(z);
SingleOpcode(opcodes, v0: v0);
CompareAgainstUnicorn();
}
[Test, Pairwise]
public void Movi_V_64bit_vector([ValueSource("_Movi_V_64bit_vector_")] uint opcodes,
[Values(0u)] uint rd,
[ValueSource("_64BIT_IMM_")] ulong imm)
{
byte imm8 = ShrinkImm64(imm);
uint abc = (imm8 & 0xE0u) >> 5;
uint defgh = (imm8 & 0x1Fu);
opcodes |= ((rd & 31) << 0);
opcodes |= (abc << 16) | (defgh << 5);
SingleOpcode(opcodes);
CompareAgainstUnicorn();
}
#endif
}
}
|