1 /* Copyright (C) 1996-2025 Free Software Foundation, Inc.
2 
3    The GNU C Library is free software; you can redistribute it and/or
4    modify it under the terms of the GNU Lesser General Public License as
5    published by the Free Software Foundation; either version 2.1 of the
6    License, or (at your option) any later version.
7 
8    The GNU C Library is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11    Lesser General Public License for more details.
12 
13    You should have received a copy of the GNU Lesser General Public
14    License along with the GNU C Library; if not, see
15    <https://www.gnu.org/licenses/>.  */
16 
17 #ifndef _AARCH64_FPU_CONTROL_H
18 #define _AARCH64_FPU_CONTROL_H
19 
20 #include <features.h>
21 
22 /* Macros for accessing the FPCR and FPSR.  */
23 
24 #if __GNUC_PREREQ (6,0)
25 # define _FPU_GETCW(fpcr) (fpcr = __builtin_aarch64_get_fpcr ())
26 # define _FPU_SETCW(fpcr) __builtin_aarch64_set_fpcr (fpcr)
27 # define _FPU_GETFPSR(fpsr) (fpsr = __builtin_aarch64_get_fpsr ())
28 # define _FPU_SETFPSR(fpsr) __builtin_aarch64_set_fpsr (fpsr)
29 #else
30 # define _FPU_GETCW(fpcr)					\
31   ({ 								\
32    __uint64_t __fpcr;						\
33    __asm__ __volatile__ ("mrs	%0, fpcr" : "=r" (__fpcr));	\
34    fpcr = __fpcr;						\
35   })
36 
37 # define _FPU_SETCW(fpcr)					\
38   ({								\
39    __uint64_t __fpcr = fpcr;					\
40    __asm__ __volatile__ ("msr	fpcr, %0" : : "r" (__fpcr));    \
41   })
42 
43 # define _FPU_GETFPSR(fpsr)					\
44   ({								\
45    __uint64_t __fpsr;						\
46    __asm__ __volatile__ ("mrs	%0, fpsr" : "=r" (__fpsr));	\
47    fpsr = __fpsr;						\
48   })
49 
50 # define _FPU_SETFPSR(fpsr)					\
51   ({								\
52    __uint64_t __fpsr = fpsr;					\
53    __asm__ __volatile__ ("msr	fpsr, %0" : : "r" (__fpsr));    \
54   })
55 #endif
56 
57 /* Reserved bits should be preserved when modifying register
58    contents. These two masks indicate which bits in each of FPCR and
59    FPSR should not be changed.  */
60 
61 #define _FPU_RESERVED		0xfe0fe0f8
62 #define _FPU_FPSR_RESERVED	0x0fffffe0
63 
64 #define _FPU_DEFAULT		0x00000000
65 #define _FPU_FPSR_DEFAULT	0x00000000
66 
67 /* Layout of FPCR and FPSR:
68 
69    |       |       |       |       |       |       |       |
70    0 0 0 0 1 1 1 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0
71    s s s s s                                       s     s s s s s
72              c c c c c c c               c c c c c
73    N Z C V Q A D F R R S S S L L L I U U I U O D I I U U I U O D I
74            C H N Z M M T T B E E E D N N X F F Z O D N N X F F Z O
75              P     O O R R Z N N N E K K E E E E E C K K C C C C C
76                    D D I I P
77                    E E D D
78                        E E
79  */
80 
81 #define _FPU_FPCR_RM_MASK  0xc00000
82 
83 #define _FPU_FPCR_MASK_IXE 0x1000
84 #define _FPU_FPCR_MASK_UFE 0x0800
85 #define _FPU_FPCR_MASK_OFE 0x0400
86 #define _FPU_FPCR_MASK_DZE 0x0200
87 #define _FPU_FPCR_MASK_IOE 0x0100
88 
89 #define _FPU_FPCR_IEEE                       \
90   (_FPU_DEFAULT  | _FPU_FPCR_MASK_IXE	     \
91    | _FPU_FPCR_MASK_UFE | _FPU_FPCR_MASK_OFE \
92    | _FPU_FPCR_MASK_DZE | _FPU_FPCR_MASK_IOE)
93 
94 #define _FPU_FPSR_IEEE 0
95 
96 typedef unsigned int fpu_control_t;
97 typedef unsigned int fpu_fpsr_t;
98 
99 /* Default control word set at startup.  */
100 extern fpu_control_t __fpu_control;
101 
102 #endif
103