RVA23 vs. ARMv9 a Small Experiment

birdculture2 pts0 comments

RVA23 vs ARMv9 a Small Experiment · GitHub

/" data-turbo-transient="true" />

Skip to content

-->

Search Gists

Search Gists

Sign in

Sign up

You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

{{ message }}

Instantly share code, notes, and snippets.

camel-cdr/rv-vs-arm-chibicc.md

Created<br>March 4, 2025 21:43

Show Gist options

Download ZIP

Star

(5)

You must be signed in to star a gist

Fork

(0)

You must be signed in to fork a gist

Embed

Select an option

Embed<br>Embed this gist in your website.

Share<br>Copy sharable link for this gist.

Clone via HTTPS<br>Clone using the web URL.

No results found

Learn more about clone URLs

Clone this repository at &lt;script src=&quot;https://gist.github.com/camel-cdr/3a7aed17e017e8cab675ad696c7d14af.js&quot;&gt;&lt;/script&gt;

" readonly="readonly" data-autoselect="true" data-target="primer-text-field.inputElement " aria-describedby="validation-8ac747a5-8253-482f-b67d-866ebb9cca76" class="form-control FormControl-monospace FormControl-input FormControl-small rounded-left-0 rounded-right-0 border-right-0" type="text" name="gist-share-url-sized-down" />

Save camel-cdr/3a7aed17e017e8cab675ad696c7d14af to your computer and use it in GitHub Desktop.

Embed

Select an option

Embed<br>Embed this gist in your website.

Share<br>Copy sharable link for this gist.

Clone via HTTPS<br>Clone using the web URL.

No results found

Learn more about clone URLs

Clone this repository at &lt;script src=&quot;https://gist.github.com/camel-cdr/3a7aed17e017e8cab675ad696c7d14af.js&quot;&gt;&lt;/script&gt;

" readonly="readonly" data-autoselect="true" data-target="primer-text-field.inputElement " aria-describedby="validation-99242d48-6e5e-4af4-8a74-9e9882ec6905" class="form-control FormControl-monospace FormControl-input FormControl-small rounded-left-0 rounded-right-0 border-right-0" type="text" name="gist-share-url-original" />

Save camel-cdr/3a7aed17e017e8cab675ad696c7d14af to your computer and use it in GitHub Desktop.

Download ZIP

RVA23 vs ARMv9 a Small Experiment

Raw

rv-vs-arm-chibicc.md

RVA23 vs ARMv9 a Small Experiment

I was curious to see how RISC-V and ARM compare in terms of dynamic instruction count and code density, so I devised a small experiment to compare the ISAs.

As a test codebase, I choose the chibicc C compiler, because it's a medium size project and is quite easy to compile.<br>To benchmark chibicc I just used it to compile itself, which should be a quite realistic workload to simulate a complex non-regular application.<br>I merged all files into one and did some minor modifications, the code can be found at: https://godbolt.org/z/xr3nEW8Wf

You may notice that I added unoptimized scalar implementations of the mem* and str* functions from musl-libc.<br>This is because I decided to not include SIMD code in this experiment, in an effort to remove more unknown variables and focus on comparing the base ISAs.<br>Without these measures, the results seemed similar.

Without further ado, below is the table comparing the results:

staticQEMUGEM5<br>ISACompilerBytesBytesInsnsuops**Sim-TimeInsnsuops

RVA22 clang-19 772K 1221M 424M +0M = 424M 0.221s 438M +0M = 438M<br>RVA22 gcc-15 772K 1309M 445M +0M = 445M 0.217s 459M +0M = 459M<br>RVA23* clang-19 772K 1185M 423M +0M = 423M 0.243s 438M +0M = 438M<br>RVA23* gcc-15 772K 1265M 441M +0M = 441M 0.217s 456M +0M = 456M<br>armv9* clang-19 944K 1543M 386M +39M = 424M 0.225s 399M +70M = 469M<br>armv9* gcc-15 936K 1688M 422M +39M = 460M 0.236s 435M +66M = 501M

*excluding SIMD/vector instructions

**Derived from the "Apple Silicon CPU Optimization Guide": ((ld|st)\w.*#\w*(\]!)*$)|ldp|stp, so load/store pairs and pre-/post-index load/stores

As mentioned before, I'm explicitly excluding SIMD from this experiment, so I used the following compiler arguments to achieve this:

RVA22: -O3 -march=rv64gcb -static

RVA23: -O3 -march=rv64gcb_zcb_zfa_zicond -static

armv9: -O3 -march=armv9-a+nosimd+nosve -static

Let's go through the results from left to right.

Firstly, the static sizes of the RISC-V binaries is about 18% smaller than the sizes of the ARM ones.<br>The sizes are extremely similar for both RVA22 and RVA23, and regardless of compiler.<br>For the dynamic instruction size however, that is the sum of executed-instructions-lengths, there is a clear improvement going from RVA22 to RVA23.<br>RVA22 needs to fetch 21% fewer bytes than armv9 and RVA23 goes down to 24% fewer bytes than armv9.<br>AFAIK QEMU doesn't come with the ability to count the executed-instruction-lengths out of the box, so I needed to patched the tcg/plugins/insn.c plugin.

When it comes to dynamic instruction count, ARM ends up the clear winner with on average of 6.5% fewer instructions that need to be decoded.<br>But the instructions them self isn't what ends up executing in the backend.<br>Due to the more complex...

gist rva23 armv9 clone small experiment

Related Articles