fpu.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. #ifndef _UAPI__ASM_ALPHA_FPU_H
  3. #define _UAPI__ASM_ALPHA_FPU_H
  4. /*
  5. * Alpha floating-point control register defines:
  6. */
  7. #define FPCR_DNOD (1UL<<47) /* denorm INV trap disable */
  8. #define FPCR_DNZ (1UL<<48) /* denorms to zero */
  9. #define FPCR_INVD (1UL<<49) /* invalid op disable (opt.) */
  10. #define FPCR_DZED (1UL<<50) /* division by zero disable (opt.) */
  11. #define FPCR_OVFD (1UL<<51) /* overflow disable (optional) */
  12. #define FPCR_INV (1UL<<52) /* invalid operation */
  13. #define FPCR_DZE (1UL<<53) /* division by zero */
  14. #define FPCR_OVF (1UL<<54) /* overflow */
  15. #define FPCR_UNF (1UL<<55) /* underflow */
  16. #define FPCR_INE (1UL<<56) /* inexact */
  17. #define FPCR_IOV (1UL<<57) /* integer overflow */
  18. #define FPCR_UNDZ (1UL<<60) /* underflow to zero (opt.) */
  19. #define FPCR_UNFD (1UL<<61) /* underflow disable (opt.) */
  20. #define FPCR_INED (1UL<<62) /* inexact disable (opt.) */
  21. #define FPCR_SUM (1UL<<63) /* summary bit */
  22. #define FPCR_DYN_SHIFT 58 /* first dynamic rounding mode bit */
  23. #define FPCR_DYN_CHOPPED (0x0UL << FPCR_DYN_SHIFT) /* towards 0 */
  24. #define FPCR_DYN_MINUS (0x1UL << FPCR_DYN_SHIFT) /* towards -INF */
  25. #define FPCR_DYN_NORMAL (0x2UL << FPCR_DYN_SHIFT) /* towards nearest */
  26. #define FPCR_DYN_PLUS (0x3UL << FPCR_DYN_SHIFT) /* towards +INF */
  27. #define FPCR_DYN_MASK (0x3UL << FPCR_DYN_SHIFT)
  28. #define FPCR_MASK 0xffff800000000000L
  29. /*
  30. * IEEE trap enables are implemented in software. These per-thread
  31. * bits are stored in the "ieee_state" field of "struct thread_info".
  32. * Thus, the bits are defined so as not to conflict with the
  33. * floating-point enable bit (which is architected). On top of that,
  34. * we want to make these bits compatible with OSF/1 so
  35. * ieee_set_fp_control() etc. can be implemented easily and
  36. * compatibly. The corresponding definitions are in
  37. * /usr/include/machine/fpu.h under OSF/1.
  38. */
  39. #define IEEE_TRAP_ENABLE_INV (1UL<<1) /* invalid op */
  40. #define IEEE_TRAP_ENABLE_DZE (1UL<<2) /* division by zero */
  41. #define IEEE_TRAP_ENABLE_OVF (1UL<<3) /* overflow */
  42. #define IEEE_TRAP_ENABLE_UNF (1UL<<4) /* underflow */
  43. #define IEEE_TRAP_ENABLE_INE (1UL<<5) /* inexact */
  44. #define IEEE_TRAP_ENABLE_DNO (1UL<<6) /* denorm */
  45. #define IEEE_TRAP_ENABLE_MASK (IEEE_TRAP_ENABLE_INV | IEEE_TRAP_ENABLE_DZE |\
  46. IEEE_TRAP_ENABLE_OVF | IEEE_TRAP_ENABLE_UNF |\
  47. IEEE_TRAP_ENABLE_INE | IEEE_TRAP_ENABLE_DNO)
  48. /* Denorm and Underflow flushing */
  49. #define IEEE_MAP_DMZ (1UL<<12) /* Map denorm inputs to zero */
  50. #define IEEE_MAP_UMZ (1UL<<13) /* Map underflowed outputs to zero */
  51. #define IEEE_MAP_MASK (IEEE_MAP_DMZ | IEEE_MAP_UMZ)
  52. /* status bits coming from fpcr: */
  53. #define IEEE_STATUS_INV (1UL<<17)
  54. #define IEEE_STATUS_DZE (1UL<<18)
  55. #define IEEE_STATUS_OVF (1UL<<19)
  56. #define IEEE_STATUS_UNF (1UL<<20)
  57. #define IEEE_STATUS_INE (1UL<<21)
  58. #define IEEE_STATUS_DNO (1UL<<22)
  59. #define IEEE_STATUS_MASK (IEEE_STATUS_INV | IEEE_STATUS_DZE | \
  60. IEEE_STATUS_OVF | IEEE_STATUS_UNF | \
  61. IEEE_STATUS_INE | IEEE_STATUS_DNO)
  62. #define IEEE_SW_MASK (IEEE_TRAP_ENABLE_MASK | \
  63. IEEE_STATUS_MASK | IEEE_MAP_MASK)
  64. #define IEEE_CURRENT_RM_SHIFT 32
  65. #define IEEE_CURRENT_RM_MASK (3UL<<IEEE_CURRENT_RM_SHIFT)
  66. #define IEEE_STATUS_TO_EXCSUM_SHIFT 16
  67. #define IEEE_INHERIT (1UL<<63) /* inherit on thread create? */
  68. /*
  69. * Convert the software IEEE trap enable and status bits into the
  70. * hardware fpcr format.
  71. *
  72. * Digital Unix engineers receive my thanks for not defining the
  73. * software bits identical to the hardware bits. The chip designers
  74. * receive my thanks for making all the not-implemented fpcr bits
  75. * RAZ forcing us to use system calls to read/write this value.
  76. */
  77. static inline unsigned long
  78. ieee_swcr_to_fpcr(unsigned long sw)
  79. {
  80. unsigned long fp;
  81. fp = (sw & IEEE_STATUS_MASK) << 35;
  82. fp |= (sw & IEEE_MAP_DMZ) << 36;
  83. fp |= (sw & IEEE_STATUS_MASK ? FPCR_SUM : 0);
  84. fp |= (~sw & (IEEE_TRAP_ENABLE_INV
  85. | IEEE_TRAP_ENABLE_DZE
  86. | IEEE_TRAP_ENABLE_OVF)) << 48;
  87. fp |= (~sw & (IEEE_TRAP_ENABLE_UNF | IEEE_TRAP_ENABLE_INE)) << 57;
  88. fp |= (sw & IEEE_MAP_UMZ ? FPCR_UNDZ | FPCR_UNFD : 0);
  89. fp |= (~sw & IEEE_TRAP_ENABLE_DNO) << 41;
  90. return fp;
  91. }
  92. static inline unsigned long
  93. ieee_fpcr_to_swcr(unsigned long fp)
  94. {
  95. unsigned long sw;
  96. sw = (fp >> 35) & IEEE_STATUS_MASK;
  97. sw |= (fp >> 36) & IEEE_MAP_DMZ;
  98. sw |= (~fp >> 48) & (IEEE_TRAP_ENABLE_INV
  99. | IEEE_TRAP_ENABLE_DZE
  100. | IEEE_TRAP_ENABLE_OVF);
  101. sw |= (~fp >> 57) & (IEEE_TRAP_ENABLE_UNF | IEEE_TRAP_ENABLE_INE);
  102. sw |= (fp >> 47) & IEEE_MAP_UMZ;
  103. sw |= (~fp >> 41) & IEEE_TRAP_ENABLE_DNO;
  104. return sw;
  105. }
  106. #endif /* _UAPI__ASM_ALPHA_FPU_H */