Skip to content

Commit 4e61987

Browse files
committed
Remove local9 variable and optimize decode entry
1 parent 84096e0 commit 4e61987

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/cpu/worker.mlog.jinja

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
#% set labels.next_tick = 14
2929

30-
#% set labels.end_instruction_with_rd_and_poll_interrupts = 153
30+
#% set labels.end_instruction_with_rd_and_poll_interrupts = 152
3131
#% set labels.end_instruction_with_rd_and_fire_interrupts = _labels_vals|last + 1
3232
#% set labels.end_instruction_with_rd = _labels_vals|last + 1
3333
#% set labels.end_instruction = _labels_vals|last + 2
@@ -78,7 +78,6 @@ reset:
7878
read {{local_variable()}} prev_proc "{{ local_variable(6) }}"
7979
read {{local_variable()}} prev_proc "{{ local_variable(7) }}"
8080
read {{local_variable()}} prev_proc "{{ local_variable(8) }}"
81-
read {{local_variable()}} prev_proc "{{ local_variable(9) }}"
8281

8382
read nonlocal1 prev_proc "nonlocal1"
8483
read nonlocal2 prev_proc "nonlocal2"
@@ -1016,6 +1015,7 @@ load_mmio_word__not_zero:
10161015
set @counter ret
10171016

10181017
load_mmio_word__uart_rhr:
1018+
#% do declare_locals(access_uart_locals)
10191019
# HACK: if mcause is 7, we're loading this word as part of a store instruction, so return 0 and don't modify UART state
10201020
jump load_mmio_word__uart_rhr__empty equal mcause 7
10211021

@@ -1032,6 +1032,7 @@ load_mmio_word__uart_rhr__empty:
10321032
set @counter ret
10331033

10341034
load_mmio_word__uart_lsr:
1035+
#% do declare_locals(access_uart_locals)
10351036
# Line Status Register: transmitter/THR empty = TX FIFO empty, overrun error = RX FIFO overflowed, data ready = RX FIFO not empty, other flags 0
10361037

10371038
# transmitter empty and THR empty
@@ -1066,23 +1067,23 @@ load_mmio_word__uart_lsr__no_rx_overrun:
10661067
decode:
10671068
#% set decode_locals = ["$$imm_4_0", "$$funct12", "$$funct7", "$$funct3"]
10681069
#% do declare_locals(decode_locals)
1070+
# decode and pack registers into the payload
1071+
op and result value 0b1111111111000000000000000 # rs1/rs2
1072+
10691073
# the lowest 2 bits are always "11" for non-compressed instructions
1070-
# check this first to increase the odds of an early exit for non-code addresses
1074+
# check this here to increase the odds of an early exit for non-code addresses
1075+
# this needs to be after putting a value in result so we don't potentially corrupt op_id
10711076
op and $tmp value 0b11
10721077
jump decode_illegal_instruction notEqual $tmp 0b11
10731078

1074-
# opcode
1075-
op and $opcode value 0b1111111
1079+
# continue packing registers
1080+
op and $instruction_11_7 value 0b0000000000000111110000000
10761081

1077-
# decode and pack registers into the payload
1078-
op and $icache_payload_rs2_rs1 value 0b1111111111000000000000000
1079-
op and $instruction_11_7 value 0b0000000000000111110000000
1080-
1081-
op shl $icache_payload_rs2_rs1 $icache_payload_rs2_rs1 22 # instruction[24:15] -> icache_payload[46:37]
1082+
op shl result result 22 # instruction[24:15] -> icache_payload[46:37]
10821083
op shl $icache_payload_rd $instruction_11_7 25 # instruction[11:7] -> icache_payload[36:32]
10831084

10841085
# we put the registers into the result variable here so that we don't have to fully pack the payload if decoding during instruction fetch
1085-
op add result $icache_payload_rs2_rs1 $icache_payload_rd
1086+
op add result result $icache_payload_rd
10861087

10871088
# this is used in both S-type and B-type
10881089
op shr $$imm_4_0 $instruction_11_7 7 # instruction[11:7] -> imm[4:0]
@@ -1101,7 +1102,8 @@ decode:
11011102

11021103
# jump table based on (opcode >> 2) since the low 2 bits don't matter
11031104
# the jump table is stored in LABELS by the controller, starting at index 128
1104-
op shr $tmp $opcode 2
1105+
op and $tmp value 0b1111111
1106+
op shr $tmp $tmp 2
11051107
op add $tmp $tmp 128
11061108
read @counter {{LABELS}} $tmp
11071109

@@ -1381,8 +1383,6 @@ decode_custom-0:
13811383
decode_illegal_instruction:
13821384
# use 0 as the illegal instruction id because null coerces to 0
13831385
set op_id 0
1384-
# this is required to prevent the op_id field from theoretically being corrupted if we jump here before setting result in decode
1385-
set result 0
13861386
# continue into end_decode
13871387

13881388
# all decoders jump here after completing successfully
@@ -1748,6 +1748,7 @@ store_mmio_word_unchecked:
17481748
# NOTE: we don't check for overflow here, see readme
17491749
# also, we don't truncate the value to 8 bits when writing
17501750
# software can take advantage of this to send larger packets if the receiver can handle them
1751+
#% do declare_locals(access_uart_locals)
17511752
op add $tmp $$tx_write {{UART_TX_START}}
17521753
write value $$uart $tmp
17531754

@@ -1761,6 +1762,7 @@ store_mmio_word_unchecked:
17611762
store_mmio_word_unchecked__uart_fcr:
17621763
# FIFO Control Register
17631764

1765+
#% do declare_locals(access_uart_locals)
17641766
op and $tmp value 0b11
17651767
jump store_mmio_word_unchecked__uart_fcr__no_reset_rx equal $tmp 0
17661768
write $$rx_write $$uart {{UART_RX_READ}}

0 commit comments

Comments
 (0)