Skip to content

Commit bc44c23

Browse files
committed
Optimize mlogsys.decode for size
1 parent 0b5e696 commit bc44c23

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

src/config/base.mlog.jinja

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
op add MEMORY_X @thisx MEMORY_X_OFFSET # absolute x position of bottom left memory proc
3131
op add MEMORY_Y @thisy MEMORY_Y_OFFSET # absolute y position of bottom left memory proc
3232

33+
op min PROGRAM_ROM_ICACHE_SIZE PROGRAM_ROM_SIZE ICACHE_SIZE
34+
3335
op add ROM_SIZE PROGRAM_ROM_SIZE DATA_ROM_SIZE
3436

3537
op add RAM_END {{RAM_START}} RAM_SIZE
@@ -56,6 +58,7 @@ set {{RAM_START}} null
5658
set _ BREAKPOINT_ADDRESS
5759
set _ MEMORY_WIDTH
5860
set _ ROM_SIZE
61+
set _ PROGRAM_ROM_ICACHE_SIZE
5962
set _ UART_FIFO_MODULO
6063
set _ MEMORY_X
6164
set _ MEMORY_Y

src/cpu/worker.mlog.jinja

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
#% set labels = namespace()
2626
#% set _labels_vals = (labels|namespace_dict).values()
2727

28-
#% set labels.next_tick = 14
28+
#% set labels.next_tick = 13
2929

30-
#% set labels.end_instruction_with_rd_and_poll_interrupts = 157
30+
#% set labels.end_instruction_with_rd_and_poll_interrupts = 156
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
@@ -47,10 +47,9 @@ reset:
4747
read MEMORY_X {{CONFIG}} "MEMORY_X"
4848
read MEMORY_Y {{CONFIG}} "MEMORY_Y"
4949
read MEMORY_WIDTH {{CONFIG}} "MEMORY_WIDTH"
50-
read PROGRAM_ROM_SIZE {{CONFIG}} "ROM_SIZE"
50+
read PROGRAM_ROM_ICACHE_SIZE {{CONFIG}} "PROGRAM_ROM_ICACHE_SIZE"
5151
read ROM_SIZE {{CONFIG}} "ROM_SIZE"
5252
read RAM_SIZE {{CONFIG}} "RAM_SIZE"
53-
read ICACHE_SIZE {{CONFIG}} "ICACHE_SIZE"
5453
read RAM_END {{CONFIG}} "RAM_END"
5554
read ICACHE_END {{CONFIG}} "ICACHE_END"
5655
read RAM_ICACHE_OFFSET {{CONFIG}} "RAM_ICACHE_OFFSET"
@@ -2731,27 +2730,31 @@ MLOGSYS:
27312730
jump ILLEGAL_OP lessThan privilege_mode 0b11
27322731

27332732
# round up to the nearest page boundary
2734-
op div rs1 rs1 4096
2735-
op ceil rs1 rs1
2736-
op mul rs1 rs1 4096
2733+
# if we're exactly on a page boundary, this results in decoding one extra page
2734+
# we use "variable" for this so we don't need to use an instruction to explicitly set it to null
2735+
# since we know reading from INCR at a numeric address will return null
2736+
op add variable rs1 4096
2737+
op and variable variable 0xfffff000
27372738

2738-
op min __etext rs1 PROGRAM_ROM_SIZE
2739-
op min __etext __etext ICACHE_SIZE
2739+
op min __etext variable PROGRAM_ROM_ICACHE_SIZE
27402740

2741-
set address 0
2742-
set variable null
2741+
# start at -4 so the first address read is 0
2742+
set address -4
2743+
2744+
#% set mlogsys_decode_loop = 5
2745+
#directive start_assert_length {{ mlogsys_decode_loop }}
2746+
op add address address 4
2747+
read variable {{INCR}} variable
27432748

2744-
MLOGSYS__decode_loop:
27452749
# load_rom_word_unchecked does not clobber ram or variable
27462750
op add ret @counter 1
2747-
jump load_rom_word_unchecked always
2748-
2749-
op add ret3 @counter 1
2750-
jump decode_value_in_result always
2751-
read variable {{INCR}} variable
2751+
jump load_rom_word_unchecked lessThan address __etext
27522752

2753-
op add address address 4
2754-
jump MLOGSYS__decode_loop lessThan address __etext
2753+
# if address is in range, decode returns to the top of this loop
2754+
# otherwise, we continue to end_instruction
2755+
op sub ret3 @counter {{# mlogsys_decode_loop }}
2756+
#directive end_assert_length
2757+
jump decode_value_in_result lessThan address __etext
27552758

27562759
jump end_instruction always
27572760

0 commit comments

Comments
 (0)