diff --git a/core/rexcode/ppc_vle/tests/branch_test.odin b/core/rexcode/ppc_vle/tests/branch_test.odin index ce86a0d9c..272ed7bea 100644 --- a/core/rexcode/ppc_vle/tests/branch_test.odin +++ b/core/rexcode/ppc_vle/tests/branch_test.odin @@ -9,99 +9,99 @@ import "../../isa" @(private="file") check :: proc(name: string, instructions: []v.Instruction, label_defs: []isa.Label_Definition, want: []u8) { - code := make([]u8, 64, context.temp_allocator) - relocs: [dynamic]v.Relocation - errors: [dynamic]v.Error - defer delete(relocs); defer delete(errors) + code := make([]u8, 64, context.temp_allocator) + relocs: [dynamic]v.Relocation + errors: [dynamic]v.Error + defer delete(relocs); defer delete(errors) - byte_count, success := v.encode(instructions, label_defs, code, &relocs, &errors) - if !success { - fmt.printf(" [FAIL] %s: encode failed\n", name) - for e in errors { fmt.printf(" code=%v inst_idx=%d\n", e.code, e.inst_idx) } - fail_count += 1 - return - } - if int(byte_count) != len(want) { - fmt.printf(" [FAIL] %s: byte_count %d (want %d)\n", name, byte_count, len(want)) - fail_count += 1 - return - } - for i in 0.. first inst: se_b with displacement 4 (encoded as 4/2=2 in 8-bit field) - // se_b form bits 0xE800, mask 0xFF00, B8 at bits 0..7, signed << 1 - // Target = pc + 4 = 4 bytes ahead, so B8 value = 2 (= 4/2) - // bits: 0xE8 | 0x04 wait no. Looking at binutils BD8(58, 0, 0) = (58 << 10) = 0xE800 - // Actually se_b is BD8(58,0,0). Let me just verify encoder produces something reasonable. - { - label_defs := [?]isa.Label_Definition{isa.Label_Definition(2)} // points to inst 2 - instructions := [?]v.Instruction{ - v.inst_branch(.SE_B, 0), - v.inst_none(.SE_BLR), - v.inst_none(.SE_BLR), - } - // Just check encode succeeds and roundtrips - code := make([]u8, 16, context.temp_allocator) - relocs: [dynamic]v.Relocation - errors: [dynamic]v.Error - defer delete(relocs); defer delete(errors) - byte_count, success := v.encode(instructions[:], label_defs[:], code, &relocs, &errors) - if !success { - fmt.printf(" [FAIL] se_b+label: encode failed\n") - for e in errors { fmt.printf(" code=%v\n", e.code) } - fail_count += 1 - } else { - fmt.printf(" [ok] se_b+label: %d bytes, bytes=", byte_count) - for i in 0.. first inst: se_b with displacement 4 (encoded as 4/2=2 in 8-bit field) + // se_b form bits 0xE800, mask 0xFF00, B8 at bits 0..7, signed << 1 + // Target = pc + 4 = 4 bytes ahead, so B8 value = 2 (= 4/2) + // bits: 0xE8 | 0x04 wait no. Looking at binutils BD8(58, 0, 0) = (58 << 10) = 0xE800 + // Actually se_b is BD8(58,0,0). Let me just verify encoder produces something reasonable. + { + label_defs := [?]isa.Label_Definition{isa.Label_Definition(2)} // points to inst 2 + instructions := [?]v.Instruction{ + v.inst_branch(.SE_B, 0), + v.inst_none(.SE_BLR), + v.inst_none(.SE_BLR), + } + // Just check encode succeeds and roundtrips + code := make([]u8, 16, context.temp_allocator) + relocs: [dynamic]v.Relocation + errors: [dynamic]v.Error + defer delete(relocs); defer delete(errors) + byte_count, success := v.encode(instructions[:], label_defs[:], code, &relocs, &errors) + if !success { + fmt.printf(" [FAIL] se_b+label: encode failed\n") + for e in errors { fmt.printf(" code=%v\n", e.code) } + fail_count += 1 + } else { + fmt.printf(" [ok] se_b+label: %d bytes, bytes=", byte_count) + for i in 0.. branch_test: %d passed, %d failed\n", ok_count, fail_count) - if fail_count > 0 { os.exit(1) } + fmt.printf("\n==> branch_test: %d passed, %d failed\n", ok_count, fail_count) + if fail_count > 0 { os.exit(1) } } diff --git a/core/rexcode/ppc_vle/tests/full_sweep.odin b/core/rexcode/ppc_vle/tests/full_sweep.odin index 1d31a1778..3eb289b7e 100644 --- a/core/rexcode/ppc_vle/tests/full_sweep.odin +++ b/core/rexcode/ppc_vle/tests/full_sweep.odin @@ -10,85 +10,85 @@ import "../../isa" stats: struct { ok, mn_alias, byte_mismatch, encode_fail, decode_fail: int } run_full_sweep :: proc() { - fmt.println("==== ppc_vle full sweep ====") + fmt.println("==== ppc_vle full sweep ====") - for mn in v.Mnemonic { - _run := v.ENCODE_RUNS[u16(mn)] - forms := v.ENCODE_FORMS[_run.start:][:_run.count] - for &f, fi in forms { - test_one(mn, fi, &f) - } - } + for mn in v.Mnemonic { + _run := v.ENCODE_RUNS[u16(mn)] + forms := v.ENCODE_FORMS[_run.start:][:_run.count] + for &f, fi in forms { + test_one(mn, fi, &f) + } + } - total := stats.ok + stats.mn_alias + stats.byte_mismatch + stats.encode_fail + stats.decode_fail - fmt.printf("\n[TOTAL] %d entries\n", total) - fmt.printf(" OK: %d (%.1f%%)\n", stats.ok, 100.0 * f32(stats.ok) / f32(total)) - fmt.printf(" MN_ALIAS: %d (%.1f%%)\n", stats.mn_alias, 100.0 * f32(stats.mn_alias) / f32(total)) - fmt.printf(" BYTE_MISMATCH: %d (%.1f%%)\n", stats.byte_mismatch, 100.0 * f32(stats.byte_mismatch) / f32(total)) - fmt.printf(" ENCODE_FAIL: %d (%.1f%%)\n", stats.encode_fail, 100.0 * f32(stats.encode_fail) / f32(total)) - fmt.printf(" DECODE_FAIL: %d (%.1f%%)\n", stats.decode_fail, 100.0 * f32(stats.decode_fail) / f32(total)) + total := stats.ok + stats.mn_alias + stats.byte_mismatch + stats.encode_fail + stats.decode_fail + fmt.printf("\n[TOTAL] %d entries\n", total) + fmt.printf(" OK: %d (%.1f%%)\n", stats.ok, 100.0 * f32(stats.ok) / f32(total)) + fmt.printf(" MN_ALIAS: %d (%.1f%%)\n", stats.mn_alias, 100.0 * f32(stats.mn_alias) / f32(total)) + fmt.printf(" BYTE_MISMATCH: %d (%.1f%%)\n", stats.byte_mismatch, 100.0 * f32(stats.byte_mismatch) / f32(total)) + fmt.printf(" ENCODE_FAIL: %d (%.1f%%)\n", stats.encode_fail, 100.0 * f32(stats.encode_fail) / f32(total)) + fmt.printf(" DECODE_FAIL: %d (%.1f%%)\n", stats.decode_fail, 100.0 * f32(stats.decode_fail) / f32(total)) } test_one :: proc(mn: v.Mnemonic, fi: int, f: ^v.Encoding) { - inst := v.Instruction{ - mnemonic = mn, - mode = .PPC32_VLE, - form_id = u16(fi + 1), - length = f.flags.short ? 2 : 4, - } - code := make([]u8, 8, context.temp_allocator) - label_defs: []isa.Label_Definition - relocs: [dynamic]v.Relocation - errors: [dynamic]v.Error - defer delete(relocs); defer delete(errors) + inst := v.Instruction{ + mnemonic = mn, + mode = .PPC32_VLE, + form_id = u16(fi + 1), + length = f.flags.short ? 2 : 4, + } + code := make([]u8, 8, context.temp_allocator) + label_defs: []isa.Label_Definition + relocs: [dynamic]v.Relocation + errors: [dynamic]v.Error + defer delete(relocs); defer delete(errors) - instructions := []v.Instruction{inst} - byte_count, success := v.encode(instructions, label_defs, code, &relocs, &errors) - if !success { - stats.encode_fail += 1 - return - } + instructions := []v.Instruction{inst} + byte_count, success := v.encode(instructions, label_defs, code, &relocs, &errors) + if !success { + stats.encode_fail += 1 + return + } - decoded: [dynamic]v.Instruction - info: [dynamic]v.Instruction_Info - dec_labels: [dynamic]v.Label_Definition - dec_errors: [dynamic]v.Error - defer delete(decoded); defer delete(info); defer delete(dec_labels); defer delete(dec_errors) + decoded: [dynamic]v.Instruction + info: [dynamic]v.Instruction_Info + dec_labels: [dynamic]v.Label_Definition + dec_errors: [dynamic]v.Error + defer delete(decoded); defer delete(info); defer delete(dec_labels); defer delete(dec_errors) - dbyte_count, dsuccess := v.decode(code[:byte_count], nil, &decoded, &info, &dec_labels, &dec_errors) - if !dsuccess || len(decoded) == 0 || decoded[0].mnemonic == .INVALID { - stats.decode_fail += 1 - return - } + dbyte_count, dsuccess := v.decode(code[:byte_count], nil, &decoded, &info, &dec_labels, &dec_errors) + if !dsuccess || len(decoded) == 0 || decoded[0].mnemonic == .INVALID { + stats.decode_fail += 1 + return + } - // Re-encode and check bytes - code2 := make([]u8, 8, context.temp_allocator) - re_relocs: [dynamic]v.Relocation - re_errors: [dynamic]v.Error - defer delete(re_relocs); defer delete(re_errors) + // Re-encode and check bytes + code2 := make([]u8, 8, context.temp_allocator) + re_relocs: [dynamic]v.Relocation + re_errors: [dynamic]v.Error + defer delete(re_relocs); defer delete(re_errors) - rrbyte_count, rrsuccess := v.encode(decoded[:], dec_labels[:], code2, &re_relocs, &re_errors) - if !rrsuccess || rrbyte_count != byte_count { - stats.byte_mismatch += 1 - return - } - for i in 0..