contributed by < RayChen
>
Selected Question
I chose the Find Leftmost 0-byte using CLZ
as my assignment from ι³ε·ζ.
The motivation is because I'm interested in his project, especially since my HW1 also involved the application of CLZ. I didn't realize there could be this kind of application, and I'd like to gain a deeper understanding of his code. I want to explore if there are ways to enhance its efficiency and contribute to his project.
Analysis Origin Code
Checking cycle counts from C code
1. C code
2. Makefile for C code
Using the gcc command converting .c file -> .S file -> .o file -> .elf file.
3. Output of cycle
The red underlined part represents the printed cycle count.

Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More β
Don't put the screenshots which contain plain text only. Instead, utilize HackMD syntax to annotate the text.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More β
jserv
4. Problem encountered during the process

Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More β
Don't put the screenshots which contain plain text only. Instead, utilize HackMD syntax to annotate the text.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More β
jserv
Solution: change the uppercase 'S' to lowercase in the makefile.
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More β
Using optimization to optimize cycle count
1. Add -On command(n represent 0~3 or fast)
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More β
2. Print out cycle count
Optimization level |
Cycles count |
-O0 |
741 |
-O1 |
204 |
-O2 |
204 |
-O3 |
0 |
-Ofast |
0 |
Analysis: I think the cycle count is 0 because the optimizer considers the part where I calculate the cycle count as non-essential code, so it optimizes it out.
Checking cycle counts from Assembly code
1. Using get_cycles function
2. Makefile for Assembly code
Using the assembler command converting .S file -> .o file
Using the linker command converting .o file -> .elf file.
3. rv32emu print out decimal
Although the code mentioned above can print the cycle count, but the rv32emu doesn't support the printf function. Therefore, we need to first store the cycle count's individual digits and convert them into ASCII codes to display it.
The code is display bellow:
4. Output of cycle

5. Problem encountered during the process
β Problem 1:
ββ The error said that I redefined _start
argument
ββ Reason : No linking file specified for the linker.

β Solution 1:
ββ Add -T hugohw.ld in command.

β Problem 2:
ββ When executing the Makefile, the "csrr" instruction cannot be executed.
ββ Reason : Incorrect compiler architecture

β Solution 2:

Rewrite and Optimize Assembly code