fp_mode.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #define RISCV_TONEAREST 0x0
  10. #define RISCV_TOWARDZERO 0x1
  11. #define RISCV_DOWNWARD 0x2
  12. #define RISCV_UPWARD 0x3
  13. #define RISCV_INEXACT 0x1
  14. CRT_FE_ROUND_MODE __fe_getround(void) {
  15. #if defined(__riscv_f) || defined(__riscv_zfinx)
  16. int frm;
  17. __asm__ __volatile__("frrm %0" : "=r" (frm));
  18. switch (frm) {
  19. case RISCV_TOWARDZERO:
  20. return CRT_FE_TOWARDZERO;
  21. case RISCV_DOWNWARD:
  22. return CRT_FE_DOWNWARD;
  23. case RISCV_UPWARD:
  24. return CRT_FE_UPWARD;
  25. case RISCV_TONEAREST:
  26. default:
  27. return CRT_FE_TONEAREST;
  28. }
  29. #else
  30. return CRT_FE_TONEAREST;
  31. #endif
  32. }
  33. int __fe_raise_inexact(void) {
  34. #if defined(__riscv_f) || defined(__riscv_zfinx)
  35. __asm__ __volatile__("csrsi fflags, %0" :: "i" (RISCV_INEXACT));
  36. #endif
  37. return 0;
  38. }