The check to see if an item was already on the heap was randomly hitting.
[jitcs.git] / tests / test_allinstructions.cpp
blob369aa5c0b7ceb77aaa9e11aae762d630776b6a3b
1 #include "jitcs.h"
2 #include "unittest.h"
3 #include "jitcs_instructionstream.h"
4 #include "jitcs_dumper.h"
5 #include "jitcs_memmgr.h"
6 #include "jitcs_x86_32.h"
7 #include "jitcs_x86_64.h"
8 #include <unordered_set>
9 #include "jitcs_int_machine.h"
10 #include "jitcs_int_bitfuncs.h"
11 #include "test_asm_x86_32.h"
12 #include "test_asm_x86_64.h"
14 #include <stdio.h>
16 using namespace jitcs;
18 static void test(UnitTest& t) {
19 typedef void (__cdecl *FT0_c)();
20 RefCounter<TempAllocator> alloc(new TempAllocator);
21 RefCounter<MemoryMgr> mgr = MemoryMgr::Create();
23 #ifdef EVM_WINDOWS
24 std::string path = "data\\";
25 #else
26 std::string path = "data/";
27 #endif
29 std::vector<std::string> x86as_files;
30 x86as_files.push_back("mov_set");
31 x86as_files.push_back("arith");
32 x86as_files.push_back("other");
33 x86as_files.push_back("other_vex");
34 x86as_files.push_back("simd_mov");
35 x86as_files.push_back("simd_arith");
36 x86as_files.push_back("simd_blend");
37 x86as_files.push_back("simd_cvt");
38 x86as_files.push_back("simd_insext");
39 x86as_files.push_back("simd_shuffle");
40 x86as_files.push_back("simd_mov_vex");
41 x86as_files.push_back("simd_arith_vex");
42 x86as_files.push_back("simd_blend_vex");
43 x86as_files.push_back("simd_cvt_vex");
44 x86as_files.push_back("simd_insext_vex");
45 x86as_files.push_back("simd_shuffle_vex");
46 x86as_files.push_back("cf");
47 x86as_files.push_back("addrmode");
49 std::unordered_set<u32> allins;
50 std::unordered_set<u32> allins_compressed;
52 std::string prefix = path + "x86_32_";
54 RefCounter<IMachineInfo> mi = GetX86_32WinMachineInfo();
55 TestAssemblerX86_32 asm_win32(mgr, alloc, mi);
56 allins.clear();
57 allins_compressed.clear();
59 for (auto fn: x86as_files)
60 asm_win32.checkFile(t, prefix + fn + ".as", &allins,
61 prefix + fn + ".bin");
63 for (auto v: allins) {
64 u32 vv = v & 0x7fffffff;
65 allins_compressed.insert(((vv >> x86_32::ICL_NonMainBits) << x86_32::ICL_SubBits)
66 + (vv & x86_32::ICL_SubMask));
69 size_t n = 0;
70 for (u32 i = x86_32::ICL_First; i < x86_32::ICL_Last; ++i) {
71 n += popcnt(x86_32::ToValidMask(static_cast<x86_32::InsClassId>(i)));
73 char buffer[128];
74 sprintf(buffer, "x86_32/completeness: %d ins available, %d ins handled", n, allins_compressed.size());
75 t.check(buffer, n == allins_compressed.size());
76 if (n > allins_compressed.size()) {
77 PrintFDumper dd;
78 MachineDumper md(dd, *mi);
79 md.write("unhandled:");
80 for (u32 i = x86_32::ICL_First; i < x86_32::ICL_Last; ++i) {
81 u32 mask = x86_32::ToValidMask(static_cast<x86_32::InsClassId>(i));
82 for (size_t i2 = 0; i2 < 32; ++i2) {
83 if ((mask & (1 << i2)) == 0) continue;
84 u32 a = (i << x86_32::ICL_NonMainBits) + i2;
85 u32 b = (i << x86_32::ICL_SubBits) + i2;
86 if (allins_compressed.find(b) == allins_compressed.end()) {
87 md.write(" ");
88 md.write(static_cast<InsId>(a));
92 md.write("\n");
97 std::string prefix = path + "x86_64_";
99 RefCounter<IMachineInfo> mi = GetX86_64WinMachineInfo();
100 TestAssemblerX86_64 asm_win64(mgr, alloc, mi);
101 allins.clear();
102 allins_compressed.clear();
104 for (auto fn: x86as_files)
105 asm_win64.checkFile(t, prefix + fn + ".as", &allins,
106 prefix + fn + ".bin");
108 for (auto v: allins) {
109 u32 vv = v & 0x7fffffff;
110 allins_compressed.insert
111 (((vv >> x86_64::ICL_NonMainBits) << x86_64::ICL_SubBits)
112 + (vv & x86_64::ICL_SubMask));
115 size_t n = 0;
116 for (u32 i = x86_64::ICL_First; i < x86_64::ICL_Last; ++i) {
117 n += popcnt(x86_64::ToValidMask(static_cast<x86_64::InsClassId>(i)));
119 char buffer[128];
120 sprintf(buffer, "x86_64/completeness: %d ins available, %d ins handled", n, allins_compressed.size());
121 t.check(buffer, n == allins_compressed.size());
122 if (n > allins_compressed.size()) {
123 PrintFDumper dd;
124 MachineDumper md(dd, *mi);
125 md.write("unhandled:");
126 for (u32 i = x86_64::ICL_First; i < x86_64::ICL_Last; ++i) {
127 u32 mask = x86_64::ToValidMask(static_cast<x86_64::InsClassId>(i));
128 for (size_t i2 = 0; i2 < 32; ++i2) {
129 if ((mask & (1 << i2)) == 0) continue;
130 u32 a = (i << x86_64::ICL_NonMainBits) + i2;
131 u32 b = (i << x86_64::ICL_SubBits) + i2;
132 if (allins_compressed.find(b) == allins_compressed.end()) {
133 md.write(" ");
134 md.write(static_cast<InsId>(a));
138 md.write("\n");
144 static UnitTestRun _("AllInstructions", test);