fperror.x 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. ! bcc 386 floating point routines (version 2)
  2. ! --- fpdenormal, fperror, fpinfinity, fpNaN, fpoverflow, fpunderflow,fpdivzero
  3. ! author: Bruce Evans
  4. #include "fperr.h"
  5. #include "fplib.h"
  6. .extern _fperr
  7. ! Cause a denormal-operand exception
  8. ! Preserves all general registers if signal handler returns
  9. .globl fpdenormal
  10. .align ALIGNMENT
  11. fpdenormal:
  12. #if 0
  13. push eax
  14. mov eax,#EFDENORMAL
  15. call fperror
  16. pop eax
  17. #endif
  18. ret
  19. ! Cause an exception with error code eax, preserving all genregs except eax
  20. .globl fperror
  21. .align ALIGNMENT
  22. fperror:
  23. push ebp ! set up usual frame ...
  24. mov ebp,esp ! ... for debugging
  25. push edx ! save default
  26. push ecx
  27. push eax ! error code is arg to C routine
  28. call _fperr
  29. add esp,#GENREG_SIZE
  30. pop ecx ! restore default
  31. pop edx
  32. pop ebp
  33. ret
  34. .align ALIGNMENT
  35. fphuge:
  36. mov ecx,#D_HUGE_LOW ! prepare number +-HUGEVAL
  37. or edx,#D_HUGE_HIGH ! ... in case signal handler returns
  38. jmp fperror
  39. ! Cause an infinite-operand exception
  40. ! Return +-HUGEVAL in edx:ecx with sign from edx
  41. .globl fpinfinity
  42. .align ALIGNMENT
  43. fpinfinity:
  44. mov eax,#EFINFINITY
  45. jmp fphuge ! almost right
  46. ! Cause an NaN-operand exception
  47. ! Return +-HUGEVAL in edx:ecx with sign from edx
  48. .globl fpNaN
  49. .align ALIGNMENT
  50. fpNaN:
  51. mov eax,#EFNAN ! there are different types of NaNs but...
  52. jmp fphuge ! WRONG
  53. ! Cause an overflow exception
  54. ! Return +-HUGEVAL in edx:ecx with sign from edx
  55. .globl fpoverflow
  56. .align ALIGNMENT
  57. fpoverflow:
  58. mov eax,#EFOVERFLOW
  59. jmp fphuge ! almost right
  60. ! Cause an underflow exception (actually assume it is masked for now)
  61. ! Return denormal or 0.0 in edx:ecx
  62. ! XXX - this should cause a denormal exception or none for the denormal case
  63. ! Args: sign in edx, fraction in esi:eax, right shift in edi
  64. ! Returns: denormalized number in edx:eax
  65. .globl fpunderflow
  66. .align ALIGNMENT
  67. fpunderflow:
  68. #if 0
  69. mov eax,#EFUNDERFLOW
  70. jmp fperror
  71. #endif
  72. cmp edi,#REG_BIT
  73. jb denormalize1
  74. mov eax,esi
  75. sub esi,esi
  76. sub edi,#REG_BIT
  77. cmp edi,#REG_BIT
  78. jb denormalize1
  79. denormalize_underflow:
  80. #if 0
  81. mov eax,#EFUNDERFLOW
  82. jmp fperror
  83. #endif
  84. sub eax,eax
  85. mov edx,eax
  86. ret
  87. .align ALIGNMENT
  88. denormalize1:
  89. mov ecx,edi
  90. shrd eax,esi,cl
  91. shr esi,cl
  92. mov ecx,esi
  93. or ecx,eax
  94. jz denormalize_underflow
  95. and edx,#D_SIGN_MASK
  96. or edx,esi
  97. ret
  98. ! Cause an fp division by zero exception
  99. ! Return +-HUGEVAL in edx:ecx with sign from edx
  100. .globl fpdivzero
  101. .align ALIGNMENT
  102. fpdivzero:
  103. mov eax,#EFDIVZERO
  104. test edx,#D_EXP_MASK
  105. jnz fphuge ! almost right
  106. sub ecx,ecx
  107. mov edx,ecx
  108. jmp fperror