poly.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*---------------------------------------------------------------------------+
  3. | poly.h |
  4. | |
  5. | Header file for the FPU-emu poly*.c source files. |
  6. | |
  7. | Copyright (C) 1994,1999 |
  8. | W. Metzenthen, 22 Parker St, Ormond, Vic 3163, |
  9. | Australia. E-mail [email protected] |
  10. | |
  11. | Declarations and definitions for functions operating on Xsig (12-byte |
  12. | extended-significand) quantities. |
  13. | |
  14. +---------------------------------------------------------------------------*/
  15. #ifndef _POLY_H
  16. #define _POLY_H
  17. /* This 12-byte structure is used to improve the accuracy of computation
  18. of transcendental functions.
  19. Intended to be used to get results better than 8-byte computation
  20. allows. 9-byte would probably be sufficient.
  21. */
  22. typedef struct {
  23. unsigned long lsw;
  24. unsigned long midw;
  25. unsigned long msw;
  26. } Xsig;
  27. asmlinkage void mul64(unsigned long long const *a, unsigned long long const *b,
  28. unsigned long long *result);
  29. asmlinkage void polynomial_Xsig(Xsig *, const unsigned long long *x,
  30. const unsigned long long terms[], const int n);
  31. asmlinkage void mul32_Xsig(Xsig *, const unsigned long mult);
  32. asmlinkage void mul64_Xsig(Xsig *, const unsigned long long *mult);
  33. asmlinkage void mul_Xsig_Xsig(Xsig *dest, const Xsig *mult);
  34. asmlinkage void shr_Xsig(Xsig *, const int n);
  35. asmlinkage int round_Xsig(Xsig *);
  36. asmlinkage int norm_Xsig(Xsig *);
  37. asmlinkage void div_Xsig(Xsig *x1, const Xsig *x2, const Xsig *dest);
  38. /* Macro to extract the most significant 32 bits from a long long */
  39. #define LL_MSW(x) (((unsigned long *)&x)[1])
  40. /* Macro to initialize an Xsig struct */
  41. #define MK_XSIG(a,b,c) { c, b, a }
  42. /* Macro to access the 8 ms bytes of an Xsig as a long long */
  43. #define XSIG_LL(x) (*(unsigned long long *)&x.midw)
  44. /*
  45. Need to run gcc with optimizations on to get these to
  46. actually be in-line.
  47. */
  48. /* Multiply two fixed-point 32 bit numbers, producing a 32 bit result.
  49. The answer is the ms word of the product. */
  50. /* Some versions of gcc make it difficult to stop eax from being clobbered.
  51. Merely specifying that it is used doesn't work...
  52. */
  53. static inline unsigned long mul_32_32(const unsigned long arg1,
  54. const unsigned long arg2)
  55. {
  56. int retval;
  57. asm volatile ("mull %2; movl %%edx,%%eax":"=a" (retval)
  58. :"0"(arg1), "g"(arg2)
  59. :"dx");
  60. return retval;
  61. }
  62. /* Add the 12 byte Xsig x2 to Xsig dest, with no checks for overflow. */
  63. static inline void add_Xsig_Xsig(Xsig *dest, const Xsig *x2)
  64. {
  65. asm volatile ("movl %1,%%edi; movl %2,%%esi;\n"
  66. "movl (%%esi),%%eax; addl %%eax,(%%edi);\n"
  67. "movl 4(%%esi),%%eax; adcl %%eax,4(%%edi);\n"
  68. "movl 8(%%esi),%%eax; adcl %%eax,8(%%edi);\n":"=g"
  69. (*dest):"g"(dest), "g"(x2)
  70. :"ax", "si", "di");
  71. }
  72. /* Add the 12 byte Xsig x2 to Xsig dest, adjust exp if overflow occurs. */
  73. /* Note: the constraints in the asm statement didn't always work properly
  74. with gcc 2.5.8. Changing from using edi to using ecx got around the
  75. problem, but keep fingers crossed! */
  76. static inline void add_two_Xsig(Xsig *dest, const Xsig *x2, long int *exp)
  77. {
  78. asm volatile ("movl %2,%%ecx; movl %3,%%esi;\n"
  79. "movl (%%esi),%%eax; addl %%eax,(%%ecx);\n"
  80. "movl 4(%%esi),%%eax; adcl %%eax,4(%%ecx);\n"
  81. "movl 8(%%esi),%%eax; adcl %%eax,8(%%ecx);\n"
  82. "jnc 0f;\n"
  83. "rcrl 8(%%ecx); rcrl 4(%%ecx); rcrl (%%ecx)\n"
  84. "movl %4,%%ecx; incl (%%ecx)\n"
  85. "movl $1,%%eax; jmp 1f;\n"
  86. "0: xorl %%eax,%%eax;\n" "1:\n":"=g" (*exp), "=g"(*dest)
  87. :"g"(dest), "g"(x2), "g"(exp)
  88. :"cx", "si", "ax");
  89. }
  90. /* Negate (subtract from 1.0) the 12 byte Xsig */
  91. /* This is faster in a loop on my 386 than using the "neg" instruction. */
  92. static inline void negate_Xsig(Xsig *x)
  93. {
  94. asm volatile ("movl %1,%%esi;\n"
  95. "xorl %%ecx,%%ecx;\n"
  96. "movl %%ecx,%%eax; subl (%%esi),%%eax; movl %%eax,(%%esi);\n"
  97. "movl %%ecx,%%eax; sbbl 4(%%esi),%%eax; movl %%eax,4(%%esi);\n"
  98. "movl %%ecx,%%eax; sbbl 8(%%esi),%%eax; movl %%eax,8(%%esi);\n":"=g"
  99. (*x):"g"(x):"si", "ax", "cx");
  100. }
  101. #endif /* _POLY_H */