43 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8#include "../fp_mode.h"9 10#define RISCV_TONEAREST 0x011#define RISCV_TOWARDZERO 0x112#define RISCV_DOWNWARD 0x213#define RISCV_UPWARD 0x314 15#define RISCV_INEXACT 0x116 17CRT_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#else33 return CRT_FE_TONEAREST;34#endif35}36 37int __fe_raise_inexact(void) {38#if defined(__riscv_f) || defined(__riscv_zfinx)39 __asm__ __volatile__("csrsi fflags, %0" :: "i" (RISCV_INEXACT));40#endif41 return 0;42}43