Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.5 KiB

  1. /* _LDnorm function -- IEEE 754 version */
  2. #include "xmath.h"
  3. _STD_BEGIN
  4. #if _DLONG == 0
  5. /* not needed -- 64-bit */
  6. #elif _DLONG == 1
  7. _CRTIMP2 short __cdecl _LDnorm(unsigned short *ps)
  8. { /* normalize long double fraction -- 80-bit */
  9. short xchar;
  10. unsigned short sign = ps[_L0];
  11. xchar = 0;
  12. for (ps[_L0] = 0; ps[_L0] == 0 && ps[_L1] < 0x100;
  13. xchar -= 16)
  14. { /* shift left by 16 */
  15. ps[_L0] = ps[_L1];
  16. ps[_L1] = ps[_L2], ps[_L2] = ps[_L3];
  17. ps[_L3] = ps[_L4], ps[_L4] = 0;
  18. }
  19. if (ps[_L0] == 0)
  20. for (; ps[_L1] < (1U << _LOFF); --xchar)
  21. { /* shift left by 1 */
  22. ps[_L1] = ps[_L1] << 1 | ps[_L2] >> 15;
  23. ps[_L2] = ps[_L2] << 1 | ps[_L3] >> 15;
  24. ps[_L3] = ps[_L3] << 1 | ps[_L4] >> 15;
  25. ps[_L4] <<= 1;
  26. }
  27. for (; ps[_L0] != 0; ++xchar)
  28. { /* shift right by 1 */
  29. ps[_L4] = ps[_L4] >> 1 | ps[_L3] << 15;
  30. ps[_L3] = ps[_L3] >> 1 | ps[_L2] << 15;
  31. ps[_L2] = ps[_L2] >> 1 | ps[_L1] << 15;
  32. ps[_L1] = ps[_L1] >> 1 | ps[_L0] << 15;
  33. ps[_L0] >>= 1;
  34. }
  35. ps[_L0] = sign;
  36. return (xchar);
  37. }
  38. #else /* 1 < _DLONG */
  39. _CRTIMP2 short __cdecl _LDnorm(unsigned short *ps)
  40. { /* normalize long double fraction -- 128-bit SPARC */
  41. short xchar;
  42. unsigned short sign = ps[_L0];
  43. xchar = 1;
  44. if (ps[_L1] != 0 || ps[_L2] != 0 || ps[_L3] != 0
  45. || ps[_L4] != 0 || ps[_L5] != 0 || ps[_L6] != 0
  46. || ps[_L7] != 0)
  47. { /* nonzero, scale */
  48. for (ps[_L0] = 0; ps[_L0] == 0 && ps[_L1] < 0x100;
  49. xchar -= 16)
  50. { /* shift left by 16 */
  51. ps[_L0] = ps[_L1];
  52. ps[_L1] = ps[_L2], ps[_L2] = ps[_L3];
  53. ps[_L3] = ps[_L4], ps[_L4] = ps[_L5];
  54. ps[_L5] = ps[_L6], ps[_L6] = ps[_L7];
  55. ps[_L7] = 0;
  56. }
  57. for (; ps[_L0] == 0; --xchar)
  58. { /* shift left by 1 */
  59. ps[_L0] = ps[_L0] << 1 | ps[_L1] >> 15;
  60. ps[_L1] = ps[_L1] << 1 | ps[_L2] >> 15;
  61. ps[_L2] = ps[_L2] << 1 | ps[_L3] >> 15;
  62. ps[_L3] = ps[_L3] << 1 | ps[_L4] >> 15;
  63. ps[_L4] = ps[_L4] << 1 | ps[_L5] >> 15;
  64. ps[_L5] = ps[_L5] << 1 | ps[_L6] >> 15;
  65. ps[_L6] = ps[_L6] << 1 | ps[_L7] >> 15;
  66. ps[_L7] <<= 1;
  67. }
  68. for (; 1 < ps[_L0]; ++xchar)
  69. { /* shift right by 1 */
  70. ps[_L7] = ps[_L7] >> 1 | ps[_L6] << 15;
  71. ps[_L6] = ps[_L6] >> 1 | ps[_L5] << 15;
  72. ps[_L5] = ps[_L5] >> 1 | ps[_L4] << 15;
  73. ps[_L4] = ps[_L4] >> 1 | ps[_L3] << 15;
  74. ps[_L3] = ps[_L3] >> 1 | ps[_L2] << 15;
  75. ps[_L2] = ps[_L2] >> 1 | ps[_L1] << 15;
  76. ps[_L1] = ps[_L1] >> 1 | ps[_L0] << 15;
  77. ps[_L0] >>= 1;
  78. }
  79. }
  80. ps[_L0] = sign;
  81. return (xchar);
  82. }
  83. #endif
  84. _STD_END
  85. /*
  86. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  87. * Consult your license regarding permissions and restrictions.
  88. V3.10:0009 */