self.comb += unmasked_loaded_value.eq(Cat(b0, b1, b23))
+ # XXX not obvious
+ loaded_value = Signal(32)
+
+ b0 = unmasked_loaded_value[0:8]
+ b1 = Mux(decoder_funct3[0:2] == 0,
+ Replicate(~decoder_funct3[2] & unmasked_loaded_value[7], 8),
+ unmasked_loaded_value[8:16])
+ b2 = Mux(decoder_funct3[1] == 0,
+ Replicate(~decoder_funct3[2] &
+ Mux(decoder_funct3[0], unmasked_loaded_value[15],
+ unmasked_loaded_value[7]),
+ 16),
+ unmasked_loaded_value[16:32])
+
+ self.comb += loaded_value.eq(Cat(b0, b1, b2))
+
if __name__ == "__main__":
example = CPU()
print(verilog.convert(example,
"""
- wire [31:0] loaded_value;
-
- assign loaded_value[7:0] = unmasked_loaded_value[7:0];
- assign loaded_value[15:8] = decoder_funct3[1:0] == 0 ? ({8{~decoder_funct3[2] & unmasked_loaded_value[7]}}) : unmasked_loaded_value[15:8];
- assign loaded_value[31:16] = decoder_funct3[1] == 0 ? ({16{~decoder_funct3[2] & (decoder_funct3[0] ? unmasked_loaded_value[15] : unmasked_loaded_value[7])}}) : unmasked_loaded_value[31:16];
-
assign memory_interface_rw_active = ~reset
& (fetch_output_state == `fetch_output_state_valid)
& ~load_store_misaligned