From d74693eb0f977f8154f98acb66ccc9b655cec0a8 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 14 Jun 2026 19:32:53 +0100 Subject: [PATCH] Minimize ppc_vle decoding tables --- core/rexcode/ppc_vle/decoding_tables.odin | 98 ++++++++++++------- core/rexcode/ppc_vle/encoding_table.odin | 2 +- .../ppc_vle/tools/gen_decode_tables.odin | 21 ++-- 3 files changed, 74 insertions(+), 47 deletions(-) diff --git a/core/rexcode/ppc_vle/decoding_tables.odin b/core/rexcode/ppc_vle/decoding_tables.odin index a61afab27..ba1482470 100644 --- a/core/rexcode/ppc_vle/decoding_tables.odin +++ b/core/rexcode/ppc_vle/decoding_tables.odin @@ -251,50 +251,80 @@ DECODE_ENTRIES := [222]Decode_Entry{ } DECODE_FORM_IDX := [222]u16{ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, } DECODE_BUCKET_LIST := [222]u16{ - 0, 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, 83, 84, 85, 86, 87, 88, 89, 93, 94, 95, 96, 97, 98, 99, 100, - 101, 106, 107, 108, 109, 110, 111, 112, 199, 200, 201, 202, 203, 204, 205, 206, - 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 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, 90, 91, 92, 102, 103, 104, 105, 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, + 0, 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, 83, 84, 85, 86, 87, 88, 89, 93, 94, 95, 96, 97, 98, 99, 100, + 101, 106, 107, 108, 109, 110, 111, 112, 199, 200, 201, 202, 203, 204, 205, 206, + 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 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, 90, 91, 92, 102, 103, 104, 105, 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, } @(rodata) DECODE_INDEX_SHORT := [64]Decode_Index{ -{0,25,0},{25,4,0},{0,0,0},{29,4,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{33,2,0},{35,2,0},{37,1,0},{38,2,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{40,3,0},{43,5,0},{48,1,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{49,2,0},{51,2,0},{53,2,0},{55,1,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{56,1,0},{0,0,0},{0,0,0},{0,0,0},{57,1,0},{0,0,0},{0,0,0},{0,0,0},{58,1,0},{0,0,0},{0,0,0},{0,0,0},{59,1,0},{0,0,0},{0,0,0},{0,0,0},{60,1,0},{0,0,0},{0,0,0},{0,0,0},{61,1,0},{0,0,0},{0,0,0},{0,0,0},{62,9,0},{71,6,0},{77,2,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}, + 0x00 = {0,25,0}, + 0x01 = {25,4,0}, + 0x03 = {29,4,0}, + 0x08 = {33,2,0}, + 0x09 = {35,2,0}, + 0x0A = {37,1,0}, + 0x0B = {38,2,0}, + 0x10 = {40,3,0}, + 0x11 = {43,5,0}, + 0x12 = {48,1,0}, + 0x18 = {49,2,0}, + 0x19 = {51,2,0}, + 0x1A = {53,2,0}, + 0x1B = {55,1,0}, + 0x20 = {56,1,0}, + 0x24 = {57,1,0}, + 0x28 = {58,1,0}, + 0x2C = {59,1,0}, + 0x30 = {60,1,0}, + 0x34 = {61,1,0}, + 0x38 = {62,9,0}, + 0x39 = {71,6,0}, + 0x3A = {77,2,0}, } @(rodata) DECODE_INDEX_LONG := [64]Decode_Index{ - -{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{79,47,0},{126,3,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{129,1,0},{130,1,0},{131,1,0},{0,0,0}, -{0,0,0},{0,0,0},{0,0,0},{0,0,0},{132,1,0},{133,1,0},{134,1,0},{135,1,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{136,15,0},{151,11,0},{162,36,0},{198,24,0}, -{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}, -{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}, + 0x06 = {79,47,0}, + 0x07 = {126,3,0}, + 0x0C = {129,1,0}, + 0x0D = {130,1,0}, + 0x0E = {131,1,0}, + 0x14 = {132,1,0}, + 0x15 = {133,1,0}, + 0x16 = {134,1,0}, + 0x17 = {135,1,0}, + 0x1C = {136,15,0}, + 0x1D = {151,11,0}, + 0x1E = {162,36,0}, + 0x1F = {198,24,0}, } diff --git a/core/rexcode/ppc_vle/encoding_table.odin b/core/rexcode/ppc_vle/encoding_table.odin index 240c88ec1..666d25a6a 100644 --- a/core/rexcode/ppc_vle/encoding_table.odin +++ b/core/rexcode/ppc_vle/encoding_table.odin @@ -8,7 +8,7 @@ package rexcode_ppc_vle // encoding. Each entry's mask covers the FIXED bits of the form (primary // opcode, sub-opcode, baked operands), leaving variable operand bits free. @(rodata) -ENCODING_TABLE: [Mnemonic][]Encoding = #partial { +ENCODING_TABLE:= #partial [Mnemonic][]Encoding{ .SE_ILLEGAL = { {.SE_ILLEGAL , {.NONE, .NONE, .NONE, .NONE}, {.NONE, .NONE, .NONE, .NONE}, 0x00000000, 0xFFFFFFFF, .BASE, .PPC32_VLE, {short=true}} }, .SE_ISYNC = { {.SE_ISYNC , {.NONE, .NONE, .NONE, .NONE}, {.NONE, .NONE, .NONE, .NONE}, 0x00000001, 0xFFFFFFFF, .BASE, .PPC32_VLE, {short=true}} }, .SE_SC = { {.SE_SC , {.NONE, .NONE, .NONE, .NONE}, {.NONE, .NONE, .NONE, .NONE}, 0x00000002, 0xFFFFFFFF, .BASE, .PPC32_VLE, {short=true}} }, diff --git a/core/rexcode/ppc_vle/tools/gen_decode_tables.odin b/core/rexcode/ppc_vle/tools/gen_decode_tables.odin index 562bde1cf..7a2d80213 100644 --- a/core/rexcode/ppc_vle/tools/gen_decode_tables.odin +++ b/core/rexcode/ppc_vle/tools/gen_decode_tables.odin @@ -165,17 +165,17 @@ Decode_Index :: struct #packed { } strings.write_string(&sb, "}\n\n") - fmt.sbprintf(&sb, "DECODE_FORM_IDX := [%d]u16{{\n", len(all)) + fmt.sbprintf(&sb, "DECODE_FORM_IDX := [%d]u16{{", len(all)) for e, i in all { - if i > 0 && i % 16 == 0 { strings.write_string(&sb, "\n") } - fmt.sbprintf(&sb, " %d,", e.form_idx) + if i % 16 == 0 { strings.write_string(&sb, "\n\t") } + fmt.sbprintf(&sb, "%d, ", e.form_idx) } strings.write_string(&sb, "\n}\n\n") - fmt.sbprintf(&sb, "DECODE_BUCKET_LIST := [%d]u16{{\n", len(bucket_list)) + fmt.sbprintf(&sb, "DECODE_BUCKET_LIST := [%d]u16{{", len(bucket_list)) for v, i in bucket_list { - if i > 0 && i % 16 == 0 { strings.write_string(&sb, "\n") } - fmt.sbprintf(&sb, " %d,", v) + if i % 16 == 0 { strings.write_string(&sb, "\n\t") } + fmt.sbprintf(&sb, "% 3d, ", v) } strings.write_string(&sb, "\n}\n\n") @@ -222,12 +222,9 @@ emit_range_table :: proc(sb: ^strings.Builder, name: string, ranges: []Range) { fmt.sbprintfln(sb, "@(rodata)") fmt.sbprintfln(sb, "%s := [%d]Decode_Index{{", name, len(ranges)) for r, i in ranges { - if r.count == 0 { - if i % 16 == 0 { strings.write_string(sb, "\n") } - strings.write_string(sb, "{0,0,0},") - } else { - fmt.sbprintf(sb, "{{%d,%d,0}},", r.start, r.count) + if r.count != 0 { + fmt.sbprintfln(sb, "\t0x%02X = {{%d,%d,0}},", i, r.start, r.count) } } - strings.write_string(sb, "\n}\n\n") + strings.write_string(sb, "}\n\n") }