DotandLog
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- tags: computer architure 2022 --- # Assignment 2: RISC-V Toolchain ## Problem description: - This problem is based on [LeetCode 1929](https://leetcode.com/problems/concatenation-of-array/) from [楊淳皓](https://hackmd.io/@Vgwl_uixQFasIvsDbsFlvA/risc-v-hw1). - motivation:In assignment 1,I tried to practice pointer in assembly,so in assignment 2,I want to practice with array. ## Code implementation - Origin C code is From [楊淳皓](https://hackmd.io/@Vgwl_uixQFasIvsDbsFlvA/risc-v-hw1) ```c= #include <stdio.h> #include <stdlib.h> int main(){ int a[3] = {1, 2, 3}; int b[6]; int i; for(i=0; i<3; i++){ b[i]=a[i]; b[i+3]=a[i]; } for(i=0; i<3*2; i++) { printf("%d ", b[i]); } return 0; } ``` - Modified C code ```c= #include <stdio.h> #include <stdlib.h> int* getConcatenation(int* nums, int numsSize) { int returnSize = numsSize * 2; int* ans = (int*)malloc(sizeof(int) * (numsSize * 2)); int i = 0; for (i = 0; i < numsSize; i++) { ans[i] = nums[i]; ans[i + numsSize] = nums[i]; } return ans; } int main() { int a[3] = {1, 2, 3}; int* b = getConcatenation(a, 3); for (int i = 0; i < 6; i++) { printf("%d ", b[i]); } return 0; } ``` - Origin Assembly code ```clike= .data arr1: .word 1, 2, 3 # a[3] = {1, 2, 3} len1: .word 3 # array length of a is 3 space: .string " " # space .text # s1 = arr a base address # s2 = arr b base address # s3 = array length of a # t0 = i # t1 = a[i] # t2 = b[i] # s4 = temp[i] main: la s1, arr1 # s1 = a lw s3, len1 # s3 = 3 add t0, x0, x0 # i = 0 jal ra, loopCon # jump to loop for concatenation add t0, x0, x0 # i = 0 jal ra, loopPrint # jump to loop for print jal ra, exit # jump to exit loopCon: lw t1, 0(s1) # t1 = a[i] sw t1, 0(s2) # b[i] = t1 sw t1, 0(s4) # temp[i] = t1 addi s1, s1, 4 # address move forward addi s2, s2, 4 # address move forward addi s4, s4, 4 addi t0, t0, 1 # i++ blt t0, s3, loopCon # if i < 3, go to loopCon ret # else, return to main loopPrint: lw t2, 0(s2) # t2 = b[i] addi s2, s2, 4 # address move forward add a0, t2, x0 # load result of array b li a7, 1 # print integer ecall la a0, space # load string - space li a7, 4 # print string ecall addi t0, t0, 1 # i++ blt t0, s3, loopPrint # if i < 3, go to loopPrint add t0, x0, x0 then: lw t2, 0(s4) addi s4, s4, 4 li a7 1 ecall la a0, space li a7, 4 ecall addi t0, t0, 1 blt t0, s3, then ret # else, return to main exit: li a7, 10 # end program ecall ``` - Modified Assembly code :::info Since the original code can't print the right output,I did some modeify. ::: ```clike= .data arr1: .word 1, 2, 3 # a[3] = {1, 2, 3} len1: .word 3 # array length of a is 3 space: .string " " # space .text # s1 = arr a base address # s2 = arr b base address # s3 = array length of a # t0 = i # t1 = a[i] # t2 = b[i] # s4 = temp[i] main: la s1, arr1 # s1 = a[] lw s3, len1 # s3 = 3 mv s5, s2 mv s6, s4 add t0, x0, x0 # i = 0 loopCon: lw t1, 0(s1) # t1 = a[i] sw t1, 0(s2) # b[i] = t1 sw t1, 0(s4) # temp[i] = t1 addi s1, s1, 4 # address move forward addi s2, s2, 4 # address move forward addi s4, s4, 4 # address move forward addi t0, t0, 1 # i++ blt t0, s3, loopCon # if i < 3, go to loopCon add t0, x0, x0 # i = 0 loopPrint: lw t2, 0(s5) # t2 = b[i] addi s5, s5, 4 # address move forward add a0, t2, x0 # load result of array b li a7, 1 # print integer ecall la a0, space # load string - space li a7, 4 # print string ecall addi t0, t0, 1 # i++ blt t0, s3, loopPrint # if i < 3, go to loopPrint add t0, x0, x0 # set i = 0 then: lw t2, 0(s6) # t2 = temp[i] addi s6, s6, 4 # address move forward add a0, t2, x0 # load result of array temp li a7 1 # print integer ecall la a0, space # load string - space li a7, 4 # print string ecall addi t0, t0, 1 # i++ blt t0, s3, then # if i < 3, go then exit: li a7, 10 # end program ecall ``` - Clock cycle ![](https://i.imgur.com/lzELuZi.png) ## Environment setup - Follow [lab2]()'s instructions to install rv32emu and GNU Toolchain for RISC-V. ## Instructions * Compile ```shell $ riscv-none-elf-gcc -march=rv32i -mabi=ilp32 -compilation options(e.g., -Ofast, -Os, etc.) -o output input.c ``` * Objdump ```shell $ riscv-none-elf-objdump -d output > output.txt ``` * Readelf ```shell $ riscv-none-elf-readelf -h output ``` * Size ```shell $ riscv-none-elf-size output ``` * Execute and Statistics of execution ```shell $ build/rv32emu --stats .output ``` ## Compare Assembly code ### -O0 #### Assembly Code - main ``` clike= 00010254 <main>: 10254: fd010113 addi sp,sp,-48 10258: 02112623 sw ra,44(sp) 1025c: 02812423 sw s0,40(sp) 10260: 03010413 addi s0,sp,48 10264: 00100793 li a5,1 10268: fcf42e23 sw a5,-36(s0) 1026c: 00200793 li a5,2 10270: fef42023 sw a5,-32(s0) 10274: 00300793 li a5,3 10278: fef42223 sw a5,-28(s0) 1027c: fdc40793 addi a5,s0,-36 10280: 00300593 li a1,3 10284: 00078513 mv a0,a5 10288: efdff0ef jal ra,10184 <getConcatenation> 1028c: fea42423 sw a0,-24(s0) 10290: fe042623 sw zero,-20(s0) 10294: 0340006f j 102c8 <main+0x74> 10298: fec42783 lw a5,-20(s0) 1029c: 00279793 slli a5,a5,0x2 102a0: fe842703 lw a4,-24(s0) 102a4: 00f707b3 add a5,a4,a5 102a8: 0007a783 lw a5,0(a5) 102ac: 00078593 mv a1,a5 102b0: 000217b7 lui a5,0x21 102b4: 76878513 addi a0,a5,1896 # 21768 <__clzsi2+0x88> 102b8: 1fd000ef jal ra,10cb4 <printf> 102bc: fec42783 lw a5,-20(s0) 102c0: 00178793 addi a5,a5,1 102c4: fef42623 sw a5,-20(s0) 102c8: fec42703 lw a4,-20(s0) 102cc: 00500793 li a5,5 102d0: fce7d4e3 bge a5,a4,10298 <main+0x44> 102d4: 00000793 li a5,0 102d8: 00078513 mv a0,a5 102dc: 02c12083 lw ra,44(sp) 102e0: 02812403 lw s0,40(sp) 102e4: 03010113 addi sp,sp,48 102e8: 00008067 ret ``` - getConcatenation ```clike= 00010184 <getConcatenation>: 10184: fd010113 addi sp,sp,-48 10188: 02112623 sw ra,44(sp) 1018c: 02812423 sw s0,40(sp) 10190: 03010413 addi s0,sp,48 10194: fca42e23 sw a0,-36(s0) 10198: fcb42c23 sw a1,-40(s0) 1019c: fd842783 lw a5,-40(s0) 101a0: 00179793 slli a5,a5,0x1 101a4: fef42423 sw a5,-24(s0) 101a8: fd842783 lw a5,-40(s0) 101ac: 00379793 slli a5,a5,0x3 101b0: 00078513 mv a0,a5 101b4: 23c000ef jal ra,103f0 <malloc> 101b8: 00050793 mv a5,a0 101bc: fef42223 sw a5,-28(s0) 101c0: fe042623 sw zero,-20(s0) 101c4: fe042623 sw zero,-20(s0) 101c8: 0680006f j 10230 <getConcatenation+0xac> 101cc: fec42783 lw a5,-20(s0) 101d0: 00279793 slli a5,a5,0x2 101d4: fdc42703 lw a4,-36(s0) 101d8: 00f70733 add a4,a4,a5 101dc: fec42783 lw a5,-20(s0) 101e0: 00279793 slli a5,a5,0x2 101e4: fe442683 lw a3,-28(s0) 101e8: 00f687b3 add a5,a3,a5 101ec: 00072703 lw a4,0(a4) 101f0: 00e7a023 sw a4,0(a5) 101f4: fec42783 lw a5,-20(s0) 101f8: 00279793 slli a5,a5,0x2 101fc: fdc42703 lw a4,-36(s0) 10200: 00f70733 add a4,a4,a5 10204: fec42683 lw a3,-20(s0) 10208: fd842783 lw a5,-40(s0) 1020c: 00f687b3 add a5,a3,a5 10210: 00279793 slli a5,a5,0x2 10214: fe442683 lw a3,-28(s0) 10218: 00f687b3 add a5,a3,a5 1021c: 00072703 lw a4,0(a4) 10220: 00e7a023 sw a4,0(a5) 10224: fec42783 lw a5,-20(s0) 10228: 00178793 addi a5,a5,1 1022c: fef42623 sw a5,-20(s0) 10230: fec42703 lw a4,-20(s0) 10234: fd842783 lw a5,-40(s0) 10238: f8f74ae3 blt a4,a5,101cc <getConcatenation+0x48> 1023c: fe442783 lw a5,-28(s0) 10240: 00078513 mv a0,a5 10244: 02c12083 lw ra,44(sp) 10248: 02812403 lw s0,40(sp) 1024c: 03010113 addi sp,sp,48 10250: 00008067 ret ``` #### ELF file header: ``` ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: RISC-V Version: 0x1 Entry point address: 0x100dc Start of program headers: 52 (bytes into file) Start of section headers: 95000 (bytes into file) Flags: 0x0 Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 3 Size of section headers: 40 (bytes) Number of section headers: 15 Section header string table index: 14 ``` #### Size: ``` text data bss dec hex filename 74876 2816 812 78504 132a8 hw2_0 ``` #### Execute and Statistics of execution ``` 1 2 3 1 2 3 inferior exit code 0 CSR cycle count: 4514 ``` ### -O1 #### Assembly Code - main ``` clike= 000101f0 <main>: 101f0: fe010113 addi sp,sp,-32 101f4: 00112e23 sw ra,28(sp) 101f8: 00812c23 sw s0,24(sp) 101fc: 00912a23 sw s1,20(sp) 10200: 01212823 sw s2,16(sp) 10204: 00100793 li a5,1 10208: 00f12223 sw a5,4(sp) 1020c: 00200793 li a5,2 10210: 00f12423 sw a5,8(sp) 10214: 00300793 li a5,3 10218: 00f12623 sw a5,12(sp) 1021c: 00300593 li a1,3 10220: 00410513 addi a0,sp,4 10224: f61ff0ef jal ra,10184 <getConcatenation> 10228: 00050413 mv s0,a0 1022c: 01850913 addi s2,a0,24 10230: 000214b7 lui s1,0x21 10234: 00042583 lw a1,0(s0) 10238: 6e048513 addi a0,s1,1760 # 216e0 <__clzsi2+0x88> 1023c: 1f1000ef jal ra,10c2c <printf> 10240: 00440413 addi s0,s0,4 10244: ff2418e3 bne s0,s2,10234 <main+0x44> 10248: 00000513 li a0,0 1024c: 01c12083 lw ra,28(sp) 10250: 01812403 lw s0,24(sp) 10254: 01412483 lw s1,20(sp) 10258: 01012903 lw s2,16(sp) 1025c: 02010113 addi sp,sp,32 10260: 00008067 ret ``` - getConcatenation ```clike= 00010184 <getConcatenation>: 10184: ff010113 addi sp,sp,-16 10188: 00112623 sw ra,12(sp) 1018c: 00812423 sw s0,8(sp) 10190: 00912223 sw s1,4(sp) 10194: 00050493 mv s1,a0 10198: 00058413 mv s0,a1 1019c: 00359513 slli a0,a1,0x3 101a0: 1c8000ef jal ra,10368 <malloc> 101a4: 02805c63 blez s0,101dc <getConcatenation+0x58> 101a8: 00048713 mv a4,s1 101ac: 00241693 slli a3,s0,0x2 101b0: 00d507b3 add a5,a0,a3 101b4: 00d48833 add a6,s1,a3 101b8: 40800633 neg a2,s0 101bc: 00261613 slli a2,a2,0x2 101c0: 00072683 lw a3,0(a4) 101c4: 00c785b3 add a1,a5,a2 101c8: 00d5a023 sw a3,0(a1) 101cc: 00d7a023 sw a3,0(a5) 101d0: 00470713 addi a4,a4,4 101d4: 00478793 addi a5,a5,4 101d8: ff0714e3 bne a4,a6,101c0 <getConcatenation+0x3c> 101dc: 00c12083 lw ra,12(sp) 101e0: 00812403 lw s0,8(sp) 101e4: 00412483 lw s1,4(sp) 101e8: 01010113 addi sp,sp,16 101ec: 00008067 ret ``` #### ELF file header: ``` ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: RISC-V Version: 0x1 Entry point address: 0x100dc Start of program headers: 52 (bytes into file) Start of section headers: 95000 (bytes into file) Flags: 0x0 Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 3 Size of section headers: 40 (bytes) Number of section headers: 15 Section header string table index: 14 ``` #### Size: ``` text data bss dec hex filename 74740 2816 812 78368 13220 hw2_1 ``` #### Execute and Statistics of execution ``` 1 2 3 1 2 3 inferior exit code 0 CSR cycle count: 4470 ``` ### -O2 #### Assembly Code - main ``` clike= 000100c4 <main>: 100c4: fe010113 addi sp,sp,-32 100c8: 00100793 li a5,1 100cc: 00f12223 sw a5,4(sp) 100d0: 00200793 li a5,2 100d4: 00f12423 sw a5,8(sp) 100d8: 00300593 li a1,3 100dc: 00300793 li a5,3 100e0: 00410513 addi a0,sp,4 100e4: 00812c23 sw s0,24(sp) 100e8: 00912a23 sw s1,20(sp) 100ec: 01212823 sw s2,16(sp) 100f0: 00112e23 sw ra,28(sp) 100f4: 00f12623 sw a5,12(sp) 100f8: 100000ef jal ra,101f8 <getConcatenation> 100fc: 00050413 mv s0,a0 10100: 01850913 addi s2,a0,24 10104: 000214b7 lui s1,0x21 10108: 00042583 lw a1,0(s0) 1010c: 6e048513 addi a0,s1,1760 # 216e0 <__clzsi2+0x8c> 10110: 00440413 addi s0,s0,4 10114: 4b9000ef jal ra,10dcc <printf> 10118: ff2418e3 bne s0,s2,10108 <main+0x44> 1011c: 01c12083 lw ra,28(sp) 10120: 01812403 lw s0,24(sp) 10124: 01412483 lw s1,20(sp) 10128: 01012903 lw s2,16(sp) 1012c: 00000513 li a0,0 10130: 02010113 addi sp,sp,32 10134: 00008067 ret ``` - getConcatenation ```clike= 00101f8 <getConcatenation>: 101f8: ff010113 addi sp,sp,-16 101fc: 01212023 sw s2,0(sp) 10200: 00050913 mv s2,a0 10204: 00359513 slli a0,a1,0x3 10208: 00812423 sw s0,8(sp) 1020c: 00912223 sw s1,4(sp) 10210: 00112623 sw ra,12(sp) 10214: 00058413 mv s0,a1 10218: 14c000ef jal ra,10364 <malloc> 1021c: 00050493 mv s1,a0 10220: 02805263 blez s0,10244 <getConcatenation+0x4c> 10224: 00241413 slli s0,s0,0x2 10228: 00040613 mv a2,s0 1022c: 00090593 mv a1,s2 10230: 0cd000ef jal ra,10afc <memcpy> 10234: 00040613 mv a2,s0 10238: 00090593 mv a1,s2 1023c: 00848533 add a0,s1,s0 10240: 0bd000ef jal ra,10afc <memcpy> 10244: 00c12083 lw ra,12(sp) 10248: 00812403 lw s0,8(sp) 1024c: 00012903 lw s2,0(sp) 10250: 00048513 mv a0,s1 10254: 00412483 lw s1,4(sp) 10258: 01010113 addi sp,sp,16 1025c: 00008067 ret ``` #### ELF file header: ``` ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: RISC-V Version: 0x1 Entry point address: 0x10150 Start of program headers: 52 (bytes into file) Start of section headers: 95016 (bytes into file) Flags: 0x0 Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 3 Size of section headers: 40 (bytes) Number of section headers: 15 Section header string table index: 14 ``` #### Size: ``` text data bss dec hex filename 74736 2816 812 78364 1321c hw2_2 ``` #### Execute and Statistics of execution ``` 1 2 3 1 2 3 inferior exit code 0 CSR cycle count: 4514 ``` ### -O3 #### Assembly Code - main ``` clike= 000100c4 <main>: 100c4: fe010113 addi sp,sp,-32 100c8: 00100793 li a5,1 100cc: 00f12223 sw a5,4(sp) 100d0: 00200793 li a5,2 100d4: 00f12423 sw a5,8(sp) 100d8: 00300593 li a1,3 100dc: 00300793 li a5,3 100e0: 00410513 addi a0,sp,4 100e4: 00812c23 sw s0,24(sp) 100e8: 00912a23 sw s1,20(sp) 100ec: 01212823 sw s2,16(sp) 100f0: 00112e23 sw ra,28(sp) 100f4: 00f12623 sw a5,12(sp) 100f8: 100000ef jal ra,101f8 <getConcatenation> 100fc: 00050413 mv s0,a0 10100: 01850913 addi s2,a0,24 10104: 000214b7 lui s1,0x21 10108: 00042583 lw a1,0(s0) 1010c: 6e048513 addi a0,s1,1760 # 216e0 <__clzsi2+0x8c> 10110: 00440413 addi s0,s0,4 10114: 4b9000ef jal ra,10dcc <printf> 10118: ff2418e3 bne s0,s2,10108 <main+0x44> 1011c: 01c12083 lw ra,28(sp) 10120: 01812403 lw s0,24(sp) 10124: 01412483 lw s1,20(sp) 10128: 01012903 lw s2,16(sp) 1012c: 00000513 li a0,0 10130: 02010113 addi sp,sp,32 10134: 00008067 ret ``` - getConcatenation ```clike= 000101f8 <getConcatenation>: 101f8: ff010113 addi sp,sp,-16 101fc: 01212023 sw s2,0(sp) 10200: 00050913 mv s2,a0 10204: 00359513 slli a0,a1,0x3 10208: 00812423 sw s0,8(sp) 1020c: 00912223 sw s1,4(sp) 10210: 00112623 sw ra,12(sp) 10214: 00058413 mv s0,a1 10218: 14c000ef jal ra,10364 <malloc> 1021c: 00050493 mv s1,a0 10220: 02805263 blez s0,10244 <getConcatenation+0x4c> 10224: 00241413 slli s0,s0,0x2 10228: 00040613 mv a2,s0 1022c: 00090593 mv a1,s2 10230: 0cd000ef jal ra,10afc <memcpy> 10234: 00040613 mv a2,s0 10238: 00090593 mv a1,s2 1023c: 00848533 add a0,s1,s0 10240: 0bd000ef jal ra,10afc <memcpy> 10244: 00c12083 lw ra,12(sp) 10248: 00812403 lw s0,8(sp) 1024c: 00012903 lw s2,0(sp) 10250: 00048513 mv a0,s1 10254: 00412483 lw s1,4(sp) 10258: 01010113 addi sp,sp,16 1025c: 00008067 ret ``` #### ELF file header: ``` ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: RISC-V Version: 0x1 Entry point address: 0x10150 Start of program headers: 52 (bytes into file) Start of section headers: 95016 (bytes into file) Flags: 0x0 Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 3 Size of section headers: 40 (bytes) Number of section headers: 15 Section header string table index: 14 ``` #### Size: ``` text data bss dec hex filename 74736 2816 812 78364 1321c hw2_3 ``` #### Execute and Statistics of execution ``` 1 2 3 1 2 3 inferior exit code 0 CSR cycle count: 4514 ``` ### -Ofast #### Assembly Code - main ``` clike= 00100c4 <main>: 100c4: fe010113 addi sp,sp,-32 100c8: 00100793 li a5,1 100cc: 00f12223 sw a5,4(sp) 100d0: 00200793 li a5,2 100d4: 00f12423 sw a5,8(sp) 1000d8: 00300593 li a1,3 100dc: 00300793 li a5,3 100e0: 00410513 addi a0,sp,4 100e4: 00812c23 sw s0,24(sp) 100e8: 00912a23 sw s1,20(sp) 100ec: 01212823 sw s2,16(sp) 100f0: 00112e23 sw ra,28(sp) 100f4: 00f12623 sw a5,12(sp) 100f8: 100000ef jal ra,101f8 <getConcatenation> 100fc: 00050413 mv s0,a0 10100: 01850913 addi s2,a0,24 10104: 000214b7 lui s1,0x21 10108: 00042583 lw a1,0(s0) 1010c: 6e048513 addi a0,s1,1760 # 216e0 <__clzsi2+0x8c> 10110: 00440413 addi s0,s0,4 10114: 4b9000ef jal ra,10dcc <printf> 10118: ff2418e3 bne s0,s2,10108 <main+0x44> 1011c: 01c12083 lw ra,28(sp) 10120: 01812403 lw s0,24(sp) 10124: 01412483 lw s1,20(sp) 10128: 01012903 lw s2,16(sp) 1012c: 00000513 li a0,0 10130: 02010113 addi sp,sp,32 10134: 00008067 ret ``` - getConcatenation ```clike= 000101f8 <getConcatenation>: 101f8: ff010113 addi sp,sp,-16 101fc: 01212023 sw s2,0(sp) 10200: 00050913 mv s2,a0 10204: 00359513 slli a0,a1,0x3 10208: 00812423 sw s0,8(sp) 1020c: 00912223 sw s1,4(sp) 10210: 00112623 sw ra,12(sp) 10214: 00058413 mv s0,a1 10218: 14c000ef jal ra,10364 <malloc> 1021c: 00050493 mv s1,a0 10220: 02805263 blez s0,10244 <getConcatenation+0x4c> 10224: 00241413 slli s0,s0,0x2 10228: 00040613 mv a2,s0 1022c: 00090593 mv a1,s2 10230: 0cd000ef jal ra,10afc <memcpy> 10234: 00040613 mv a2,s0 10238: 00090593 mv a1,s2 1023c: 00848533 add a0,s1,s0 10240: 0bd000ef jal ra,10afc <memcpy> 10244: 00c12083 lw ra,12(sp) 10248: 00812403 lw s0,8(sp) 1024c: 00012903 lw s2,0(sp) 10250: 00048513 mv a0,s1 10254: 00412483 lw s1,4(sp) 10258: 01010113 addi sp,sp,16 1025c: 00008067 ret ``` #### ELF file header: ``` ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: RISC-V Version: 0x1 Entry point address: 0x10150 Start of program headers: 52 (bytes into file) Start of section headers: 95016 (bytes into file) Flags: 0x0 Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 3 Size of section headers: 40 (bytes) Number of section headers: 15 Section header string table index: 14 ``` #### Size: ``` text data bss dec hex filename 74736 2816 812 78364 1321c hw2_fast ``` #### Execute and Statistics of execution ``` 1 2 3 1 2 3 inferior exit code 0 CSR cycle count: 4514 ``` ## Summary | | O0 | O1 | O2 | O3 | Ofast | | -------- | -------- | -------- | -------- | -------- | -------- | | CSR cycle count | 4514 | 4470 | 4514 | 4514 | 4514 | | Lines of Code: main | 39 | 30 | 30 | 30 | 30 | | Lines of Code: searchInsert | 53 | 28 | 27 | 27 | 27 | Lines of code: total | 92 | 58 | 57 | 57 | 57| * Comparison (">" means better) * CSR: O0 = Ofast = O3 = O2 = O1 * LOC total: O3 = O1 = Ofast > O1 > O0

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully