Skip to content

olokelo/riscv-cordic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RISC-V CORDIC Implementation

Simple algorithm for approximating sine and cosine of given degree written in pure RISC-V assembly. It uses fixed point arithmetic - the smallest unit is 1/256. You should represent your argument as degree*256 and scale down the return values dividing by 256.

Floating-Point extension is not required - it should work even on RV32I ISA.

Don't use it in your project if it's somewhat important. This implementation may contain bugs!

I wrote this in my 5th day of learning RISC-V assembly in RARS and tested it on a Fedora virtual machine using QEMU in GAS.

The algorithm is basically a modified version the one shown in this awesome paper.

Usage from C

cordic routine in assembly returns normally the value of sin in a0 and cos in a1 to avoid allocating space in the system memory. This means that you can get only the value of sin using plain C.

To get the value of cos I used the register property which allows the C language to access a1 after the function is called. (see main.c)

Benchmarks and Figures

This piece of assembly is clearly not written for benchmarking purposes rather for learning but you can check it anyway using bench.c .

$ ./bench 
Cordic asm took: 34.686128 ms
For: 256321 iterations
C math library took: 161.709872 ms
For: 256694 iterations

Sine_graph

Cosine_graph

About

CORDIC Algorithm written in RISC-V assembly

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors