├── LICENSE-EXCEPTION.txt
├── LICENSE.txt
├── Makefile
├── README.md
├── include
└── rvfplib.h
├── script
├── check1.py
├── check2.py
├── fp_util.py
├── test.sh
└── topScript_test.sh
└── src
├── asm
├── ieee754
│ ├── __adddf3.S
│ ├── __addsf3.S
│ ├── __divdf3.S
│ ├── __divsf3.S
│ ├── __eqdf2.S
│ ├── __eqsf2.S
│ ├── __extendsfdf2.S
│ ├── __fixdfdi.S
│ ├── __fixdfsi.S
│ ├── __fixsfdi.S
│ ├── __fixsfsi.S
│ ├── __fixunsdfdi.S
│ ├── __fixunsdfsi.S
│ ├── __fixunssfdi.S
│ ├── __fixunssfsi.S
│ ├── __floatdidf.S
│ ├── __floatdisf.S
│ ├── __floatsidf.S
│ ├── __floatsisf.S
│ ├── __floatundidf.S
│ ├── __floatundisf.S
│ ├── __floatunsidf.S
│ ├── __floatunsisf.S
│ ├── __gedf2.S
│ ├── __gesf2.S
│ ├── __gtdf2.S
│ ├── __gtsf2.S
│ ├── __ledf2.S
│ ├── __lesf2.S
│ ├── __ltdf2.S
│ ├── __ltsf2.S
│ ├── __muldf3.S
│ ├── __mulsf3.S
│ ├── __subdf3.S
│ ├── __subsf3.S
│ └── __truncdfsf2.S
└── ieee754_nd
│ ├── __adddf3.S
│ ├── __addsf3.S
│ ├── __divdf3.S
│ ├── __divsf3.S
│ ├── __eqdf2.S
│ ├── __eqsf2.S
│ ├── __extendsfdf2.S
│ ├── __fixdfdi.S
│ ├── __fixdfsi.S
│ ├── __fixsfdi.S
│ ├── __fixsfsi.S
│ ├── __fixunsdfdi.S
│ ├── __fixunsdfsi.S
│ ├── __fixunssfdi.S
│ ├── __fixunssfsi.S
│ ├── __floatdidf.S
│ ├── __floatdisf.S
│ ├── __floatsidf.S
│ ├── __floatsisf.S
│ ├── __floatundidf.S
│ ├── __floatundisf.S
│ ├── __floatunsidf.S
│ ├── __floatunsisf.S
│ ├── __gedf2.S
│ ├── __gesf2.S
│ ├── __gtdf2.S
│ ├── __gtsf2.S
│ ├── __ledf2.S
│ ├── __lesf2.S
│ ├── __ltdf2.S
│ ├── __ltsf2.S
│ ├── __muldf3.S
│ ├── __mulsf3.S
│ ├── __subdf3.S
│ ├── __subsf3.S
│ └── __truncdfsf2.S
└── c
├── f32_add
└── main.c
├── f32_div
└── main.c
├── f32_eq
└── main.c
├── f32_ge
└── main.c
├── f32_gt
└── main.c
├── f32_le
└── main.c
├── f32_lt
└── main.c
├── f32_mul
└── main.c
├── f32_ne
└── main.c
├── f32_sub
└── main.c
├── f32_to_f64
└── main.c
├── f32_to_i32
└── main.c
├── f32_to_i64
└── main.c
├── f32_to_ui32
└── main.c
├── f32_to_ui64
└── main.c
├── f64_add
└── main.c
├── f64_div
└── main.c
├── f64_eq
└── main.c
├── f64_ge
└── main.c
├── f64_gt
└── main.c
├── f64_le
└── main.c
├── f64_lt
└── main.c
├── f64_mul
└── main.c
├── f64_ne
└── main.c
├── f64_sub
└── main.c
├── f64_to_f32
└── main.c
├── f64_to_i32
└── main.c
├── f64_to_i64
└── main.c
├── f64_to_ui32
└── main.c
├── f64_to_ui64
└── main.c
├── i32_to_f32
└── main.c
├── i32_to_f64
└── main.c
├── i64_to_f32
└── main.c
├── i64_to_f64
└── main.c
├── ui32_to_f32
└── main.c
├── ui32_to_f64
└── main.c
├── ui64_to_f32
└── main.c
└── ui64_to_f64
└── main.c
/LICENSE-EXCEPTION.txt:
--------------------------------------------------------------------------------
1 | GCC RUNTIME LIBRARY EXCEPTION
2 |
3 | Version 3.1, 31 March 2009
4 |
5 | Copyright (C) 2009 Free Software Foundation, Inc.
6 |
7 | Everyone is permitted to copy and distribute verbatim copies of this
8 | license document, but changing it is not allowed.
9 |
10 | This GCC Runtime Library Exception ("Exception") is an additional
11 | permission under section 7 of the GNU General Public License, version
12 | 3 ("GPLv3"). It applies to a given file (the "Runtime Library") that
13 | bears a notice placed by the copyright holder of the file stating that
14 | the file is governed by GPLv3 along with this Exception.
15 |
16 | When you use GCC to compile a program, GCC may combine portions of
17 | certain GCC header files and runtime libraries with the compiled
18 | program. The purpose of this Exception is to allow compilation of
19 | non-GPL (including proprietary) programs to use, in this way, the
20 | header files and runtime libraries covered by this Exception.
21 |
22 | 0. Definitions.
23 |
24 | A file is an "Independent Module" if it either requires the Runtime
25 | Library for execution after a Compilation Process, or makes use of an
26 | interface provided by the Runtime Library, but is not otherwise based
27 | on the Runtime Library.
28 |
29 | "GCC" means a version of the GNU Compiler Collection, with or without
30 | modifications, governed by version 3 (or a specified later version) of
31 | the GNU General Public License (GPL) with the option of using any
32 | subsequent versions published by the FSF.
33 |
34 | "GPL-compatible Software" is software whose conditions of propagation,
35 | modification and use would permit combination with GCC in accord with
36 | the license of GCC.
37 |
38 | "Target Code" refers to output from any compiler for a real or virtual
39 | target processor architecture, in executable form or suitable for
40 | input to an assembler, loader, linker and/or execution
41 | phase. Notwithstanding that, Target Code does not include data in any
42 | format that is used as a compiler intermediate representation, or used
43 | for producing a compiler intermediate representation.
44 |
45 | The "Compilation Process" transforms code entirely represented in
46 | non-intermediate languages designed for human-written code, and/or in
47 | Java Virtual Machine byte code, into Target Code. Thus, for example,
48 | use of source code generators and preprocessors need not be considered
49 | part of the Compilation Process, since the Compilation Process can be
50 | understood as starting with the output of the generators or
51 | preprocessors.
52 |
53 | A Compilation Process is "Eligible" if it is done using GCC, alone or
54 | with other GPL-compatible software, or if it is done without using any
55 | work based on GCC. For example, using non-GPL-compatible Software to
56 | optimize any GCC intermediate representations would not qualify as an
57 | Eligible Compilation Process.
58 |
59 | 1. Grant of Additional Permission.
60 |
61 | You have permission to propagate a work of Target Code formed by
62 | combining the Runtime Library with Independent Modules, even if such
63 | propagation would otherwise violate the terms of GPLv3, provided that
64 | all Target Code was generated by Eligible Compilation Processes. You
65 | may then convey such a combination under terms of your choice,
66 | consistent with the licensing of the Independent Modules.
67 |
68 | 2. No Weakening of GCC Copyleft.
69 |
70 | The availability of this Exception does not imply any general
71 | presumption that third-party software is unaffected by the copyleft
72 | requirements of the license of GCC.
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with rvfplib If not, see .
19 | # Copyright ETH Zurich 2020
20 |
21 | # rvfplib Makefile
22 | # Build the default lib optimized for performance (librvfp.a), and the lib optimized for size (librvfp_s.a), in both the standard and non-subnormal versions
23 |
24 | ###############
25 | ## Variables ##
26 | ###############
27 |
28 | LIB_NAME := librvfp
29 | LIB_ND_NAME := librvfp_nd
30 |
31 | CC := riscv32-unknown-elf-gcc
32 | CCFLAGS := -march=rv32imc -mabi=ilp32
33 | OBJDUMP := riscv32-unknown-elf-objdump
34 |
35 | PERF_FLAG := -DPERFORMANCE=1
36 | SIZE_FLAG := -DSIZE=1
37 |
38 | BUILD_DIR := build
39 | LIB_DIR := $(BUILD_DIR)/lib
40 | SRC_DIR := src/asm/ieee754
41 | SRC_ND_DIR := src/asm/ieee754_nd
42 | OBJ_DIR := $(BUILD_DIR)/obj
43 | OBJ_ND_DIR := $(BUILD_DIR)/obj_nd
44 | OBJ_S_DIR := $(BUILD_DIR)/obj_s
45 | OBJ_ND_S_DIR := $(BUILD_DIR)/obj_nd_s
46 |
47 | SRC_FILES := $(wildcard $(SRC_DIR)/*.S)
48 | SRC_ND_FILES := $(wildcard $(SRC_ND_DIR)/*.S)
49 | OBJ_FILES := $(patsubst $(SRC_DIR)/%.S, $(OBJ_DIR)/%.o, $(SRC_FILES))
50 | OBJ_ND_FILES := $(patsubst $(SRC_ND_DIR)/%.S, $(OBJ_ND_DIR)/%.o, $(SRC_ND_FILES))
51 | OBJ_S_FILES := $(patsubst $(SRC_DIR)/%.S, $(OBJ_S_DIR)/%.o, $(SRC_FILES))
52 | OBJ_ND_S_FILES := $(patsubst $(SRC_ND_DIR)/%.S, $(OBJ_ND_S_DIR)/%.o, $(SRC_ND_FILES))
53 | LIB := $(LIB_DIR)/$(LIB_NAME).a
54 | LIB_ND := $(LIB_DIR)/$(LIB_ND_NAME).a
55 | LIB_S := $(LIB_DIR)/$(LIB_NAME)_s.a
56 | LIB_ND_S := $(LIB_DIR)/$(LIB_ND_NAME)_s.a
57 |
58 | DUMP := $(LIB_DIR)/$(LIB_NAME).dump
59 | DUMP_ND := $(LIB_DIR)/$(LIB_ND_NAME).dump
60 | DUMP_S := $(LIB_DIR)/$(LIB_NAME)_s.dump
61 | DUMP_ND_S := $(LIB_DIR)/$(LIB_ND_NAME)_s.dump
62 |
63 | #####################
64 | ## Targets&Recipes ##
65 | #####################
66 |
67 | .PHONY: all
68 | .PHONY: size
69 | .PHONY: performance
70 | .PHONY: clean
71 | .PHONY: build_dirs
72 |
73 | # Build all the 4 libraries, by default
74 | all: performance size
75 |
76 | # Targets for the performance-optimized libraries
77 | performance: CCFLAGS += $(PERF_FLAG)
78 | performance: build_dirs $(LIB) $(LIB_ND) $(DUMP) $(DUMP_ND)
79 |
80 | # Targets for the size-optimized libraries
81 | size: CCFLAGS += $(SIZE_FLAG)
82 | size: build_dirs $(LIB_S) $(LIB_ND_S) $(DUMP_S) $(DUMP_ND_S)
83 |
84 | # Disassemble the libraries
85 | $(DUMP): $(LIB)
86 | $(OBJDUMP) -xD $^ > $@
87 | $(DUMP_ND): $(LIB_ND)
88 | $(OBJDUMP) -xD $^ > $@
89 |
90 | $(DUMP_S): $(LIB_S)
91 | $(OBJDUMP) -xD $^ > $@
92 | $(DUMP_ND_S): $(LIB_ND_S)
93 | $(OBJDUMP) -xD $^ > $@
94 |
95 | # Build the libraries
96 | $(LIB): $(OBJ_FILES)
97 | $(AR) rcs $@ $^
98 | $(LIB_ND): $(OBJ_ND_FILES)
99 | $(AR) rcs $@ $^
100 |
101 | $(LIB_S): $(OBJ_S_FILES)
102 | $(AR) rcs $@ $^
103 | $(LIB_ND_S): $(OBJ_ND_S_FILES)
104 | $(AR) rcs $@ $^
105 |
106 | # Compile the functions
107 | $(OBJ_DIR)/%.o: $(SRC_DIR)/%.S
108 | $(CC) $(CCFLAGS) -c $< -o $@
109 | $(OBJ_ND_DIR)/%.o: $(SRC_ND_DIR)/%.S
110 | $(CC) $(CCFLAGS) -c $< -o $@
111 |
112 | $(OBJ_S_DIR)/%.o: $(SRC_DIR)/%.S
113 | $(CC) $(CCFLAGS) -c $< -o $@
114 | $(OBJ_ND_S_DIR)/%.o: $(SRC_ND_DIR)/%.S
115 | $(CC) $(CCFLAGS) -c $< -o $@
116 |
117 | # Create the directory tree
118 | build_dirs:
119 | mkdir -p $(OBJ_DIR) $(OBJ_ND_DIR) $(OBJ_S_DIR) $(OBJ_ND_S_DIR) $(LIB_DIR)
120 |
121 | # Clean the files
122 | clean:
123 | rm -rf $(BUILD_DIR)
124 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # RVfplib - Optimized RISC-V FP emulation for 32-bit processors #
2 | RVfplib is an optimized RISC-V library for FP arithmetic on 32-bit integer processors, for single and double-precision FP.
3 | RVfplib is IEEE 754 compliant, with the following exceptions:
4 | - It does not support exception flags.
5 | - It does not support signaling `NaNs`, all the produced `NaNs` are quiet in the form of `0x7FC00000` and `0x7FF8000000000000`.
6 | - The only provided rounding mode is `RNE`.
7 |
8 | RVfplib is available in 4 versions:
9 | - **RVfplib**, optimized for performance. It is compatible with RV32IM[C] processors.
10 | - **RVfplib_s**, optimized for low code-size. It is compatible with RV32IM[C] processors.
11 | - **RVfplib_nd**, optimized for performance, with no support for subnormal values (they are considered correctly signed zeroes). It is compatible with RV32EM[C] processors.
12 | - **RVfplib_nd_s**, optimized for low code-size, with no support for subnormal values (they are considered correctly signed zeroes). It is compatible with RV32EM[C] processors.
13 |
14 | The optimizations for performance are input-dependent, and in certain contextes can lead to slower code. If in doubt, use the the code optimized for size.
15 |
16 | The functions are aliased with those automatically linked from `libgcc`, e.g. the single-precision addition is called `__addsf3`.
17 |
18 | ## Dependencies ##
19 | To build the library, a RISC-V RV32IM[C] toolchain is needed. Make sure that ``riscv32-unknown-elf-gcc`` is available in the used shell.
20 | To do so, add to the ``PATH`` variable the path to the ``bin`` directory of your ``riscv32-unknown-elf`` toolchain. If this directory is called ``${RISCV_TOOLS_BIN_DIR}``, then execute the following command in the shell that will be used to build the library.
21 |
22 | `export PATH="${RISCV_TOOLS_BIN_DIR}:$PATH"`
23 |
24 | For custom needs, modify the Makefile.
25 |
26 | The library itself has no external dependencies.
27 |
28 | ## Build the library ##
29 | In the following, the directory in which this file is stored will be identified as `$(BASE_DIR)`
30 |
31 | To build the library, open a terminal in this directory and execute:
32 |
33 | ``make``
34 |
35 | This command will build the four libraries in `$(BASE_DIR)/build/lib/`.
36 |
37 | ## Use the library ##
38 | The following steps work with a RISC-V GCC toolchain.
39 |
40 | To use the library, add:
41 |
42 | ``-L $(BASE_DIR)/build/lib -nolibc -lc``
43 |
44 | to the linker flags, and:
45 |
46 | ``-lrvfp``
47 |
48 | to the linker flags, but only after the source files and the other external needed libraries.
49 |
50 | For example, to compile a `main.c` program with RVfplib, use:
51 |
52 | ``riscv32-unknown-elf-gcc -march=rv32imc main.c -L $(BASE_DIR)/build/lib -nolibc -lc -lm -lrvfp``
53 |
54 | ## Use another RVfplib version ##
55 | To link one of the other three RVfplib versions, just replace
56 |
57 | ``-lrvfp``
58 |
59 | with one of the following:
60 |
61 | ``-lrvfp_s``
62 | ``-lrvfp_nd``
63 | ``-lrvfp_nd_s``
64 |
65 | ## Source ##
66 | The source code of the functions is kept in `src/asm/`, whereas `src/c/` contains test-related C code.
67 |
68 | ## Test ##
69 | It's possible to select which function to test commenting/un-commenting the related line in the file `script/topScript_test.sh`.
70 |
71 | Then, from `$(BASE_DIR)`, launch:
72 |
73 | ``./script/topScript_test.sh size`` - To test the size-optimized library
74 |
75 | ``./script/topScript_test.sh performance`` - To test the performance-optimized library
76 |
77 | The test depends upon `riscv32-unknown-elf-` tools, `TestFloat` programs, `SPIKE`, `PK`, and Python3. The `TestFloat` programs and Python3 should be accessible from the shell. For the others, make sure to define and export the following variables before calling the script:
78 |
79 | - `GCC_TOOLS_BIN_PATH` : the bin path to your GCC tools
80 | - `SPIKE_PATH` : the path to your SPIKE program
81 | - `PK_PATH` : the path to your Proxy Kernel program
82 |
83 | ## Acknowledgements ##
84 | Part of this library is inspired by the Arm FP support provided within libgcc:
85 | - https://github.com/gcc-mirror/gcc/blob/master/libgcc/config/arm/ieee754-sf.S
86 | - https://github.com/gcc-mirror/gcc/blob/master/libgcc/config/arm/ieee754-df.S
87 |
--------------------------------------------------------------------------------
/include/rvfplib.h:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | // Arithmetical functions
22 | // Single precision FP addition
23 | float __addsf3(float op0, float op1);
24 | // Single precision FP subtracion
25 | float __subsf3(float op0, float op1);
26 | // Single precision FP multiplication
27 | float __mulsf3(float op0, float op1);
28 | // Single precision FP division
29 | float __divsf3(float op0, float op1);
30 | // Double precision FP addition
31 | double __adddf3(double op0, double op1);
32 | // Double precision FP subtraction
33 | double __subdf3(double op0, double op1);
34 | // Double precision FP multiplication
35 | double __muldf3(double op0, double op1);
36 | // Double precision FP division
37 | double __divdf3(double op0, double op1);
38 |
39 | // Comparison functions
40 | int __eqsf2(float op0, float op1);
41 | int __nesf2(float op0, float op1);
42 | int __ltsf2(float op0, float op1);
43 | int __lesf2(float op0, float op1);
44 | int __gtsf2(float op0, float op1);
45 | int __gesf2(float op0, float op1);
46 | int __eqdf2(double op0, double op1);
47 | int __nedf2(double op0, double op1);
48 | int __ltdf2(double op0, double op1);
49 | int __ledf2(double op0, double op1);
50 | int __gtdf2(double op0, double op1);
51 | int __gedf2(double op0, double op1);
52 |
53 | // Conversion functions
54 | int __fixsfsi(float op0);
55 | unsigned int __fixunssfsi(float op0);
56 | long long int __fixsfdi(float op0);
57 | unsigned long long int __fixunssfdi(float op0);
58 | float __floatsisf(int op0);
59 | float __floatunsisf(unsigned int op0);
60 | float __floatdisf(long long int op0);
61 | float __floatundisf(unsigned long long int op0);
62 | double __extendsfdf2(float op0);
63 |
64 | int __fixdfsi(double op0);
65 | unsigned int __fixunsdfsi(double op0);
66 | long long int __fixdfdi(double op0);
67 | unsigned long long int __fixunsdfdi(double op0);
68 | double __floatsidf(int op0);
69 | double __floatunsidf(unsigned int op0);
70 | double __floatdidf(long long int op0);
71 | double __floatundidf(unsigned long long int op0);
72 | float __truncdfsf2(double op0);
73 |
--------------------------------------------------------------------------------
/script/check1.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | # Copyright ETH Zurich 2020
4 | #
5 | # Author: Matteo Perotti
6 | #
7 | # This file is part of rvfplib.
8 | #
9 | # rvfplib is free software: you can redistribute it and/or modify
10 | # it under the terms of the GNU General Public License as published by
11 | # the Free Software Foundation, either version 3 of the License, or
12 | # (at your option) any later version.
13 | #
14 | # rvfplib is distributed in the hope that it will be useful,
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | # GNU General Public License for more details.
18 | #
19 | # You should have received a copy of the GNU General Public License
20 | # along with rvfplib If not, see .
21 | # Copyright ETH Zurich 2020
22 |
23 | # This script needs to be called from test64.sh
24 |
25 | import sys
26 | from fp_util import *
27 |
28 | # Check if out is correct, considering golden_out
29 | # Avoid fp comparisons, they can be misleading
30 | # All the arguments are binary strings, except for op, which is a string indicating the FUT (like "f32_add")
31 | def check_op(in0, out, out_g, operation, prec_in, prec_out):
32 | # Check if we need to analyze the non-standard cases
33 | if out_g == out:
34 | # Strings are equal or they are both NaN
35 | return 1
36 | else:
37 | if operation == 'f32_to_f64' or operation == 'f64_to_f32':
38 | if isNan(out, prec_out) and isNan(out_g, prec_out):
39 | return 1
40 | return 0
41 |
42 | def check_op_nd(in0, out, out_g, operation, prec_in, prec_out):
43 | # Check if we need to analyze the non-standard cases
44 | if out_g == out:
45 | # Strings are equal or they are both NaN
46 | return 1
47 | else:
48 | if operation == 'f32_to_f64' or operation == 'f64_to_f32':
49 | if isDenormal(in0, prec_in) and isZero(out, prec_out):
50 | return 1
51 | if operation == 'f64_to_f32':
52 | if isDenormal(out_g, prec_out) and isZero(out, prec_out):
53 | return 1
54 | if isZero(out, prec_out) and out[0] == '0' and out_g == '00000000100000000000000000000000' or isZero(out, prec_out) and out[0] == '1' and out_g == '10000000100000000000000000000000':
55 | # This is a denormal input, that would become a normalized value only after rounding. Treated as a denormal.
56 | return 1
57 | if isNan(out, prec_out) and isNan(out_g, prec_out):
58 | return 1
59 | return 0
60 |
61 | def main():
62 | # Output from FUT and Golden Model
63 | FUT = sys.argv[1]
64 | ND = sys.argv[2]
65 | PREC_IN = sys.argv[3]
66 | PREC_OUT = sys.argv[4]
67 | OUT_PATH = sys.argv[5]
68 | G_OUT_PATH = sys.argv[6]
69 |
70 | # No error detected
71 | error = 0
72 | with open(OUT_PATH, "r") as out, open(G_OUT_PATH, "r") as gout:
73 | for out_line, golden_line in zip(out, gout):
74 | out_line = out_line.split()
75 | golden_line = golden_line.split()
76 | # Convert data to binary
77 | in_b = hex2bin(out_line[0], PREC_IN)
78 | out_b = hex2bin(out_line[1], PREC_OUT)
79 | gold_b = hex2bin(golden_line[1], PREC_OUT)
80 | # Check
81 | if ND == 'nd':
82 | line_ok = check_op_nd(in_b, out_b, gold_b, FUT, PREC_IN, PREC_OUT)
83 | else:
84 | line_ok = check_op(in_b, out_b, gold_b, FUT, PREC_IN, PREC_OUT)
85 | # Output potential error
86 | if not line_ok:
87 | print('Error detected. FUT line: ')
88 | print(out_line)
89 | print('is not compatible with golden line: ')
90 | print(golden_line)
91 | print('\n')
92 | error = 1
93 |
94 | if not error:
95 | print('{} - test against libgcc successful.'.format(FUT))
96 | else:
97 | print('{} - test against libgcc failed.'.format(FUT))
98 |
99 | if __name__ == '__main__':
100 | main()
101 |
--------------------------------------------------------------------------------
/script/fp_util.py:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with rvfplib If not, see .
19 | # Copyright ETH Zurich 2020
20 |
21 | # Return 1 if bin_string on prec bit is either Inf or NaN
22 | def isSpecial(bin_string, prec):
23 | if prec == '32':
24 | if bin_string[1:9] == '1'*8:
25 | return 1
26 | else:
27 | return 0
28 | elif prec == '64':
29 | if bin_string[1:12] == '1'*11:
30 | return 1
31 | else:
32 | return 0
33 | else:
34 | print('Error: precision should be either 32 or 64.')
35 |
36 | # Return 1 if bin_string on prec bit is Inf
37 | def isInf(bin_string, prec):
38 | if prec == '32':
39 | if isSpecial(bin_string, prec) and bin_string[9:32] == '0'*23:
40 | return 1
41 | else:
42 | return 0
43 | elif prec == '64':
44 | if isSpecial(bin_string, prec) and bin_string[12:64] == '0'*52:
45 | return 1
46 | else:
47 | return 0
48 | else:
49 | print('Error: precision should be either 32 or 64.')
50 |
51 | # Return 1 if bin_string on prec bit is NaN
52 | def isNan(bin_string, prec):
53 | if prec == '32':
54 | if isSpecial(bin_string, prec) and bin_string[9:32] != '0'*23:
55 | return 1
56 | else:
57 | return 0
58 | elif prec == '64':
59 | if isSpecial(bin_string, prec) and bin_string[12:64] != '0'*52:
60 | return 1
61 | else:
62 | return 0
63 | else:
64 | print('Error: precision should be either 32 or 64.')
65 |
66 | # Return 1 if bin_string on prec bit is denormal
67 | def isDenormal(bin_string, prec):
68 | if prec == '32':
69 | if bin_string[1:9] == '0'*8 and bin_string[9:32] != '0'*23:
70 | return 1
71 | else:
72 | return 0
73 | elif prec == '64':
74 | if bin_string[1:12] == '0'*11 and bin_string[12:64] != '0'*52:
75 | return 1
76 | else:
77 | return 0
78 | else:
79 | print('Error: precision should be either 32 or 64.')
80 |
81 | # Return 1 if bin_string on prec bit is zero
82 | def isZero(bin_string, prec):
83 | if prec == '32':
84 | if bin_string[1:9] == '0'*8 and bin_string[9:32] == '0'*23:
85 | return 1
86 | else:
87 | return 0
88 | elif prec == '64':
89 | if bin_string[1:12] == '0'*11 and bin_string[12:64] == '0'*52:
90 | return 1
91 | else:
92 | return 0
93 | else:
94 | print('Error: precision should be either 32 or 64.')
95 |
96 | # Return 1 if bin_string on prec bit is zero
97 | def isZeroDenormal(bin_string, prec):
98 | if prec == '32':
99 | if bin_string[1:9] == '0'*8:
100 | return 1
101 | else:
102 | return 0
103 | elif prec == '64':
104 | if bin_string[1:12] == '0'*11:
105 | return 1
106 | else:
107 | return 0
108 | else:
109 | print('Error: precision should be either 32 or 64.')
110 |
111 | # Convert an hex string into a bin string of precision prec
112 | def hex2bin(hex_string, prec):
113 | if prec == '32':
114 | return format(int(hex_string, 16), '032b')
115 | elif prec == '64':
116 | return format(int(hex_string, 16), '064b')
117 | else:
118 | print('Error: precision should be either 32 or 64.')
119 |
--------------------------------------------------------------------------------
/script/test.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Copyright ETH Zurich 2020
4 | #
5 | # Author: Matteo Perotti
6 | #
7 | # This file is part of rvfplib.
8 | #
9 | # rvfplib is free software: you can redistribute it and/or modify
10 | # it under the terms of the GNU General Public License as published by
11 | # the Free Software Foundation, either version 3 of the License, or
12 | # (at your option) any later version.
13 | #
14 | # rvfplib is distributed in the hope that it will be useful,
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | # GNU General Public License for more details.
18 | #
19 | # You should have received a copy of the GNU General Public License
20 | # along with rvfplib If not, see .
21 | # Copyright ETH Zurich 2020
22 |
23 | # This script allows testing the standard versions of the FP lib function
24 | # This is only a wrapper to generate inputs for the test, the IEEE-compliant output and the output of the function under test
25 |
26 | # This script should be launched from the root folder, e.g. from the same level of the test/ folder
27 |
28 | # Function Under Test. SoftFloat format (e.g. f32_add)
29 | FUT=$1
30 | # Pass nd to test the no-denormal function. Pass any other string for the standard one
31 | ND=$2
32 | # Some functions do not have a respective in TestFloat or are problematic. Compare only against libgcc
33 | NO_TESTFLOAT_CHECK=$3
34 | # FP precision of the function inputs. Can be either 32 or 64. e.g., if FUT=f32_add, PREC_IN must be 32
35 | PREC_IN=$4
36 | # FP precision of the function output. Can be either 32 or 64. e.g., if FUT=f32_add, PREC_OUT must be 32
37 | PREC_OUT=$5
38 | # Number of inputs of the function. e.g., f32_add has N_IN=2
39 | N_IN=$6
40 | # Testing depth. It can be either 1 (superficial tests) or 2 (deep tests)
41 | LV=$7
42 | # Library optimization. It can be either performance or size.
43 | LIB_OPT=$8
44 | # Rounding mode, in TestFloat argument format (e.g. -rminMag). Leave empty not to pass any argument (default is RNE)
45 | RND=$9
46 |
47 | if [[ "$ND" == "std" && "$LIB_OPT" == "performance" ]] ; then
48 | LIB="-lrvfp"
49 | elif [[ "$ND" == "nd" && "$LIB_OPT" == "performance" ]] ; then
50 | LIB="-lrvfp_nd"
51 | elif [[ "$ND" == "std" && "$LIB_OPT" == "size" ]]; then
52 | LIB="-lrvfp_s"
53 | elif [[ "$ND" == "nd" && "$LIB_OPT" == "size" ]]; then
54 | LIB="-lrvfp_nd_s"
55 | fi
56 | # Variables
57 | BIN_PATH="test/${FUT}_${ND}_${LIB_OPT}/bin/"
58 | G_BIN_PATH="$BIN_PATH/check/"
59 | BIN="$BIN_PATH/$FUT.test"
60 | G_BIN="$G_BIN_PATH/$FUT.test"
61 | DUMP="$BIN_PATH/$FUT.dump"
62 | G_DUMP="$G_BIN_PATH/$FUT.dump"
63 | SRC="src/c/$FUT/main.c"
64 | INC_PATH="include"
65 | LIB_PATH="build/lib"
66 | OUT_PATH="test/${FUT}_${ND}_${LIB_OPT}/out/"
67 | G_OUT_PATH="$OUT_PATH/golden/"
68 | IN_PATH="test/${FUT}_${ND}_${LIB_OPT}/in"
69 | IN="$IN_PATH/in.txt"
70 | OUT="$OUT_PATH/out.txt"
71 | G_OUT="$G_OUT_PATH/out.txt"
72 | GCC_PREFIX="${GCC_TOOLS_BIN_PATH}/riscv32-unknown-elf"
73 | SPIKE="${SPIKE_PATH} --isa=rv32imc ${PK_PATH}"
74 |
75 | # nesf2, gesf2, gtsf2, ... special cases. Alias with the respective (opposite) SoftFloat functions
76 | SF_FUT=$FUT
77 | if [[ "$(echo $FUT | cut -d '_' -f 2)" == "ne" ]] ; then
78 | SF_FUT="f${PREC_IN}_eq"
79 | elif [[ "$(echo $FUT | cut -d '_' -f 2)" == "gt" ]] ; then
80 | SF_FUT="f${PREC_IN}_lt"
81 | elif [[ "$(echo $FUT | cut -d '_' -f 2)" == "ge" ]] ; then
82 | SF_FUT="f${PREC_IN}_le"
83 | fi
84 |
85 | # Make the library
86 | make -s clean
87 | make -s
88 |
89 | # Create the folder structure, if not present
90 | mkdir -p $BIN_PATH
91 | mkdir -p $G_BIN_PATH
92 | mkdir -p $G_OUT_PATH
93 | mkdir -p $IN_PATH
94 |
95 | # Compile the two programs and obtain their dumps
96 | $GCC_PREFIX-gcc -march=rv32imc -mabi=ilp32 -I $INC_PATH -L $LIB_PATH $SRC $LIB -o $BIN
97 | $GCC_PREFIX-gcc -march=rv32imc -mabi=ilp32 -I $INC_PATH $SRC -o $G_BIN
98 | $GCC_PREFIX-objdump -xD $BIN > $DUMP
99 | $GCC_PREFIX-objdump -xD $G_BIN > $G_DUMP
100 |
101 | # Generate input
102 | testfloat_gen -level $LV $RND $SF_FUT > $IN
103 |
104 | # Process the input with the golden model
105 | cat $IN | $SPIKE $G_BIN > $G_OUT
106 | # Remove the first output line (trash from spike)
107 | tail -n +2 $G_OUT > $G_OUT.tmp
108 | mv $G_OUT.tmp $G_OUT
109 |
110 | # Process the input with the FUT
111 | cat $IN | $SPIKE $BIN > $OUT
112 | # Remove the first output line (trash from spike)
113 | tail -n +2 $OUT > $OUT.tmp
114 | mv $OUT.tmp $OUT
115 |
116 | # Double check the result
117 | # Check with libgcc and TestFloat. Use scripts+libgcc only if testing the no-denormal version
118 | if [[ "$ND" == "std" && "${NO_TESTFLOAT_CHECK}" == "0" ]] ; then
119 | cat $OUT | testfloat_ver $RND $SF_FUT
120 | fi
121 | if [[ "$N_IN" == "1" ]] ; then
122 | ./script/check1.py $FUT $ND $PREC_IN $PREC_OUT $OUT $G_OUT
123 | else
124 | ./script/check2.py $FUT $ND $PREC_IN $PREC_OUT $OUT $G_OUT
125 | fi
126 |
--------------------------------------------------------------------------------
/script/topScript_test.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Copyright ETH Zurich 2020
4 | #
5 | # Author: Matteo Perotti
6 | #
7 | # This file is part of rvfplib.
8 | #
9 | # rvfplib is free software: you can redistribute it and/or modify
10 | # it under the terms of the GNU General Public License as published by
11 | # the Free Software Foundation, either version 3 of the License, or
12 | # (at your option) any later version.
13 | #
14 | # rvfplib is distributed in the hope that it will be useful,
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | # GNU General Public License for more details.
18 | #
19 | # You should have received a copy of the GNU General Public License
20 | # along with rvfplib If not, see .
21 | # Copyright ETH Zurich 2020
22 |
23 | # Test the rvfplib functions
24 | # Uncomment a line to test the corresponding function, otherwise comment it
25 |
26 | # FORMAT
27 | # test_script | function_name | lib_version | skip_testfloat | inputs_precision | output_precision | number_of_inputs | testing_depth | optimization | [rounding mode]
28 | # ./script/test.sh | [f32_add, f32_eq, ...] | [std, nd] | [0, 1] | [32, 64] | [32, 64]] | [1, 2] | [1, 2] | [size, performance] | [ , -rminMag]
29 |
30 | # Hardcode this variable to optimize on performance or on size, otherwise it's up to the caller.
31 | LIB_OPT=$1
32 | #LIB_OPT=performance
33 | #LIB_OPT=size
34 |
35 | ### Standard
36 | ./script/test.sh f32_add std 0 32 32 2 1 $LIB_OPT &&\
37 | ./script/test.sh f32_sub std 0 32 32 2 1 $LIB_OPT &&\
38 | ./script/test.sh f32_mul std 0 32 32 2 1 $LIB_OPT &&\
39 | ./script/test.sh f32_div std 0 32 32 2 1 $LIB_OPT &&\
40 | ./script/test.sh f32_eq std 0 32 32 2 1 $LIB_OPT &&\
41 | ./script/test.sh f32_le std 0 32 32 2 1 $LIB_OPT &&\
42 | ./script/test.sh f32_lt std 1 32 32 2 1 $LIB_OPT &&\
43 | ./script/test.sh f32_ne std 0 32 32 2 1 $LIB_OPT &&\
44 | ./script/test.sh f32_ge std 1 32 32 2 1 $LIB_OPT &&\
45 | ./script/test.sh f32_gt std 1 32 32 2 1 $LIB_OPT &&\
46 | ./script/test.sh f32_to_i32 std 0 32 32 1 1 $LIB_OPT -rminMag &&\
47 | ./script/test.sh f32_to_ui32 std 0 32 32 1 1 $LIB_OPT -rminMag &&\
48 | ./script/test.sh f32_to_i64 std 0 32 64 1 1 $LIB_OPT -rminMag &&\
49 | ./script/test.sh f32_to_ui64 std 0 32 64 1 1 $LIB_OPT -rminMag &&\
50 | ./script/test.sh i32_to_f32 std 0 32 32 1 1 $LIB_OPT &&\
51 | ./script/test.sh ui32_to_f32 std 0 32 32 1 1 $LIB_OPT &&\
52 | ./script/test.sh i64_to_f32 std 0 64 32 1 1 $LIB_OPT &&\
53 | ./script/test.sh ui64_to_f32 std 0 64 32 1 1 $LIB_OPT &&\
54 | ./script/test.sh f64_add std 0 64 64 2 1 $LIB_OPT &&\
55 | ./script/test.sh f64_sub std 0 64 64 2 1 $LIB_OPT &&\
56 | ./script/test.sh f64_mul std 0 64 64 2 1 $LIB_OPT &&\
57 | ./script/test.sh f64_div std 0 64 64 2 1 $LIB_OPT &&\
58 | ./script/test.sh f64_eq std 0 64 32 2 1 $LIB_OPT &&\
59 | ./script/test.sh f64_le std 0 64 32 2 1 $LIB_OPT &&\
60 | ./script/test.sh f64_lt std 1 64 32 2 1 $LIB_OPT &&\
61 | ./script/test.sh f64_ne std 0 64 32 2 1 $LIB_OPT &&\
62 | ./script/test.sh f64_ge std 1 64 32 2 1 $LIB_OPT &&\
63 | ./script/test.sh f64_gt std 1 64 32 2 1 $LIB_OPT &&\
64 | ./script/test.sh f64_to_i32 std 0 64 32 1 1 $LIB_OPT -rminMag &&\
65 | ./script/test.sh f64_to_ui32 std 0 64 32 1 1 $LIB_OPT -rminMag &&\
66 | ./script/test.sh f64_to_i64 std 0 64 64 1 1 $LIB_OPT -rminMag &&\
67 | ./script/test.sh f64_to_ui64 std 0 64 64 1 1 $LIB_OPT -rminMag &&\
68 | ./script/test.sh i32_to_f64 std 0 32 64 1 1 $LIB_OPT &&\
69 | ./script/test.sh ui32_to_f64 std 0 32 64 1 1 $LIB_OPT &&\
70 | ./script/test.sh i64_to_f64 std 0 64 64 1 1 $LIB_OPT &&\
71 | ./script/test.sh ui64_to_f64 std 0 64 64 1 1 $LIB_OPT &&\
72 | ./script/test.sh f32_to_f64 std 0 32 64 1 1 $LIB_OPT &&\
73 | ./script/test.sh f64_to_f32 std 0 64 32 1 1 $LIB_OPT &&\
74 | ### RV32EM, no-denormal
75 | ./script/test.sh f32_add nd 0 32 32 2 1 $LIB_OPT &&\
76 | ./script/test.sh f32_sub nd 0 32 32 2 1 $LIB_OPT &&\
77 | ./script/test.sh f32_mul nd 0 32 32 2 1 $LIB_OPT &&\
78 | ./script/test.sh f32_div nd 0 32 32 2 1 $LIB_OPT &&\
79 | ./script/test.sh f64_add nd 0 64 64 2 1 $LIB_OPT &&\
80 | ./script/test.sh f64_sub nd 0 64 64 2 1 $LIB_OPT &&\
81 | ./script/test.sh f64_mul nd 0 64 64 2 1 $LIB_OPT &&\
82 | ./script/test.sh f64_div nd 0 64 64 2 1 $LIB_OPT &&\
83 | ./script/test.sh f64_eq nd 0 64 32 2 1 $LIB_OPT &&\
84 | ./script/test.sh f64_le nd 0 64 32 2 1 $LIB_OPT &&\
85 | ./script/test.sh f64_lt nd 1 64 32 2 1 $LIB_OPT &&\
86 | ./script/test.sh f64_ne nd 0 64 32 2 1 $LIB_OPT &&\
87 | ./script/test.sh f64_ge nd 1 64 32 2 1 $LIB_OPT &&\
88 | ./script/test.sh f64_gt nd 1 64 32 2 1 $LIB_OPT &&\
89 | ./script/test.sh f32_to_f64 nd 0 32 64 1 1 $LIB_OPT &&\
90 | ./script/test.sh f64_to_f32 nd 0 64 32 1 1 $LIB_OPT &&\
91 |
92 | echo "Test for optimization=$LIB_OPT completed"
93 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__eqdf2.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # Double Precision FP equivalence checker
27 | # Return 0 if the arguments are equal and neither of them is NaN
28 | # +0 == -0
29 |
30 | #define xh a1
31 | #define xl a0
32 | #define yh a3
33 | #define yl a2
34 |
35 | .global __eqdf2
36 | .global __nedf2
37 |
38 | __nedf2:
39 | __eqdf2:
40 | # Check for NaN first
41 | snez a4, xl
42 | slli a5, xh, 1
43 | or a5, a5, a4
44 | lui a4, 0xFFE00 # Load shifted NaN pattern
45 | bltu a4, a5, nan # Branch if NaN is detected
46 | snez a5, yl
47 | slli t0, yh, 1
48 | or t0, t0, a5
49 | bltu a4, t0, nan # Branch if NaN is detected
50 | # Check for +0 -0
51 | or a4, xh, yh
52 | slli a4, a4, 1
53 | or a4, a4, xl
54 | or a4, a4, yl
55 | beqz a4, normal_end
56 | # Check for equality
57 | xor xl, xl, yl
58 | xor xh, xh, yh
59 | or a4, xh, xl
60 | normal_end:
61 | nan:
62 | snez xl, a4 # Set the correct result
63 | ret
64 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__eqsf2.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # Single Precision FP equivalence checker
27 | # Return 0 if the arguments are equal and neither of them is NaN
28 | # +0 == -0
29 |
30 | .global __eqsf2
31 | .global __nesf2
32 |
33 | __nesf2:
34 | __eqsf2:
35 | lui a5,0xff000 # Load shifted NaN pattern
36 | # Check for NaN
37 | slli a2,a0,0x1
38 | bltu a5,a2,end # Branch if NaN is detected
39 | slli a3,a1,0x1
40 | bltu a5,a3,end # Branch if NaN is detected
41 | # Check for +0, -0
42 | or a5,a2,a3
43 | beqz a5,end
44 | # Effective comparison
45 | xor a5,a0,a1 # Two numbers are equal if they are equal
46 | end:
47 | snez a0,a5
48 | ret
49 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__extendsfdf2.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | .global __extendsfdf2
27 |
28 | #ifdef PERFORMANCE
29 |
30 | __extendsfdf2:
31 | lui a1, 0x80000 # Mask for the sign
32 | and a1, a1, a0 # Save the sign
33 | slli a3, a0, 1 # Eat the sign
34 | # Check for zeroes/denormals
35 | srai a4, a3, 24
36 | beqz a4, zero_den
37 | # Prepare a0 and a1
38 | srai a5, a3, 3 # Position the exponent and mantissa bits (trick to easily adjust the bias)
39 | srli a5, a5, 1 # Prepare a void for the sign
40 | slli a0, a3, 28 # Adjust LSbs
41 | or a1, a1, a5 # Restore the sign
42 | # Check for inf/NaN
43 | addi a4, a4, 1
44 | beqz a4, inf_nan
45 | # Adjust the bias for the exponent (add 1023-127 with a trick)
46 | lui a5, 0x38000
47 | xor a1, a1, a5
48 | exit:
49 | ret
50 |
51 | inf_nan:
52 | # Check for NaN, otherwise the result is correct
53 | slli a3, a3, 8
54 | beqz a3, exit
55 | lui a1, 0x7FF80 # Make the output a quiet NaN
56 | li a0, 0
57 | ret
58 |
59 | # Flush denormals to corretly signed 0
60 | zero_den:
61 | bnez a3, denormal
62 | li a0, 0
63 | ret
64 |
65 | denormal:
66 | # Normalize the mantissa where it is, shift later. In the end, add the implicit 1 to the exponent
67 | li a4, 0x380 # Load minimum exponent
68 | # CLZ
69 | lui a5, 0x00002
70 | bgeu a3, a5, 1f
71 | slli a3, a3, 12
72 | addi a4, a4, -12
73 | 1:
74 | slli a5, a5, 6
75 | bgeu a3, a5, 2f
76 | slli a3, a3, 6
77 | addi a4, a4, -6
78 | 2:
79 | slli a5, a5, 3
80 | bgeu a3, a5, 3f
81 | slli a3, a3, 3
82 | addi a4, a4, -3
83 | 3:
84 | slli a5, a5, 1
85 | bgeu a3, a5, 4f
86 | slli a3, a3, 1
87 | addi a4, a4, -1
88 | 4:
89 | slli a5, a5, 1
90 | bgeu a3, a5, 5f
91 | slli a3, a3, 1
92 | addi a4, a4, -1
93 | 5:
94 | # Shift the mantissa and align to a double-precision format
95 | slli a0, a3, 28 # Save the bits that would be lost after adaptation
96 | srli a3, a3, 4 # Adapt to DP format
97 | slli a4, a4, 20 # Add the exponent
98 | add a3, a3, a4
99 | or a1, a1, a3 # Merge the sign
100 | ret
101 |
102 | #else
103 |
104 | __extendsfdf2:
105 | lui a1, 0x80000 # Mask for the sign
106 | and a1, a1, a0 # Save the sign
107 | slli a3, a0, 1 # Eat the sign
108 | # Check for zeroes/denormals
109 | srai a4, a3, 24
110 | beqz a4, zero_den
111 | # Prepare a0 and a1
112 | srai a5, a3, 3 # Position the exponent and mantissa bits (trick to easily adjust the bias)
113 | srli a5, a5, 1 # Prepare a void for the sign
114 | slli a0, a3, 28 # Adjust LSbs
115 | or a1, a1, a5 # Restore the sign
116 | # Check for inf/NaN
117 | addi a4, a4, 1
118 | beqz a4, inf_nan
119 | # Adjust the bias for the exponent (add 1023-127 with a trick)
120 | lui a5, 0x38000
121 | xor a1, a1, a5
122 | exit:
123 | ret
124 |
125 | inf_nan:
126 | # Check for NaN, otherwise the result is correct
127 | slli a3, a3, 8
128 | beqz a3, exit
129 | lui a4, 0x00080 # Make the output a quiet NaN
130 | or a1, a1, a4
131 | ret
132 |
133 | # Flush denormals to corretly signed 0
134 | zero_den:
135 | bnez a3, denormal
136 | li a0, 0
137 | ret
138 |
139 | denormal:
140 | # Normalize the mantissa where it is, shift later. In the end, add the implicit 1 to the exponent
141 | lui a5, 0x01000
142 | li a4, 0x380 # Load minimum exponent
143 | clz_loop:
144 | slli a3, a3, 1
145 | addi a4, a4, -1
146 | bltu a3, a5, clz_loop
147 | # Shift the mantissa and align to a double-precision format
148 | slli a0, a3, 28 # Save the bits that would be lost after adaptation
149 | srli a3, a3, 4 # Adapt to DP format
150 | slli a4, a4, 20 # Add the exponent
151 | add a3, a3, a4
152 | or a1, a1, a3 # Merge the sign
153 | ret
154 |
155 | #endif
156 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__fixdfdi.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # #define ZERO_NAN 1
27 |
28 | .global __fixdfdi
29 |
30 | #ifdef ZERO_NAN
31 |
32 | __fixdfdi:
33 | # Check special cases
34 | lui a4, 0x80000
35 | srai a5, a1, 31 # Reproduce sign
36 | slli t1, a1, 1 # Remove the sign
37 | srli a2, t1, 21 # Isolate Exponent
38 | # Add bias to the exponent
39 | addi a2, a2, -1023
40 | bltz a2, undflow # Branch if underflow and ret 0
41 | # Isolate mantissa and load implicit 1
42 | slli a1, t1, 10
43 | srli a3, a0, 21
44 | or a1, a1, a3
45 | slli a0, a0, 11
46 | or a1, a1, a4 # Add implicit 1
47 | # At this point, the 12 LSbs of H and the 12 MSbs of L are ==
48 | # Understand if the exp falls within [0, 31)
49 | neg a2, a2
50 | addi a2, a2, 31
51 | bltz a2, ge_32
52 | # lt_32
53 | # Multiply number by 2^exp
54 | # a1 is empty
55 | srl a0, a1, a2
56 | li a1, 0
57 | # Neg it if necessary
58 | beqz a5, 1f
59 | neg a0, a0
60 | not a1, a1
61 | seqz a4, a0
62 | add a1, a1, a4
63 | 1:
64 | ret
65 |
66 | ge_32:
67 | # Check for overflow
68 | addi a2, a2, 32
69 | blez a2, ovflow
70 | # Move mantissa
71 | neg a4, a2
72 | sll a3, a1, a4
73 | srl a0, a0, a2
74 | or a0, a0, a3
75 | srl a1, a1, a2
76 | # Neg it if necessary
77 | beqz a5, 1f
78 | neg a0, a0
79 | not a1, a1
80 | seqz a4, a0
81 | add a1, a1, a4
82 | # Ret
83 | 1:
84 | ret
85 |
86 | ovflow:
87 | snez a0, a0
88 | or a0, a0, t1
89 | lui a3, 0xFFE00
90 | bgt a0, a3, nan
91 | li a0, -1
92 | not a1, a4
93 | xor a0, a0, a5
94 | xor a1, a1, a5
95 | ret
96 |
97 | nan:
98 | undflow:
99 | li a0, 0
100 | li a1, 0
101 | ret
102 |
103 | #else
104 |
105 | __fixdfdi:
106 | # Check special cases
107 | lui a4, 0x80000
108 | srai a5, a1, 31 # Reproduce sign
109 | slli a1, a1, 1 # Remove the sign
110 | srli a2, a1, 21 # Isolate Exponent
111 | # Add bias to the exponent
112 | addi a2, a2, -1023
113 | bltz a2, undflow # Branch if underflow and ret 0
114 | # Isolate mantissa and load implicit 1
115 | slli a1, a1, 10
116 | srli a3, a0, 21
117 | or a1, a1, a3
118 | slli a0, a0, 11
119 | or a1, a1, a4 # Add implicit 1
120 | # At this point, the 12 LSbs of H and the 12 MSbs of L are ==
121 | # Understand if the exp falls within [0, 31]
122 | neg a2, a2
123 | addi a2, a2, 31
124 | bltz a2, ge_32
125 | # lt_32, 0 <= a2 <= 31
126 | # Multiply number by 2^exp
127 | # a1 is empty
128 | srl a0, a1, a2
129 | li a1, 0
130 | # Neg it if necessary
131 | beqz a5, 1f
132 | neg a0, a0
133 | not a1, a1
134 | seqz a4, a0
135 | add a1, a1, a4
136 | 1:
137 | ret
138 |
139 | ge_32:
140 | # Check if -31 <= a2 <= -1
141 | # Check for overflow
142 | addi a2, a2, 32
143 | # 1 <= a2 <= 31
144 | blez a2, ovflow
145 | # 1 <= a2 <= 31
146 | # Move mantissa
147 | neg a4, a2
148 | # a4 behaves as (31 < a4 < 1)
149 | sll a3, a1, a4
150 | srl a0, a0, a2
151 | or a0, a0, a3
152 | srl a1, a1, a2
153 | # Neg it if necessary
154 | beqz a5, 1f
155 | neg a0, a0
156 | not a1, a1
157 | seqz a4, a0
158 | add a1, a1, a4
159 | # Ret
160 | 1:
161 | ret
162 |
163 | ovflow:
164 | li a0, -1
165 | not a1, a4
166 | xor a0, a0, a5
167 | xor a1, a1, a5
168 | ret
169 |
170 | undflow:
171 | li a0, 0
172 | li a1, 0
173 | ret
174 |
175 | #endif
176 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__fixdfsi.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # Define ZERO_NAN to return a 0 if the input is a NaN. Otherwise, they are treaten as signed infinities.
27 | # libgcc function treats NaN as signed infinities, so here the default is doing the same
28 | # #define ZERO_NAN 1
29 |
30 | .global __fixdfsi
31 |
32 | __fixdfsi:
33 | # Check special cases
34 | lui a4, 0x80000
35 | srai a5, a1, 31 # Reproduce sign
36 | slli a1, a1, 1 # Remove the sign
37 | srli a2, a1, 21 # Isolate Exponent
38 | # Add bias to the exponent
39 | addi a2, a2, -1023
40 | bltz a2, undflow # Branch if underflow and ret 0
41 | neg a2, a2
42 | addi a2, a2, 31
43 | blez a2, ovflow
44 | # Isolate mantissa and load implicit 1
45 | slli a1, a1, 10
46 | srli a0, a0, 21
47 | or a1, a1, a0
48 | or a1, a1, a4 # Add implicit 1
49 | # Multiply number by 2^exp
50 | srl a0, a1, a2
51 | # Neg it if necessary
52 | xor a0, a0, a5
53 | sub a0, a0, a5
54 | # Ret
55 | ret
56 |
57 | ovflow:
58 | #ifdef ZERO_NAN
59 | lui a3, 0xFFE00
60 | snez a0, a0
61 | or a1, a1, a0
62 | bgt a1, a3, nan
63 | #endif
64 | addi a0, a4, -1
65 | xor a0, a0, a5
66 | ret
67 |
68 | #ifdef ZERO_NAN
69 | nan:
70 | #endif
71 | undflow:
72 | li a0, 0
73 | ret
74 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__fixsfdi.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # #define ZERO_NAN 1
27 |
28 | .global __fixsfdi
29 |
30 | __fixsfdi:
31 | # Check special cases
32 | lui a4, 0x80000
33 | srai a5, a0, 31 # Reproduce sign
34 | slli a0, a0, 1 # Remove the sign
35 | srli a2, a0, 24 # Isolate Exponent
36 | # Add bias to the exponent
37 | addi a2, a2, -127
38 | bltz a2, undflow # Branch if underflow and ret 0
39 | # Isolate mantissa and load implicit 1
40 | slli a0, a0, 7
41 | or a0, a0, a4 # Add implicit 1
42 | # Understand if the exp falls within [0, 31)
43 | neg a2, a2
44 | addi a2, a2, 31
45 | bltz a2, ge_32
46 | # lt_32
47 | # Multiply number by 2^exp
48 | # a1 is empty
49 | li a1, 0
50 | srl a0, a0, a2
51 | # Neg it if necessary
52 | beqz a5, 1f
53 | neg a0, a0
54 | not a1, a1
55 | seqz a4, a0
56 | add a1, a1, a4
57 | 1:
58 | ret
59 |
60 | ge_32:
61 | addi a2, a2, 32
62 | blez a2, ovflow
63 | mv a1, a0
64 | li a0, 0
65 | neg a4, a2
66 | sll a0, a1, a4
67 | srl a1, a1, a2
68 | # Neg it if necessary
69 | beqz a5, 1f
70 | neg a0, a0
71 | not a1, a1
72 | seqz a4, a0
73 | add a1, a1, a4
74 | # Ret
75 | 1:
76 | ret
77 |
78 | ovflow:
79 | #ifdef ZERO_NAN
80 | lui a3, 0xFF000
81 | bgt a0, a3, nan
82 | #endif
83 | li a0, -1
84 | not a1, a4
85 | xor a0, a0, a5
86 | xor a1, a1, a5
87 | ret
88 |
89 | #ifdef ZERO_NAN
90 | nan:
91 | #endif
92 | undflow:
93 | li a0, 0
94 | li a1, 0
95 | ret
96 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__fixsfsi.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # Define ZERO_NAN to return a 0 if the input is a NaN. Otherwise, they are treaten as signed infinities.
27 | # libgcc function treats NaN as signed infinities, so here the default is doing the same
28 | # #define ZERO_NAN 1
29 |
30 | .global __fixsfsi
31 |
32 | __fixsfsi:
33 | # Check special cases
34 | lui a4, 0x80000
35 | srai a5, a0, 31 # Reproduce sign
36 | slli a0, a0, 1 # Remove the sign
37 | srli a1, a0, 24 # Isolate Exponent
38 | # Add bias to the exponent
39 | addi a1, a1, -127
40 | bltz a1, undflow # Branch if underflow and ret 0
41 | neg a1, a1
42 | addi a1, a1, 31
43 | blez a1, ovflow
44 | # Isolate mantissa and load implicit 1
45 | slli a0, a0, 7
46 | or a0, a0, a4 # Add implicit 1
47 | # Multiply number by 2^exp
48 | srl a0, a0, a1
49 | # Neg it if necessary
50 | xor a0, a0, a5
51 | sub a0, a0, a5
52 | # Ret
53 | ret
54 |
55 | ovflow:
56 | #ifdef ZERO_NAN
57 | lui a3, 0xFF000
58 | bgt a0, a3, nan
59 | #endif
60 | addi a0, a4, -1
61 | xor a0, a0, a5
62 | ret
63 |
64 | #ifdef ZERO_NAN
65 | nan:
66 | #endif
67 | undflow:
68 | li a0, 0
69 | ret
70 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__fixunsdfdi.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # #define ZERO_NAN 1
27 |
28 | .global __fixunsdfdi
29 |
30 | #ifdef ZERO_NAN
31 |
32 | __fixunsdfdi:
33 | # Check special cases
34 | bltz a1, undflow
35 | lui a4, 0x80000
36 | slli t1, a1, 1 # Remove the sign
37 | srli a2, t1, 21 # Isolate Exponent
38 | # Add bias to the exponent
39 | addi a2, a2, -1023
40 | bltz a2, undflow # Branch if underflow and ret 0
41 | # Isolate mantissa and load implicit 1
42 | slli a1, t1, 10
43 | srli a3, a0, 21
44 | or a1, a1, a3
45 | slli a0, a0, 11
46 | or a1, a1, a4 # Add implicit 1
47 | # At this point, the 12 LSbs of H and the 12 MSbs of L are ==
48 | # Understand if the exp falls within [0, 31)
49 | neg a2, a2
50 | addi a2, a2, 31
51 | bltz a2, ge_32
52 | # lt_32
53 | # Multiply number by 2^exp
54 | # a1 is empty
55 | srl a0, a1, a2
56 | li a1, 0
57 | ret
58 |
59 | ge_32:
60 | # Check for overflow
61 | addi a2, a2, 32
62 | bltz a2, ovflow
63 | # Move mantissa
64 | beqz a2, eq_63_end
65 | neg a4, a2
66 | sll a3, a1, a4
67 | srl a1, a1, a2
68 | srl a0, a0, a2
69 | or a0, a0, a3
70 | eq_63_end:
71 | ret
72 |
73 | ovflow:
74 | snez a0, a0
75 | or a0, a0, t1
76 | lui a3, 0xFFE00
77 | bgt a0, a3, nan
78 | li a0, -1
79 | mv a1, a0
80 | ret
81 |
82 | nan:
83 | undflow:
84 | li a1, 0
85 | li a0, 0
86 | ret
87 |
88 | #else
89 |
90 | __fixunsdfdi:
91 | # Check special cases
92 | bltz a1, undflow
93 | lui a4, 0x80000
94 | slli a1, a1, 1 # Remove the sign
95 | srli a2, a1, 21 # Isolate Exponent
96 | # Add bias to the exponent
97 | addi a2, a2, -1023
98 | bltz a2, undflow # Branch if underflow and ret 0
99 | # Isolate mantissa and load implicit 1
100 | slli a1, a1, 10
101 | srli a3, a0, 21
102 | or a1, a1, a3
103 | slli a0, a0, 11
104 | or a1, a1, a4 # Add implicit 1
105 | # At this point, the 12 LSbs of H and the 12 MSbs of L are ==
106 | # Understand if the exp falls within [0, 31]
107 | neg a2, a2
108 | addi a2, a2, 31
109 | bltz a2, ge_32
110 | # lt_32, 0 <= a2 <= 31
111 | # Multiply number by 2^exp
112 | # a1 is empty
113 | srl a0, a1, a2
114 | li a1, 0
115 | ret
116 |
117 | ge_32:
118 | # Check if -31 <= a2 <= -1
119 | # Check for overflow
120 | addi a2, a2, 32
121 | # 1 <= a2 <= 31
122 | bltz a2, ovflow
123 | # 1 <= a2 <= 31
124 | # Move mantissa
125 | beqz a2, eq_63_end
126 | neg a4, a2
127 | # a4 behaves as (31 < a4 < 1)
128 | sll a3, a1, a4
129 | srl a0, a0, a2
130 | or a0, a0, a3
131 | srl a1, a1, a2
132 | eq_63_end:
133 | ret
134 |
135 | ovflow:
136 | li a0, -1
137 | mv a1, a0
138 | ret
139 |
140 | undflow:
141 | li a0, 0
142 | li a1, 0
143 | ret
144 |
145 | #endif
146 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__fixunsdfsi.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # Define ZERO_NAN to return a 0 if the input is a NaN. Otherwise, they are treaten as signed infinities.
27 | # libgcc function treats NaN as signed infinities, so here the default is doing the same
28 | # #define ZERO_NAN 1
29 |
30 | .global __fixunsdfsi
31 |
32 | __fixunsdfsi:
33 | # Return 0 if negative
34 | blez a1, undflow
35 | slli a1, a1, 1 # Remove the sign
36 | srli a2, a1, 21 # Isolate Exponent
37 | # Add bias to the exponent
38 | addi a2, a2, -1023
39 | bltz a2, undflow # Branch if underflow and ret 0
40 | neg a2, a2
41 | addi a2, a2, 31
42 | bltz a2, ovflow
43 | # Isolate mantissa and load implicit 1
44 | slli a1, a1, 10
45 | srli a0, a0, 21
46 | or a1, a1, a0
47 | lui a4, 0x80000
48 | or a1, a1, a4 # Add implicit 1
49 | # Multiply number by 2^exp
50 | srl a0, a1, a2
51 | # Ret
52 | ret
53 |
54 | ovflow:
55 | #ifdef ZERO_NAN
56 | lui a3, 0xFFE00
57 | snez a0, a0
58 | or a1, a1, a0
59 | bgt a1, a3, nan
60 | #endif
61 | li a0, -1
62 | ret
63 |
64 | #ifdef ZERO_NAN
65 | nan:
66 | #endif
67 | undflow:
68 | li a0, 0
69 | ret
70 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__fixunssfdi.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | .global __fixunssfdi
27 |
28 | __fixunssfdi:
29 | # Check special cases
30 | blez a0, undflow
31 | lui a4, 0x80000
32 | slli a0, a0, 1 # Remove the sign
33 | srli a2, a0, 24 # Isolate Exponent
34 | # Add bias to the exponent
35 | addi a2, a2, -127
36 | bltz a2, undflow # Branch if underflow and ret 0
37 | # Isolate mantissa and load implicit 1
38 | slli a0, a0, 7
39 | or a0, a0, a4 # Add implicit 1
40 | # Understand if the exp falls within [0, 31)
41 | neg a2, a2
42 | addi a2, a2, 31
43 | bltz a2, ge_32
44 | # lt_32
45 | # Multiply number by 2^exp
46 | # a1 is empty
47 | li a1, 0
48 | srl a0, a0, a2
49 | ret
50 |
51 | ge_32:
52 | addi a2, a2, 32
53 | bltz a2, ovflow
54 | srl a1, a0, a2
55 | beqz a2, eq_63_end
56 | neg a4, a2
57 | sll a0, a0, a4
58 | ret
59 |
60 | ovflow:
61 | #ifdef ZERO_NAN
62 | lui a3, 0xFF000
63 | bgt a0, a3, nan
64 | #endif
65 | li a0, -1
66 | li a1, -1
67 | ret
68 |
69 | #ifdef ZERO_NAN
70 | nan:
71 | #endif
72 | undflow:
73 | li a1, 0
74 | eq_63_end:
75 | li a0, 0
76 | ret
77 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__fixunssfsi.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | .global __fixunssfsi
27 |
28 | __fixunssfsi:
29 | # Check special cases
30 | blez a0, undflow # Return 0 if negative
31 | slli a0, a0, 1 # Remove the sign
32 | srli a1, a0, 24 # Isolate Exponent
33 | # Add bias to the exponent
34 | addi a1, a1, -127
35 | bltz a1, undflow # Branch if underflow and ret 0
36 | neg a1, a1
37 | addi a1, a1, 31
38 | bltz a1, ovflow
39 | # Isolate mantissa and load implicit 1
40 | slli a0, a0, 7
41 | lui a4, 0x80000
42 | or a0, a0, a4 # Add implicit 1
43 | # Multiply number by 2^exp
44 | srl a0, a0, a1
45 | # Ret
46 | ret
47 |
48 | ovflow:
49 | #ifdef ZERO_NAN
50 | lui a3, 0xFF000
51 | bgt a0, a3, nan
52 | #endif
53 | li a0, -1
54 | ret
55 |
56 | #ifdef ZERO_NAN
57 | nan:
58 | #endif
59 | undflow:
60 | li a0, 0
61 | ret
62 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__floatdidf.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | .global __floatdidf
27 |
28 | __floatdidf:
29 | srli a5, a1, 31 # Isolate the sign
30 | # c2 the input if negative
31 | bgez a1, 1f
32 | neg a0, a0
33 | not a1, a1
34 | seqz a2, a0
35 | add a1, a1, a2
36 | 1:
37 | slli a5, a5, 31 # Prepare the sign
38 | # CLZ
39 | li a2, 1085 # 30 + 32 + 1023 (+ 1), since we will add also the implicit 1
40 | bnez a1, 2f # Jump if the MSreg is not 0
41 | beqz a0, exit # The input number is 0
42 | mv a1, a0 # Swap a1 and a0, this works as a preshift
43 | li a0, 0
44 | addi a2, a2, -32
45 | 2:
46 | bltz a1, 4f # If the implicit 1 is already positioned, skip the clz
47 | 3:
48 | addi a2, a2, -1
49 | slli a1, a1, 1
50 | bgtz a1, 3b
51 | # Shift_right. The MSB is now the implicit bit
52 | # Round to nearest even
53 | 4:
54 | # Adjust the shift outside the loop to save time!
55 | addi a4, a2, -1053 # (-1085 + 32)
56 | srl a3, a0, a4
57 | or a1, a1, a3
58 | neg a4, a4
59 | sll a0, a0, a4
60 | # Store the bits that would be ejected
61 | sll a4, a0, 21 # Rounding bits
62 | # Keep into account also the shifted-out LSbs in a0
63 | srli a0, a0, 11
64 | slli a3, a1, 21
65 | srli a1, a1, 11
66 | or a0, a0, a3
67 | bgez a4, 1f
68 | addi a0, a0, 1 # Preventively round up
69 | seqz a3, a0
70 | add a1, a1, a3
71 | slli a4, a4, 1 # Check if clearing the LSB (RNE)
72 | seqz a4, a4
73 | not a4, a4
74 | and a0, a0, a4
75 | 1:
76 | # Biased Exp and sign
77 | slli a2, a2, 20
78 | add a1, a1, a2
79 | or a1, a1, a5
80 | exit:
81 | ret
82 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__floatdisf.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | .global __floatdisf
27 |
28 | __floatdisf:
29 | srli a5, a1, 31
30 | # c2 the input if negative
31 | bgez a1, 1f
32 | neg a0, a0
33 | not a1, a1
34 | seqz a2, a0
35 | add a1, a1, a2
36 | 1:
37 | slli a5, a5, 31 # Prepare the sign
38 | # CLZ
39 | li a2, 189 # 30 + 32 + 127 (+ 1), since we will add also the implicit 1
40 | bnez a1, 2f # Jump if the MSreg is not 0
41 | beqz a0, exit # The input number is 0
42 | mv a1, a0 # Swap a1 and a0, this works as a preshift
43 | li a0, 0
44 | addi a2, a2, -32
45 | 2:
46 | bltz a1, 4f # If the implicit 1 is already positioned, skip the clz
47 | 3:
48 | addi a2, a2, -1
49 | slli a1, a1, 1
50 | bgtz a1, 3b
51 | # Shift_right. The MSB is now the implicit bit
52 | # Round to nearest even
53 | 4:
54 | # Adjust the shift outside the loop to save a lot of time!
55 | addi a4, a2, -157 # (-189 + 32)
56 | srl a3, a0, a4
57 | or a1, a1, a3
58 | neg a4, a4
59 | sll a0, a0, a4
60 | # Keep into account also the shifted-out LSbs in a0
61 | snez a4, a0
62 | srli a0, a1, 8
63 | slli a1, a1, 24
64 | or a1, a1, a4
65 | bgez a1, 1f
66 | addi a0, a0, 1
67 | slli a1, a1, 1
68 | seqz a1, a1
69 | not a1, a1
70 | and a0, a0, a1
71 | 1:
72 | # Biased Exp and sign
73 | slli a2, a2, 23
74 | add a0, a0, a2
75 | or a0, a0, a5
76 | exit:
77 | ret
78 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__floatsidf.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | .global __floatsidf
27 |
28 | __floatsidf:
29 | srai a5, a0, 31 # Negate if needed
30 | xor a1, a0, a5
31 | sub a1, a1, a5
32 | beqz a0, exit
33 | slli a5, a5, 31 # Prepare the sign
34 | # CLZ
35 | li a2, 1053 # 30 + 1023 (+ 1 after), since we will add also the implicit 1
36 | bltz a1, 2f # Check if the input was 0x80000000
37 | # The MSB cannot be zero here (number always positive)
38 | 1:
39 | addi a2, a2, -1
40 | slli a1, a1, 1
41 | bgtz a1, 1b
42 | # Shift_right. The MSB is now the implicit bit
43 | # No need for rounding
44 | 2:
45 | slli a0, a1, 21
46 | srli a1, a1, 11
47 | # Biased Exp and sign
48 | slli a2, a2, 20
49 | add a1, a1, a2
50 | or a1, a1, a5
51 | exit:
52 | ret
53 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__floatsisf.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | .global __floatsisf
27 |
28 | __floatsisf:
29 | beqz a0, exit
30 | srai a5, a0, 31 # Negate if needed
31 | xor a0, a0, a5
32 | sub a0, a0, a5
33 | slli a5, a5, 31 # Prepare the sign
34 | # CLZ
35 | li a1, 157 # 30 + 127 (+ 1), since we will add also the implicit 1
36 | bltz a0, 2f # Check if the input was 0x80000000
37 | # The MSB cannot be zero here (number always positive)
38 | 1:
39 | addi a1, a1, -1
40 | slli a0, a0, 1
41 | bgtz a0, 1b
42 | # Shift_right. The MSB is now the implicit bit
43 | # Round to nearest even
44 | 2:
45 | slli a2, a0, 24
46 | srli a0, a0, 8
47 | bgez a2, 1f
48 | addi a0, a0, 1
49 | slli a2, a2, 1
50 | seqz a2, a2
51 | not a2, a2
52 | and a0, a0, a2
53 | 1:
54 | # Biased Exp and sign
55 | slli a1, a1, 23
56 | add a0, a0, a1
57 | or a0, a0, a5
58 | exit:
59 | ret
60 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__floatundidf.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | .global __floatundidf
27 |
28 | __floatundidf:
29 | # CLZ
30 | li a2, 1085 # 30 + 32 + 1023 (+ 1), since we will add also the implicit 1
31 | bnez a1, 2f # Jump if the MSreg is not 0
32 | beqz a0, exit # The input number is 0
33 | mv a1, a0 # Swap a1 and a0, this works as a preshift
34 | li a0, 0
35 | addi a2, a2, -32
36 | 2:
37 | bltz a1, 4f # If the implicit 1 is already positioned, skip the clz
38 | 3:
39 | addi a2, a2, -1
40 | slli a1, a1, 1
41 | bgtz a1, 3b
42 | # Shift_right. The MSB is now the implicit bit
43 | # Round to nearest even
44 | 4:
45 | # Adjust the shift outside the loop to save time!
46 | addi a4, a2, -1085
47 | beqz a4, 5f
48 | srl a3, a0, a4
49 | or a1, a1, a3
50 | neg a4, a4
51 | sll a0, a0, a4
52 | # Store the bits that would be ejected
53 | 5:
54 | sll a4, a0, 21 # Rounding bits
55 | # Keep into account also the shifted-out LSbs in a0
56 | srli a0, a0, 11
57 | slli a3, a1, 21
58 | srli a1, a1, 11
59 | or a0, a0, a3
60 | bgez a4, 1f
61 | addi a0, a0, 1 # Preventively round up
62 | seqz a3, a0
63 | add a1, a1, a3
64 | slli a4, a4, 1 # Check if clearing the LSB (RNE)
65 | seqz a4, a4
66 | not a4, a4
67 | and a0, a0, a4
68 | 1:
69 | # Biased Exp and sign
70 | slli a2, a2, 20
71 | add a1, a1, a2
72 | exit:
73 | ret
74 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__floatundisf.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | .global __floatundisf
27 |
28 | __floatundisf:
29 | # CLZ
30 | li a2, 189 # 30 + 32 + 127 (+ 1), since we will add also the implicit 1
31 | bnez a1, 2f # Jump if the MSreg is not 0
32 | beqz a0, exit # The input number is 0
33 | mv a1, a0 # Swap a1 and a0, this works as a preshift
34 | li a0, 0
35 | addi a2, a2, -32
36 | 2:
37 | bltz a1, 4f # If the implicit 1 is already positioned, skip the clz
38 | 3:
39 | addi a2, a2, -1
40 | slli a1, a1, 1
41 | bgtz a1, 3b
42 | # Shift_right. The MSB is now the implicit bit
43 | # Round to nearest even
44 | 4:
45 | # Adjust the shift outside the loop to save time!
46 | addi a4, a2, -189
47 | beqz a4, 5f
48 | srl a3, a0, a4
49 | or a1, a1, a3
50 | neg a4, a4
51 | sll a0, a0, a4
52 | # Keep into account also the shifted-out LSbs in a0
53 | 5:
54 | snez a4, a0
55 | srli a0, a1, 8
56 | slli a1, a1, 24
57 | or a1, a1, a4
58 | bgez a1, 1f
59 | addi a0, a0, 1
60 | slli a1, a1, 1
61 | seqz a1, a1
62 | not a1, a1
63 | and a0, a0, a1
64 | 1:
65 | # Biased Exp
66 | slli a2, a2, 23
67 | add a0, a0, a2
68 | exit:
69 | ret
70 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__floatunsidf.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | .global __floatunsidf
27 |
28 | __floatunsidf:
29 | mv a1, a0
30 | beqz a0, exit
31 | # CLZ
32 | li a2, 1053 # 30 + 1023 (+ 1 after), since we will add also the implicit 1
33 | bltz a1, 2f # Check if the input was 0x80000000
34 | # The MSB cannot be zero here (number always positive)
35 | 1:
36 | addi a2, a2, -1
37 | slli a1, a1, 1
38 | bgez a1, 1b
39 | # Shift_right. The MSB is now the implicit bit
40 | # No need for rounding
41 | 2:
42 | slli a0, a1, 21
43 | srli a1, a1, 11
44 | # Biased Exp and sign
45 | slli a2, a2, 20
46 | add a1, a1, a2
47 | exit:
48 | ret
49 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__floatunsisf.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | .global __floatunsisf
27 |
28 | __floatunsisf:
29 | beqz a0, exit
30 | # CLZ
31 | li a1, 157 # 31 + 127 (+ 1), since we will add also the implicit 1
32 | bltz a0, 2f
33 | # The MSB cannot be zero here (number always positive)
34 | 1:
35 | addi a1, a1, -1
36 | slli a0, a0, 1
37 | bgtz a0, 1b
38 | # Shift_right. The MSB is now the implicit bit
39 | # Round to nearest even
40 | 2:
41 | slli a2, a0, 24
42 | srli a0, a0, 8
43 | bgez a2, 1f
44 | addi a0, a0, 1
45 | slli a2, a2, 1
46 | seqz a2, a2
47 | not a2, a2
48 | and a0, a0, a2
49 | 1:
50 | # Biased Exp and sign
51 | slli a1, a1, 23
52 | add a0, a0, a1
53 | exit:
54 | ret
55 |
56 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__gedf2.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # Double Precision FP equivalence checker
27 | # Return 0 if the arguments are equal and neither of them is NaN
28 | # +0 == -0
29 |
30 | #define xh a1
31 | #define xl a0
32 | #define yh a3
33 | #define yl a2
34 |
35 | .global __gedf2
36 |
37 | __gedf2:
38 | # Check for NaN first
39 | snez a4, xl
40 | slli a5, xh, 1
41 | or a5, a5, a4
42 | lui a4, 0xFFE00 # Load shifted NaN pattern
43 | bltu a4, a5, nan # Branch if NaN is detected
44 | snez a5, yl
45 | slli t0, yh, 1
46 | or t0, t0, a5
47 | bltu a4, t0, nan # Branch if NaN is detected
48 | # Check for +0 -0
49 | or a4, xh, yh
50 | slli a4, a4, 1
51 | or a4, a4, xl
52 | or a4, a4, yl
53 | beqz a4, xor_end
54 | # Check for equality
55 | xor a4, xh, yh # Check the signs
56 | bltz a4, pn_np # Branch if different signs
57 | # pp_nn
58 | beq xh, yh, pp_nn_h_eq
59 | # pp_nn_not_eq
60 | sltu a4, xh, yh
61 | sltz a0, yh
62 | xor_end:
63 | xor a0, a0, a4
64 | slli a0, a0, 31
65 | ret
66 |
67 | pp_nn_h_eq:
68 | beq xl, yl, ret_0
69 | # pp_nn_h_eq_l_neq
70 | sltu a4, yl, xl
71 | sltz a0, xh
72 | xori a0, a0, 1
73 | j xor_end
74 |
75 | ret_0:
76 | li a0, 0
77 | ret
78 |
79 | nan:
80 | mv xh, a4
81 | pn_np:
82 | sltz a0, xh # Return 1 if x is positive and y negative, 0 if the opposite
83 | slli a0, a0, 31
84 | ret
85 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__gesf2.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | .global __gesf2
27 |
28 | __gesf2:
29 | # Check for NaN first
30 | lui a3, 0xFF000 # Load shifted NaN pattern
31 | slli a2, a0, 1
32 | bltu a3, a2, ret_m1 # Branch if NaN is detected
33 | slli a2, a1, 1
34 | bltu a3, a2, ret_m1 # Branch if NaN is detected
35 | # Check for +0 -0 (special equality)
36 | or a3, a0, a1
37 | slli a3, a3, 1
38 | beqz a3, ret_0 # +0 == -0, return 0
39 | # Check for the signs
40 | and a3, a0, a1
41 | bltz a3, nn
42 | # pp_pn_np
43 | slt a0, a0, a1
44 | slli a0, a0, 31
45 | ret
46 |
47 | ret_0:
48 | li a0, 0
49 | ret
50 |
51 | ret_m1:
52 | li a0, -1
53 | ret
54 |
55 | nn:
56 | slt a0, a1, a0
57 | slli a0, a0, 31
58 | ret
59 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__gtdf2.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # Double Precision FP equivalence checker
27 | # Return 0 if the arguments are equal and neither of them is NaN
28 | # +0 == -0
29 |
30 | #define xh a1
31 | #define xl a0
32 | #define yh a3
33 | #define yl a2
34 |
35 | .global __gtdf2
36 |
37 | __gtdf2:
38 | # Check for NaN first
39 | snez a4, xl
40 | slli a5, xh, 1
41 | or a5, a5, a4
42 | lui a4, 0xFFE00 # Load shifted NaN pattern
43 | bltu a4, a5, ret_0 # Branch if NaN is detected
44 | snez a5, yl
45 | slli t0, yh, 1
46 | or t0, t0, a5
47 | bltu a4, t0, ret_0 # Branch if NaN is detected
48 | # Check for +0 -0
49 | or a4, xh, yh
50 | slli a4, a4, 1
51 | or a4, a4, xl
52 | or a4, a4, yl
53 | beqz a4, ret_0
54 | # Check the signs
55 | xor a4, xh, yh # Check the signs
56 | bltz a4, pn_np # Branch if different signs
57 | # pp_nn
58 | beq xh, yh, pp_nn_h_eq
59 | # pp_nn_not_eq
60 | sltu a4, yh, xh
61 | end:
62 | sltz a0, yh
63 | xor a0, a0, a4
64 | ret
65 |
66 | pp_nn_h_eq:
67 | beq xl, yl, ret_0
68 | sltu a4, yl, xl
69 | j end
70 |
71 | ret_0:
72 | li a0, 0
73 | ret
74 |
75 | pn_np:
76 | sltz a0, yh # Return 1 if x is negative and y positive, 0 if the opposite
77 | ret
78 |
79 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__gtsf2.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | .global __gtsf2
27 |
28 | __gtsf2:
29 | # Check for NaN first
30 | lui a3, 0xFF000 # Load shifted NaN pattern
31 | slli a2, a0, 1
32 | bltu a3, a2, ret_0 # Branch if NaN is detected
33 | slli a2, a1, 1
34 | bltu a3, a2, ret_0 # Branch if NaN is detected
35 | # Check for +0 -0 (special equality)
36 | or a3, a0, a1
37 | slli a3, a3, 1
38 | beqz a3, ret_0 # +0 == -0
39 | # Check for the signs
40 | and a3, a0, a1
41 | bltz a3, nn
42 | # pp_pn_np
43 | slt a0, a1, a0
44 | ret
45 |
46 | ret_0:
47 | li a0, 0
48 | ret
49 |
50 | nn:
51 | slt a0, a0, a1
52 | ret
53 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__ledf2.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # Double Precision FP equivalence checker
27 | # Return 0 if the arguments are equal and neither of them is NaN
28 | # +0 == -0
29 |
30 | #define xh a1
31 | #define xl a0
32 | #define yh a3
33 | #define yl a2
34 |
35 | .global __ledf2
36 |
37 | __ledf2:
38 | # Check for NaN first
39 | snez a4, xl
40 | slli a5, xh, 1
41 | or a5, a5, a4
42 | lui a4, 0xFFE00 # Load shifted NaN pattern
43 | bltu a4, a5, nan # Branch if NaN is detected
44 | snez a5, yl
45 | slli t0, yh, 1
46 | or t0, t0, a5
47 | bltu a4, t0, nan # Branch if NaN is detected
48 | # Check for +0 -0
49 | or a4, xh, yh
50 | slli a4, a4, 1
51 | or a4, a4, xl
52 | or a4, a4, yl
53 | beqz a4, xor_end
54 | # Check for equality
55 | xor a4, xh, yh # Check the signs
56 | bltz a4, pn_np # Branch if different signs
57 | # pp_nn
58 | beq xh, yh, pp_nn_h_eq
59 | # pp_nn_not_eq
60 | sgtu a4, xh, yh
61 | sltz a0, xh
62 | xor_end:
63 | xor a0, a0, a4
64 | ret
65 |
66 | pp_nn_h_eq:
67 | beq xl, yl, ret_0
68 | # pp_nn_h_eq_l_neq
69 | sltu a4, yl, xl
70 | sltz a0, xh
71 | j xor_end
72 |
73 | ret_0:
74 | li a0, 0
75 | ret
76 |
77 | nan:
78 | mv yh, a4
79 | pn_np:
80 | sltz a0, yh # Return 0 if x is negative and y positive, 1 if the opposite
81 | ret
82 |
83 | # xor a4, xl, yl
84 | # xor a5, xh, yh
85 | # or a4, a4, a5
86 | # beqz a4, normal_end
87 | ## Operands differ
88 | # slt a4, yh, xh
89 | # beq xh, yh, 1f
90 | # beqz a4, neg_check
91 | #1:
92 | # sltu a4, yl, xl
93 | # xor a6, xh, yh
94 | # snez a6, a6
95 | # or a4, a4, a6
96 | ## Check if one is negative
97 | #neg_check:
98 | # and xh, xh, yh
99 | # bgez xh, normal_end
100 | # xori a4, a4, 1
101 | #normal_end:
102 | #nan:
103 | # seqz xl, a4 # Set the correct result
104 | # ret
105 | #
106 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__lesf2.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # Single Precision FP equivalence checker
27 | # Return value less than or equal to zero if the arguments are not NaN and x <= y
28 | # +0 == -0
29 |
30 | .global __lesf2
31 |
32 | __lesf2:
33 | # Check for NaN first
34 | lui a3, 0xFF000 # Load shifted NaN pattern
35 | slli a2, a0, 1
36 | bltu a3, a2, ret_1 # Branch if NaN is detected
37 | slli a2, a1, 1
38 | bltu a3, a2, ret_1 # Branch if NaN is detected
39 | # Check for +0 -0 (special equality)
40 | or a3, a0, a1
41 | slli a3, a3, 1
42 | beqz a3, ret_0 # +0 == -0, return 0
43 | # Check for the signs
44 | beq a0, a1, ret_0
45 | and a3, a0, a1
46 | bltz a3, nn
47 | # pp_pn_np
48 | slt a0, a1, a0
49 | ret
50 |
51 | ret_1:
52 | li a0, 1
53 | ret
54 |
55 | ret_0:
56 | li a0, 0
57 | ret
58 |
59 | nn:
60 | slt a0, a0, a1
61 | ret
62 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__ltdf2.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # Double Precision FP equivalence checker
27 | # Return 0 if the arguments are equal and neither of them is NaN
28 | # +0 == -0
29 |
30 | #define xh a1
31 | #define xl a0
32 | #define yh a3
33 | #define yl a2
34 |
35 | .global __ltdf2
36 |
37 | __ltdf2:
38 | # Check for NaN first
39 | snez a4, xl
40 | slli a5, xh, 1
41 | or a5, a5, a4
42 | lui a4, 0xFFE00 # Load shifted NaN pattern
43 | bltu a4, a5, ret_0 # Branch if NaN is detected
44 | snez a5, yl
45 | slli t0, yh, 1
46 | or t0, t0, a5
47 | bltu a4, t0, ret_0 # Branch if NaN is detected
48 | # Check for +0 -0
49 | or a4, xh, yh
50 | slli a4, a4, 1
51 | or a4, a4, xl
52 | or a4, a4, yl
53 | beqz a4, ret_0
54 | # Check the signs
55 | xor a4, xh, yh # Check the signs
56 | bltz a4, pn_np # Branch if different signs
57 | # pp_nn
58 | beq xh, yh, pp_nn_h_eq
59 | # pp_nn_not_eq
60 | sltu a4, xh, yh
61 | end:
62 | sltz a0, xh
63 | xor a0, a0, a4
64 | slli a0, a0, 31 # Only to interface with libgcc (negative result instead of positive)
65 | ret
66 |
67 | pp_nn_h_eq:
68 | beq xl, yl, ret_0
69 | sltu a4, xl, yl
70 | j end
71 |
72 | ret_0:
73 | li a0, 0
74 | ret
75 |
76 | pn_np:
77 | sltz a0, xh # Return 1 if x is negative and y positive, 0 if the opposite
78 | slli a0, a0, 31 # Only to interface with libgcc (negative result instead of positive)
79 | ret
80 |
81 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__ltsf2.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # Single Precision FP equivalence checker
27 | # Return value less than 0 if the arguments are not NaN and x < y
28 | # +0 == -0
29 |
30 | # This function can also be faster, removing the two "slli" at the ends. We provide a negative result only for compliancy to libgcc interface
31 |
32 | .global __ltsf2
33 |
34 | __ltsf2:
35 | # Check for NaN first
36 | lui a3, 0xFF000 # Load shifted NaN pattern
37 | slli a2, a0, 1
38 | bltu a3, a2, ret_0 # Branch if NaN is detected
39 | slli a2, a1, 1
40 | bltu a3, a2, ret_0 # Branch if NaN is detected
41 | # Check for +0 -0 (special equality)
42 | or a3, a0, a1
43 | slli a3, a3, 1
44 | beqz a3, ret_0 # +0 == -0
45 | # Check for the signs
46 | and a3, a0, a1
47 | bltz a3, nn
48 | # pp_pn_np
49 | slt a0, a0, a1
50 | slli a0, a0, 31 # Neg only for standard libgcc interface
51 | ret
52 |
53 | ret_0:
54 | li a0, 0
55 | ret
56 |
57 | nn:
58 | slt a0, a1, a0
59 | slli a0, a0, 31 # Neg only for standard libgcc interface
60 | ret
61 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__subdf3.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # RISC-V 64-bit FP sub
27 | # Define SPLIT_SUB to keep the subtraction split from the addition. This can be more modular, but less effective in performance and also bigger in code size if both the functions are required
28 |
29 | #ifdef SPLIT_SUB
30 |
31 | .global __subdf3
32 | .global __adddf3
33 |
34 | #define xh a1
35 | #define xl a0
36 | #define yh a3
37 | #define yl a2
38 |
39 | __subdf3:
40 | lui a4, 0x80000 # Load sign mask
41 | xor yh, yh, a4 # Reverse sign Y
42 | j __adddf3 # Jump to add
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__subsf3.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # RISC-V f32_sub
27 |
28 | # Define SPLIT_SUB to keep the subtraction split from the addition. This can be more modular, but less effective in performance and also bigger in code size if both the functions are required
29 |
30 | #ifdef SPLIT_SUB
31 |
32 | .global __subsf3
33 | .global __addsf3
34 |
35 | __subsf3:
36 | lui a5, 0x80000 # change sign
37 | xor a1, a1, a5 # change sign of opB
38 | j __addsf3 # jump to fadd
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/src/asm/ieee754/__truncdfsf2.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # libgcc rounds toward zero and flush the input NaN to a generic quiet NaN
27 | # This function is optimized for common case = numbers within bounds.
28 | # To balance for special numbers (especially infinities), add explicit inf-nan check at the beginning
29 |
30 | .global __truncdfsf2
31 |
32 | #define libgcc
33 |
34 | #ifdef libgcc
35 |
36 | __truncdfsf2:
37 | lui a2, 0x80000 # Mask for the sign
38 | and a3, a2, a1 # Save the sign
39 | slli a1, a1, 1 # Eat the sign
40 | srli a4, a1, 21 # Isolate exponent
41 | addi a4, a4, -896 # Check for an underfow -> exp-(1023-127)
42 | blez a4, undflow # If exponent is less than zero, we have a denormal or zero
43 | addi a5, a4, -254 # Check for an overflow
44 | bgtz a5, inf_nan
45 | # Normal number
46 | slli a5, a0, 3 # Bits to round RNE
47 | srli a0, a0, 29 # Save the lsb of a0 that can be brought to a1
48 | slli a1, a1, 11 # Remove the exponent from a1
49 | srli a1, a1, 9 # Put the mantissa as for a single-precision FP
50 | or a0, a0, a1 # Merge this mantissa with a0 saved bits to form the new mantissa
51 | # Add exponent
52 | slli a4, a4, 23 # Move the final exponent in the correct position
53 | add a0, a0, a4 # Merge the exponent
54 | # Merge the last bits
55 | round:
56 | bgez a5, sign_exit
57 | addi a0, a0, 1
58 | bne a5, a2, sign_exit
59 | andi a0, a0, -2
60 | sign_exit:
61 | or a0, a0, a3 # Merge the sign
62 | ret
63 |
64 | inf_nan:
65 | snez a0, a0 # Keep into account lsbs in a0 for NaN checking
66 | or a1, a1, a0
67 | lui a0, 0xFFE00
68 | bgtu a1, a0, nan
69 | # Inf
70 | lui a0, 0x7F800
71 | or a0, a0, a3
72 | ret
73 |
74 | nan:
75 | # Return the correct NaN
76 | lui a0, 0x7FC00
77 | ret
78 |
79 | # Denormal or zero
80 | undflow:
81 | # Check if denormalized value is possible
82 | addi t1, a4, 23
83 | bltz t1, zero
84 | # Denormalize
85 | lui t0, 0x00200 # Set the implicit 1 (a1 was left shifted by 1)
86 | or a1, a1, t0
87 | slli a1, a1, 10 # Clean mantissa from exponent
88 | srli a1, a1, 8 # Compress to a single-precision format
89 | srli a4, a0, 29 # Save the lsb of a0 that can be brought to a1
90 | or a1, a1, a4 # Merge these bits into a1
91 | slli a0, a0, 3 # Shift also a0
92 | # Shift
93 | addi t1, t1, -24 # t1 is the complementary-right-shift amount
94 | neg a4, t1 # a4 is the correct right shift amount
95 | sll t0, a0, t1 # LSbs that would be lost after the shift (useful for RNE)
96 | srl a5, a0, a4 # Actual a0 right shift
97 | snez t0, t0 # Condense the lost-LSbs
98 | or a5, a5, t0 # Merge them in a0 LSbit
99 | sll t2, a1, t1 # Save the a1 bits that would be lost
100 | or a5, a5, t2 # Save them in a5, that will be used for rounding
101 | srl a0, a1, a4 # Shift a1 by the actual right shift amount, and put it in a0
102 | j round
103 |
104 | zero:
105 | mv a0, a3 # Add sign
106 | ret
107 |
108 |
109 | #else
110 |
111 | .global __truncdfsf2
112 |
113 | __truncdfsf2:
114 | lui a2, 0x80000 # Mask for the sign
115 | and a3, a2, a1 # Save the sign
116 | slli a1, a1, 1 # Eat the sign
117 | lui a4, 0xFFE00
118 | bgeu a1, a4, inf_nan
119 | srli a4, a1, 21
120 | addi a4, a4, -896 # Check for an underfow -> exp-(1023-127)
121 | blez a4, undflow # If exponent is less than zero, we have a denormal or zero
122 | addi a5, a4, -254 # Check for an overflow
123 | bgtz a5, inf
124 | # Normal number
125 | slli a5, a0, 3 # Bits to round RNE
126 | srli a0, a0, 29 # Save the lsb of a0 that can be brought to a1
127 | slli a1, a1, 11 # Remove the exponent from a1
128 | srli a1, a1, 9 # Put the mantissa as for a single-precision FP
129 | or a0, a0, a1 # Merge this mantissa with a0 saved bits to form the new mantissa
130 | slli a4, a4, 23 # Move the exponent in the correct position
131 | add a0, a0, a4 # Merge the exponent
132 | round:
133 | bgez a5, exp_sign_exit
134 | addi a0, a0, 1
135 | bne a5, a2, exp_sign_exit
136 | andi a0, a0, -2
137 | exp_sign_exit:
138 | or a0, a0, a3 # Merge the sign
139 | ret
140 |
141 | inf_nan:
142 | bgtu a1, a4, nan
143 | bnez a0, nan
144 | inf:
145 | lui a0, 0x7F800
146 | or a0, a0, a3
147 | ret
148 |
149 | nan:
150 | # Return the correct quiet NaN
151 | slli a1, a1, 3
152 | srli a0, a0, 29
153 | srli a1, a1, 1
154 | srli a2, a2, 9
155 | or a0, a0, a2
156 | or a0, a0, a1
157 | or a0, a0, a3
158 | ret
159 |
160 | # Denormal or zero
161 | undflow:
162 | # Check if denormalized value is possible
163 | addi t1, a4, 23
164 | bltz t1, zero
165 | # Denormalize
166 | lui t0, 0x00200 # Set the implicit 1 (a1 was left shifted by 1)
167 | or a1, a1, t0
168 | slli a1, a1, 10 # Clean mantissa from exponent
169 | srli a1, a1, 8 # Compress to a single-precision format
170 | srli a4, a0, 29 # Save the lsb of a0 that can be brought to a1
171 | or a1, a1, a4 # Merge these bits into a1
172 | slli a0, a0, 3 # Shift also a0
173 | # Shift
174 | addi t1, t1, -24 # t1 is the complementary-right-shift amount
175 | neg a4, t1 # a4 is the correct right shift amount
176 | sll t0, a0, t1 # LSbs that would be lost after the shift (useful for RNE)
177 | srl a5, a0, a4 # Actual a0 right shift
178 | snez t0, t0 # Condense the lost-LSbs
179 | or a5, a5, t0 # Merge them in a0 LSbit
180 | sll t2, a1, t1 # Save the a1 bits that would be lost
181 | or a5, a5, t2 # Save them in a5, that will be used for rounding
182 | srl a0, a1, a4 # Shift a1 by the actual right shift amount, and put it in a0
183 | j round
184 |
185 | zero:
186 | mv a0, a3 # Add sign
187 | ret
188 |
189 | #endif
190 |
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__divsf3.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # Define OPPORTUNISTIC_NAN to save code size. The information in the input NaN will be discarded, and the output will be a quiet NaN different from the input one
27 | # If OPPORTUNISTIC_NAN is not defined, the input NaN is extended and transformed into a quiet NaN (consistent with libgcc)
28 |
29 | .global __divsf3
30 |
31 | #ifdef PERFORMANCE
32 |
33 | __divsf3:
34 | # Determine the final sign
35 | lui t0, 0x80000 # Load the sign mask
36 | # Check special cases
37 | li a5, 0xff # Load the exponent mask
38 | srli a2, a0, 23 # Isolate X's sign and exponent
39 | and a2, a2, a5 # Isolate X's exponent
40 | srli a3, a1, 23 # Isolate Y's sign and exponent
41 | and a3, a3, a5 # Isolate Y's exponent
42 | beq a2, a5, inf_nan # Jump if A is Inf/NaN
43 | beq a3, a5, inf_nan # Jump if B is Inf/NaN
44 | beqz a2, zero_denormal # Jump if A is zero/denormal
45 | beqz a3, zero_denormal # Jump if B is zero/denormal
46 |
47 | normal_case:
48 | # Subtract Y exponent from X exponent together
49 | sub a2, a2, a3
50 |
51 | # Preserve the final sign
52 | xor t2, a0, a1 # Determine the final sign
53 |
54 | # Convert mantissa to unsigned integer
55 | # Dividend in a3, divisor in a1
56 | slli a0, a0, 9 # Isolate X's mantissa
57 | slli a1, a1, 9 # Isolate Y's mantissa
58 | beqz a1, pow_2 # Check if divisor is power of 2
59 | lui a3, 0x10000 # Prepare the implicit 1
60 | srli a0, a0, 4
61 | srli a1, a1, 4
62 | or a1, a1, a3 # Add implicit 1 to dividend (a3) and divisor (a1)
63 | or a3, a3, a0
64 |
65 | # Initialize the result with the final sign
66 | and a0, t2, t0 # Isolate the sign
67 |
68 | # Add exponent bias and check if dividend < divisor
69 | # If no, left shift dividend and adjut the exponent accordingly
70 | slt a5, a3, a1
71 | sll a3, a3, a5
72 | addi a2, a2, 126 # Add one less as we will add also the implicit 1 to the exponent
73 | sub a2, a2, a5 # Subtract one if needed
74 |
75 | # Division loop
76 | lui a5, 0x00800
77 | div_loop_start:
78 | blt a3, a1, 1f
79 | sub a3, a3, a1
80 | or a0, a0, a5
81 | 1:
82 | srli a4, a1, 1
83 | blt a3, a4, 2f
84 | srli t1, a5, 1
85 | sub a3, a3, a4
86 | or a0, a0, t1
87 | 2:
88 | srli a4, a1, 2
89 | blt a3, a4, 3f
90 | srli t1, a5, 2
91 | sub a3, a3, a4
92 | or a0, a0, t1
93 | 3:
94 | srli a4, a1, 3
95 | blt a3, a4, 4f
96 | srli t1, a5, 3
97 | sub a3, a3, a4
98 | or a0, a0, t1
99 | 4:
100 | slli a3, a3, 4
101 | beqz a3, div_loop_exit
102 | srli a5, a5, 4
103 | bnez a5, div_loop_start
104 |
105 | div_loop_exit:
106 | # Check for under/overflow
107 | li t2, 254
108 | bgeu a2, t2, und_ov_flow
109 |
110 | # Round the result and merge the final exponent
111 | slli a2, a2, 23
112 | add a0, a0, a2
113 | bltu a3, a1, exit
114 | addi a0, a0, 1
115 | bne a3, a1, exit
116 | andi a0, a0, -2
117 | exit:
118 | ret
119 |
120 | # The divisor is a multiple of 2
121 | pow_2:
122 | and t2, t2, t0 # Isolate the sign
123 | srli a5, a0, 9
124 | or a0, t2, a5
125 | addi a2, a2, 127 # Add full bias, as we don't have the implicit bit
126 | blez a2, pre_und_ov_flow
127 | li a3, 255
128 | bge a2, a3, pre_und_ov_flow
129 | slli a2, a2, 23
130 | or a0, a0, a2
131 | ret
132 |
133 | # Under/overflow: fix things up for the code below
134 | pre_und_ov_flow:
135 | addi a2, a2, -1
136 | und_ov_flow:
137 | # Overflow?
138 | bgtz a2, ovf # If here, a2 is either in ovf (> 0) or in underflow (<= 0)
139 | # Return signed 0
140 | srli a0, a0, 31
141 | slli a0, a0, 31
142 | ret
143 |
144 | zero_denormal:
145 | # Here, one or more arguments are either denormalized or zero.
146 | bnez a2, inf # Jump to Inf if X is not zero (Y is 0)
147 | # X == 0
148 | beqz a3, nan # Return NaN if 0/0
149 | # Result is 0, but determine sign anyway.
150 | zero:
151 | xor a0, a0, a1 # Determine the correct sign of the multiplication
152 | # t0 = 0x80000
153 | and a0, a0, t0 # Append Zero
154 | ret
155 |
156 | # One or both args are INF or NAN.
157 | inf_nan:
158 | slli a5, a5, 24 # Prepare the mask for NaN
159 | # Check for NaN first
160 | slli a2, a0, 1 # Eliminate the sign of A
161 | bltu a5, a2, nan # Return NaN if A is NaN
162 | slli a3, a1, 1 # Eliminate the sign of B
163 | bltu a5, a3, nan # Return NaN if B is NaN
164 | # Check for Inf
165 | beq a2, a3, nan # They are both Inf -> return NaN
166 | # There is only one Inf.
167 | beq a3, a5, zero # Y is an inf, return zero
168 | # X is inf, Y is a number. Result is INF, but we need to determine its sign.
169 | inf:
170 | xor a0, a0, a1 # Put the correct sign into a0
171 |
172 | # Overflow: return Inf (sign already in a0).
173 | ovf:
174 | # t0 = 0x80000
175 | and a0, a0, t0 # Isolate the sign
176 | lui t0, 0x7f800 # Set max exponent
177 | or a0, a0, t0 # Set max exponent
178 | ret # Return
179 |
180 | # Return a quiet NaN.
181 | nan:
182 | lui a0, 0x7fc00
183 | ret
184 |
185 | #else
186 |
187 | __divsf3:
188 | # Determine the final sign
189 | lui t0, 0x80000 # Load the sign mask
190 | # Check special cases
191 | li a5, 0xff # Load the exponent mask
192 | srli a2, a0, 23 # Isolate X's sign and exponent
193 | and a2, a2, a5 # Isolate X's exponent
194 | srli a3, a1, 23 # Isolate Y's sign and exponent
195 | and a3, a3, a5 # Isolate Y's exponent
196 | beq a2, a5, inf_nan # Jump if A is Inf/NaN
197 | beq a3, a5, inf_nan # Jump if B is Inf/NaN
198 | beqz a2, zero_denormal # Jump if A is zero/denormal
199 | beqz a3, zero_denormal # Jump if B is zero/denormal
200 |
201 | normal_case:
202 | # Subtract Y exponent from X exponent together
203 | sub a2, a2, a3
204 |
205 | # Preserve the final sign
206 | xor t2, a0, a1 # Determine the final sign
207 |
208 | # Convert mantissa to unsigned integer
209 | # Dividend in a3, divisor in a1
210 | slli a0, a0, 9 # Isolate X's mantissa
211 | slli a1, a1, 9 # Isolate Y's mantissa
212 | lui a3, 0x10000 # Prepare the implicit 1
213 | srli a0, a0, 4
214 | srli a1, a1, 4
215 | or a1, a1, a3 # Add implicit 1 to dividend (a3) and divisor (a1)
216 | or a3, a3, a0
217 |
218 | # Initialize the result with the final sign
219 | and a0, t2, t0 # Isolate the sign
220 |
221 | # Add exponent bias and check if dividend < divisor
222 | # If no, left shift dividend and adjut the exponent accordingly
223 | slt a5, a3, a1
224 | sll a3, a3, a5
225 | addi a2, a2, 126 # Add one less as we will add also the implicit 1 to the exponent
226 | sub a2, a2, a5 # Subtract one if needed
227 |
228 | # Condensed division loop
229 | lui a5, 0x00800
230 | div_loop_start:
231 | blt a3, a1, 1f
232 | sub a3, a3, a1
233 | or a0, a0, a5
234 | 1:
235 | slli a3, a3, 1
236 | beqz a3, div_loop_exit
237 | srli a5, a5, 1
238 | bnez a5, div_loop_start
239 |
240 | div_loop_exit:
241 | # Check for under/overflow
242 | li t2, 254
243 | bgeu a2, t2, und_ov_flow
244 |
245 | # Round the result and merge the final exponent
246 | slli a2, a2, 23
247 | add a0, a0, a2
248 | bltu a3, a1, exit
249 | addi a0, a0, 1
250 | bne a3, a1, exit
251 | andi a0, a0, -2
252 | exit:
253 | ret
254 |
255 | und_ov_flow:
256 | # Overflow?
257 | bgtz a2, ovf # If here, a2 is either in ovf (> 0) or in underflow (<= 0)
258 | srli a0, a0, 31
259 | slli a0, a0, 31
260 | # Return signed 0
261 | ret
262 |
263 | zero_denormal:
264 | # Here, one or more arguments are either denormalized or zero.
265 | bnez a2, inf # Jump to Inf if X is not zero (Y is 0)
266 | # X == 0
267 | beqz a3, nan # Return NaN if 0/0
268 | # Result is 0, but determine sign anyway.
269 | zero:
270 | xor a0, a0, a1 # Determine the correct sign of the multiplication
271 | # t0 = 0x80000
272 | and a0, a0, t0 # Append Zero
273 | ret
274 |
275 | # One or both args are INF or NAN.
276 | inf_nan:
277 | slli a5, a5, 24 # Prepare the mask for NaN
278 | # Check for NaN first
279 | slli a2, a0, 1 # Eliminate the sign of A
280 | bltu a5, a2, nan # Return NaN if A is NaN
281 | slli a3, a1, 1 # Eliminate the sign of B
282 | bltu a5, a3, nan # Return NaN if B is NaN
283 | # Check for Inf
284 | beq a2, a3, nan # They are both Inf -> return NaN
285 | # There is only one Inf.
286 | beq a3, a5, zero # Y is an inf, return zero
287 | # X is inf, Y is a number. Result is INF, but we need to determine its sign.
288 | inf:
289 | xor a0, a0, a1 # Put the correct sign into a0
290 | # Overflow: return Inf (sign already in a0).
291 | ovf:
292 | # t0 = 0x80000
293 | and a0, a0, t0 # Isolate the sign
294 | lui t0, 0x7f800 # Set max exponent
295 | or a0, a0, t0 # Set max exponent
296 | ret # Return
297 |
298 | # Return a quiet NaN.
299 | nan:
300 | lui a0, 0x7fc00
301 | ret
302 |
303 | #endif
304 |
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__eqdf2.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # Double Precision FP equivalence checker
27 | # Return 0 if the arguments are equal and neither of them is special (NaN or Inf)
28 | # +0 == -0
29 |
30 | #define xh a1
31 | #define xl a0
32 | #define yh a3
33 | #define yl a2
34 |
35 | .global __eqdf2
36 | .global __nedf2
37 |
38 | __nedf2:
39 | __eqdf2:
40 | # Check for Special first
41 | lui a4, 0xFFE00 # Load shifted Special pattern
42 | slli a5, xh, 1
43 | bgeu a5, a4, nan # Branch if Special is detected
44 | slli a5, yh, 1
45 | bgeu a5, a4, nan # Branch if Special is detected
46 | # Check for +0 -0
47 | or a4, xh, yh
48 | slli a4, a4, 1
49 | or a4, a4, xl
50 | or a4, a4, yl
51 | beqz a4, normal_end
52 | # Check for equality
53 | xor xl, xl, yl
54 | xor xh, xh, yh
55 | or a4, xh, xl
56 | normal_end:
57 | nan:
58 | snez xl, a4 # Set the correct result
59 | ret
60 |
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__eqsf2.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__eqsf2.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__extendsfdf2.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | .global __extendsfdf2
27 |
28 | __extendsfdf2:
29 | lui a1, 0x80000 # Mask for the sign
30 | and a1, a1, a0 # Save the sign
31 | slli a3, a0, 1 # Eat the sign
32 | # Check for zeroes/denormals
33 | srai a4, a3, 24
34 | beqz a4, zero_den
35 | # Prepare a0 and a1
36 | srai a5, a3, 3 # Position the exponent and mantissa bits (trick to easily adjust the bias)
37 | srli a5, a5, 1 # Prepare a void for the sign
38 | slli a0, a3, 28 # Adjust LSbs
39 | or a1, a1, a5 # Restore the sign
40 | # Check for inf/NaN
41 | addi a4, a4, 1
42 | beqz a4, inf_nan
43 | # Adjust the bias for the exponent (add 1023-127 with a trick)
44 | lui a5, 0x38000
45 | xor a1, a1, a5
46 | exit:
47 | ret
48 |
49 | inf_nan:
50 | # Check for NaN, otherwise the result is correct
51 | slli a3, a3, 8
52 | beqz a3, exit
53 | lui a4, 0x00080 # Make the output a quiet NaN
54 | or a1, a1, a4
55 | ret
56 |
57 | # Flush denormals to corretly signed 0
58 | zero_den:
59 | li a0, 0
60 | ret
61 |
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__fixdfdi.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__fixdfdi.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__fixdfsi.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__fixdfsi.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__fixsfdi.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__fixsfdi.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__fixsfsi.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__fixsfsi.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__fixunsdfdi.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__fixunsdfdi.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__fixunsdfsi.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__fixunsdfsi.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__fixunssfdi.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__fixunssfdi.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__fixunssfsi.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__fixunssfsi.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__floatdidf.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__floatdidf.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__floatdisf.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__floatdisf.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__floatsidf.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__floatsidf.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__floatsisf.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__floatsisf.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__floatundidf.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__floatundidf.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__floatundisf.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__floatundisf.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__floatunsidf.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__floatunsidf.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__floatunsisf.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__floatunsisf.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__gedf2.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # Double Precision FP equivalence checker
27 | # Return 0 if the arguments are equal and neither of them is NaN
28 | # +0 == -0
29 |
30 | #define xh a1
31 | #define xl a0
32 | #define yh a3
33 | #define yl a2
34 |
35 | .global __gedf2
36 |
37 | __gedf2:
38 | # Check for NaN first
39 | lui a4, 0xFFE00 # Load shifted NaN pattern
40 | slli a5, xh, 1
41 | bgeu a5, a4, nan # Branch if NaN is detected
42 | slli a5, yh, 1
43 | bgeu a5, a4, nan # Branch if NaN is detected
44 | # Check for +0 -0
45 | or a4, xh, yh
46 | slli a4, a4, 1
47 | or a4, a4, xl
48 | or a4, a4, yl
49 | beqz a4, xor_end
50 | # Check for equality
51 | xor a4, xh, yh # Check the signs
52 | bltz a4, pn_np # Branch if different signs
53 | # pp_nn
54 | beq xh, yh, pp_nn_h_eq
55 | # pp_nn_not_eq
56 | sltu a4, xh, yh
57 | sltz a0, yh
58 | xor_end:
59 | xor a0, a0, a4
60 | slli a0, a0, 31
61 | ret
62 |
63 | pp_nn_h_eq:
64 | beq xl, yl, ret_0
65 | # pp_nn_h_eq_l_neq
66 | sltu a4, yl, xl
67 | sltz a0, xh
68 | xori a0, a0, 1
69 | j xor_end
70 |
71 | ret_0:
72 | li a0, 0
73 | ret
74 |
75 | nan:
76 | mv xh, a4
77 | pn_np:
78 | sltz a0, xh # Return 1 if x is positive and y negative, 0 if the opposite
79 | slli a0, a0, 31
80 | ret
81 |
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__gesf2.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__gesf2.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__gtdf2.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # Double Precision FP equivalence checker
27 | # Return 0 if the arguments are equal and neither of them is NaN
28 | # +0 == -0
29 |
30 | #define xh a1
31 | #define xl a0
32 | #define yh a3
33 | #define yl a2
34 |
35 | .global __gtdf2
36 |
37 | __gtdf2:
38 | # Check for NaN first
39 | lui a4, 0xFFE00 # Load shifted NaN pattern
40 | slli t0, xh, 1
41 | bgeu t0, a4, ret_0 # Branch if NaN is detected
42 | slli t1, yh, 1
43 | bgeu t1, a4, ret_0 # Branch if NaN is detected
44 | # Check for +0 -0
45 | or a4, xh, yh
46 | slli a4, a4, 1
47 | or a4, a4, xl
48 | or a4, a4, yl
49 | beqz a4, ret_0
50 | # Check the signs
51 | xor a4, xh, yh # Check the signs
52 | bltz a4, pn_np # Branch if different signs
53 | # pp_nn
54 | beq xh, yh, pp_nn_h_eq
55 | # pp_nn_not_eq
56 | sltu a4, yh, xh
57 | end:
58 | sltz a0, yh
59 | xor a0, a0, a4
60 | ret
61 |
62 | pp_nn_h_eq:
63 | beq xl, yl, ret_0
64 | sltu a4, yl, xl
65 | j end
66 |
67 | ret_0:
68 | li a0, 0
69 | ret
70 |
71 | pn_np:
72 | sltz a0, yh # Return 1 if x is negative and y positive, 0 if the opposite
73 | ret
74 |
75 |
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__gtsf2.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__gtsf2.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__ledf2.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # Double Precision FP equivalence checker
27 | # Return 0 if the arguments are equal and neither of them is Special
28 | # +0 == -0
29 |
30 | #define xh a1
31 | #define xl a0
32 | #define yh a3
33 | #define yl a2
34 |
35 | .global __ledf2
36 |
37 | __ledf2:
38 | # Check for NaN first
39 | lui a4, 0xFFE00 # Load shifted Special pattern
40 | slli a5, xh, 1
41 | bgeu a5, a4, nan # Branch if Special is detected
42 | slli a5, yh, 1
43 | bgeu a5, a4, nan # Branch if Special is detected
44 | # Check for +0 -0
45 | or a4, xh, yh
46 | slli a4, a4, 1
47 | or a4, a4, xl
48 | or a4, a4, yl
49 | beqz a4, ret_0
50 | # Check for equality
51 | xor a4, xh, yh # Check the signs
52 | bltz a4, pn_np # Branch if different signs
53 | # pp_nn
54 | beq xh, yh, pp_nn_h_eq
55 | # pp_nn_not_eq
56 | sgtu a4, xh, yh
57 | sltz a0, xh
58 | xor_end:
59 | xor a0, a0, a4
60 | ret
61 |
62 | pp_nn_h_eq:
63 | beq xl, yl, ret_0
64 | sltu a4, yl, xl
65 | sltz a0, xh
66 | j xor_end
67 |
68 | ret_0:
69 | li a0, 0
70 | ret
71 |
72 | nan:
73 | mv yh, a4
74 | pn_np:
75 | sltz a0, yh # Return 0 if x is negative and y positive, 1 if the opposite
76 | ret
77 |
78 |
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__lesf2.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__lesf2.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__ltdf2.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # Double Precision FP equivalence checker
27 | # Return 0 if the arguments are equal and neither of them is Special
28 | # +0 == -0
29 |
30 | #define xh a1
31 | #define xl a0
32 | #define yh a3
33 | #define yl a2
34 |
35 | .global __ltdf2
36 |
37 | __ltdf2:
38 | # Check for Special first
39 | lui a4, 0xFFE00 # Load shifted Special pattern
40 | slli a5, xh, 1
41 | bgeu a5, a4, ret_0 # Branch if Special is detected
42 | slli a5, yh, 1
43 | bgeu a5, a4, ret_0 # Branch if Special is detected
44 | # Check for +0 -0
45 | or a4, xh, yh
46 | slli a4, a4, 1
47 | or a4, a4, xl
48 | or a4, a4, yl
49 | beqz a4, ret_0
50 | # Check the signs
51 | xor a4, xh, yh # Check the signs
52 | bltz a4, pn_np # Branch if different signs
53 | # pp_nn
54 | beq xh, yh, pp_nn_h_eq
55 | # pp_nn_not_eq
56 | sltu a4, xh, yh
57 | end:
58 | sltz a0, xh
59 | xor a0, a0, a4
60 | slli a0, a0, 31 # Only to interface with libgcc (negative result instead of positive)
61 | ret
62 |
63 | pp_nn_h_eq:
64 | beq xl, yl, ret_0
65 | sltu a4, xl, yl
66 | j end
67 |
68 | ret_0:
69 | li a0, 0
70 | ret
71 |
72 | pn_np:
73 | sltz a0, xh # Return 1 if x is negative and y positive, 0 if the opposite
74 | slli a0, a0, 31 # Only to interface with libgcc (negative result instead of positive)
75 | ret
76 |
77 |
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__ltsf2.S:
--------------------------------------------------------------------------------
1 | ../ieee754/__ltsf2.S
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__muldf3.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # RISC-V 64-bit mul, denormals flushed to 0
27 |
28 | .global __muldf3
29 |
30 | #define xl a0
31 | #define xh a1
32 | #define yl a2
33 | #define yh a3
34 |
35 | # Add two numbers stored in two and three regs (x1-x0 and y2-y1-y0).
36 | # x1 and y2 are the most significant regs
37 | # The MSb of x1 and y2 is zero
38 | # Result stored in y2, y1, y0
39 | # x1 and x0 can be overwritten
40 | .macro ADD3Rto2T y2, y1, y0, x1, x0
41 | add \y0, \y0, \x0
42 | sltu \x0, \y0, \x0
43 | add \x1, \x1, \x0
44 | add \y1, \y1, \x1
45 | sltu \x1, \y1, \x1
46 | add \y2, \y2, \x1
47 | .endm
48 |
49 | # Add two numbers stored in two couples of regs (x1-x0 and y1-y0).
50 | # x1 and y1 are the most significant regs
51 | # The MSb of x1 and y1 is zero
52 | # Result stored in y1-y0
53 | # x1 and x0 can be overwritten
54 | .macro ADD2Rto2R y1, y0, x1, x0
55 | add \y0, \y0, \x0
56 | sltu \x0, \y0, \x0
57 | add \x1, \x1, \x0
58 | add \y1, \y1, \x1
59 | .endm
60 |
61 | # Shift left by 1 a number stored in two registers
62 | # MSB in x1
63 | .macro SLLI1_2R x1, x0, a5
64 | slli \x1, \x1, 1
65 | srli \a5, \x0, 31
66 | or \x1, \x1, \a5
67 | slli \x0, \x0, 1
68 | .endm
69 |
70 | # Shift left by 1 a number stored in three registers
71 | # MSB in x2
72 | .macro SLLI1_3R x2, x1, x0, a5
73 | slli \x2, \x2, 1
74 | srli \a5, \x1, 31
75 | or \x2, \x2, \a5
76 | slli \x1, \x1, 1
77 | srli \a5, \x0, 31
78 | or \x1, \x1, \a5
79 | slli \x0, \x0, 1
80 | .endm
81 |
82 | # Mask out exponents, trap any zero/denormal/inf/NaN
83 | __muldf3:
84 | xor a4, xh, yh # Determine the final sign xor xh and yh to have also the correct sign
85 | lui a5, 0x80000 # Load 0x80000 mask for the sign
86 | and t0, a4, a5 # Isolate the product sign
87 | li a5, 0x7FF # Load mask to isolate the exponent
88 | srli a4, xh, 20 # Isolate sign and exponent of X
89 | and a4, a4, a5 # Isolate exp of X
90 | srli t1, yh, 20 # Isolate sign and exponent of Y
91 | and t1, t1, a5 # Isolate exp of Y
92 | beq a4, a5, inf_nan # Jump if X is inf/NaN
93 | beq t1, a5, inf_nan # Jump if Y is inf/NaN
94 | beqz a4, zero_denormal # Jump if X is zero/denormal
95 | beqz t1, zero_denormal # Jump if Y is zero/denormal
96 |
97 | normal_case:
98 | # Add exponents together
99 | add a4, a4, t1 # Add exponents together
100 |
101 | # Convert mantissa to unsigned integer
102 | lui a5, 0xFFF00 # Mask to isolate mantissa
103 | not a5, a5 # Mask to isolate mantissa
104 | and xh, xh, a5 # Isolate mantissa X
105 | and yh, yh, a5 # Isolate mantissa Y
106 | lui a5, 0x00100 # Prepare the implicit 1 mask
107 | or xh, xh, a5 # Add the implicit 1 to X
108 | or yh, yh, a5 # Add the implicit 1 to Y
109 |
110 | # The actual multiplication.
111 | # (xh*yh)<<64 + (xh*yl + xl*yh)<<32 + (xl*yl)
112 | # Put the 128-bit result in xh-xl-yl-a5
113 | # Todo: check if all these numbers are actually needed
114 | # (xh*yl)<<32
115 | # (xl*yh)<<32
116 | # Add these two results together: mix the operations to fit in RV32E
117 | mul t1, xh, yl
118 | mul a5, xl, yh
119 | add t1, t1, a5
120 | sltu a5, t1, a5
121 | mulhu t2, xh, yl
122 | add t2, t2, a5
123 | mulhu a5, xl, yh
124 | add t2, t2, a5
125 | # (xl*yl)
126 | mul a5, xl, yl
127 | mulhu yl, xl, yl
128 | #(xh*yh)<<64
129 | mul xl, xh, yh
130 | mulhu xh, xh, yh
131 | # Add together
132 | ADD3Rto2T xh, xl, yl, t2, t1
133 |
134 | # LSBs in a5 are significant only for the final rounding. Merge them into yl
135 | snez a5, a5
136 | or yl, yl, a5
137 |
138 | # Adjust the result upon the MSB position
139 | li t2, 512 # Prepare the mask in position 10. t2 = 1 << 9
140 | bgeu xh, t2, 1f # Branch if there is no need for adjusting
141 | SLLI1_3R xh, xl, yl, a5 # Adjust: shift left the result by 1
142 | addi a4, a4, -1 # Adjust the exponent after the shift
143 |
144 | 1:
145 | # Shift to the final position and add the sign to result
146 | slli xh, xh, 11 # Shift the implicit 1 in its correct position (position 21, shift by 11)
147 | srli a5, xl, 21 # Save the bits of the lower P that should shift in the higher P
148 | or xh, xh, a5 # Add the lower P shifted bits to higher P
149 | slli xl, xl, 11 # Shift the lower part of the product by 11
150 | srli a5, yl, 21 # Save the bits of R that should shift in the lower P
151 | or xl, xl, a5 # Add the R bits to lower P
152 | slli yl, yl, 11 # Shift R by 11
153 |
154 | # Apply exponent bias and check exponent range for under/overflow
155 | addi a4, a4, -1023 # Apply exponent bias
156 | li t1, 2046 # Prepare to check for under/over flow
157 | bgeu a4, t1, und_ov_flow # We have either an underflow or an overflow
158 |
159 | # Round the result, merge final exponent.
160 | slli a4, a4, 20 # Bring the exponent to its position
161 | add xh, xh, a4 # Add the exponent to the result (the implicit 1 is added)
162 | rounding:
163 | lui a5, 0x80000 # Prepare the mask for the RNE
164 | bltu yl, a5, exit # Branch if we cannot guess to round up
165 | addi xl, xl, 1 # Guess a first rounding up
166 | seqz t1, xl # Guess a first rounding up
167 | add xh, xh, t1 # Guess a first rounding up
168 | bne yl, a5, exit # Check for a tie -> in the case, RNE. Jump if there is no tie
169 | andi xl, xl, -2 # RNE (we have already added 1)
170 | exit:
171 | or xh, xh, t0 # Add the correct sign to the result
172 | ret # Return
173 |
174 | # Check for overflow/underflow
175 | # If we are here, we ore either in ovf or in underflow
176 | und_ov_flow:
177 | # Overflow?
178 | blt x0, a4, inf # Branch to Ovf handling if an overflow occurred
179 | # Underflow: return signed 0
180 | j signed_zero
181 |
182 | # One or more arguments are either denormalized or zero
183 | # a5 contains 0x000007FF
184 | zero_denormal:
185 | # Result is zero, but determine sign anyway
186 | # a5 contains 0x80000000
187 | signed_zero:
188 | mv xh, t0 # Load correctly signed zero
189 | zero_xl:
190 | li xl, 0 # Append zero
191 | ret
192 |
193 | # One or both args are inf or NaN
194 | inf_nan:
195 | li t2, 0x7FF
196 | # Return NaN if one of the operands is 0 or denormal
197 | slli a5, a4, 21
198 | beqz a5, nan
199 | slli a5, t1, 21
200 | beqz a5, nan
201 | # Return NaN if one of the elements is a NaN
202 | # a5 contains 0x000007FF
203 | bne a4, t2, 1f # Jump away if X is not a Inf/Nan
204 | slli a5, xh, 12
205 | or a5, a5, xl
206 | bnez a5, nan # Jump away if X is NaN, return NaN
207 | 1:
208 | bne t1, t2, inf # Jump away if Y is not a Inf/Nan
209 | slli a4, yh, 12
210 | or a4, a4, yl
211 | bnez a4, nan # Jump away if Y is NaN, return NaN
212 |
213 | inf:
214 | lui xh, 0x7FF00 # Load inf pattern
215 | or xh, xh, t0
216 | j zero_xl
217 |
218 | # Return a quiet NaN
219 | nan:
220 | lui xh, 0x7FF80 # Load qNaN pattern
221 | j zero_xl
222 |
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__mulsf3.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # RISC-V mul, denormals flushed to 0
27 |
28 | .global __mulsf3
29 |
30 | __mulsf3:
31 | lui a4, 0x80000 # Prepare the mask for the sign
32 | xor a5, a0, a1 # Determine the final sign
33 | and a4, a4, a5 # Determine the final sign
34 | # Mask out exponents, trap any zero/denormal/INF/NAN.
35 | addi a5, x0, 0xff # Prepare the exp. mask
36 | srli a2, a0, 23 # Isolate sign and exp. (A)
37 | and a2, a2, a5 # Isolate exp. (A)
38 | srli a3, a1, 23 # Isolate sign and exp. (B)
39 | and a3, a3, a5 # Isolate exp. (B)
40 | beq a2, a5, inf_nan # Jump if A is Inf/NaN
41 | beq a3, a5, inf_nan # Jump if B is Inf/NaN
42 | beqz a2, zero_denormal # Jump if A is zero/denormal
43 | beqz a3, zero_denormal # Jump if B is zero/denormal
44 |
45 | normal_case:
46 | # Add exponents together
47 | add a2, a2, a3 # Add exponents together
48 |
49 | # Convert mantissa to unsigned integer.
50 | # If power of two, branch to a separate path.
51 | # Make up for final alignment.
52 | slli a0, a0, 9 # Isolate mantissa A
53 | slli a1, a1, 9 # Isolate mantissa B
54 | lui a3, 0x08000 # Prepare the implicit 1
55 | srli a0, a0, 5 # Shift mantissa A to have the MSB of the result in a convenient position
56 | srli a1, a1, 5 # Shift mantissa B to have the MSB of the result in a convenient position
57 | or a0, a0, a3 # Add the implicit 1 (A) in position 28
58 | or a1, a1, a3 # Add the implicit 1 (B) in position 28
59 |
60 | # The actual multiplication.
61 | mul a3, a0, a1 # LSbs of the result
62 | mulhu a1, a0, a1 # MSbs of the result
63 |
64 | # Put final sign in a0.
65 | mv a0, a4 # Write the correct sign in a0
66 |
67 | # Adjust result upon the MSB position.
68 | lui a5, 0x00800 # Prepare the mask in position 24
69 | bgeu a1, a5, 1f # Branch if there is no need for normalizing
70 | slli a1, a1, 1 # Normalize: shift left the result (1)
71 | srli a5, a3, 31 # Normalize: shift left the result (2)
72 | or a1, a1, a5 # Normalize: shift left the result (3)
73 | slli a3, a3, 1 # Normalize: shift left the result (4)
74 | addi a2, a2, -1 # Adjust the final exponent because of the normalization
75 |
76 | # Move the result in a0. Sign already in a0
77 | 1:
78 | or a0, a0, a1 # Add sign to the result
79 |
80 | # Apply exponent bias, check for under/overflow.
81 | addi a2, a2, -127 # Apply exponent bias
82 | addi a5, x0, 254 # Prepare to check for under/overflow
83 | bgeu a2, a5, und_ov_flow
84 |
85 | # Round the result, merge final exponent.
86 | # CIAONE = 0x80000
87 | lui a4, 0x80000
88 | slli a2, a2, 23
89 | add a0, a0, a2
90 | bltu a3, a4, exit
91 | addi a0, a0, 1
92 | bne a3, a4, exit
93 | andi a0, a0, -2
94 | exit:
95 | ret
96 |
97 | und_ov_flow:
98 | # Overflow?
99 | blt x0, a2, inf # If here, a2 is either in ovf (> 0) or in underflow (<= 0)
100 | # Underflow: return signed 0.
101 | # a4 = 0x80000
102 | j append_zero
103 |
104 | zero_denormal:
105 | # Here, one or more arguments are either denormalized or zero.
106 | # Result is 0, but determine sign anyway.
107 | append_zero:
108 | mv a0, a4
109 | ret
110 |
111 | # One or both args are INF or NAN.
112 | inf_nan:
113 | slli a2, a2, 24 # Isolate the exponent of A
114 | slli a3, a3, 24 # Isolate the exponent of B
115 | beqz a2, nan # Return NaN if A is 0 or denormal
116 | beqz a3, nan # Return NaN if B is 0 or denormal
117 | slli a5, a5, 24 # Prepare the mask for NaN
118 | slli a3, a0, 1 # Eliminate the sign of A
119 | bltu a5, a3, nan # Return NaN if A is NaN
120 | slli a3, a1, 1 # Eliminate the sign of B
121 | bltu a5, a3, nan # Return NaN if B is NaN
122 | # One of the operands is Inf, the other is an Inf or a number.
123 |
124 | # Overflow: return Inf (sign already in a0).
125 | inf:
126 | lui a0, 0x7f800 # Set max exponent
127 | or a0, a0, a4 # Put the sign
128 | ret # Return
129 |
130 | # Return a quiet NaN.
131 | nan:
132 | lui a0, 0x7fc00
133 | ret
134 |
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__subdf3.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # RISC-V 64-bit FP sub
27 |
28 | # Define SPLIT_SUB to keep the subtraction split from the addition. This can be more modular, but less effective in performance and also bigger in code size if both the functions are required
29 |
30 | #ifdef SPLIT_SUB
31 |
32 | .global __subdf3
33 | .global __adddf3
34 |
35 | #define xh a1
36 | #define xl a0
37 | #define yh a3
38 | #define yl a2
39 |
40 | __subdf3:
41 | lui a4, 0x80000 # Load sign mask
42 | xor yh, yh, a4 # Reverse sign Y
43 | j __adddf3 # Jump to add
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__subsf3.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # RISC-V f32_sub
27 |
28 | # Define SPLIT_SUB to keep the subtraction split from the addition. This can be more modular, but less effective in performance and also bigger in code size if both the functions are required
29 |
30 | #ifdef SPLIT_SUB
31 |
32 | .global __subsf3
33 | .global __addsf3
34 |
35 | __subsf3:
36 | lui a5, 0x80000 # change sign
37 | xor a1, a1, a5 # change sign of opB
38 | j __addsf3 # jump to fadd
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/src/asm/ieee754_nd/__truncdfsf2.S:
--------------------------------------------------------------------------------
1 | # Copyright ETH Zurich 2020
2 | #
3 | # Author: Matteo Perotti
4 | #
5 | # This file is part of rvfplib.
6 | #
7 | # rvfplib is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # rvfplib is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # Under Section 7 of GPL version 3, you are granted additional
18 | # permissions described in the GCC Runtime Library Exception, version
19 | # 3.1, as published by the Free Software Foundation.
20 | #
21 | # You should have received a copy of the GNU General Public License and
22 | # a copy of the GCC Runtime Library Exception along with this program;
23 | # see the files LICENSE.txt and LICENSE-EXCEPTION.txt respectively. If not, see
24 | # . */
25 |
26 | # libgcc rounds toward zero and flush the input NaN to a generic quiet NaN
27 |
28 | .global __truncdfsf2
29 |
30 | #define libgcc
31 |
32 | #ifdef libgcc
33 |
34 | __truncdfsf2:
35 | lui a2, 0x80000 # Mask for the sign
36 | and a3, a2, a1 # Save the sign
37 | slli a1, a1, 1 # Eat the sign
38 | lui a4, 0xFFE00
39 | bgeu a1, a4, inf_nan
40 | srli a4, a1, 21
41 | addi a4, a4, -896 # Check for an underfow -> exp-(1023-127)
42 | blez a4, undflow # If exponent is less than zero, we have a denormal or zero
43 | addi a5, a4, -254 # Check for an overflow
44 | bgtz a5, inf
45 | # Normal number
46 | slli a5, a0, 3 # Bits to round RNE
47 | srli a0, a0, 29 # Save the lsb of a0 that can be brought to a1
48 | slli a1, a1, 11 # Remove the exponent from a1
49 | srli a1, a1, 9 # Put the mantissa as for a single-precision FP
50 | or a0, a0, a1 # Merge this mantissa with a0 saved bits to form the new mantissa
51 | bgez a5, exp_sign_exit
52 | addi a0, a0, 1
53 | bne a5, a2, exp_sign_exit
54 | andi a0, a0, -2
55 | exp_sign_exit:
56 | slli a4, a4, 23 # Move the exponent in the correct position
57 | add a0, a0, a4 # Merge the exponent
58 | or a0, a0, a3 # Merge the sign
59 | ret
60 |
61 | inf_nan:
62 | bgtu a1, a4, nan
63 | bnez a0, nan
64 | inf:
65 | lui a0, 0x7F800
66 | or a0, a0, a3
67 | ret
68 |
69 | nan:
70 | # Return the correct NaN
71 | lui a0, 0x7FC00
72 | ret
73 |
74 | # Flush denormals to correctly signed 0
75 | undflow:
76 | mv a0, a3
77 | ret
78 |
79 | #else
80 |
81 | .global __truncdfsf2
82 |
83 | __truncdfsf2:
84 | lui a2, 0x80000 # Mask for the sign
85 | and a3, a2, a1 # Save the sign
86 | slli a1, a1, 1 # Eat the sign
87 | lui a4, 0xFFE00
88 | bgeu a1, a4, inf_nan
89 | srli a4, a1, 21
90 | addi a4, a4, -896 # Check for an underfow -> exp-(1023-127)
91 | blez a4, undflow # If exponent is less than zero, we have a denormal or zero
92 | addi a5, a4, -254 # Check for an overflow
93 | bgtz a5, inf
94 | # Normal number
95 | slli a5, a0, 3 # Bits to round RNE
96 | srli a0, a0, 29 # Save the lsb of a0 that can be brought to a1
97 | slli a1, a1, 11 # Remove the exponent from a1
98 | srli a1, a1, 9 # Put the mantissa as for a single-precision FP
99 | or a0, a0, a1 # Merge this mantissa with a0 saved bits to form the new mantissa
100 | bgez a5, exp_sign_exit
101 | addi a0, a0, 1
102 | bne a5, a2, exp_sign_exit
103 | andi a0, a0, -2
104 | exp_sign_exit:
105 | slli a4, a4, 23 # Move the exponent in the correct position
106 | add a0, a0, a4 # Merge the exponent
107 | or a0, a0, a3 # Merge the sign
108 | ret
109 |
110 | inf_nan:
111 | bgtu a1, a4, nan
112 | bnez a0, nan
113 | inf:
114 | lui a0, 0x7F800
115 | or a0, a0, a3
116 | ret
117 |
118 | nan:
119 | # Return the correct quiet NaN
120 | slli a1, a1, 3
121 | srli a0, a0, 29
122 | srli a1, a1, 1
123 | srli a2, a2, 9
124 | or a0, a0, a2
125 | or a0, a0, a1
126 | or a0, a0, a3
127 | ret
128 |
129 | # Flush denormals to correctly signed 0
130 | undflow:
131 | mv a0, a3
132 | ret
133 |
134 | #endif
135 |
--------------------------------------------------------------------------------
/src/c/f32_add/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | float op0, op1, res, gold_res;
31 | char flags[10];
32 | int ret = 0;
33 |
34 | // Read the operands from stdin, print on stdout
35 | while (ret != EOF) {
36 | ret = scanf("%X %X %X %s", &op0, &op1, &gold_res, flags);
37 | res = __addsf3(op0, op1);
38 | printf("%08X %08X %08X %s\n", *(uint32_t*)&op0, *(uint32_t*)&op1, *(uint32_t*)&res, flags);
39 | }
40 |
41 | return 0;
42 | }
43 |
--------------------------------------------------------------------------------
/src/c/f32_div/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | float op0, op1, res, gold_res;
31 | char flags[10];
32 | int ret = 0;
33 |
34 | // Read the operands from stdin, print on stdout
35 | while (ret != EOF) {
36 | ret = scanf("%X %X %X %s", &op0, &op1, &gold_res, flags);
37 | res = __divsf3(op0, op1);
38 | printf("%08X %08X %08X %s\n", *(uint32_t*)&op0, *(uint32_t*)&op1, *(uint32_t*)&res, flags);
39 | }
40 |
41 | return 0;
42 | }
43 |
--------------------------------------------------------------------------------
/src/c/f32_eq/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | float op0, op1;
31 | int res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%X %X %d %s", &op0, &op1, &gold_res, flags);
38 | res = __eqsf2(op0, op1);
39 | // SoftFloat f32_add does exactly the opposite of libgcc __eqsf2
40 | // So, invert both libgcc and rvfplib results, for testing purposes
41 | res ^= 0x1;
42 | printf("%08X %08X %d %s\n", *(uint32_t*)&op0, *(uint32_t*)&op1, res, flags);
43 | }
44 |
45 | return 0;
46 | }
47 |
--------------------------------------------------------------------------------
/src/c/f32_ge/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | float op0, op1;
31 | int res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%X %X %d %s", &op0, &op1, &gold_res, flags);
38 | res = __gesf2(op0, op1);
39 | printf("%08X %08X %d %s\n", *(uint32_t*)&op0, *(uint32_t*)&op1, res, flags);
40 | }
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/src/c/f32_gt/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | float op0, op1;
31 | int res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%X %X %d %s", &op0, &op1, &gold_res, flags);
38 | res = __gtsf2(op0, op1);
39 | printf("%08X %08X %d %s\n", *(uint32_t*)&op0, *(uint32_t*)&op1, res, flags);
40 | }
41 |
42 | // Dummy call to __lesf2 to avoid problems at link time
43 | // In libgcc, __lesf2 calls also the libgcc __ltsf2. We don't want this, otherwise we would have 2 __ltsf2 definitions
44 | // Therefore, link rvfplib's __lesf2
45 | __lesf2(op0, op1);
46 |
47 | return 0;
48 | }
49 |
--------------------------------------------------------------------------------
/src/c/f32_le/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | float op0, op1;
31 | int res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%X %X %d %s", &op0, &op1, &gold_res, flags);
38 | res = __lesf2(op0, op1);
39 | // SoftFloat requires this precise interface, different from the one of libgcc
40 | // We have the same interface of libgcc, so if we apply this operation to both, nothing is changed
41 | res ^= 0x1;
42 | printf("%08X %08X %d %s\n", *(uint32_t*)&op0, *(uint32_t*)&op1, res, flags);
43 | }
44 |
45 | return 0;
46 | }
47 |
--------------------------------------------------------------------------------
/src/c/f32_lt/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | float op0, op1;
31 | int res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%X %X %d %s", &op0, &op1, &gold_res, flags);
38 | res = __ltsf2(op0, op1);
39 | printf("%08X %08X %d %s\n", *(uint32_t*)&op0, *(uint32_t*)&op1, res, flags);
40 | }
41 |
42 | // Dummy call to __lesf2 to avoid problems at link time
43 | // In libgcc, __lesf2 calls also the libgcc __ltsf2. We don't want this, otherwise we would have 2 __ltsf2 definitions
44 | // Therefore, link rvfplib's __lesf2
45 | __lesf2(op0, op1);
46 |
47 | return 0;
48 | }
49 |
--------------------------------------------------------------------------------
/src/c/f32_mul/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | float op0, op1, res, gold_res;
31 | char flags[10];
32 | int ret = 0;
33 |
34 | // Read the operands from stdin, print on stdout
35 | while (ret != EOF) {
36 | ret = scanf("%X %X %X %s", &op0, &op1, &gold_res, flags);
37 | res = __mulsf3(op0, op1);
38 | printf("%08X %08X %08X %s\n", *(uint32_t*)&op0, *(uint32_t*)&op1, *(uint32_t*)&res, flags);
39 | }
40 |
41 | return 0;
42 | }
43 |
--------------------------------------------------------------------------------
/src/c/f32_ne/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | float op0, op1;
31 | int res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%X %X %d %s", &op0, &op1, &gold_res, flags);
38 | res = __nesf2(op0, op1);
39 | // SoftFloat f32_add does exactly the opposite of libgcc __eqsf2
40 | // So, invert both libgcc and rvfplib results, for testing purposes
41 | res ^= 0x1;
42 | printf("%08X %08X %d %s\n", *(uint32_t*)&op0, *(uint32_t*)&op1, res, flags);
43 | }
44 |
45 | return 0;
46 | }
47 |
--------------------------------------------------------------------------------
/src/c/f32_sub/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | float op0, op1, res, gold_res;
31 | char flags[10];
32 | int ret = 0;
33 |
34 | // Read the operands from stdin, print on stdout
35 | while (ret != EOF) {
36 | ret = scanf("%X %X %X %s", &op0, &op1, &gold_res, flags);
37 | res = __subsf3(op0, op1);
38 | printf("%08X %08X %08X %s\n", *(uint32_t*)&op0, *(uint32_t*)&op1, *(uint32_t*)&res, flags);
39 | }
40 |
41 | return 0;
42 | }
43 |
--------------------------------------------------------------------------------
/src/c/f32_to_f64/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | float op0;
31 | double res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%X %llX %s", &op0, &gold_res, flags);
38 | res = __extendsfdf2(op0);
39 | printf("%08X %016llX %s\n", *(uint32_t*)&op0, *(uint64_t*)&res, flags);
40 | }
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/src/c/f32_to_i32/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | float op0;
31 | int res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%X %X %s", &op0, &gold_res, flags);
38 | res = __fixsfsi(op0);
39 | printf("%08X %08X %s\n", *(uint32_t*)&op0, *(uint32_t*)&res, flags);
40 | }
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/src/c/f32_to_i64/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | float op0;
31 | long long int res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%X %llX %s", &op0, &gold_res, flags);
38 | res = __fixsfdi(op0);
39 | printf("%08X %016llX %s\n", *(uint32_t*)&op0, res, flags);
40 | }
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/src/c/f32_to_ui32/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | float op0;
31 | unsigned int res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%X %X %s", &op0, &gold_res, flags);
38 | res = __fixunssfsi(op0);
39 | printf("%08X %08X %s\n", *(uint32_t*)&op0, res, flags);
40 | }
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/src/c/f32_to_ui64/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | float op0;
31 | unsigned long long int res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%X %llX %s", &op0, &gold_res, flags);
38 | res = __fixunssfdi(op0);
39 | printf("%08X %016llX %s\n", *(uint32_t*)&op0, res, flags);
40 | }
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/src/c/f64_add/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | double op0, op1, res, gold_res;
31 | char flags[10];
32 | int ret = 0;
33 |
34 | // Read the operands from stdin, print on stdout
35 | while (ret != EOF) {
36 | ret = scanf("%llX %llX %llX %s", &op0, &op1, &gold_res, flags);
37 | res = __adddf3(op0, op1);
38 | printf("%016llX %016llX %016llX %s\n", *(uint64_t*)&op0, *(uint64_t*)&op1, *(uint64_t*)&res, flags);
39 | }
40 |
41 | return 0;
42 | }
43 |
--------------------------------------------------------------------------------
/src/c/f64_div/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | double op0, op1, res, gold_res;
31 | char flags[10];
32 | int ret = 0;
33 |
34 | // Read the operands from stdin, print on stdout
35 | while (ret != EOF) {
36 | ret = scanf("%llX %llX %llX %s", &op0, &op1, &gold_res, flags);
37 | res = __divdf3(op0, op1);
38 | printf("%016llX %016llX %016llX %s\n", *(uint64_t*)&op0, *(uint64_t*)&op1, *(uint64_t*)&res, flags);
39 | }
40 |
41 | return 0;
42 | }
43 |
--------------------------------------------------------------------------------
/src/c/f64_eq/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | double op0, op1;
31 | int res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%llX %llX %d %s", &op0, &op1, &gold_res, flags);
38 | res = __eqdf2(op0, op1);
39 | // SoftFloat f32_add does exactly the opposite of libgcc __eqsf2
40 | // So, invert both libgcc and rvfplib results, for testing purposes
41 | res ^= 0x1;
42 | printf("%016llX %016llX %d %s\n", *(uint64_t*)&op0, *(uint64_t*)&op1, res, flags);
43 | }
44 |
45 | return 0;
46 | }
47 |
--------------------------------------------------------------------------------
/src/c/f64_ge/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | double op0, op1;
31 | int res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%llX %llX %d %s", &op0, &op1, &gold_res, flags);
38 | res = __gedf2(op0, op1);
39 | printf("%016llX %016llX %d %s\n", *(uint64_t*)&op0, *(uint64_t*)&op1, res, flags);
40 | }
41 |
42 | __gtdf2(op0, op1);
43 |
44 | return 0;
45 | }
46 |
--------------------------------------------------------------------------------
/src/c/f64_gt/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | double op0, op1;
31 | int res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%llX %llX %d %s", &op0, &op1, &gold_res, flags);
38 | res = __gtdf2(op0, op1);
39 | printf("%016llX %016llX %d %s\n", *(uint64_t*)&op0, *(uint64_t*)&op1, res, flags);
40 | }
41 |
42 | // Dummy call to __lesf2 to avoid problems at link time
43 | // In libgcc, __lesf2 calls also the libgcc __ltsf2. We don't want this, otherwise we would have 2 __ltsf2 definitions
44 | // Therefore, link rvfplib's __lesf2
45 | __gedf2(op0, op1);
46 |
47 | return 0;
48 | }
49 |
--------------------------------------------------------------------------------
/src/c/f64_le/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | double op0, op1;
31 | int res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%llX %llX %d %s", &op0, &op1, &gold_res, flags);
38 | res = __ledf2(op0, op1);
39 | // SoftFloat requires this precise interface, different from the one of libgcc
40 | // We have the same interface of libgcc, so if we apply this operation to both, nothing is changed
41 | res ^= 0x1;
42 | printf("%016llX %016llX %d %s\n", *(uint64_t*)&op0, *(uint64_t*)&op1, res, flags);
43 | }
44 |
45 | __ltdf2(op0, op1);
46 |
47 | return 0;
48 | }
49 |
--------------------------------------------------------------------------------
/src/c/f64_lt/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | double op0, op1;
31 | int res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%llX %llX %d %s", &op0, &op1, &gold_res, flags);
38 | res = __ltdf2(op0, op1);
39 | printf("%016llX %016llX %d %s\n", *(uint64_t*)&op0, *(uint64_t*)&op1, res, flags);
40 | }
41 |
42 | // Dummy call to __lesf2 to avoid problems at link time
43 | // In libgcc, __lesf2 calls also the libgcc __ltsf2. We don't want this, otherwise we would have 2 __ltsf2 definitions
44 | // Therefore, link rvfplib's __lesf2
45 | __ledf2(op0, op1);
46 |
47 | return 0;
48 | }
49 |
--------------------------------------------------------------------------------
/src/c/f64_mul/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | double op0, op1, res, gold_res;
31 | char flags[10];
32 | int ret = 0;
33 |
34 | // Read the operands from stdin, print on stdout
35 | while (ret != EOF) {
36 | ret = scanf("%llX %llX %llX %s", &op0, &op1, &gold_res, flags);
37 | res = __muldf3(op0, op1);
38 | printf("%016llX %016llX %016llX %s\n", *(uint64_t*)&op0, *(uint64_t*)&op1, *(uint64_t*)&res, flags);
39 | }
40 |
41 | return 0;
42 | }
43 |
--------------------------------------------------------------------------------
/src/c/f64_ne/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | double op0, op1;
31 | int res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%llX %llX %d %s", &op0, &op1, &gold_res, flags);
38 | res = __nedf2(op0, op1);
39 | // SoftFloat f32_add does exactly the opposite of libgcc __eqsf2
40 | // So, invert both libgcc and rvfplib results, for testing purposes
41 | res ^= 0x1;
42 | printf("%016llX %016llX %d %s\n", *(uint64_t*)&op0, *(uint64_t*)&op1, res, flags);
43 | }
44 |
45 | return 0;
46 | }
47 |
--------------------------------------------------------------------------------
/src/c/f64_sub/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | double op0, op1, res, gold_res;
31 | char flags[10];
32 | int ret = 0;
33 |
34 | // Read the operands from stdin, print on stdout
35 | while (ret != EOF) {
36 | ret = scanf("%llX %llX %llX %s", &op0, &op1, &gold_res, flags);
37 | res = __subdf3(op0, op1);
38 | printf("%016llX %016llX %016llX %s\n", *(uint64_t*)&op0, *(uint64_t*)&op1, *(uint64_t*)&res, flags);
39 | }
40 |
41 | return 0;
42 | }
43 |
--------------------------------------------------------------------------------
/src/c/f64_to_f32/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | double op0;
31 | float res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%llX %X %s", &op0, &gold_res, flags);
38 | res = __truncdfsf2(op0);
39 | printf("%016llX %08X %s\n", *(uint64_t*)&op0, *(uint32_t*)&res, flags);
40 | }
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/src/c/f64_to_i32/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | double op0;
31 | int res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%llX %X %s", &op0, &gold_res, flags);
38 | res = __fixdfsi(op0);
39 | printf("%016llX %08X %s\n", *(uint64_t*)&op0, res, flags);
40 | }
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/src/c/f64_to_i64/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | double op0;
31 | long long int res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%llX %llX %s", &op0, &gold_res, flags);
38 | res = __fixdfdi(op0);
39 | printf("%016llX %016llX %s\n", *(uint64_t*)&op0, res, flags);
40 | }
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/src/c/f64_to_ui32/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | double op0;
31 | unsigned int res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%llX %X %s", &op0, &gold_res, flags);
38 | res = __fixunsdfsi(op0);
39 | printf("%016llX %08X %s\n", *(uint64_t*)&op0, res, flags);
40 | }
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/src/c/f64_to_ui64/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | double op0;
31 | unsigned long long int res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%llX %llX %s", &op0, &gold_res, flags);
38 | res = __fixunsdfdi(op0);
39 | printf("%016llX %016llX %s\n", *(uint64_t*)&op0, res, flags);
40 | }
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/src/c/i32_to_f32/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | int op0;
31 | float res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%X %X %s", &op0, &gold_res, flags);
38 | res = __floatsisf(op0);
39 | printf("%08X %08X %s\n", op0, *(uint32_t*)&res, flags);
40 | }
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/src/c/i32_to_f64/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | int op0;
31 | double res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%X %llX %s", &op0, &gold_res, flags);
38 | res = __floatsidf(op0);
39 | printf("%08X %016llX %s\n", op0, *(uint64_t*)&res, flags);
40 | }
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/src/c/i64_to_f32/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | long long int op0;
31 | float res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%llX %X %s", &op0, &gold_res, flags);
38 | res = __floatdisf(op0);
39 | printf("%016llX %08X %s\n", op0, *(uint32_t*)&res, flags);
40 | }
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/src/c/i64_to_f64/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | long long int op0;
31 | double res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%llX %llX %s", &op0, &gold_res, flags);
38 | res = __floatdidf(op0);
39 | printf("%016llX %016llX %s\n", op0, *(uint64_t*)&res, flags);
40 | }
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/src/c/ui32_to_f32/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | unsigned int op0;
31 | float res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%X %X %s", &op0, &gold_res, flags);
38 | res = __floatunsisf(op0);
39 | printf("%08X %08X %s\n", op0, *(uint32_t*)&res, flags);
40 | }
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/src/c/ui32_to_f64/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | unsigned int op0;
31 | double res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%X %llX %s", &op0, &gold_res, flags);
38 | res = __floatunsidf(op0);
39 | printf("%08X %016llX %s\n", op0, *(uint64_t*)&res, flags);
40 | }
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/src/c/ui64_to_f32/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | unsigned long long int op0;
31 | float res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%llX %X %s", &op0, &gold_res, flags);
38 | res = __floatundisf(op0);
39 | printf("%016llX %08X %s\n", op0, *(uint32_t*)&res, flags);
40 | }
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/src/c/ui64_to_f64/main.c:
--------------------------------------------------------------------------------
1 | // Copyright ETH Zurich 2020
2 | //
3 | // Author: Matteo Perotti
4 | //
5 | // This file is part of rvfplib.
6 | //
7 | // rvfplib is free software: you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation, either version 3 of the License, or
10 | // (at your option) any later version.
11 | //
12 | // rvfplib is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // You should have received a copy of the GNU General Public License
18 | // along with rvfplib If not, see .
19 | // Copyright ETH Zurich 2020
20 |
21 | /*
22 | Wrapper for ASM RISC-V functions.
23 | */
24 |
25 | #include
26 | #include "rvfplib.h"
27 |
28 | int main(int argc, char** argv) {
29 |
30 | unsigned long long int op0;
31 | double res, gold_res;
32 | char flags[10];
33 | int ret = 0;
34 |
35 | // Read the operands from stdin, print on stdout
36 | while (ret != EOF) {
37 | ret = scanf("%llX %llX %s", &op0, &gold_res, flags);
38 | res = __floatundidf(op0);
39 | printf("%016llX %016llX %s\n", op0, *(uint64_t*)&res, flags);
40 | }
41 |
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------