Pārlūkot izejas kodu

Move around and add some assertions

Fabian 6 gadi atpakaļ
vecāks
revīzija
a9b5f153a8
5 mainītis faili ar 20 papildinājumiem un 11 dzēšanām
  1. 1 5
      gen/generate_analyzer.js
  2. 0 5
      gen/generate_jit.js
  3. 16 0
      gen/x86_table.js
  4. 2 0
      src/native/codegen/codegen.c
  5. 1 1
      src/native/cpu.c

+ 1 - 5
gen/generate_analyzer.js

@@ -149,11 +149,6 @@ function gen_instruction_body(encodings, size)
         if((e.opcode >>> 16) === 0xF3) has_F3 = true;
     }
 
-    console.assert(
-        !encodings.some(e => e.nonfaulting && e.block_boundary),
-        "Unsupported: instruction cannot be both a jump and nonfaulting. Opcode: 0x" + hex(encoding.opcode)
-    );
-
     if(has_66 || has_F2 || has_F3)
     {
         console.assert((encoding.opcode & 0xFF00) === 0x0F00);
@@ -416,6 +411,7 @@ function gen_instruction_body(encodings, size)
 
         if(encoding.conditional_jump)
         {
+            console.assert((encoding.opcode & ~0xF) === 0x70 || (encoding.opcode & ~0xF) === 0x0F80);
             instruction_postfix.push("analysis.condition_index = " + (encoding.opcode & 0xF) + ";");
         }
 

+ 0 - 5
gen/generate_jit.js

@@ -168,11 +168,6 @@ function gen_instruction_body(encodings, size)
         if((e.opcode >>> 16) === 0xF3) has_F3 = true;
     }
 
-    console.assert(
-        !encodings.some(e => e.nonfaulting && e.block_boundary),
-        "Unsupported: instruction cannot be both a block boundary and nonfaulting. Opcode: 0x" + hex(encoding.opcode)
-    );
-
     if(has_66 || has_F2 || has_F3)
     {
         console.assert((encoding.opcode & 0xFF00) === 0x0F00);

+ 16 - 0
gen/x86_table.js

@@ -1,5 +1,7 @@
 "use strict";
 
+const { hex } = require("./util");
+
 // http://ref.x86asm.net/coder32.html
 
 const zf = 1 << 6;
@@ -678,4 +680,18 @@ encodings.sort((e1, e2) => {
     return o1 - o2 || e1.fixed_g - e2.fixed_g;
 });
 
+function test_encodings()
+{
+    const invalid = encodings.find(e => e.nonfaulting && e.block_boundary);
+
+    if(invalid)
+    {
+        console.assert(
+            false,
+            "Unsupported: instruction cannot be both a block boundary and nonfaulting. Opcode: " + hex(invalid.opcode)
+        );
+    }
+}
+test_encodings();
+
 module.exports = Object.freeze(encodings.map(entry => Object.freeze(entry)));

+ 2 - 0
src/native/codegen/codegen.c

@@ -296,6 +296,8 @@ void gen_return(void)
 // where [i] is passed on the wasm stack
 void gen_switch(int32_t cases_count)
 {
+    assert(cases_count >= 0);
+
     write_raw_u8(&instruction_body, OP_BRTABLE);
     write_leb_u32(&instruction_body, cases_count);
 

+ 1 - 1
src/native/cpu.c

@@ -1024,7 +1024,7 @@ static void jit_find_basic_blocks()
     {
         int32_t to_visit = to_visit_stack[--to_visit_stack_count];
 
-        assert((*instruction_pointer & ~0xFFF) == (to_visit & ~0xFFF));
+        assert(same_page(*instruction_pointer, to_visit));
         *instruction_pointer = *instruction_pointer & ~0xFFF | to_visit & 0xFFF;
 
         if(find_basic_block_index(&basic_blocks, *instruction_pointer) != -1)