From 5c822f65797b714e7c7dc0868500c39c573e5f87 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 28 Nov 2024 23:41:07 +0900 Subject: [PATCH] [gamecode] Tidy up shiftops a little The various indices were a little inconsistent making modifications tricky. I discovered that signed left-shifts are considered UB if the value overflows the non-sign bits (but unsigned left shifts are fine), and signed right shifts are implementation dependent. Whee. However, it's likely that signed right shifts can be relied upon, at least well enough for unit tests. I imagine signed left, too, but I plan on converting them to unsigned. Also, negative shift values are UB, but that's less of a worry, but also needs "fixing" (ie, make unsigned). However, later. --- libs/gamecode/opcodes.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libs/gamecode/opcodes.py b/libs/gamecode/opcodes.py index 896d11b38..bbd863371 100644 --- a/libs/gamecode/opcodes.py +++ b/libs/gamecode/opcodes.py @@ -488,19 +488,22 @@ scale_formats = { }, } shiftops_formats = { - "opcode": "OP_{mn_shift[u*2+r].upper()}_{shift_type[u*2+t]}_{ss+1}", - "mnemonic": "{mn_shift[u*2+r]}.{shift_type[u*2+t]}", + "opcode": "OP_{mn_shift[u*2+r].upper()}_{shift_type[t][u*2+r]}_{ss+1}", + "mnemonic": "{mn_shift[u*2+r]}.{shift_type[t][u*2+r]}", "opname": "{op_shift[u*2+r]}", "widths": "{ss+1}, {ss+1}, {ss+1}", "columns": "1, 1, 1", - "types": "{shift_types[t][u]}, {shift_types[t][0]}, {shift_types[t][u]}", + "types": "{shift_types[t][u*2+r]}, {shift_types[t][0]}, {shift_types[t][u*2+r]}", "args": { "mn_shift": ["shl", "asr", "shl", "shr"], "op_shift": ["shl", "shr", "shl", "shr"], - "shift_type": ['I', 'L', 'u', 'U'], + "shift_type": [ + ['I', 'I', 'u', 'u'], + ['L', 'L', 'U', 'U'], + ], "shift_types": [ - ["ev_int", "ev_uint"], - ["ev_long", "ev_ulong"], + ["ev_int", "ev_int", "ev_uint", "ev_uint"], + ["ev_long", "ev_long", "ev_ulong", "ev_ulong"], ], }, }