1 //=== lib/builtins/riscv/fp_mode.c - Floaing-point mode utilities -*- C -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
8 #include "../fp_mode.h"
10 #define RISCV_TONEAREST 0x0
11 #define RISCV_TOWARDZERO 0x1
12 #define RISCV_DOWNWARD 0x2
13 #define RISCV_UPWARD 0x3
15 #define RISCV_INEXACT 0x1
17 CRT_FE_ROUND_MODE
__fe_getround(void) {
18 #if defined(__riscv_f) || defined(__riscv_zfinx)
20 __asm__
__volatile__("frrm %0" : "=r" (frm
));
22 case RISCV_TOWARDZERO
:
23 return CRT_FE_TOWARDZERO
;
25 return CRT_FE_DOWNWARD
;
30 return CRT_FE_TONEAREST
;
33 return CRT_FE_TONEAREST
;
37 int __fe_raise_inexact(void) {
38 #if defined(__riscv_f) || defined(__riscv_zfinx)
39 __asm__
__volatile__("csrsi fflags, %0" :: "i" (RISCV_INEXACT
));