4 ; Standard maths routines for Sapphire
9 ;----- Standard header ------------------------------------------------------
16 ;----- Macros ---------------------------------------------------------------
85 IMPORT |__sph_workoff|,WEAK
88 DCD |__sph_workoff| + &E51B0004 + ($tmp<<12)
91 ;----- Error numbers --------------------------------------------------------
97 ;----- Main code ------------------------------------------------------------
99 AREA |Sapphire$$Code|,CODE,READONLY
101 ; --- Simple FP ops ---
103 ; These map onto FP instructions in a simple way. Some of
104 ; the simpler ops are actually inlined by the compiler
122 |__sapph_sqrt| CUNOP SQT
135 ; --- Rounding functions ---
151 ; --- Hyperbolic functions ---
181 ; --- Horrific FP-number-building functions ---
192 BICNE R0,R0,#&40000000
193 BICNE R0,R0,#&00100000
194 ORRNE R0,R0,#&3FC00000
195 ORRNE R0,R0,#&00200000
218 ; --- Error handling ---
220 ; --- cmath__error ---
222 ; On entry: R1 == error status indicator
224 ; On exit: errno set up nicely
226 ; Use: Handles errors in maths routines.
230 TST R1,#&3 ;Check for IVO and DVZ
231 MOVNE R0,#EDOM ;Domain error
232 BNE %50cmath__error ;So return that then
234 TST R1,#&8 ;Check for UFL condition
235 MVFNEE F0,#0 ;Underflowed -- zero result
236 MOVNE R0,#ERANGE ;And return a range error
237 BNE %50cmath__error ;And return the result
239 CMFE F0,#0 ;Is result positive?
240 LDFGTD F0,cmath__huge ;Yes -- get positive huge
241 LDFLED F0,cmath__nhuge ;No -- get negative huge
242 MOV R0,#ERANGE ;And return a range error
245 WS cmath__wSpace,R12,R3 ;Find workspace location
246 STR R0,[R12,R3] ;Store the error value
247 MOVS PC,R14 ;And return to caller
250 cmath__huge DCD &7FEFFFFF,-1
251 cmath__nhuge DCD &FFEFFFFF,-1
255 ; --- cmath_errno ---
259 ; On exit: R0 == address of `errno'
261 ; Use: Finds the address of the `errno' variable.
266 WS cmath__wSpace,R12,R0
274 ;----- Workspace ------------------------------------------------------------
279 cmath__errno # 4 ;Global `errno' variable
281 cmath__wSize EQU {VAR}-cmath__wStart
283 AREA |Sapphire$$LibData|,CODE,READONLY
290 ;----- That's all, folks ----------------------------------------------------