From f463d544793ff83efd8b95d0bce5ec80fd8170f3 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 4 Dec 2024 21:42:37 +0100 Subject: Remove old test code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is some code that I had there after messing with some of the topics on Uros' blog (https://popovicu.com/), but that became irrelevant after working on some other projects (e.g. fbos) or on other examples. This commit also brings about a major overhaul on the structure of the project. Hopefully it's now at a more ready state. Signed-off-by: Miquel Sabaté Solà --- arch/riscv/user/basics/float.S | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 arch/riscv/user/basics/float.S (limited to 'arch/riscv/user/basics/float.S') diff --git a/arch/riscv/user/basics/float.S b/arch/riscv/user/basics/float.S new file mode 100644 index 0000000..f481f3e --- /dev/null +++ b/arch/riscv/user/basics/float.S @@ -0,0 +1,40 @@ +.text +.globl greater_than_ten +.type greater_than_ten, @function + +// bool greater_than_ten(double a, uint64_t b); +greater_than_ten: + // Upon entry a -> fa0; and b -> a0. That is, the ABI increments the + //(f)a register per argument type. + + // Change the rounding to "Rounds Towards Zero" (bits: 0b001). + li t0, 0b001 + fsrm t0 + + // Convert the second parameter to double. + fcvt.d.lu ft0, a0 + + // ret = a + b + fadd.d fa0, fa0, ft0 + + // ret = (ret * b) + b + fmv.d ft1, ft0 + fmadd.d fa0, fa0, ft0, ft1 + + // Now we need to compare the number with 10.0. There are multiple ways to + // load a floating point immediate: + // 1. Loading an integer immediate and then convert it into a double. This + // is discouraged on the RISC-V assembly manual. + // 2. Load a double with `fld` from a memory location on the data section. + // 3. Load a floating point immediate with `fli` (requires the `Zfa` + // extension). + // I don't have the `Zfa` extension on my board, so I'm opting for the + // second way. + fld ft1, .TEN, t0 + fle.d a0, ft1, fa0 + + ret + +.data +.TEN: + .double 10.0 -- cgit v1.2.3