fpu_control.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Copyright (C) 1996-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  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. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. #ifndef _AARCH64_FPU_CONTROL_H
  15. #define _AARCH64_FPU_CONTROL_H
  16. #include <features.h>
  17. #include <sys/types.h>
  18. /* Macros for accessing the FPCR and FPSR. */
  19. #if __GNUC_PREREQ (6,0)
  20. # define _FPU_GETCW(fpcr) (fpcr = __builtin_aarch64_get_fpcr ())
  21. # define _FPU_SETCW(fpcr) __builtin_aarch64_set_fpcr (fpcr)
  22. # define _FPU_GETFPSR(fpsr) (fpsr = __builtin_aarch64_get_fpsr ())
  23. # define _FPU_SETFPSR(fpsr) __builtin_aarch64_set_fpsr (fpsr)
  24. #else
  25. # define _FPU_GETCW(fpcr) \
  26. ({ \
  27. __uint64_t __fpcr; \
  28. __asm__ __volatile__ ("mrs %0, fpcr" : "=r" (__fpcr)); \
  29. fpcr = __fpcr; \
  30. })
  31. # define _FPU_SETCW(fpcr) \
  32. ({ \
  33. __uint64_t __fpcr = fpcr; \
  34. __asm__ __volatile__ ("msr fpcr, %0" : : "r" (__fpcr)); \
  35. })
  36. # define _FPU_GETFPSR(fpsr) \
  37. ({ \
  38. __uint64_t __fpsr; \
  39. __asm__ __volatile__ ("mrs %0, fpsr" : "=r" (__fpsr)); \
  40. fpsr = __fpsr; \
  41. })
  42. # define _FPU_SETFPSR(fpsr) \
  43. ({ \
  44. __uint64_t __fpsr = fpsr; \
  45. __asm__ __volatile__ ("msr fpsr, %0" : : "r" (__fpsr)); \
  46. })
  47. #endif
  48. /* Reserved bits should be preserved when modifying register
  49. contents. These two masks indicate which bits in each of FPCR and
  50. FPSR should not be changed. */
  51. #define _FPU_RESERVED 0xfe0fe0f8
  52. #define _FPU_FPSR_RESERVED 0x0fffffe0
  53. #define _FPU_DEFAULT 0x00000000
  54. #define _FPU_FPSR_DEFAULT 0x00000000
  55. /* Layout of FPCR and FPSR:
  56. | | | | | | | |
  57. 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
  58. s s s s s s s s s s s
  59. c c c c c c c c c c c c
  60. 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
  61. 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
  62. 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
  63. D D I I P
  64. E E D D
  65. E E
  66. */
  67. #define _FPU_FPCR_RM_MASK 0xc00000
  68. #define _FPU_FPCR_MASK_IXE 0x1000
  69. #define _FPU_FPCR_MASK_UFE 0x0800
  70. #define _FPU_FPCR_MASK_OFE 0x0400
  71. #define _FPU_FPCR_MASK_DZE 0x0200
  72. #define _FPU_FPCR_MASK_IOE 0x0100
  73. #define _FPU_FPCR_IEEE \
  74. (_FPU_DEFAULT | _FPU_FPCR_MASK_IXE \
  75. | _FPU_FPCR_MASK_UFE | _FPU_FPCR_MASK_OFE \
  76. | _FPU_FPCR_MASK_DZE | _FPU_FPCR_MASK_IOE)
  77. #define _FPU_FPSR_IEEE 0
  78. typedef unsigned int fpu_control_t;
  79. typedef unsigned int fpu_fpsr_t;
  80. /* Default control word set at startup. */
  81. extern fpu_control_t __fpu_control;
  82. #endif