From 6d0bc8538bde71f99b8b3b405d6cce1cb4d90dee Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Sun, 19 Oct 2025 15:31:10 -0500 Subject: [PATCH] assembler: add support for VE_SAT/ME_SAT --- regs/assembler/emitter.py | 7 ++++++- regs/assembler/keywords.py | 2 ++ regs/assembler/parser.py | 16 +++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/regs/assembler/emitter.py b/regs/assembler/emitter.py index 53bbb62..d45538f 100644 --- a/regs/assembler/emitter.py +++ b/regs/assembler/emitter.py @@ -38,16 +38,21 @@ def emit_destination_op(dst_op: DestinationOp): math_inst = int(type(dst_op.opcode) is ME) if dst_op.macro: assert dst_op.opcode.value in {0, 1} + ve_sat = int((not math_inst) and dst_op.sat) + me_sat = int(math_inst and dst_op.sat) + value = ( pvs_dst.OPCODE_gen(dst_op.opcode.value) | pvs_dst.MATH_INST_gen(math_inst) + | pvs_dst.MACRO_INST_gen(int(dst_op.macro)) | pvs_dst.REG_TYPE_gen(dst_reg_type(dst_op.type)) | pvs_dst.OFFSET_gen(dst_op.offset) | pvs_dst.WE_X_gen(we_x(dst_op.write_enable)) | pvs_dst.WE_Y_gen(we_y(dst_op.write_enable)) | pvs_dst.WE_Z_gen(we_z(dst_op.write_enable)) | pvs_dst.WE_W_gen(we_w(dst_op.write_enable)) - | pvs_dst.MACRO_INST_gen(int(dst_op.macro)) + | pvs_dst.VE_SAT_gen(ve_sat) + | pvs_dst.ME_SAT_gen(me_sat) ) yield value diff --git a/regs/assembler/keywords.py b/regs/assembler/keywords.py index f0e6a05..3b3ae46 100644 --- a/regs/assembler/keywords.py +++ b/regs/assembler/keywords.py @@ -102,6 +102,7 @@ class KW(Enum): relative_a0 = auto() relative_i0 = auto() constant = auto() + saturation = auto() keywords = [ (KW.temporary , b"temporary" , b"temp"), @@ -114,6 +115,7 @@ keywords = [ (KW.relative_a0 , b"relative_a0" , None), (KW.relative_i0 , b"relative_i0" , None), (KW.constant , b"constant" , b"const"), + (KW.saturation , b"saturation" , b"sat"), ] def find_keyword(b: memoryview): diff --git a/regs/assembler/parser.py b/regs/assembler/parser.py index 40a6c13..1c7a651 100644 --- a/regs/assembler/parser.py +++ b/regs/assembler/parser.py @@ -25,6 +25,7 @@ class DestinationOp: offset: int write_enable: set[int] opcode: Union[VE, ME] + sat: bool macro: bool @dataclass @@ -173,8 +174,21 @@ class Parser: write_enable = parse_dest_write_enable(write_enable_token) self.consume(TT.equal, "expected equals") opcode = self.opcode() + sat = False + if self.match(TT.dot): + self.advance() + suffix = self.consume(TT.keyword, "expected saturation suffix") + if suffix.keyword is not KW.saturation: + raise ParserError("expected saturation suffix", token) + sat = True + macro = False - return DestinationOp(destination_type, offset_value, write_enable, opcode, macro) + return DestinationOp(type=destination_type, + offset=offset_value, + write_enable=write_enable, + opcode=opcode, + sat=sat, + macro=macro) def source_type(self): token = self.consume(TT.keyword, "expected source type")