Andrew Borg
    • 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
    # Rust ISA benchmarks Codebase: https://github.com/aborg-dev/isa_benchmarks Index document: https://hackmd.io/@aborg-dev/H1JgUcGCR This document describes the set of experiments to find the best ISA that we can use as an intermediate representation when compiling Rust code to Zisk. This involves: - Selecting a [set of benchmarks](https://github.com/aborg-dev/isa_benchmarks/tree/main/src/bin) and implementing them in Rust - Compiling the resulting programs to a range of ISAs supported by Rust compiler with right optimization flags - Running the resulting binaries in QEMU and measuring the execution costs in the number and complexity of instructions ## Results ### Summary for Ethereum block - rustc -> x86: 250M steps (with vectorized instr 2.5M) - rustc -> aarch64: 191M steps - rustc -> riscv64gc: 320M steps - ziskemu steps match qemu instruction counter: 320M steps - `rustc_codegen_cranelift` is around 8x slower with default settings - Code is indeed much less optimized, needs inlining, loop unrolling, etc. - rustc -> WASM -> x86: 600M steps - rustc -> WASM -> w2c2 -> C -> x86: 376M steps ### Remaining steps - Understand why "rustc -> x86" is so fast for SHA 256 - So far seems to be due to more complex instructions which leads to less instructions used overall - Understand why rust -> WASM -> x86 is 10x-15x slower - Is inlining to blame for the results? No, it is properly inlined - Or do we need to example WASM vectorized instructions? Not really, I disabled all of these - Also could be due to WASM interpreter overhead - the most likely one, need to verify - Measure WASM -> Cranelift -> RISC-V path - If we are at the same level, might be a viable path ## Setup - QEMU version 9.1 - https://github.com/rust-lang/rustc_codegen_cranelift - Rustup setup: ``` rustup target add riscv64gc-unknown-linux-gnu rustup target add aarch64-unknown-linux-gnu ``` ### Profiling Profiling commands: ```shell # For RISC-V qemu-riscv64 -L /usr/riscv64-linux-gnu -cpu rv64 \ -plugin tests/tcg/plugins/libinsn.so -d plugin \ sha_hasher # For ziskos ziskemu -i build/input.bin -xm -e sha_hasher # For x86 qemu-x86_64 \ -plugin tests/tcg/plugins/libinsn.so -d plugin \ sha_hasher # For ARM qemu-aarch64 \ -plugin tests/tcg/plugins/libinsn.so -d plugin \ sha_hasher ``` ## Raw data ### rustc -> riscv64ima-polygon-ziskos-elf, ziskemu Release: ``` n:10000 [82, 229, 228, 9, 207, 11, 252, 118, 235, 27, 13, 44, 75, 164, 54, 106, 253, 126, 193, 14, 54, 32, 188, 119, 81, 120, 47, 45, 222, 206, 161, 159] Cost definitions: AREA_PER_SEC: 1000000 steps COST_MEMA_R1: 0.00002 sec COST_MEMA_R2: 0.00004 sec COST_MEMA_W1: 0.00004 sec COST_MEMA_W2: 0.00008 sec COST_USUAL: 0.000008 sec COST_STEP: 0.00005 sec Total Cost: 6392.55 sec Main Cost: 2122.73 sec 42454507 steps Mem Cost: 1107.83 sec 110782774 steps Mem Align: 21.22 sec 1061034 steps Opcodes: 3125.94 sec 1432 steps (40600544 ops) Usual: 14.83 sec 1853964 steps Memory: 67849727 a reads + 680496 na1 reads + 0 na2 reads + 42062282 a writes + 190269 na1 writes + 0 na2 writes = 68530223 reads + 42252551 writes = 110782774 r/w Registy: 65366939 reads + 40389901 writes = 105756840 r/w Opcodes: flag: 0.00 sec (0 steps/op) (40583 ops) copyb: 0.00 sec (0 steps/op) (5266028 ops) add: 553.92 sec (77 steps/op) (7193707 ops) sub: 0.00 sec (77 steps/op) (11 ops) ltu: 6.95 sec (77 steps/op) (90237 ops) eq: 1.54 sec (77 steps/op) (19953 ops) sll: 620.18 sec (109 steps/op) (5689699 ops) srl: 8.73 sec (109 steps/op) (80061 ops) add_w: 0.00 sec (77 steps/op) (55 ops) sub_w: 0.77 sec (77 steps/op) (10005 ops) srl_w: 718.31 sec (109 steps/op) (6589961 ops) and: 168.70 sec (77 steps/op) (2190887 ops) or: 471.96 sec (77 steps/op) (6129357 ops) xor: 531.30 sec (77 steps/op) (6899979 ops) signextend_b: 17.44 sec (109 steps/op) (160000 ops) signextend_w: 26.16 sec (109 steps/op) (240000 ops) mul: 0.00 sec (97 steps/op) (20 ops) muluh: 0.00 sec (97 steps/op) (1 ops) process_rom() steps=42454508 duration=0.3956 tp=107.3291 Msteps/s freq=2209.0000 20.5815 clocks/step ``` Debug (failed): ``` Cost definitions: AREA_PER_SEC: 1000000 steps COST_MEMA_R1: 0.00002 sec COST_MEMA_R2: 0.00004 sec COST_MEMA_W1: 0.00004 sec COST_MEMA_W2: 0.00008 sec COST_USUAL: 0.000008 sec COST_STEP: 0.00005 sec Total Cost: 6193.56 sec Main Cost: 0.00 sec 0 steps Mem Cost: 2492.99 sec 249299312 steps Mem Align: 351.37 sec 17568549 steps Opcodes: 3279.52 sec 1695 steps (91290009 ops) Usual: 69.68 sec 8709991 steps Memory: 153039236 a reads + 5137271 na1 reads + 0 na2 reads + 84907166 a writes + 6215639 na1 writes + 0 na2 writes = 158176507 reads + 91122805 writes = 249299312 r/w Registy: 135842625 reads + 61924758 writes = 197767383 r/w Opcodes: flag: 0.00 sec (0 steps/op) (5436123 ops) copyb: 0.00 sec (0 steps/op) (47777178 ops) add: 953.99 sec (77 steps/op) (12389493 ops) sub: 4.54 sec (77 steps/op) (59012 ops) ltu: 110.80 sec (77 steps/op) (1439009 ops) lt: 2.20 sec (77 steps/op) (28608 ops) eq: 16.39 sec (77 steps/op) (212832 ops) sll: 281.81 sec (109 steps/op) (2585452 ops) srl: 158.03 sec (109 steps/op) (1449818 ops) add_w: 140.57 sec (77 steps/op) (1825616 ops) sub_w: 7.99 sec (77 steps/op) (103724 ops) sll_w: 115.75 sec (109 steps/op) (1061885 ops) srl_w: 104.07 sec (109 steps/op) (954784 ops) and: 480.65 sec (77 steps/op) (6242245 ops) or: 286.44 sec (77 steps/op) (3720043 ops) xor: 100.09 sec (77 steps/op) (1299881 ops) signextend_b: 6.24 sec (109 steps/op) (57220 ops) signextend_w: 486.26 sec (109 steps/op) (4461098 ops) mul: 10.93 sec (97 steps/op) (112665 ops) divu: 12.76 sec (174 steps/op) (73323 ops) Error during emulation: EmulationNoCompleted ``` Crashes under QEMU: ``` fish: Job SIGSEGV, 'Address boundary error' terminated by signal () ``` ### rustc -> riscv64gc-unknown-linux-gnu Release: ``` n:10000 [82, 229, 228, 9, 207, 11, 252, 118, 235, 27, 13, 44, 75, 164, 54, 106, 253, 126, 193, 14, 54, 32, 188, 119, 81, 120, 47, 45, 222, 206, 161, 159] cpu 0 insns: 42868656 total insns: 42868656 ``` Debug: ``` n:10000 [82, 229, 228, 9, 207, 11, 252, 118, 235, 27, 13, 44, 75, 164, 54, 106, 253, 126, 193, 14, 54, 32, 188, 119, 81, 120, 47, 45, 222, 206, 161, 159] cpu 0 insns: 555737110 total insns: 555737110 ``` ### rustc_codegen_cranelift -> riscv64gc-unknown-linux-gnu Release: ``` n:10000 [82, 229, 228, 9, 207, 11, 252, 118, 235, 27, 13, 44, 75, 164, 54, 106, 253, 126, 193, 14, 54, 32, 188, 119, 81, 120, 47, 45, 222, 206, 161, 159] cpu 0 insns: 342801902 total insns: 342801902 ``` Debug: ``` n:10000 [82, 229, 228, 9, 207, 11, 252, 118, 235, 27, 13, 44, 75, 164, 54, 106, 253, 126, 193, 14, 54, 32, 188, 119, 81, 120, 47, 45, 222, 206, 161, 159] cpu 0 insns: 1065241694 total insns: 1065241694 ``` ### rustc_codegen_cranelift -> x86 Release: ``` n:10000 [82, 229, 228, 9, 207, 11, 252, 118, 235, 27, 13, 44, 75, 164, 54, 106, 253, 126, 193, 14, 54, 32, 188, 119, 81, 120, 47, 45, 222, 206, 161, 159] cpu 0 insns: 380275949 total insns: 380275949 ``` ### Rustc -> WASM -> CLIF -> x86 ``` qemu-x86_64 \ -plugin tests/tcg/plugins/libinsn.so -d plugin \ ./target/release/wasmtime run -O opt-level=0 -C cache=yes ../hello_world_nozisk/target/wasm32-wasip1/release/sha_hasher.wasm ``` ``` n:10000 [82, 229, 228, 9, 207, 11, 252, 118, 235, 27, 13, 44, 75, 164, 54, 106, 253, 126, 193, 14, 54, 32, 188, 119, 81, 120, 47, 45, 222, 206, 161, 159] cpu 0 insns: 45184403 total insns: 45693833 ``` ### Rustc -> WASM -> CLIF -> RISC-V :construction: ### rustc -> x86 Release: ``` n:10000 [82, 229, 228, 9, 207, 11, 252, 118, 235, 27, 13, 44, 75, 164, 54, 106, 253, 126, 193, 14, 54, 32, 188, 119, 81, 120, 47, 45, 222, 206, 161, 159] cpu 0 insns: 2998513 total insns: 2998513 ``` Debug: ``` n:10000 [82, 229, 228, 9, 207, 11, 252, 118, 235, 27, 13, 44, 75, 164, 54, 106, 253, 126, 193, 14, 54, 32, 188, 119, 81, 120, 47, 45, 222, 206, 161, 159] cpu 0 insns: 342708134 total insns: 342708134 ``` ### rustc -> aarch64 Release: ``` n:10000 [82, 229, 228, 9, 207, 11, 252, 118, 235, 27, 13, 44, 75, 164, 54, 106, 253, 126, 193, 14, 54, 32, 188, 119, 81, 120, 47, 45, 222, 206, 161, 159] cpu 0 insns: 20349879 total insns: 20349879 ``` Debug: ``` n:10000 [82, 229, 228, 9, 207, 11, 252, 118, 235, 27, 13, 44, 75, 164, 54, 106, 253, 126, 193, 14, 54, 32, 188, 119, 81, 120, 47, 45, 222, 206, 161, 159] cpu 0 insns: 417514369 total insns: 417514369 ```

    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