1 //===----- lib/arm/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 //===----------------------------------------------------------------------===//
11 #include "../fp_mode.h"
13 #define ARM_TONEAREST 0x0
14 #define ARM_UPWARD 0x1
15 #define ARM_DOWNWARD 0x2
16 #define ARM_TOWARDZERO 0x3
17 #define ARM_RMODE_MASK (ARM_TONEAREST | ARM_UPWARD | \
18 ARM_DOWNWARD | ARM_TOWARDZERO)
19 #define ARM_RMODE_SHIFT 22
21 #define ARM_INEXACT 0x10
24 // For soft float targets, allow changing rounding mode by overriding the weak
25 // __arm_fe_default_rmode symbol.
26 CRT_FE_ROUND_MODE
__attribute__((weak
)) __arm_fe_default_rmode
=
30 CRT_FE_ROUND_MODE
__fe_getround(void) {
33 __asm__
__volatile__("vmrs %0, fpscr" : "=r" (fpscr
));
34 fpscr
= fpscr
>> ARM_RMODE_SHIFT
& ARM_RMODE_MASK
;
39 return CRT_FE_DOWNWARD
;
41 return CRT_FE_TOWARDZERO
;
44 return CRT_FE_TONEAREST
;
47 return __arm_fe_default_rmode
;
51 int __fe_raise_inexact(void) {
54 __asm__
__volatile__("vmrs %0, fpscr" : "=r" (fpscr
));
55 __asm__
__volatile__("vmsr fpscr, %0" : : "ri" (fpscr
| ARM_INEXACT
));