1ace6e172Sluxufan //=== lib/builtins/riscv/fp_mode.c - Floaing-point mode utilities -*- C -*-===// 2ace6e172Sluxufan // 3ace6e172Sluxufan // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4ace6e172Sluxufan // See https://llvm.org/LICENSE.txt for license information. 5ace6e172Sluxufan // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6ace6e172Sluxufan // 7ace6e172Sluxufan //===----------------------------------------------------------------------===// 8ace6e172Sluxufan #include "../fp_mode.h" 9ace6e172Sluxufan 10ace6e172Sluxufan #define RISCV_TONEAREST 0x0 11ace6e172Sluxufan #define RISCV_TOWARDZERO 0x1 12ace6e172Sluxufan #define RISCV_DOWNWARD 0x2 13ace6e172Sluxufan #define RISCV_UPWARD 0x3 14ace6e172Sluxufan 15ace6e172Sluxufan #define RISCV_INEXACT 0x1 16ace6e172Sluxufan __fe_getround(void)17ace6e172SluxufanCRT_FE_ROUND_MODE __fe_getround(void) { 18*2b5ea51aSKito Cheng #if defined(__riscv_f) || defined(__riscv_zfinx) 19ace6e172Sluxufan int frm; 20ace6e172Sluxufan __asm__ __volatile__("frrm %0" : "=r" (frm)); 21ace6e172Sluxufan switch (frm) { 22ace6e172Sluxufan case RISCV_TOWARDZERO: 23ace6e172Sluxufan return CRT_FE_TOWARDZERO; 24ace6e172Sluxufan case RISCV_DOWNWARD: 25ace6e172Sluxufan return CRT_FE_DOWNWARD; 26ace6e172Sluxufan case RISCV_UPWARD: 27ace6e172Sluxufan return CRT_FE_UPWARD; 28ace6e172Sluxufan case RISCV_TONEAREST: 29ace6e172Sluxufan default: 30ace6e172Sluxufan return CRT_FE_TONEAREST; 31ace6e172Sluxufan } 32ace6e172Sluxufan #else 33ace6e172Sluxufan return CRT_FE_TONEAREST; 34ace6e172Sluxufan #endif 35ace6e172Sluxufan } 36ace6e172Sluxufan __fe_raise_inexact(void)37ace6e172Sluxufanint __fe_raise_inexact(void) { 38*2b5ea51aSKito Cheng #if defined(__riscv_f) || defined(__riscv_zfinx) 39ace6e172Sluxufan __asm__ __volatile__("csrsi fflags, %0" :: "i" (RISCV_INEXACT)); 40ace6e172Sluxufan #endif 41ace6e172Sluxufan return 0; 42ace6e172Sluxufan } 43