1 //=== lib/builtins/loongarch/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 LOONGARCH_TONEAREST 0x0000
11 #define LOONGARCH_TOWARDZERO 0x0100
12 #define LOONGARCH_UPWARD 0x0200
13 #define LOONGARCH_DOWNWARD 0x0300
15 #define LOONGARCH_RMODE_MASK (LOONGARCH_TONEAREST | LOONGARCH_TOWARDZERO | \
16 LOONGARCH_UPWARD | LOONGARCH_DOWNWARD)
18 #define LOONGARCH_INEXACT 0x10000
20 CRT_FE_ROUND_MODE
__fe_getround(void) {
21 #if __loongarch_frlen != 0
24 __asm__
__volatile__("movfcsr2gr %0, $fcsr0" : "=r" (fcsr
));
26 __asm__
__volatile__("movfcsr2gr %0, $r0" : "=r" (fcsr
));
28 fcsr
&= LOONGARCH_RMODE_MASK
;
30 case LOONGARCH_TOWARDZERO
:
31 return CRT_FE_TOWARDZERO
;
32 case LOONGARCH_DOWNWARD
:
33 return CRT_FE_DOWNWARD
;
34 case LOONGARCH_UPWARD
:
36 case LOONGARCH_TONEAREST
:
38 return CRT_FE_TONEAREST
;
41 return CRT_FE_TONEAREST
;
45 int __fe_raise_inexact(void) {
46 #if __loongarch_frlen != 0
49 __asm__
__volatile__("movfcsr2gr %0, $fcsr0" : "=r" (fcsr
));
51 "movgr2fcsr $fcsr0, %0" :: "r" (fcsr
| LOONGARCH_INEXACT
));
53 __asm__
__volatile__("movfcsr2gr %0, $r0" : "=r" (fcsr
));
55 "movgr2fcsr $r0, %0" :: "r" (fcsr
| LOONGARCH_INEXACT
));