contributed by < paulpeng-popo
>
I selected Bitwise AND of Numbers Range from JoshuaLee
, because its concept is similar to my topic which I have chosen in assignment 1.
This question is asking us to find the common prefix of left and right 's binary code.
To find the common prefix of left and right, we can shift both of them to the right until they are equal.
After making optimization by JoshuaLee
it looks like
He uses bitmask trick to remove loops in previous implementation.
To compare between these two function, I add read_cycles
to calculate how much clock cycles will take during execution.
And modify main()
Compile it
Result of execution on rv32emu
Disassembly of a.elf
Display the a.elf
header
Program size
According to rv32emu docs, rv32emu
does not support printf system call.
Error will be like
TODO: Modify assembly code
From gcc man page, there’s 8 different valid -O options
Optimization Options
-faggressive-loop-optimizations
…
-fweb -fwhole-program -fwpa -fuse-linker-plugin –param
name=value -O -O0 -O1 -O2 -O3 -Os -Ofast -Og
In Makefile, we add OPT
for variable to change compilation settings.
Default is -O0
Below we can observe at code size and cycle count it took
Cycle Count: 1573
Cycle Count: 1493
Cycle Count: 1493
Cycle Count: 1452
Cycle Count: 1493
Cycle Count: 1452
Cycle Count: 1506
CSR
Name | cycle count | size |
---|---|---|
O0 | 1573 | 51524 |
O1 | 1493 | 51194 |
O2 | 1493 | 51186 |
O3 | 1452 | 51256 |
Os | 1493 | 51188 |
Ofast | 1452 | 51256 |
Besides option -O0
, other options explicitly reduce the cycle count. The reason could be that the code is too simple, there is no more room for optimization.
And with option -Os
, it indeed reduce the code size compare to others.
Improve your English writing. Explain more according to the experiments.
:notes: jserv