1 #include <algorithm>
2 #include <array>
3 #include <cstdio>
4 #include <memory>
5 #include <random>
6 #include <unordered_set>
7 #include "common_types.h"
8 #include "decoder.h"
9 #include "operand.h"
10 #include "test.h"
11 
12 namespace Teakra::Test {
13 
14 enum class RegConfig { Any = 0, Memory = 1 };
15 
16 enum class ExpandConfig {
17     None = 0, // or Zero
18     Any = 1,
19     Memory = 2,
20 };
21 
22 namespace Random {
23 namespace {
24 std::mt19937 gen(std::random_device{}());
25 
uniform(u64 a,u64 b)26 u64 uniform(u64 a, u64 b) {
27     std::uniform_int_distribution<u64> dist(a, b);
28     return dist(gen);
29 }
30 
bit40()31 u64 bit40() {
32     static std::uniform_int_distribution<u64> dist(0, 0xFF'FFFF'FFFF);
33     static std::uniform_int_distribution<int> dist2(0, 4);
34     u64 v = dist(gen);
35     switch (dist2(gen)) {
36     case 0:
37         v = SignExtend<40>(v);
38         break;
39     case 1:
40         v &= 0xFFFF;
41         break;
42     case 2:
43         v &= 0xFFFF'FFFF;
44         break;
45     case 3:
46         v = SignExtend<32>(v);
47         break;
48     case 4:
49         v = SignExtend<16>(v);
50         break;
51     }
52     return v;
53 }
54 
bit32()55 u32 bit32() {
56     static std::uniform_int_distribution<u32> dist;
57     return dist(gen);
58 }
59 
bit16()60 u16 bit16() {
61     static std::uniform_int_distribution<u16> dist;
62     return dist(gen);
63 }
64 } // Anonymous namespace
65 } // namespace Random
66 
67 namespace {
68 struct Config {
69     bool enable = false;
70     bool lock_page = false;
71     bool lock_r7 = false;
72     std::array<RegConfig, 8> r{};
73     std::array<RegConfig, 4> ar{};
74     std::array<RegConfig, 4> arp{};
75 
76     ExpandConfig expand = ExpandConfig::None;
77 
WithAnyExpandTeakra::Test::__anon3030058b0211::Config78     Config WithAnyExpand() {
79         Config copy = *this;
80         copy.expand = ExpandConfig::Any;
81         return copy;
82     }
83 
WithMemoryExpandTeakra::Test::__anon3030058b0211::Config84     Config WithMemoryExpand() {
85         Config copy = *this;
86         copy.expand = ExpandConfig::Memory;
87         return copy;
88     }
89 
GenerateRandomStateTeakra::Test::__anon3030058b0211::Config90     State GenerateRandomState() {
91         State state;
92         state.stepi0 = Random::bit16();
93         state.stepj0 = Random::bit16();
94         state.mixp = Random::bit16();
95         state.sv = Random::bit16();
96         if (Random::uniform(0, 1) == 1) {
97             state.sv &= 128;
98             state.sv = SignExtend<7>(state.sv);
99         }
100         state.repc = Random::bit16();
101         state.lc = Random::bit16();
102         state.cfgi = Random::bit16();
103         state.cfgj = Random::bit16();
104         state.stt0 = Random::bit16();
105         state.stt1 = Random::bit16();
106         state.stt2 = Random::bit16();
107         state.mod0 = Random::bit16();
108         state.mod1 = Random::bit16();
109         state.mod2 = Random::bit16();
110         if (lock_page) {
111             state.mod1 &= 0xFF00;
112             state.mod1 |= TestSpaceX >> 8;
113         }
114         std::generate(state.ar.begin(), state.ar.end(), Random::bit16);
115         std::generate(state.arp.begin(), state.arp.end(), Random::bit16);
116         std::generate(state.x.begin(), state.x.end(), Random::bit16);
117         std::generate(state.y.begin(), state.y.end(), Random::bit16);
118         std::generate(state.p.begin(), state.p.end(), Random::bit32);
119         std::generate(state.a.begin(), state.a.end(), Random::bit40);
120         std::generate(state.b.begin(), state.b.end(), Random::bit40);
121         std::generate(state.r.begin(), state.r.end(), Random::bit16);
122         std::generate(state.test_space_x.begin(), state.test_space_x.end(), Random::bit16);
123         std::generate(state.test_space_y.begin(), state.test_space_y.end(), Random::bit16);
124 
125         auto rp = r;
126         for (std::size_t i = 0; i < ar.size(); ++i) {
127             if (ar[i] == RegConfig::Memory) {
128                 rp[(state.ar[i / 2] >> (13 - 3 * (i % 2))) & 7] = RegConfig::Memory;
129             }
130         }
131         for (std::size_t i = 0; i < arp.size(); ++i) {
132             if (arp[i] == RegConfig::Memory) {
133                 rp[(state.arp[i] >> 10) & 3] = RegConfig::Memory;
134                 rp[((state.arp[i] >> 13) & 3) + 4] = RegConfig::Memory;
135             }
136         }
137         for (std::size_t i = 0; i < rp.size(); ++i) {
138             if (rp[i] == RegConfig::Memory) {
139                 state.r[i] = (i < 4 ? TestSpaceX : TestSpaceY) +
140                              (u16)Random::uniform(10, TestSpaceSize - 10);
141                 if (!((state.mod2 >> i) & 1) && (((state.mod2 >> (i + 8)) & 1))) {
142                     state.r[i] = BitReverse(state.r[i]);
143                 }
144             }
145         }
146         if (lock_r7) {
147             state.r[7] = TestSpaceY + (u16)Random::uniform(10, TestSpaceSize - 10);
148         }
149         return state;
150     }
151 };
152 
153 Config DisabledConfig{false};
154 Config AnyConfig{true};
155 
ConfigWithAddress(Rn r)156 Config ConfigWithAddress(Rn r) {
157     Config config{true};
158     config.r[r.Index()] = RegConfig::Memory;
159     return config;
160 }
161 
162 template <typename ArRnX>
ConfigWithArAddress(ArRnX r)163 Config ConfigWithArAddress(ArRnX r) {
164     static_assert(std::is_same_v<ArRnX, ArRn1> || std::is_same_v<ArRnX, ArRn2>);
165     Config config{true};
166     config.ar[r.Index()] = RegConfig::Memory;
167     return config;
168 }
169 
170 template <typename ArpRnX>
ConfigWithArpAddress(ArpRnX r)171 Config ConfigWithArpAddress(ArpRnX r) {
172     static_assert(std::is_same_v<ArpRnX, ArpRn1> || std::is_same_v<ArpRnX, ArpRn2>);
173     Config config{true};
174     config.arp[r.Index()] = RegConfig::Memory;
175     return config;
176 }
177 
ConfigWithImm8(Imm8 imm)178 Config ConfigWithImm8(Imm8 imm) {
179     std::unordered_set<u16> random_pos = {
180         0,
181         35,
182         0xE3,
183     };
184     if (random_pos.count(imm.Unsigned16())) {
185         return AnyConfig;
186     } else {
187         return DisabledConfig;
188     }
189 }
190 
ConfigWithMemImm8(MemImm8 mem)191 Config ConfigWithMemImm8(MemImm8 mem) {
192     std::unordered_set<u16> random_pos = {
193         0,
194         0x88,
195         0xFF,
196     };
197     if (random_pos.count(mem.Unsigned16())) {
198         Config c = AnyConfig;
199         c.lock_page = true;
200         return c;
201     } else {
202         return DisabledConfig;
203     }
204 }
205 
ConfigWithMemR7Imm16()206 Config ConfigWithMemR7Imm16() {
207     Config c = AnyConfig;
208     c.lock_r7 = true;
209     return c;
210 }
211 
ConfigWithMemR7Imm7s(MemR7Imm7s mem)212 Config ConfigWithMemR7Imm7s(MemR7Imm7s mem) {
213     std::unordered_set<u16> random_pos = {
214         0,
215         4,
216         0xFFFE,
217     };
218     if (random_pos.count(mem.Signed16())) {
219         Config c = AnyConfig;
220         c.lock_r7 = true;
221         return c;
222     } else {
223         return DisabledConfig;
224     }
225 }
226 
227 class TestGenerator {
228 public:
IsUnimplementedRegister(RegName r)229     bool IsUnimplementedRegister(RegName r) {
230         return r == RegName::pc || r == RegName::undefine || r == RegName::st0 ||
231                r == RegName::st1 || r == RegName::st2 || r == RegName::stt2 || r == RegName::ext0 ||
232                r == RegName::ext1 || r == RegName::ext2 || r == RegName::ext3 ||
233                r == RegName::mod3 || r == RegName::sp;
234     }
235 
236     using instruction_return_type = Config;
237 
undefined(u16 opcode)238     Config undefined(u16 opcode) {
239         return DisabledConfig;
240     }
241 
nop()242     Config nop() {
243         return DisabledConfig;
244     }
245 
norm(Ax a,Rn b,StepZIDS bs)246     Config norm(Ax a, Rn b, StepZIDS bs) {
247         return AnyConfig;
248     }
swap(SwapType swap)249     Config swap(SwapType swap) {
250         if (swap.GetName() == SwapTypeValue::reserved0 ||
251             swap.GetName() == SwapTypeValue::reserved1)
252             return DisabledConfig;
253         return AnyConfig;
254     }
trap()255     Config trap() {
256         return DisabledConfig;
257     }
258 
alm(Alm op,MemImm8 a,Ax b)259     Config alm(Alm op, MemImm8 a, Ax b) {
260         if (op.GetName() == AlmOp::Sqr && b.GetName() != RegName::a0) {
261             return DisabledConfig;
262         }
263         return ConfigWithMemImm8(a);
264     }
alm(Alm op,Rn a,StepZIDS as,Ax b)265     Config alm(Alm op, Rn a, StepZIDS as, Ax b) {
266         if (op.GetName() == AlmOp::Sqr && b.GetName() != RegName::a0) {
267             return DisabledConfig;
268         }
269         return ConfigWithAddress(a);
270     }
alm(Alm op,Register a,Ax b)271     Config alm(Alm op, Register a, Ax b) {
272         if (op.GetName() == AlmOp::Sqr && b.GetName() != RegName::a0) {
273             return DisabledConfig;
274         }
275 
276         if (IsUnimplementedRegister(a.GetName())) {
277             return DisabledConfig;
278         }
279 
280         switch (a.GetName()) {
281         case RegName::p:
282         case RegName::a0:
283         case RegName::a1: {
284             static const std::unordered_set<AlmOp> allowed_instruction{
285                 AlmOp::Or, AlmOp::And, AlmOp::Xor, AlmOp::Add, AlmOp::Cmp, AlmOp::Sub,
286             };
287             if (allowed_instruction.count(op.GetName()) != 0)
288                 return AnyConfig;
289             else
290                 return DisabledConfig;
291         }
292         default:
293             return AnyConfig;
294         }
295     }
alm_r6(Alm op,Ax b)296     Config alm_r6(Alm op, Ax b) {
297         // op = sqr, b = a1 is excluded by decoder
298         return AnyConfig;
299     }
300 
alu(Alu op,MemImm16 a,Ax b)301     Config alu(Alu op, MemImm16 a, Ax b) {
302         // reserved op excluded by decoder
303         return AnyConfig.WithMemoryExpand();
304     }
alu(Alu op,MemR7Imm16 a,Ax b)305     Config alu(Alu op, MemR7Imm16 a, Ax b) {
306         return ConfigWithMemR7Imm16();
307     }
alu(Alu op,Imm16 a,Ax b)308     Config alu(Alu op, Imm16 a, Ax b) {
309         return AnyConfig.WithAnyExpand();
310     }
alu(Alu op,Imm8 a,Ax b)311     Config alu(Alu op, Imm8 a, Ax b) {
312         return ConfigWithImm8(a);
313     }
alu(Alu op,MemR7Imm7s a,Ax b)314     Config alu(Alu op, MemR7Imm7s a, Ax b) {
315         return ConfigWithMemR7Imm7s(a);
316     }
317 
or_(Ab a,Ax b,Ax c)318     Config or_(Ab a, Ax b, Ax c) {
319         return AnyConfig;
320     }
or_(Ax a,Bx b,Ax c)321     Config or_(Ax a, Bx b, Ax c) {
322         return AnyConfig;
323     }
or_(Bx a,Bx b,Ax c)324     Config or_(Bx a, Bx b, Ax c) {
325         return AnyConfig;
326     }
327 
alb(Alb op,Imm16 a,MemImm8 b)328     Config alb(Alb op, Imm16 a, MemImm8 b) {
329         return ConfigWithMemImm8(b).WithAnyExpand();
330     }
alb(Alb op,Imm16 a,Rn b,StepZIDS bs)331     Config alb(Alb op, Imm16 a, Rn b, StepZIDS bs) {
332         return ConfigWithAddress(b).WithAnyExpand();
333     }
alb(Alb op,Imm16 a,Register b)334     Config alb(Alb op, Imm16 a, Register b) {
335         if (IsUnimplementedRegister(b.GetName())) {
336             return DisabledConfig;
337         }
338         switch (b.GetName()) {
339         case RegName::a0:
340         case RegName::a1:
341             return DisabledConfig;
342         default:
343             return AnyConfig.WithAnyExpand();
344         }
345     }
alb_r6(Alb op,Imm16 a)346     Config alb_r6(Alb op, Imm16 a) {
347         return AnyConfig.WithAnyExpand();
348     }
alb(Alb op,Imm16 a,SttMod b)349     Config alb(Alb op, Imm16 a, SttMod b) {
350         if (IsUnimplementedRegister(b.GetName())) {
351             return DisabledConfig;
352         }
353         return AnyConfig.WithAnyExpand();
354     }
355 
add(Ab a,Bx b)356     Config add(Ab a, Bx b) {
357         return AnyConfig;
358     }
add(Bx a,Ax b)359     Config add(Bx a, Ax b) {
360         return AnyConfig;
361     }
add_p1(Ax b)362     Config add_p1(Ax b) {
363         return AnyConfig;
364     }
add(Px a,Bx b)365     Config add(Px a, Bx b) {
366         return AnyConfig;
367     }
368 
sub(Ab a,Bx b)369     Config sub(Ab a, Bx b) {
370         return AnyConfig;
371     }
sub(Bx a,Ax b)372     Config sub(Bx a, Ax b) {
373         return AnyConfig;
374     }
sub_p1(Ax b)375     Config sub_p1(Ax b) {
376         return AnyConfig;
377     }
sub(Px a,Bx b)378     Config sub(Px a, Bx b) {
379         return AnyConfig;
380     }
381 
app(Ab c,SumBase base,bool sub_p0,bool p0_align,bool sub_p1,bool p1_align)382     Config app(Ab c, SumBase base, bool sub_p0, bool p0_align, bool sub_p1, bool p1_align) {
383         return AnyConfig;
384     }
385 
add_add(ArpRn1 a,ArpStep1 asi,ArpStep1 asj,Ab b)386     Config add_add(ArpRn1 a, ArpStep1 asi, ArpStep1 asj, Ab b) {
387         return ConfigWithArpAddress(a);
388     }
add_sub(ArpRn1 a,ArpStep1 asi,ArpStep1 asj,Ab b)389     Config add_sub(ArpRn1 a, ArpStep1 asi, ArpStep1 asj, Ab b) {
390         return ConfigWithArpAddress(a);
391     }
sub_add(ArpRn1 a,ArpStep1 asi,ArpStep1 asj,Ab b)392     Config sub_add(ArpRn1 a, ArpStep1 asi, ArpStep1 asj, Ab b) {
393         return ConfigWithArpAddress(a);
394     }
sub_sub(ArpRn1 a,ArpStep1 asi,ArpStep1 asj,Ab b)395     Config sub_sub(ArpRn1 a, ArpStep1 asi, ArpStep1 asj, Ab b) {
396         return ConfigWithArpAddress(a);
397     }
398 
add_sub_sv(ArRn1 a,ArStep1 as,Ab b)399     Config add_sub_sv(ArRn1 a, ArStep1 as, Ab b) {
400         return ConfigWithArAddress(a);
401     }
sub_add_sv(ArRn1 a,ArStep1 as,Ab b)402     Config sub_add_sv(ArRn1 a, ArStep1 as, Ab b) {
403         return ConfigWithArAddress(a);
404     }
405 
sub_add_i_mov_j_sv(ArpRn1 a,ArpStep1 asi,ArpStep1 asj,Ab b)406     Config sub_add_i_mov_j_sv(ArpRn1 a, ArpStep1 asi, ArpStep1 asj, Ab b) {
407         return ConfigWithArpAddress(a);
408     }
sub_add_j_mov_i_sv(ArpRn1 a,ArpStep1 asi,ArpStep1 asj,Ab b)409     Config sub_add_j_mov_i_sv(ArpRn1 a, ArpStep1 asi, ArpStep1 asj, Ab b) {
410         return ConfigWithArpAddress(a);
411     }
add_sub_i_mov_j(ArpRn1 a,ArpStep1 asi,ArpStep1 asj,Ab b)412     Config add_sub_i_mov_j(ArpRn1 a, ArpStep1 asi, ArpStep1 asj, Ab b) {
413         return ConfigWithArpAddress(a);
414     }
add_sub_j_mov_i(ArpRn1 a,ArpStep1 asi,ArpStep1 asj,Ab b)415     Config add_sub_j_mov_i(ArpRn1 a, ArpStep1 asi, ArpStep1 asj, Ab b) {
416         return ConfigWithArpAddress(a);
417     }
418 
moda4(Moda4 op,Ax a,Cond cond)419     Config moda4(Moda4 op, Ax a, Cond cond) {
420         // reserved op excluded by decoder
421         return AnyConfig;
422     }
423 
moda3(Moda3 op,Bx a,Cond cond)424     Config moda3(Moda3 op, Bx a, Cond cond) {
425         return AnyConfig;
426     }
427 
pacr1(Ax a)428     Config pacr1(Ax a) {
429         return AnyConfig;
430     }
clr(Ab a,Ab b)431     Config clr(Ab a, Ab b) {
432         return AnyConfig;
433     }
clrr(Ab a,Ab b)434     Config clrr(Ab a, Ab b) {
435         return AnyConfig;
436     }
437 
bkrep(Imm8 a,Address16 addr)438     Config bkrep(Imm8 a, Address16 addr) {
439         return DisabledConfig;
440     }
bkrep(Register a,Address18_16 addr_low,Address18_2 addr_high)441     Config bkrep(Register a, Address18_16 addr_low, Address18_2 addr_high) {
442         return DisabledConfig;
443     }
bkrep_r6(Address18_16 addr_low,Address18_2 addr_high)444     Config bkrep_r6(Address18_16 addr_low, Address18_2 addr_high) {
445         return DisabledConfig;
446     }
bkreprst(ArRn2 a)447     Config bkreprst(ArRn2 a) {
448         return DisabledConfig;
449     }
bkreprst_memsp()450     Config bkreprst_memsp() {
451         return DisabledConfig;
452     }
bkrepsto(ArRn2 a)453     Config bkrepsto(ArRn2 a) {
454         return DisabledConfig;
455     }
bkrepsto_memsp()456     Config bkrepsto_memsp() {
457         return DisabledConfig;
458     }
459 
banke(BankFlags flags)460     Config banke(BankFlags flags) {
461         return DisabledConfig;
462     }
bankr()463     Config bankr() {
464         return DisabledConfig;
465     }
bankr(Ar a)466     Config bankr(Ar a) {
467         return DisabledConfig;
468     }
bankr(Ar a,Arp b)469     Config bankr(Ar a, Arp b) {
470         return DisabledConfig;
471     }
bankr(Arp a)472     Config bankr(Arp a) {
473         return DisabledConfig;
474     }
475 
bitrev(Rn a)476     Config bitrev(Rn a) {
477         return AnyConfig;
478     }
bitrev_dbrv(Rn a)479     Config bitrev_dbrv(Rn a) {
480         return AnyConfig;
481     }
bitrev_ebrv(Rn a)482     Config bitrev_ebrv(Rn a) {
483         return AnyConfig;
484     }
485 
br(Address18_16 addr_low,Address18_2 addr_high,Cond cond)486     Config br(Address18_16 addr_low, Address18_2 addr_high, Cond cond) {
487         return DisabledConfig;
488     }
489 
brr(RelAddr7 addr,Cond cond)490     Config brr(RelAddr7 addr, Cond cond) {
491         return DisabledConfig;
492     }
493 
break_()494     Config break_() {
495         return DisabledConfig;
496     }
497 
call(Address18_16 addr_low,Address18_2 addr_high,Cond cond)498     Config call(Address18_16 addr_low, Address18_2 addr_high, Cond cond) {
499         return DisabledConfig;
500     }
calla(Axl a)501     Config calla(Axl a) {
502         return DisabledConfig;
503     }
calla(Ax a)504     Config calla(Ax a) {
505         return DisabledConfig;
506     }
callr(RelAddr7 addr,Cond cond)507     Config callr(RelAddr7 addr, Cond cond) {
508         return DisabledConfig;
509     }
510 
cntx_s()511     Config cntx_s() {
512         return DisabledConfig;
513     }
cntx_r()514     Config cntx_r() {
515         return DisabledConfig;
516     }
517 
ret(Cond c)518     Config ret(Cond c) {
519         return DisabledConfig;
520     }
retd()521     Config retd() {
522         return DisabledConfig;
523     }
reti(Cond c)524     Config reti(Cond c) {
525         return DisabledConfig;
526     }
retic(Cond c)527     Config retic(Cond c) {
528         return DisabledConfig;
529     }
retid()530     Config retid() {
531         return DisabledConfig;
532     }
retidc()533     Config retidc() {
534         return DisabledConfig;
535     }
rets(Imm8 a)536     Config rets(Imm8 a) {
537         return DisabledConfig;
538     }
539 
load_ps(Imm2 a)540     Config load_ps(Imm2 a) {
541         return AnyConfig;
542     }
load_stepi(Imm7s a)543     Config load_stepi(Imm7s a) {
544         return AnyConfig;
545     }
load_stepj(Imm7s a)546     Config load_stepj(Imm7s a) {
547         return AnyConfig;
548     }
load_page(Imm8 a)549     Config load_page(Imm8 a) {
550         return AnyConfig;
551     }
load_modi(Imm9 a)552     Config load_modi(Imm9 a) {
553         return AnyConfig;
554     }
load_modj(Imm9 a)555     Config load_modj(Imm9 a) {
556         return AnyConfig;
557     }
load_movpd(Imm2 a)558     Config load_movpd(Imm2 a) {
559         return DisabledConfig;
560     }
load_ps01(Imm4 a)561     Config load_ps01(Imm4 a) {
562         return AnyConfig;
563     }
564 
push(Imm16 a)565     Config push(Imm16 a) {
566         return DisabledConfig;
567     }
push(Register a)568     Config push(Register a) {
569         return DisabledConfig;
570     }
push(Abe a)571     Config push(Abe a) {
572         return DisabledConfig;
573     }
push(ArArpSttMod a)574     Config push(ArArpSttMod a) {
575         return DisabledConfig;
576     }
push_prpage()577     Config push_prpage() {
578         return DisabledConfig;
579     }
push(Px a)580     Config push(Px a) {
581         return DisabledConfig;
582     }
push_r6()583     Config push_r6() {
584         return DisabledConfig;
585     }
push_repc()586     Config push_repc() {
587         return DisabledConfig;
588     }
push_x0()589     Config push_x0() {
590         return DisabledConfig;
591     }
push_x1()592     Config push_x1() {
593         return DisabledConfig;
594     }
push_y1()595     Config push_y1() {
596         return DisabledConfig;
597     }
pusha(Ax a)598     Config pusha(Ax a) {
599         return DisabledConfig;
600     }
pusha(Bx a)601     Config pusha(Bx a) {
602         return DisabledConfig;
603     }
604 
pop(Register a)605     Config pop(Register a) {
606         return DisabledConfig;
607     }
pop(Abe a)608     Config pop(Abe a) {
609         return DisabledConfig;
610     }
pop(ArArpSttMod a)611     Config pop(ArArpSttMod a) {
612         return DisabledConfig;
613     }
pop(Bx a)614     Config pop(Bx a) {
615         return DisabledConfig;
616     }
pop_prpage()617     Config pop_prpage() {
618         return DisabledConfig;
619     }
pop(Px a)620     Config pop(Px a) {
621         return DisabledConfig;
622     }
pop_r6()623     Config pop_r6() {
624         return DisabledConfig;
625     }
pop_repc()626     Config pop_repc() {
627         return DisabledConfig;
628     }
pop_x0()629     Config pop_x0() {
630         return DisabledConfig;
631     }
pop_x1()632     Config pop_x1() {
633         return DisabledConfig;
634     }
pop_y1()635     Config pop_y1() {
636         return DisabledConfig;
637     }
popa(Ab a)638     Config popa(Ab a) {
639         return DisabledConfig;
640     }
641 
rep(Imm8 a)642     Config rep(Imm8 a) {
643         return DisabledConfig;
644     }
rep(Register a)645     Config rep(Register a) {
646         return DisabledConfig;
647     }
rep_r6()648     Config rep_r6() {
649         return DisabledConfig;
650     }
651 
shfc(Ab a,Ab b,Cond cond)652     Config shfc(Ab a, Ab b, Cond cond) {
653         return AnyConfig;
654     }
shfi(Ab a,Ab b,Imm6s s)655     Config shfi(Ab a, Ab b, Imm6s s) {
656         return AnyConfig;
657     }
658 
tst4b(ArRn2 b,ArStep2 bs)659     Config tst4b(ArRn2 b, ArStep2 bs) {
660         return ConfigWithArAddress(b);
661     }
tst4b(ArRn2 b,ArStep2 bs,Ax c)662     Config tst4b(ArRn2 b, ArStep2 bs, Ax c) {
663         return ConfigWithArAddress(b);
664     }
tstb(MemImm8 a,Imm4 b)665     Config tstb(MemImm8 a, Imm4 b) {
666         return ConfigWithMemImm8(a);
667     }
tstb(Rn a,StepZIDS as,Imm4 b)668     Config tstb(Rn a, StepZIDS as, Imm4 b) {
669         return ConfigWithAddress(a);
670     }
tstb(Register a,Imm4 b)671     Config tstb(Register a, Imm4 b) {
672         if (IsUnimplementedRegister(a.GetName()))
673             return DisabledConfig;
674         return AnyConfig;
675     }
tstb_r6(Imm4 b)676     Config tstb_r6(Imm4 b) {
677         return AnyConfig;
678     }
tstb(SttMod a,Imm16 b)679     Config tstb(SttMod a, Imm16 b) {
680         // TODO deal with the expansion
681         return DisabledConfig;
682     }
683 
and_(Ab a,Ab b,Ax c)684     Config and_(Ab a, Ab b, Ax c) {
685         return AnyConfig;
686     }
687 
dint()688     Config dint() {
689         return DisabledConfig;
690     }
eint()691     Config eint() {
692         return DisabledConfig;
693     }
694 
mul(Mul3 op,Rn y,StepZIDS ys,Imm16 x,Ax a)695     Config mul(Mul3 op, Rn y, StepZIDS ys, Imm16 x, Ax a) {
696         return ConfigWithAddress(y);
697     }
mul_y0(Mul3 op,Rn x,StepZIDS xs,Ax a)698     Config mul_y0(Mul3 op, Rn x, StepZIDS xs, Ax a) {
699         return ConfigWithAddress(x);
700     }
mul_y0(Mul3 op,Register x,Ax a)701     Config mul_y0(Mul3 op, Register x, Ax a) {
702         if (IsUnimplementedRegister(x.GetName()))
703             return DisabledConfig;
704         return AnyConfig;
705     }
mul(Mul3 op,R45 y,StepZIDS ys,R0123 x,StepZIDS xs,Ax a)706     Config mul(Mul3 op, R45 y, StepZIDS ys, R0123 x, StepZIDS xs, Ax a) {
707         return DisabledConfig;
708     }
mul_y0_r6(Mul3 op,Ax a)709     Config mul_y0_r6(Mul3 op, Ax a) {
710         return AnyConfig;
711     }
mul_y0(Mul2 op,MemImm8 x,Ax a)712     Config mul_y0(Mul2 op, MemImm8 x, Ax a) {
713         return ConfigWithMemImm8(x);
714     }
715 
mpyi(Imm8s x)716     Config mpyi(Imm8s x) {
717         return AnyConfig;
718     }
719 
msu(R45 y,StepZIDS ys,R0123 x,StepZIDS xs,Ax a)720     Config msu(R45 y, StepZIDS ys, R0123 x, StepZIDS xs, Ax a) {
721         return DisabledConfig;
722     }
msu(Rn y,StepZIDS ys,Imm16 x,Ax a)723     Config msu(Rn y, StepZIDS ys, Imm16 x, Ax a) {
724         return ConfigWithAddress(y).WithAnyExpand();
725     }
msusu(ArRn2 x,ArStep2 xs,Ax a)726     Config msusu(ArRn2 x, ArStep2 xs, Ax a) {
727         return ConfigWithArAddress(x);
728     }
mac_x1to0(Ax a)729     Config mac_x1to0(Ax a) {
730         return AnyConfig;
731     }
mac1(ArpRn1 xy,ArpStep1 xis,ArpStep1 yjs,Ax a)732     Config mac1(ArpRn1 xy, ArpStep1 xis, ArpStep1 yjs, Ax a) {
733         return ConfigWithArpAddress(xy);
734     }
735 
modr(Rn a,StepZIDS as)736     Config modr(Rn a, StepZIDS as) {
737         return AnyConfig;
738     }
modr_dmod(Rn a,StepZIDS as)739     Config modr_dmod(Rn a, StepZIDS as) {
740         return AnyConfig;
741     }
modr_i2(Rn a)742     Config modr_i2(Rn a) {
743         return AnyConfig;
744     }
modr_i2_dmod(Rn a)745     Config modr_i2_dmod(Rn a) {
746         return AnyConfig;
747     }
modr_d2(Rn a)748     Config modr_d2(Rn a) {
749         return AnyConfig;
750     }
modr_d2_dmod(Rn a)751     Config modr_d2_dmod(Rn a) {
752         return AnyConfig;
753     }
modr_eemod(ArpRn2 a,ArpStep2 asi,ArpStep2 asj)754     Config modr_eemod(ArpRn2 a, ArpStep2 asi, ArpStep2 asj) {
755         return AnyConfig;
756     }
modr_edmod(ArpRn2 a,ArpStep2 asi,ArpStep2 asj)757     Config modr_edmod(ArpRn2 a, ArpStep2 asi, ArpStep2 asj) {
758         return AnyConfig;
759     }
modr_demod(ArpRn2 a,ArpStep2 asi,ArpStep2 asj)760     Config modr_demod(ArpRn2 a, ArpStep2 asi, ArpStep2 asj) {
761         return AnyConfig;
762     }
modr_ddmod(ArpRn2 a,ArpStep2 asi,ArpStep2 asj)763     Config modr_ddmod(ArpRn2 a, ArpStep2 asi, ArpStep2 asj) {
764         return AnyConfig;
765     }
766 
movd(R0123 a,StepZIDS as,R45 b,StepZIDS bs)767     Config movd(R0123 a, StepZIDS as, R45 b, StepZIDS bs) {
768         return DisabledConfig;
769     }
movp(Axl a,Register b)770     Config movp(Axl a, Register b) {
771         return DisabledConfig;
772     }
movp(Ax a,Register b)773     Config movp(Ax a, Register b) {
774         return DisabledConfig;
775     }
movp(Rn a,StepZIDS as,R0123 b,StepZIDS bs)776     Config movp(Rn a, StepZIDS as, R0123 b, StepZIDS bs) {
777         return DisabledConfig;
778     }
movpdw(Ax a)779     Config movpdw(Ax a) {
780         return DisabledConfig;
781     }
782 
mov(Ab a,Ab b)783     Config mov(Ab a, Ab b) {
784         return AnyConfig;
785     }
mov_dvm(Abl a)786     Config mov_dvm(Abl a) {
787         return DisabledConfig;
788     }
mov_x0(Abl a)789     Config mov_x0(Abl a) {
790         return AnyConfig;
791     }
mov_x1(Abl a)792     Config mov_x1(Abl a) {
793         return AnyConfig;
794     }
mov_y1(Abl a)795     Config mov_y1(Abl a) {
796         return AnyConfig;
797     }
mov(Ablh a,MemImm8 b)798     Config mov(Ablh a, MemImm8 b) {
799         return ConfigWithMemImm8(b);
800     }
mov(Axl a,MemImm16 b)801     Config mov(Axl a, MemImm16 b) {
802         return AnyConfig.WithMemoryExpand();
803     }
mov(Axl a,MemR7Imm16 b)804     Config mov(Axl a, MemR7Imm16 b) {
805         return ConfigWithMemR7Imm16();
806     }
mov(Axl a,MemR7Imm7s b)807     Config mov(Axl a, MemR7Imm7s b) {
808         return ConfigWithMemR7Imm7s(b);
809     }
mov(MemImm16 a,Ax b)810     Config mov(MemImm16 a, Ax b) {
811         return AnyConfig.WithMemoryExpand();
812     }
mov(MemImm8 a,Ab b)813     Config mov(MemImm8 a, Ab b) {
814         return ConfigWithMemImm8(a);
815     }
mov(MemImm8 a,Ablh b)816     Config mov(MemImm8 a, Ablh b) {
817         return ConfigWithMemImm8(a);
818     }
mov_eu(MemImm8 a,Axh b)819     Config mov_eu(MemImm8 a, Axh b) {
820         return DisabledConfig;
821     }
mov(MemImm8 a,RnOld b)822     Config mov(MemImm8 a, RnOld b) {
823         return ConfigWithMemImm8(a);
824     }
mov_sv(MemImm8 a)825     Config mov_sv(MemImm8 a) {
826         return ConfigWithMemImm8(a);
827     }
mov_dvm_to(Ab b)828     Config mov_dvm_to(Ab b) {
829         return DisabledConfig;
830     }
mov_icr_to(Ab b)831     Config mov_icr_to(Ab b) {
832         return DisabledConfig;
833     }
mov(Imm16 a,Bx b)834     Config mov(Imm16 a, Bx b) {
835         return AnyConfig.WithAnyExpand();
836     }
mov(Imm16 a,Register b)837     Config mov(Imm16 a, Register b) {
838         if (IsUnimplementedRegister(b.GetName()))
839             return DisabledConfig;
840         return AnyConfig.WithAnyExpand();
841     }
mov_icr(Imm5 a)842     Config mov_icr(Imm5 a) {
843         return DisabledConfig;
844     }
mov(Imm8s a,Axh b)845     Config mov(Imm8s a, Axh b) {
846         return AnyConfig;
847     }
mov(Imm8s a,RnOld b)848     Config mov(Imm8s a, RnOld b) {
849         return AnyConfig;
850     }
mov_sv(Imm8s a)851     Config mov_sv(Imm8s a) {
852         return AnyConfig;
853     }
mov(Imm8 a,Axl b)854     Config mov(Imm8 a, Axl b) {
855         return AnyConfig;
856     }
mov(MemR7Imm16 a,Ax b)857     Config mov(MemR7Imm16 a, Ax b) {
858         return ConfigWithMemR7Imm16();
859     }
mov(MemR7Imm7s a,Ax b)860     Config mov(MemR7Imm7s a, Ax b) {
861         return ConfigWithMemR7Imm7s(a);
862     }
mov(Rn a,StepZIDS as,Bx b)863     Config mov(Rn a, StepZIDS as, Bx b) {
864         return ConfigWithAddress(a);
865     }
mov(Rn a,StepZIDS as,Register b)866     Config mov(Rn a, StepZIDS as, Register b) {
867         if (IsUnimplementedRegister(b.GetName()))
868             return DisabledConfig;
869         return ConfigWithAddress(a);
870     }
mov_memsp_to(Register b)871     Config mov_memsp_to(Register b) {
872         return DisabledConfig;
873     }
mov_mixp_to(Register b)874     Config mov_mixp_to(Register b) {
875         if (IsUnimplementedRegister(b.GetName()))
876             return DisabledConfig;
877         return AnyConfig;
878     }
mov(RnOld a,MemImm8 b)879     Config mov(RnOld a, MemImm8 b) {
880         return ConfigWithMemImm8(b);
881     }
mov_icr(Register a)882     Config mov_icr(Register a) {
883         return DisabledConfig;
884     }
mov_mixp(Register a)885     Config mov_mixp(Register a) {
886         if (IsUnimplementedRegister(a.GetName()))
887             return DisabledConfig;
888         return AnyConfig;
889     }
mov(Register a,Rn b,StepZIDS bs)890     Config mov(Register a, Rn b, StepZIDS bs) {
891         if (IsUnimplementedRegister(a.GetName()))
892             return DisabledConfig;
893         return ConfigWithAddress(b);
894     }
mov(Register a,Bx b)895     Config mov(Register a, Bx b) {
896         if (IsUnimplementedRegister(a.GetName()))
897             return DisabledConfig;
898         return AnyConfig;
899     }
mov(Register a,Register b)900     Config mov(Register a, Register b) {
901         if (IsUnimplementedRegister(a.GetName()))
902             return DisabledConfig;
903         if (IsUnimplementedRegister(b.GetName()))
904             return DisabledConfig;
905         return AnyConfig;
906     }
mov_repc_to(Ab b)907     Config mov_repc_to(Ab b) {
908         return AnyConfig;
909     }
mov_sv_to(MemImm8 b)910     Config mov_sv_to(MemImm8 b) {
911         return ConfigWithMemImm8(b);
912     }
mov_x0_to(Ab b)913     Config mov_x0_to(Ab b) {
914         return AnyConfig;
915     }
mov_x1_to(Ab b)916     Config mov_x1_to(Ab b) {
917         return AnyConfig;
918     }
mov_y1_to(Ab b)919     Config mov_y1_to(Ab b) {
920         return AnyConfig;
921     }
mov(Imm16 a,ArArp b)922     Config mov(Imm16 a, ArArp b) {
923         if (IsUnimplementedRegister(b.GetName())) {
924             return DisabledConfig;
925         }
926         return AnyConfig.WithAnyExpand();
927     }
mov_r6(Imm16 a)928     Config mov_r6(Imm16 a) {
929         return AnyConfig.WithAnyExpand();
930     }
mov_repc(Imm16 a)931     Config mov_repc(Imm16 a) {
932         return AnyConfig.WithAnyExpand();
933     }
mov_stepi0(Imm16 a)934     Config mov_stepi0(Imm16 a) {
935         return AnyConfig.WithAnyExpand();
936     }
mov_stepj0(Imm16 a)937     Config mov_stepj0(Imm16 a) {
938         return AnyConfig.WithAnyExpand();
939     }
mov(Imm16 a,SttMod b)940     Config mov(Imm16 a, SttMod b) {
941         if (IsUnimplementedRegister(b.GetName())) {
942             return DisabledConfig;
943         }
944         return AnyConfig.WithAnyExpand();
945     }
mov_prpage(Imm4 a)946     Config mov_prpage(Imm4 a) {
947         return DisabledConfig;
948     }
949 
mov_a0h_stepi0()950     Config mov_a0h_stepi0() {
951         return AnyConfig;
952     }
mov_a0h_stepj0()953     Config mov_a0h_stepj0() {
954         return AnyConfig;
955     }
mov_stepi0_a0h()956     Config mov_stepi0_a0h() {
957         return AnyConfig;
958     }
mov_stepj0_a0h()959     Config mov_stepj0_a0h() {
960         return AnyConfig;
961     }
962 
mov_prpage(Abl a)963     Config mov_prpage(Abl a) {
964         return DisabledConfig;
965     }
mov_repc(Abl a)966     Config mov_repc(Abl a) {
967         return AnyConfig;
968     }
mov(Abl a,ArArp b)969     Config mov(Abl a, ArArp b) {
970         if (IsUnimplementedRegister(b.GetName())) {
971             return DisabledConfig;
972         }
973         return AnyConfig;
974     }
mov(Abl a,SttMod b)975     Config mov(Abl a, SttMod b) {
976         if (IsUnimplementedRegister(b.GetName())) {
977             return DisabledConfig;
978         }
979         return AnyConfig;
980     }
981 
mov_prpage_to(Abl b)982     Config mov_prpage_to(Abl b) {
983         return DisabledConfig;
984     }
mov_repc_to(Abl b)985     Config mov_repc_to(Abl b) {
986         return AnyConfig;
987     }
mov(ArArp a,Abl b)988     Config mov(ArArp a, Abl b) {
989         if (IsUnimplementedRegister(a.GetName())) {
990             return DisabledConfig;
991         }
992         return AnyConfig;
993     }
mov(SttMod a,Abl b)994     Config mov(SttMod a, Abl b) {
995         if (IsUnimplementedRegister(a.GetName())) {
996             return DisabledConfig;
997         }
998         return AnyConfig;
999     }
1000 
mov_repc_to(ArRn1 b,ArStep1 bs)1001     Config mov_repc_to(ArRn1 b, ArStep1 bs) {
1002         return ConfigWithArAddress(b);
1003     }
mov(ArArp a,ArRn1 b,ArStep1 bs)1004     Config mov(ArArp a, ArRn1 b, ArStep1 bs) {
1005         if (IsUnimplementedRegister(a.GetName())) {
1006             return DisabledConfig;
1007         }
1008         return ConfigWithArAddress(b);
1009     }
mov(SttMod a,ArRn1 b,ArStep1 bs)1010     Config mov(SttMod a, ArRn1 b, ArStep1 bs) {
1011         if (IsUnimplementedRegister(a.GetName())) {
1012             return DisabledConfig;
1013         }
1014         return ConfigWithArAddress(b);
1015     }
1016 
mov_repc(ArRn1 a,ArStep1 as)1017     Config mov_repc(ArRn1 a, ArStep1 as) {
1018         return ConfigWithArAddress(a);
1019     }
mov(ArRn1 a,ArStep1 as,ArArp b)1020     Config mov(ArRn1 a, ArStep1 as, ArArp b) {
1021         if (IsUnimplementedRegister(b.GetName())) {
1022             return DisabledConfig;
1023         }
1024         return ConfigWithArAddress(a);
1025     }
mov(ArRn1 a,ArStep1 as,SttMod b)1026     Config mov(ArRn1 a, ArStep1 as, SttMod b) {
1027         if (IsUnimplementedRegister(b.GetName())) {
1028             return DisabledConfig;
1029         }
1030         return ConfigWithArAddress(a);
1031     }
1032 
mov_repc_to(MemR7Imm16 b)1033     Config mov_repc_to(MemR7Imm16 b) {
1034         return ConfigWithMemR7Imm16();
1035     }
mov(ArArpSttMod a,MemR7Imm16 b)1036     Config mov(ArArpSttMod a, MemR7Imm16 b) {
1037         if (IsUnimplementedRegister(a.GetName())) {
1038             return DisabledConfig;
1039         }
1040         return ConfigWithMemR7Imm16();
1041     }
1042 
mov_repc(MemR7Imm16 a)1043     Config mov_repc(MemR7Imm16 a) {
1044         return ConfigWithMemR7Imm16();
1045     }
mov(MemR7Imm16 a,ArArpSttMod b)1046     Config mov(MemR7Imm16 a, ArArpSttMod b) {
1047         if (IsUnimplementedRegister(b.GetName())) {
1048             return DisabledConfig;
1049         }
1050         return ConfigWithMemR7Imm16();
1051     }
1052 
mov_pc(Ax a)1053     Config mov_pc(Ax a) {
1054         return DisabledConfig;
1055     }
mov_pc(Bx a)1056     Config mov_pc(Bx a) {
1057         return DisabledConfig;
1058     }
1059 
mov_mixp_to(Bx b)1060     Config mov_mixp_to(Bx b) {
1061         return AnyConfig;
1062     }
mov_mixp_r6()1063     Config mov_mixp_r6() {
1064         return AnyConfig;
1065     }
mov_p0h_to(Bx b)1066     Config mov_p0h_to(Bx b) {
1067         return AnyConfig;
1068     }
mov_p0h_r6()1069     Config mov_p0h_r6() {
1070         return AnyConfig;
1071     }
mov_p0h_to(Register b)1072     Config mov_p0h_to(Register b) {
1073         if (IsUnimplementedRegister(b.GetName()))
1074             return DisabledConfig;
1075         return AnyConfig;
1076     }
mov_p0(Ab a)1077     Config mov_p0(Ab a) {
1078         return AnyConfig;
1079     }
mov_p1_to(Ab b)1080     Config mov_p1_to(Ab b) {
1081         return AnyConfig;
1082     }
1083 
mov2(Px a,ArRn2 b,ArStep2 bs)1084     Config mov2(Px a, ArRn2 b, ArStep2 bs) {
1085         return ConfigWithArAddress(b);
1086     }
mov2s(Px a,ArRn2 b,ArStep2 bs)1087     Config mov2s(Px a, ArRn2 b, ArStep2 bs) {
1088         return ConfigWithArAddress(b);
1089     }
mov2(ArRn2 a,ArStep2 as,Px b)1090     Config mov2(ArRn2 a, ArStep2 as, Px b) {
1091         return ConfigWithArAddress(a);
1092     }
mova(Ab a,ArRn2 b,ArStep2 bs)1093     Config mova(Ab a, ArRn2 b, ArStep2 bs) {
1094         return ConfigWithArAddress(b);
1095     }
mova(ArRn2 a,ArStep2 as,Ab b)1096     Config mova(ArRn2 a, ArStep2 as, Ab b) {
1097         return ConfigWithArAddress(a);
1098     }
1099 
mov_r6_to(Bx b)1100     Config mov_r6_to(Bx b) {
1101         return AnyConfig;
1102     }
mov_r6_mixp()1103     Config mov_r6_mixp() {
1104         return AnyConfig;
1105     }
mov_r6_to(Register b)1106     Config mov_r6_to(Register b) {
1107         if (IsUnimplementedRegister(b.GetName()))
1108             return DisabledConfig;
1109         return AnyConfig;
1110     }
mov_r6(Register a)1111     Config mov_r6(Register a) {
1112         if (IsUnimplementedRegister(a.GetName()))
1113             return DisabledConfig;
1114         return AnyConfig;
1115     }
mov_memsp_r6()1116     Config mov_memsp_r6() {
1117         return DisabledConfig;
1118     }
mov_r6_to(Rn b,StepZIDS bs)1119     Config mov_r6_to(Rn b, StepZIDS bs) {
1120         return ConfigWithAddress(b);
1121     }
mov_r6(Rn a,StepZIDS as)1122     Config mov_r6(Rn a, StepZIDS as) {
1123         return ConfigWithAddress(a);
1124     }
1125 
movs(MemImm8 a,Ab b)1126     Config movs(MemImm8 a, Ab b) {
1127         return ConfigWithMemImm8(a);
1128     }
movs(Rn a,StepZIDS as,Ab b)1129     Config movs(Rn a, StepZIDS as, Ab b) {
1130         return ConfigWithAddress(a);
1131     }
movs(Register a,Ab b)1132     Config movs(Register a, Ab b) {
1133         if (IsUnimplementedRegister(a.GetName()))
1134             return DisabledConfig;
1135         return AnyConfig;
1136     }
movs_r6_to(Ax b)1137     Config movs_r6_to(Ax b) {
1138         return AnyConfig;
1139     }
movsi(RnOld a,Ab b,Imm5s s)1140     Config movsi(RnOld a, Ab b, Imm5s s) {
1141         return AnyConfig;
1142     }
1143 
mov2_axh_m_y0_m(Axh a,ArRn2 b,ArStep2 bs)1144     Config mov2_axh_m_y0_m(Axh a, ArRn2 b, ArStep2 bs) {
1145         return ConfigWithArAddress(b);
1146     }
mov2_ax_mij(Ab a,ArpRn1 b,ArpStep1 bsi,ArpStep1 bsj)1147     Config mov2_ax_mij(Ab a, ArpRn1 b, ArpStep1 bsi, ArpStep1 bsj) {
1148         return ConfigWithArpAddress(b);
1149     }
mov2_ax_mji(Ab a,ArpRn1 b,ArpStep1 bsi,ArpStep1 bsj)1150     Config mov2_ax_mji(Ab a, ArpRn1 b, ArpStep1 bsi, ArpStep1 bsj) {
1151         return ConfigWithArpAddress(b);
1152     }
mov2_mij_ax(ArpRn1 a,ArpStep1 asi,ArpStep1 asj,Ab b)1153     Config mov2_mij_ax(ArpRn1 a, ArpStep1 asi, ArpStep1 asj, Ab b) {
1154         return ConfigWithArpAddress(a);
1155     }
mov2_mji_ax(ArpRn1 a,ArpStep1 asi,ArpStep1 asj,Ab b)1156     Config mov2_mji_ax(ArpRn1 a, ArpStep1 asi, ArpStep1 asj, Ab b) {
1157         return ConfigWithArpAddress(a);
1158     }
mov2_abh_m(Abh ax,Abh ay,ArRn1 b,ArStep1 bs)1159     Config mov2_abh_m(Abh ax, Abh ay, ArRn1 b, ArStep1 bs) {
1160         return ConfigWithArAddress(b);
1161     }
exchange_iaj(Axh a,ArpRn2 b,ArpStep2 bsi,ArpStep2 bsj)1162     Config exchange_iaj(Axh a, ArpRn2 b, ArpStep2 bsi, ArpStep2 bsj) {
1163         return ConfigWithArpAddress(b);
1164     }
exchange_riaj(Axh a,ArpRn2 b,ArpStep2 bsi,ArpStep2 bsj)1165     Config exchange_riaj(Axh a, ArpRn2 b, ArpStep2 bsi, ArpStep2 bsj) {
1166         return ConfigWithArpAddress(b);
1167     }
exchange_jai(Axh a,ArpRn2 b,ArpStep2 bsi,ArpStep2 bsj)1168     Config exchange_jai(Axh a, ArpRn2 b, ArpStep2 bsi, ArpStep2 bsj) {
1169         return ConfigWithArpAddress(b);
1170     }
exchange_rjai(Axh a,ArpRn2 b,ArpStep2 bsi,ArpStep2 bsj)1171     Config exchange_rjai(Axh a, ArpRn2 b, ArpStep2 bsi, ArpStep2 bsj) {
1172         return ConfigWithArpAddress(b);
1173     }
1174 
movr(ArRn2 a,ArStep2 as,Abh b)1175     Config movr(ArRn2 a, ArStep2 as, Abh b) {
1176         return ConfigWithArAddress(a);
1177     }
movr(Rn a,StepZIDS as,Ax b)1178     Config movr(Rn a, StepZIDS as, Ax b) {
1179         return ConfigWithAddress(a);
1180     }
movr(Register a,Ax b)1181     Config movr(Register a, Ax b) {
1182         if (IsUnimplementedRegister(a.GetName()))
1183             return DisabledConfig;
1184         return AnyConfig;
1185     }
movr(Bx a,Ax b)1186     Config movr(Bx a, Ax b) {
1187         return AnyConfig;
1188     }
movr_r6_to(Ax b)1189     Config movr_r6_to(Ax b) {
1190         return AnyConfig;
1191     }
1192 
exp(Bx a)1193     Config exp(Bx a) {
1194         return AnyConfig;
1195     }
exp(Bx a,Ax b)1196     Config exp(Bx a, Ax b) {
1197         return AnyConfig;
1198     }
exp(Rn a,StepZIDS as)1199     Config exp(Rn a, StepZIDS as) {
1200         return ConfigWithAddress(a);
1201     }
exp(Rn a,StepZIDS as,Ax b)1202     Config exp(Rn a, StepZIDS as, Ax b) {
1203         return ConfigWithAddress(a);
1204     }
exp(Register a)1205     Config exp(Register a) {
1206         if (IsUnimplementedRegister(a.GetName()))
1207             return DisabledConfig;
1208         return AnyConfig;
1209     }
exp(Register a,Ax b)1210     Config exp(Register a, Ax b) {
1211         if (IsUnimplementedRegister(a.GetName()))
1212             return DisabledConfig;
1213         return AnyConfig;
1214     }
exp_r6()1215     Config exp_r6() {
1216         return AnyConfig;
1217     }
exp_r6(Ax b)1218     Config exp_r6(Ax b) {
1219         return AnyConfig;
1220     }
1221 
lim(Ax a,Ax b)1222     Config lim(Ax a, Ax b) {
1223         return AnyConfig;
1224     }
1225 
vtrclr0()1226     Config vtrclr0() {
1227         return DisabledConfig;
1228     }
vtrclr1()1229     Config vtrclr1() {
1230         return DisabledConfig;
1231     }
vtrclr()1232     Config vtrclr() {
1233         return DisabledConfig;
1234     }
vtrmov0(Axl a)1235     Config vtrmov0(Axl a) {
1236         return DisabledConfig;
1237     }
vtrmov1(Axl a)1238     Config vtrmov1(Axl a) {
1239         return DisabledConfig;
1240     }
vtrmov(Axl a)1241     Config vtrmov(Axl a) {
1242         return DisabledConfig;
1243     }
vtrshr()1244     Config vtrshr() {
1245         return DisabledConfig;
1246     }
1247 
clrp0()1248     Config clrp0() {
1249         return AnyConfig;
1250     }
clrp1()1251     Config clrp1() {
1252         return AnyConfig;
1253     }
clrp()1254     Config clrp() {
1255         return AnyConfig;
1256     }
1257 
max_ge(Ax a,StepZIDS bs)1258     Config max_ge(Ax a, StepZIDS bs) {
1259         return AnyConfig;
1260     }
max_gt(Ax a,StepZIDS bs)1261     Config max_gt(Ax a, StepZIDS bs) {
1262         return AnyConfig;
1263     }
min_le(Ax a,StepZIDS bs)1264     Config min_le(Ax a, StepZIDS bs) {
1265         return AnyConfig;
1266     }
min_lt(Ax a,StepZIDS bs)1267     Config min_lt(Ax a, StepZIDS bs) {
1268         return AnyConfig;
1269     }
1270 
max_ge_r0(Ax a,StepZIDS bs)1271     Config max_ge_r0(Ax a, StepZIDS bs) {
1272         return ConfigWithAddress(Rn{0});
1273     }
max_gt_r0(Ax a,StepZIDS bs)1274     Config max_gt_r0(Ax a, StepZIDS bs) {
1275         return ConfigWithAddress(Rn{0});
1276     }
min_le_r0(Ax a,StepZIDS bs)1277     Config min_le_r0(Ax a, StepZIDS bs) {
1278         return ConfigWithAddress(Rn{0});
1279     }
min_lt_r0(Ax a,StepZIDS bs)1280     Config min_lt_r0(Ax a, StepZIDS bs) {
1281         return ConfigWithAddress(Rn{0});
1282     }
divs(MemImm8 a,Ax b)1283     Config divs(MemImm8 a, Ax b) {
1284         return ConfigWithMemImm8(a);
1285     }
1286 
sqr_sqr_add3(Ab a,Ab b)1287     Config sqr_sqr_add3(Ab a, Ab b) {
1288         return AnyConfig;
1289     }
sqr_sqr_add3(ArRn2 a,ArStep2 as,Ab b)1290     Config sqr_sqr_add3(ArRn2 a, ArStep2 as, Ab b) {
1291         return ConfigWithArAddress(a);
1292     }
sqr_mpysu_add3a(Ab a,Ab b)1293     Config sqr_mpysu_add3a(Ab a, Ab b) {
1294         return AnyConfig;
1295     }
1296 
cmp(Ax a,Bx b)1297     Config cmp(Ax a, Bx b) {
1298         return AnyConfig;
1299     }
cmp_b0_b1()1300     Config cmp_b0_b1() {
1301         return AnyConfig;
1302     }
cmp_b1_b0()1303     Config cmp_b1_b0() {
1304         return AnyConfig;
1305     }
cmp(Bx a,Ax b)1306     Config cmp(Bx a, Ax b) {
1307         return AnyConfig;
1308     }
cmp_p1_to(Ax b)1309     Config cmp_p1_to(Ax b) {
1310         return AnyConfig;
1311     }
1312 
max2_vtr(Ax a)1313     Config max2_vtr(Ax a) {
1314         return AnyConfig;
1315     }
min2_vtr(Ax a)1316     Config min2_vtr(Ax a) {
1317         return AnyConfig;
1318     }
max2_vtr(Ax a,Bx b)1319     Config max2_vtr(Ax a, Bx b) {
1320         return AnyConfig;
1321     }
min2_vtr(Ax a,Bx b)1322     Config min2_vtr(Ax a, Bx b) {
1323         return AnyConfig;
1324     }
max2_vtr_movl(Ax a,Bx b,ArRn1 c,ArStep1 cs)1325     Config max2_vtr_movl(Ax a, Bx b, ArRn1 c, ArStep1 cs) {
1326         return ConfigWithArAddress(c);
1327     }
max2_vtr_movh(Ax a,Bx b,ArRn1 c,ArStep1 cs)1328     Config max2_vtr_movh(Ax a, Bx b, ArRn1 c, ArStep1 cs) {
1329         return ConfigWithArAddress(c);
1330     }
max2_vtr_movl(Bx a,Ax b,ArRn1 c,ArStep1 cs)1331     Config max2_vtr_movl(Bx a, Ax b, ArRn1 c, ArStep1 cs) {
1332         return ConfigWithArAddress(c);
1333     }
max2_vtr_movh(Bx a,Ax b,ArRn1 c,ArStep1 cs)1334     Config max2_vtr_movh(Bx a, Ax b, ArRn1 c, ArStep1 cs) {
1335         return ConfigWithArAddress(c);
1336     }
min2_vtr_movl(Ax a,Bx b,ArRn1 c,ArStep1 cs)1337     Config min2_vtr_movl(Ax a, Bx b, ArRn1 c, ArStep1 cs) {
1338         return ConfigWithArAddress(c);
1339     }
min2_vtr_movh(Ax a,Bx b,ArRn1 c,ArStep1 cs)1340     Config min2_vtr_movh(Ax a, Bx b, ArRn1 c, ArStep1 cs) {
1341         return ConfigWithArAddress(c);
1342     }
min2_vtr_movl(Bx a,Ax b,ArRn1 c,ArStep1 cs)1343     Config min2_vtr_movl(Bx a, Ax b, ArRn1 c, ArStep1 cs) {
1344         return ConfigWithArAddress(c);
1345     }
min2_vtr_movh(Bx a,Ax b,ArRn1 c,ArStep1 cs)1346     Config min2_vtr_movh(Bx a, Ax b, ArRn1 c, ArStep1 cs) {
1347         return ConfigWithArAddress(c);
1348     }
max2_vtr_movij(Ax a,Bx b,ArpRn1 c,ArpStep1 csi,ArpStep1 csj)1349     Config max2_vtr_movij(Ax a, Bx b, ArpRn1 c, ArpStep1 csi, ArpStep1 csj) {
1350         return ConfigWithArpAddress(c);
1351     }
max2_vtr_movji(Ax a,Bx b,ArpRn1 c,ArpStep1 csi,ArpStep1 csj)1352     Config max2_vtr_movji(Ax a, Bx b, ArpRn1 c, ArpStep1 csi, ArpStep1 csj) {
1353         return ConfigWithArpAddress(c);
1354     }
min2_vtr_movij(Ax a,Bx b,ArpRn1 c,ArpStep1 csi,ArpStep1 csj)1355     Config min2_vtr_movij(Ax a, Bx b, ArpRn1 c, ArpStep1 csi, ArpStep1 csj) {
1356         return ConfigWithArpAddress(c);
1357     }
min2_vtr_movji(Ax a,Bx b,ArpRn1 c,ArpStep1 csi,ArpStep1 csj)1358     Config min2_vtr_movji(Ax a, Bx b, ArpRn1 c, ArpStep1 csi, ArpStep1 csj) {
1359         return ConfigWithArpAddress(c);
1360     }
1361 
1362     template <typename ArpStepX>
mov_sv_app(ArRn1 a,ArpStepX as,Bx b,SumBase base,bool sub_p0,bool p0_align,bool sub_p1,bool p1_align)1363     Config mov_sv_app(ArRn1 a, ArpStepX as, Bx b, SumBase base, bool sub_p0, bool p0_align,
1364                       bool sub_p1, bool p1_align) {
1365         return ConfigWithArAddress(a);
1366     }
1367 
cbs(Axh a,CbsCond c)1368     Config cbs(Axh a, CbsCond c) {
1369         // return AnyConfig;
1370         return DisabledConfig;
1371     }
cbs(Axh a,Bxh b,CbsCond c)1372     Config cbs(Axh a, Bxh b, CbsCond c) {
1373         // return AnyConfig;
1374         return DisabledConfig;
1375     }
cbs(ArpRn1 a,ArpStep1 asi,ArpStep1 asj,CbsCond c)1376     Config cbs(ArpRn1 a, ArpStep1 asi, ArpStep1 asj, CbsCond c) {
1377         // return ConfigWithArpAddress(a);
1378         return DisabledConfig;
1379     }
1380 
mma(RegName a,bool x0_sign,bool y0_sign,bool x1_sign,bool y1_sign,SumBase base,bool sub_p0,bool p0_align,bool sub_p1,bool p1_align)1381     Config mma(RegName a, bool x0_sign, bool y0_sign, bool x1_sign, bool y1_sign, SumBase base,
1382                bool sub_p0, bool p0_align, bool sub_p1, bool p1_align) {
1383         return AnyConfig;
1384     }
1385 
1386     template <typename ArpRnX, typename ArpStepX>
mma(ArpRnX xy,ArpStepX i,ArpStepX j,bool dmodi,bool dmodj,RegName a,bool x0_sign,bool y0_sign,bool x1_sign,bool y1_sign,SumBase base,bool sub_p0,bool p0_align,bool sub_p1,bool p1_align)1387     Config mma(ArpRnX xy, ArpStepX i, ArpStepX j, bool dmodi, bool dmodj, RegName a, bool x0_sign,
1388                bool y0_sign, bool x1_sign, bool y1_sign, SumBase base, bool sub_p0, bool p0_align,
1389                bool sub_p1, bool p1_align) {
1390         return ConfigWithArpAddress(xy);
1391     }
1392 
mma_mx_xy(ArRn1 y,ArStep1 ys,RegName a,bool x0_sign,bool y0_sign,bool x1_sign,bool y1_sign,SumBase base,bool sub_p0,bool p0_align,bool sub_p1,bool p1_align)1393     Config mma_mx_xy(ArRn1 y, ArStep1 ys, RegName a, bool x0_sign, bool y0_sign, bool x1_sign,
1394                      bool y1_sign, SumBase base, bool sub_p0, bool p0_align, bool sub_p1,
1395                      bool p1_align) {
1396         return ConfigWithArAddress(y);
1397     }
1398 
mma_xy_mx(ArRn1 y,ArStep1 ys,RegName a,bool x0_sign,bool y0_sign,bool x1_sign,bool y1_sign,SumBase base,bool sub_p0,bool p0_align,bool sub_p1,bool p1_align)1399     Config mma_xy_mx(ArRn1 y, ArStep1 ys, RegName a, bool x0_sign, bool y0_sign, bool x1_sign,
1400                      bool y1_sign, SumBase base, bool sub_p0, bool p0_align, bool sub_p1,
1401                      bool p1_align) {
1402         return ConfigWithArAddress(y);
1403     }
1404 
mma_my_my(ArRn1 x,ArStep1 xs,RegName a,bool x0_sign,bool y0_sign,bool x1_sign,bool y1_sign,SumBase base,bool sub_p0,bool p0_align,bool sub_p1,bool p1_align)1405     Config mma_my_my(ArRn1 x, ArStep1 xs, RegName a, bool x0_sign, bool y0_sign, bool x1_sign,
1406                      bool y1_sign, SumBase base, bool sub_p0, bool p0_align, bool sub_p1,
1407                      bool p1_align) {
1408         return ConfigWithArAddress(x);
1409     }
1410 
mma_mov(Axh u,Bxh v,ArRn1 w,ArStep1 ws,RegName a,bool x0_sign,bool y0_sign,bool x1_sign,bool y1_sign,SumBase base,bool sub_p0,bool p0_align,bool sub_p1,bool p1_align)1411     Config mma_mov(Axh u, Bxh v, ArRn1 w, ArStep1 ws, RegName a, bool x0_sign, bool y0_sign,
1412                    bool x1_sign, bool y1_sign, SumBase base, bool sub_p0, bool p0_align,
1413                    bool sub_p1, bool p1_align) {
1414         return ConfigWithArAddress(w);
1415     }
1416 
mma_mov(ArRn2 w,ArStep1 ws,RegName a,bool x0_sign,bool y0_sign,bool x1_sign,bool y1_sign,SumBase base,bool sub_p0,bool p0_align,bool sub_p1,bool p1_align)1417     Config mma_mov(ArRn2 w, ArStep1 ws, RegName a, bool x0_sign, bool y0_sign, bool x1_sign,
1418                    bool y1_sign, SumBase base, bool sub_p0, bool p0_align, bool sub_p1,
1419                    bool p1_align) {
1420         return ConfigWithArAddress(w);
1421     }
1422 
addhp(ArRn2 a,ArStep2 as,Px b,Ax c)1423     Config addhp(ArRn2 a, ArStep2 as, Px b, Ax c) {
1424         return ConfigWithArAddress(a);
1425     }
1426 
mov_ext0(Imm8s a)1427     Config mov_ext0(Imm8s a) {
1428         return DisabledConfig;
1429     }
mov_ext1(Imm8s a)1430     Config mov_ext1(Imm8s a) {
1431         return DisabledConfig;
1432     }
mov_ext2(Imm8s a)1433     Config mov_ext2(Imm8s a) {
1434         return DisabledConfig;
1435     }
mov_ext3(Imm8s a)1436     Config mov_ext3(Imm8s a) {
1437         return DisabledConfig;
1438     }
1439 };
1440 } // Anonymous namespace
1441 
GenerateTestCasesToFile(const char * path)1442 bool GenerateTestCasesToFile(const char* path) {
1443     std::unique_ptr<std::FILE, decltype(&std::fclose)> f{std::fopen(path, "wb"), std::fclose};
1444     if (!f) {
1445         return false;
1446     }
1447 
1448     TestGenerator generator;
1449     for (u32 i = 0; i < 0x10000; ++i) {
1450         u16 opcode = (u16)i;
1451         auto decoded = Decode<TestGenerator>(opcode);
1452         Config config = decoded.call(generator, opcode, 0);
1453         if (!config.enable)
1454             continue;
1455 
1456         for (int j = 0; j < 4; ++j) {
1457             TestCase test_case{};
1458             test_case.before = config.GenerateRandomState();
1459             test_case.opcode = opcode;
1460 
1461             switch (config.expand) {
1462             case ExpandConfig::None:
1463                 test_case.expand = 0;
1464                 break;
1465             case ExpandConfig::Any:
1466                 test_case.expand = Random::bit16();
1467                 break;
1468             case ExpandConfig::Memory:
1469                 test_case.expand = TestSpaceX + (u16)Random::uniform(10, TestSpaceSize - 10);
1470                 break;
1471             }
1472 
1473             if (std::fwrite(&test_case, sizeof(test_case), 1, f.get()) == 0) {
1474                 return false;
1475             }
1476         }
1477     }
1478 
1479     return true;
1480 }
1481 
1482 } // namespace Teakra::Test
1483