From 3ed2e1f891da98a8d9ec711be058ae7f06556e5d Mon Sep 17 00:00:00 2001 From: Alex Mykyta Date: Fri, 7 Mar 2025 19:39:57 -0800 Subject: [PATCH] Simplify stickybit implementation for single-bit fields to not create redundant expression. #127 --- .../field_logic/hw_interrupts.py | 83 ++++++++++++------- 1 file changed, 55 insertions(+), 28 deletions(-) diff --git a/src/peakrdl_regblock/field_logic/hw_interrupts.py b/src/peakrdl_regblock/field_logic/hw_interrupts.py index e4ed0cc..85d4446 100644 --- a/src/peakrdl_regblock/field_logic/hw_interrupts.py +++ b/src/peakrdl_regblock/field_logic/hw_interrupts.py @@ -46,15 +46,24 @@ class Stickybit(NextStateConditional): def get_predicate(self, field: 'FieldNode') -> str: F = self.exp.hwif.get_input_identifier(field) - return f"{F} != '0" + if field.width == 1: + return str(F) + else: + return f"{F} != '0" def get_assignments(self, field: 'FieldNode') -> List[str]: - I = self.exp.hwif.get_input_identifier(field) - R = self.exp.field_logic.get_storage_identifier(field) - return [ - f"next_c = {R} | {I};", - "load_next_c = '1;", - ] + if field.width == 1: + return [ + "next_c = '1;", + "load_next_c = '1;", + ] + else: + I = self.exp.hwif.get_input_identifier(field) + R = self.exp.field_logic.get_storage_identifier(field) + return [ + f"next_c = {R} | {I};", + "load_next_c = '1;", + ] class PosedgeStickybit(NextStateConditional): """ @@ -74,13 +83,19 @@ class PosedgeStickybit(NextStateConditional): return f"(~{Iq} & {I}) != '0" def get_assignments(self, field: 'FieldNode') -> List[str]: - I = self.exp.hwif.get_input_identifier(field) - Iq = self.exp.field_logic.get_next_q_identifier(field) - R = self.exp.field_logic.get_storage_identifier(field) - return [ - f"next_c = {R} | (~{Iq} & {I});", - "load_next_c = '1;", - ] + if field.width == 1: + return [ + "next_c = '1;", + "load_next_c = '1;", + ] + else: + I = self.exp.hwif.get_input_identifier(field) + Iq = self.exp.field_logic.get_next_q_identifier(field) + R = self.exp.field_logic.get_storage_identifier(field) + return [ + f"next_c = {R} | (~{Iq} & {I});", + "load_next_c = '1;", + ] class NegedgeStickybit(NextStateConditional): """ @@ -100,13 +115,19 @@ class NegedgeStickybit(NextStateConditional): return f"({Iq} & ~{I}) != '0" def get_assignments(self, field: 'FieldNode') -> List[str]: - I = self.exp.hwif.get_input_identifier(field) - Iq = self.exp.field_logic.get_next_q_identifier(field) - R = self.exp.field_logic.get_storage_identifier(field) - return [ - f"next_c = {R} | ({Iq} & ~{I});", - "load_next_c = '1;", - ] + if field.width == 1: + return [ + "next_c = '1;", + "load_next_c = '1;", + ] + else: + I = self.exp.hwif.get_input_identifier(field) + Iq = self.exp.field_logic.get_next_q_identifier(field) + R = self.exp.field_logic.get_storage_identifier(field) + return [ + f"next_c = {R} | ({Iq} & ~{I});", + "load_next_c = '1;", + ] class BothedgeStickybit(NextStateConditional): """ @@ -126,13 +147,19 @@ class BothedgeStickybit(NextStateConditional): return f"{Iq} != {I}" def get_assignments(self, field: 'FieldNode') -> List[str]: - I = self.exp.hwif.get_input_identifier(field) - Iq = self.exp.field_logic.get_next_q_identifier(field) - R = self.exp.field_logic.get_storage_identifier(field) - return [ - f"next_c = {R} | ({Iq} ^ {I});", - "load_next_c = '1;", - ] + if field.width == 1: + return [ + "next_c = '1;", + "load_next_c = '1;", + ] + else: + I = self.exp.hwif.get_input_identifier(field) + Iq = self.exp.field_logic.get_next_q_identifier(field) + R = self.exp.field_logic.get_storage_identifier(field) + return [ + f"next_c = {R} | ({Iq} ^ {I});", + "load_next_c = '1;", + ] class PosedgeNonsticky(NextStateUnconditional): """