Code Monkey home page Code Monkey logo

rvv_example's Introduction

Simple RISC-V Vector example

This is an example of writing the same vector processing function in C and in assembly language for RISC-V Vector extension v1.0, and comparing the results.

By default the generated program is run in qemu, but another emulator such as Spike could also be used, or run on real RVV-capable hardware if you have it.

Getting the toolchain

I'm using the "embedded" toolchain which uses the Newlib C library and statically links all needed libraries into the main program. This is more convenient for running on emulators or downloading to a microcontroller-style boars, but will also work on a native RISC-V Linux system.

Your favourite software repository might have a recent enough RISC-V toolchain, but maybe not as the B and V extensions are still quite new as I write this.

Check out the latest version from https://github.com/riscv-collab/riscv-gnu-toolchain

Support for B and V extensions are already included in master branch.

Follow the instructions there, or copy what I use:

# first install any neccessary packages for your OS, then....
git clone https://github.com/riscv-collab/riscv-gnu-toolchain.git --recursive
cd riscv-gnu-toolchain
./configure 
make
make build-qemu

Notes:

The instructions say you don't need recursive, but I find it more convenient to get everything at one time so the build itself is faster.

Unusually, there is no "make install" step, so you need write permissions for the installation location, or run "make" with sudo (ugh)

As always, add --prefix= to ./configure if you don't want the RISC-V toolchain in /usr/local

By default you will get libraries for rv64gc only. If you want a good set of libraries so you can experiment with rv32i, rv64i or other reduced configurations then add "--enable-multilib" to the ./configure.

Compiling and running the example

Just type "make"

Expected output:

$ make
riscv64-unknown-elf-gcc -O main.c vec.S -o main -march=rv64gcv_zba -lm
qemu-riscv64 -cpu rv64,v=true,zba=true,vlen=128 ./main
3.741657 3.741657
8.774964 8.774964
13.928389 13.928389
19.104973 19.104973
24.289915 24.289915
29.478806 29.478806

You can trace the qemu execution by adding "-singlestep -d nochain,cpu" to the qemu command line. Cross-reference instruction addresses with the output from "riscv64-unknown-elf-objdump -d main".

rvv_example's People

Contributors

brucehoult avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.