fpu_control.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* FPU control word bits. LoongArch64 version.
  2. Copyright (C) 2024 uClibc-ng contributors.
  3. Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  4. */
  5. #ifndef _FPU_CONTROL_H
  6. #define _FPU_CONTROL_H
  7. /* LoongArch FPU floating point control register bits.
  8. *
  9. * Bits 8-9: RM (rounding mode)
  10. * 00 = round to nearest
  11. * 01 = round towards zero
  12. * 10 = round towards positive infinity
  13. * 11 = round towards negative infinity
  14. *
  15. * Bits 16-20: Flags (cumulative exception flags)
  16. * Bit 16: V (invalid operation)
  17. * Bit 17: Z (division by zero)
  18. * Bit 18: O (overflow)
  19. * Bit 19: U (underflow)
  20. * Bit 20: I (inexact)
  21. *
  22. * Bits 0-4: Enables
  23. * Bit 0: V enable
  24. * Bit 1: Z enable
  25. * Bit 2: O enable
  26. * Bit 3: U enable
  27. * Bit 4: I enable
  28. */
  29. #include <features.h>
  30. /* Masks for rounding mode bits. */
  31. #define _FPU_RC_NEAREST 0x000 /* RECOMMENDED */
  32. #define _FPU_RC_ZERO 0x100
  33. #define _FPU_RC_UP 0x200
  34. #define _FPU_RC_DOWN 0x300
  35. #define _FPU_RESERVED 0xFFE0E0E0 /* Reserved bits */
  36. #define _FPU_DEFAULT 0x00000000
  37. #define _FPU_IEEE 0x00000000
  38. /* Type of the control word. */
  39. typedef unsigned int fpu_control_t;
  40. /* Macros for accessing the hardware control word. */
  41. #define _FPU_GETCW(cw) \
  42. __asm__ volatile ("movfcsr2gr %0, $fcsr0" : "=r" (cw))
  43. #define _FPU_SETCW(cw) \
  44. __asm__ volatile ("movgr2fcsr $fcsr0, %0" : : "r" (cw))
  45. /* Default control word set at startup. */
  46. extern fpu_control_t __fpu_control;
  47. #endif /* fpu_control.h */