Try   HackMD

Assignment2: RISC-V Toolchain

Due: Oct 31, 2022

Requirements

  1. Following the instructions of Lab2: RISC-V RV32I[MACF] emulator with ELF support, pick up one assembly program listed at Assignment1: RISC-V Assembly and Instruction Pipeline and adapt it into both RISC-V assembly and C implementations which can be flawlessly executed with rv32emu.
    • You must NOT pick up the program(s) that you have previously submitted on your own.
    • You should briefly describe your motivations for picking up.
    • You may choose to study the same subject as other students, but you must make your own discoveries.
    • There are just RV32I instructions that can be used. This means that you MUST build C programs with the -march=rv32i -mabi=ilp32 flags.
      • RV32M (multiply and divide) and RV32F (single-precision floating point) are not permitted.
    • 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 →
      rv32emu and Ripes may not work together, therefore please be aware of the potential incompatibility. Please check docs/syscall.md and src/syscall.c in advance.
    • Do not duplicate workspaces or the entire repository from rv32emu. As a starting point, copy the asm-hello directory instead. You shall modify Makefile and the linker script accordingly.
    • kdnvt produced some excellent work that can be used as a benchmark for program analysis and future optimizations. Please read his report carefully and pay attention to certain suggestions and observations.
    • (Optional) You have the choice to choose the programs, pi.c and nqueens.c, and create RISC-V assembly that is superior to that produced by GNU Toolchain. That is, your handwritten RISC-V assembly program should run more quickly and occupy less space in the ELF image.
  2. Disassemble the ELF files produced by the C compiler and contrast the handwritten and compiler-optimized assembly listings.
    • You can append the compilation options to experiment. e.g., Change -Ofast (optimized for speed) to -Os (optimized for size).
    • Describe your obserations and explain.
  3. Check the results of rv32emu --stats for the statistics of your program's execution. Then, try to optimize the handwritten/generated assembly. You shall read RISC-V Assembly Programmer's Manual carefully.
    • 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 →
      We care about CSR cycles at the moment.
    • Can you improve the assembly code generated by gcc with optimizations? Or, can you write even faster/smaller programs in RISC-V assembly?
    • You may drop some function calls and apply techniques such as loop unrolling and peephole optimization.
  4. Write down your thoughts and progress in HackMD notes.
    • Example page

      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 →
      Do not modify this note.

    • Insert your HackMD notes and programs in the following table.
    • Of course, you MUST write in English.
  5. BONUS: Find the bugs inside rv32emu and send pull requests to improve it!

Fill in the table for your homework

Formal given name Descriptions HackMD note
Sample1 Sort Colors Homework2
Sample2 Length of Last Word Homework2
Sample3 Single number Homework2
黃昱澄 Decompress Run-Length Encoded List Homework2
王昱承 Decode XORed Array Homework2
黃冠予 Find Numbers with Even Number of Digits Homework2
賴致文 Build Array from Permutation Homework2
王漢祺 Move zeroes Homework2
江坤諦 Valid Anagram Homework2
俞杉麒 Running Sum of 1d Array Homework2
張瑞甫 Best Time to Buy and Sell Stock II Homework2
黃榆哲 Jewels and Stones Homework2
鄒崴丞 Length of Last Word Homework2
何坤霖 Find Target Indices After Sorting Array Homework2
吳宇晨 Majority Element Homework2
潘鴻福 Contains Duplicate Homework2
謝長成 Find the Highest Altitude Homework2
杜孟聰 Monotonic Array Homework2
洪嘉志 Reverse Linked List Homework2
鄭至崴 Convert Binary Number in a Linked List to Integer Homework2
陳彥甫 Long Pressed Name Homework2
莊集 Roman to Integer Homework2
鄭明奇 Concatenation of Array Homework2
陳韋勳 Pascal’s Triangle II Homework2
吳紀寬 Lemonade Change Homework2
吳峻廷 Binary Search Homework2
張中龍 Single Number Homework2
蘇勇達 Three Consecutive Odds Homework2
方宣翔 Move Zeroes Homework2
馮柏為 Two sum Homework2
楊淳皓 Search Insert Position Homework2
黃柏瑜 Best Time to Buy and Sell Stock Homework2
陳嘉晟 Invert Binary Tree Homework2
陳品崴 Find the Highest Altitude Homework2
周士翔 Pascal’s triangle Homework2
陳靖雯 Contains Duplicate Homework2
曾晧峖 Decode XORed Array Homework2
吳昱 Monotonic Array Homework2
李協儒 Run-Length Encoded List Homework2
陳柏瑋 Remove Linked List Elements Homework2