1 //=== lib/builtins/riscv/fp_mode.c - Floaing-point mode utilities -*- C -*-===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 #include "../fp_mode.h" 9 10 #define RISCV_TONEAREST 0x0 11 #define RISCV_TOWARDZERO 0x1 12 #define RISCV_DOWNWARD 0x2 13 #define RISCV_UPWARD 0x3 14 15 #define RISCV_INEXACT 0x1 16 17 CRT_FE_ROUND_MODE __fe_getround(void) { 18 #if defined(__riscv_f) || defined(__riscv_zfinx) 19 int frm; 20 __asm__ __volatile__("frrm %0" : "=r" (frm)); 21 switch (frm) { 22 case RISCV_TOWARDZERO: 23 return CRT_FE_TOWARDZERO; 24 case RISCV_DOWNWARD: 25 return CRT_FE_DOWNWARD; 26 case RISCV_UPWARD: 27 return CRT_FE_UPWARD; 28 case RISCV_TONEAREST: 29 default: 30 return CRT_FE_TONEAREST; 31 } 32 #else 33 return CRT_FE_TONEAREST; 34 #endif 35 } 36 37 int __fe_raise_inexact(void) { 38 #if defined(__riscv_f) || defined(__riscv_zfinx) 39 __asm__ __volatile__("csrsi fflags, %0" :: "i" (RISCV_INEXACT)); 40 #endif 41 return 0; 42 } 43