Debian Codegraph @

libgcc/config/m68k/lb1sf68.S

raw
1 /* libgcc routines for 68000 w/o floating-point hardware.
2 Copyright (C) 1994-2025 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 This file is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
19
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
24
25 /* Use this one for any 680x0; assumes no floating point hardware.
26 The trailing " '" appearing on some lines is for ANSI preprocessors. Yuk.
27 Some of this code comes from MINIX, via the folks at ericsson.
28 D. V. Henkel-Wallace ([email protected]) Fete Bastille, 1992
29 */
30
31 /* These are predefined by new versions of GNU cpp. */
32
33 #ifndef __USER_LABEL_PREFIX__
34 #define __USER_LABEL_PREFIX__ _
35 #endif
36
37 #ifndef __REGISTER_PREFIX__
38 #define __REGISTER_PREFIX__
39 #endif
40
41 #ifndef __IMMEDIATE_PREFIX__
42 #define __IMMEDIATE_PREFIX__ #
43 #endif
44
45 /* ANSI concatenation macros. */
46
47 #define CONCAT1(a, b) CONCAT2(a, b)
48 #define CONCAT2(a, b) a ## b
49
50 /* Use the right prefix for global labels. */
51
52 #define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
53
54 /* Note that X is a function. */
55
56 #ifdef __ELF__
57 #define FUNC(x) .type SYM(x),function
58 #else
59 /* The .proc pseudo-op is accepted, but ignored, by GAS. We could just
60 define this to the empty string for non-ELF systems, but defining it
61 to .proc means that the information is available to the assembler if
62 the need arises. */
63 #define FUNC(x) .proc
64 #endif
65
66 /* Use the right prefix for registers. */
67
68 #define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
69
70 /* Use the right prefix for immediate values. */
71
72 #define IMM(x) CONCAT1 (__IMMEDIATE_PREFIX__, x)
73
74 #define d0 REG (d0)
75 #define d1 REG (d1)
76 #define d2 REG (d2)
77 #define d3 REG (d3)
78 #define d4 REG (d4)
79 #define d5 REG (d5)
80 #define d6 REG (d6)
81 #define d7 REG (d7)
82 #define a0 REG (a0)
83 #define a1 REG (a1)
84 #define a2 REG (a2)
85 #define a3 REG (a3)
86 #define a4 REG (a4)
87 #define a5 REG (a5)
88 #define a6 REG (a6)
89 #define fp REG (fp)
90 #define sp REG (sp)
91 #define pc REG (pc)
92
93 /* Provide a few macros to allow for PIC code support.
94 * With PIC, data is stored A5 relative so we've got to take a bit of special
95 * care to ensure that all loads of global data is via A5. PIC also requires
96 * jumps and subroutine calls to be PC relative rather than absolute. We cheat
97 * a little on this and in the PIC case, we use short offset branches and
98 * hope that the final object code is within range (which it should be).
99 */
100 #ifndef __PIC__
101
102 /* Non PIC (absolute/relocatable) versions */
103
104 .macro PICCALL addr
105 jbsr \addr
106 .endm
107
108 .macro PICJUMP addr
109 jmp \addr
110 .endm
111
112 .macro PICLEA sym, reg
113 lea \sym, \reg
114 .endm
115
116 .macro PICPEA sym, areg
117 pea \sym
118 .endm
119
120 #else /* __PIC__ */
121
122 # if defined (__uClinux__)
123
124 /* Versions for uClinux */
125
126 # if defined(__ID_SHARED_LIBRARY__)
127
128 /* -mid-shared-library versions */
129
130 .macro PICLEA sym, reg
131 movel a5@(_current_shared_library_a5_offset_), \reg
132 movel \sym@GOT(\reg), \reg
133 .endm
134
135 .macro PICPEA sym, areg
136 movel a5@(_current_shared_library_a5_offset_), \areg
137 movel \sym@GOT(\areg), sp@-
138 .endm
139
140 .macro PICCALL addr
141 PICLEA \addr,a0
142 jsr a0@
143 .endm
144
145 .macro PICJUMP addr
146 PICLEA \addr,a0
147 jmp a0@
148 .endm
149
150 # else /* !__ID_SHARED_LIBRARY__ */
151
152 /* Versions for -msep-data */
153
154 .macro PICLEA sym, reg
155 movel \sym@GOT(a5), \reg
156 .endm
157
158 .macro PICPEA sym, areg
159 movel \sym@GOT(a5), sp@-
160 .endm
161
162 .macro PICCALL addr
163 #if defined (__mcoldfire__) && !defined (__mcfisab__) && !defined (__mcfisac__)
164 lea \addr-.-8,a0
165 jsr pc@(a0)
166 #else
167 jbsr \addr
168 #endif
169 .endm
170
171 .macro PICJUMP addr
172 /* ISA C has no bra.l instruction, and since this assembly file
173 gets assembled into multiple object files, we avoid the
174 bra instruction entirely. */
175 #if defined (__mcoldfire__) && !defined (__mcfisab__)
176 lea \addr-.-8,a0
177 jmp pc@(a0)
178 #else
179 bra \addr
180 #endif
181 .endm
182
183 # endif
184
185 # else /* !__uClinux__ */
186
187 /* Versions for Linux */
188
189 .macro PICLEA sym, reg
190 movel #_GLOBAL_OFFSET_TABLE_@GOTPC, \reg
191 lea (-6, pc, \reg), \reg
192 movel \sym@GOT(\reg), \reg
193 .endm
194
195 .macro PICPEA sym, areg
196 movel #_GLOBAL_OFFSET_TABLE_@GOTPC, \areg
197 lea (-6, pc, \areg), \areg
198 movel \sym@GOT(\areg), sp@-
199 .endm
200
201 .macro PICCALL addr
202 #if defined (__mcoldfire__) && !defined (__mcfisab__) && !defined (__mcfisac__)
203 lea \addr-.-8,a0
204 jsr pc@(a0)
205 #else
206 jbsr \addr
207 #endif
208 .endm
209
210 .macro PICJUMP addr
211 /* ISA C has no bra.l instruction, and since this assembly file
212 gets assembled into multiple object files, we avoid the
213 bra instruction entirely. */
214 #if defined (__mcoldfire__) && !defined (__mcfisab__)
215 lea \addr-.-8,a0
216 jmp pc@(a0)
217 #else
218 bra \addr
219 #endif
220 .endm
221
222 # endif
223 #endif /* __PIC__ */
224
225
226 #ifdef L_floatex
227
228 | This is an attempt at a decent floating point (single, double and
229 | extended double) code for the GNU C compiler. It should be easy to
230 | adapt to other compilers (but beware of the local labels!).
231
232 | Starting date: 21 October, 1990
233
234 | It is convenient to introduce the notation (s,e,f) for a floating point
235 | number, where s=sign, e=exponent, f=fraction. We will call a floating
236 | point number fpn to abbreviate, independently of the precision.
237 | Let MAX_EXP be in each case the maximum exponent (255 for floats, 1023
238 | for doubles and 16383 for long doubles). We then have the following
239 | different cases:
240 | 1. Normalized fpns have 0 < e < MAX_EXP. They correspond to
241 | (-1)^s x 1.f x 2^(e-bias-1).
242 | 2. Denormalized fpns have e=0. They correspond to numbers of the form
243 | (-1)^s x 0.f x 2^(-bias).
244 | 3. +/-INFINITY have e=MAX_EXP, f=0.
245 | 4. Quiet NaN (Not a Number) have all bits set.
246 | 5. Signaling NaN (Not a Number) have s=0, e=MAX_EXP, f=1.
247
248 |=============================================================================
249 | exceptions
250 |=============================================================================
251
252 | This is the floating point condition code register (_fpCCR):
253 |
254 | struct {
255 | short _exception_bits;
256 | short _trap_enable_bits;
257 | short _sticky_bits;
258 | short _rounding_mode;
259 | short _format;
260 | short _last_operation;
261 | union {
262 | float sf;
263 | double df;
264 | } _operand1;
265 | union {
266 | float sf;
267 | double df;
268 | } _operand2;
269 | } _fpCCR;
270
271 .data
272 .even
273
274 .globl SYM (_fpCCR)
275
276 SYM (_fpCCR):
277 __exception_bits:
278 .word 0
279 __trap_enable_bits:
280 .word 0
281 __sticky_bits:
282 .word 0
283 __rounding_mode:
284 .word ROUND_TO_NEAREST
285 __format:
286 .word NIL
287 __last_operation:
288 .word NOOP
289 __operand1:
290 .long 0
291 .long 0
292 __operand2:
293 .long 0
294 .long 0
295
296 | Offsets:
297 EBITS = __exception_bits - SYM (_fpCCR)
298 TRAPE = __trap_enable_bits - SYM (_fpCCR)
299 STICK = __sticky_bits - SYM (_fpCCR)
300 ROUND = __rounding_mode - SYM (_fpCCR)
301 FORMT = __format - SYM (_fpCCR)
302 LASTO = __last_operation - SYM (_fpCCR)
303 OPER1 = __operand1 - SYM (_fpCCR)
304 OPER2 = __operand2 - SYM (_fpCCR)
305
306 | The following exception types are supported:
307 INEXACT_RESULT = 0x0001
308 UNDERFLOW = 0x0002
309 OVERFLOW = 0x0004
310 DIVIDE_BY_ZERO = 0x0008
311 INVALID_OPERATION = 0x0010
312
313 | The allowed rounding modes are:
314 UNKNOWN = -1
315 ROUND_TO_NEAREST = 0 | round result to nearest representable value
316 ROUND_TO_ZERO = 1 | round result towards zero
317 ROUND_TO_PLUS = 2 | round result towards plus infinity
318 ROUND_TO_MINUS = 3 | round result towards minus infinity
319
320 | The allowed values of format are:
321 NIL = 0
322 SINGLE_FLOAT = 1
323 DOUBLE_FLOAT = 2
324 LONG_FLOAT = 3
325
326 | The allowed values for the last operation are:
327 NOOP = 0
328 ADD = 1
329 MULTIPLY = 2
330 DIVIDE = 3
331 NEGATE = 4
332 COMPARE = 5
333 EXTENDSFDF = 6
334 TRUNCDFSF = 7
335
336 |=============================================================================
337 | __clear_sticky_bits
338 |=============================================================================
339
340 | The sticky bits are normally not cleared (thus the name), whereas the
341 | exception type and exception value reflect the last computation.
342 | This routine is provided to clear them (you can also write to _fpCCR,
343 | since it is globally visible).
344
345 .globl SYM (__clear_sticky_bit)
346
347 .text
348 .even
349
350 | void __clear_sticky_bits(void);
351 SYM (__clear_sticky_bit):
352 PICLEA SYM (_fpCCR),a0
353 #ifndef __mcoldfire__
354 movew IMM (0),a0@(STICK)
355 #else
356 clr.w a0@(STICK)
357 #endif
358 rts
359
360 |=============================================================================
361 | $_exception_handler
362 |=============================================================================
363
364 .globl $_exception_handler
365
366 .text
367 .even
368
369 | This is the common exit point if an exception occurs.
370 | NOTE: it is NOT callable from C!
371 | It expects the exception type in d7, the format (SINGLE_FLOAT,
372 | DOUBLE_FLOAT or LONG_FLOAT) in d6, and the last operation code in d5.
373 | It sets the corresponding exception and sticky bits, and the format.
374 | Depending on the format if fills the corresponding slots for the
375 | operands which produced the exception (all this information is provided
376 | so if you write your own exception handlers you have enough information
377 | to deal with the problem).
378 | Then checks to see if the corresponding exception is trap-enabled,
379 | in which case it pushes the address of _fpCCR and traps through
380 | trap FPTRAP (15 for the moment).
381
382 FPTRAP = 15
383
384 $_exception_handler:
385 PICLEA SYM (_fpCCR),a0
386 movew d7,a0@(EBITS) | set __exception_bits
387 #ifndef __mcoldfire__
388 orw d7,a0@(STICK) | and __sticky_bits
389 #else
390 movew a0@(STICK),d4
391 orl d7,d4
392 movew d4,a0@(STICK)
393 #endif
394 movew d6,a0@(FORMT) | and __format
395 movew d5,a0@(LASTO) | and __last_operation
396
397 | Now put the operands in place:
398 #ifndef __mcoldfire__
399 cmpw IMM (SINGLE_FLOAT),d6
400 #else
401 cmpl IMM (SINGLE_FLOAT),d6
402 #endif
403 beq 1f
404 movel a6@(8),a0@(OPER1)
405 movel a6@(12),a0@(OPER1+4)
406 movel a6@(16),a0@(OPER2)
407 movel a6@(20),a0@(OPER2+4)
408 bra 2f
409 1: movel a6@(8),a0@(OPER1)
410 movel a6@(12),a0@(OPER2)
411 2:
412 | And check whether the exception is trap-enabled:
413 #ifndef __mcoldfire__
414 andw a0@(TRAPE),d7 | is exception trap-enabled?
415 #else
416 clrl d6
417 movew a0@(TRAPE),d6
418 andl d6,d7
419 #endif
420 beq 1f | no, exit
421 PICPEA SYM (_fpCCR),a1 | yes, push address of _fpCCR
422 trap IMM (FPTRAP) | and trap
423 #ifndef __mcoldfire__
424 1: moveml sp@+,d2-d7 | restore data registers
425 #else
426 1: moveml sp@,d2-d7
427 | XXX if frame pointer is ever removed, stack pointer must
428 | be adjusted here.
429 #endif
430 unlk a6 | and return
431 rts
432 #endif /* L_floatex */
433
434 #ifdef L_mulsi3
435 .text
436 FUNC(__mulsi3)
437 .globl SYM (__mulsi3)
438 .globl SYM (__mulsi3_internal)
439 .hidden SYM (__mulsi3_internal)
440 SYM (__mulsi3):
441 SYM (__mulsi3_internal):
442 movew sp@(4), d0 /* x0 -> d0 */
443 muluw sp@(10), d0 /* x0*y1 */
444 movew sp@(6), d1 /* x1 -> d1 */
445 muluw sp@(8), d1 /* x1*y0 */
446 #ifndef __mcoldfire__
447 addw d1, d0
448 #else
449 addl d1, d0
450 #endif
451 swap d0
452 clrw d0
453 movew sp@(6), d1 /* x1 -> d1 */
454 muluw sp@(10), d1 /* x1*y1 */
455 addl d1, d0
456
457 rts
458 #endif /* L_mulsi3 */
459
460 #ifdef L_udivsi3
461 .text
462 FUNC(__udivsi3)
463 .globl SYM (__udivsi3)
464 .globl SYM (__udivsi3_internal)
465 .hidden SYM (__udivsi3_internal)
466 SYM (__udivsi3):
467 SYM (__udivsi3_internal):
468 #ifndef __mcoldfire__
469 movel d2, sp@-
470 movel sp@(12), d1 /* d1 = divisor */
471 movel sp@(8), d0 /* d0 = dividend */
472
473 cmpl IMM (0x10000), d1 /* divisor >= 2 ^ 16 ? */
474 jcc L3 /* then try next algorithm */
475 movel d0, d2
476 clrw d2
477 swap d2
478 divu d1, d2 /* high quotient in lower word */
479 movew d2, d0 /* save high quotient */
480 swap d0
481 movew sp@(10), d2 /* get low dividend + high rest */
482 divu d1, d2 /* low quotient */
483 movew d2, d0
484 jra L6
485
486 L3: movel d1, d2 /* use d2 as divisor backup */
487 L4: lsrl IMM (1), d1 /* shift divisor */
488 lsrl IMM (1), d0 /* shift dividend */
489 cmpl IMM (0x10000), d1 /* still divisor >= 2 ^ 16 ? */
490 jcc L4
491 divu d1, d0 /* now we have 16-bit divisor */
492 andl IMM (0xffff), d0 /* mask out divisor, ignore remainder */
493
494 /* Multiply the 16-bit tentative quotient with the 32-bit divisor. Because of
495 the operand ranges, this might give a 33-bit product. If this product is
496 greater than the dividend, the tentative quotient was too large. */
497 movel d2, d1
498 mulu d0, d1 /* low part, 32 bits */
499 swap d2
500 mulu d0, d2 /* high part, at most 17 bits */
501 swap d2 /* align high part with low part */
502 tstw d2 /* high part 17 bits? */
503 jne L5 /* if 17 bits, quotient was too large */
504 addl d2, d1 /* add parts */
505 jcs L5 /* if sum is 33 bits, quotient was too large */
506 cmpl sp@(8), d1 /* compare the sum with the dividend */
507 jls L6 /* if sum > dividend, quotient was too large */
508 L5: subql IMM (1), d0 /* adjust quotient */
509
510 L6: movel sp@+, d2
511 rts
512
513 #else /* __mcoldfire__ */
514
515 /* ColdFire implementation of non-restoring division algorithm from
516 Hennessy & Patterson, Appendix A. */
517 link a6,IMM (-12)
518 moveml d2-d4,sp@
519 movel a6@(8),d0
520 movel a6@(12),d1
521 clrl d2 | clear p
522 moveq IMM (31),d4
523 L1: addl d0,d0 | shift reg pair (p,a) one bit left
524 addxl d2,d2
525 movl d2,d3 | subtract b from p, store in tmp.
526 subl d1,d3
527 jcs L2 | if no carry,
528 bset IMM (0),d0 | set the low order bit of a to 1,
529 movl d3,d2 | and store tmp in p.
530 L2: subql IMM (1),d4
531 jcc L1
532 moveml sp@,d2-d4 | restore data registers
533 unlk a6 | and return
534 rts
535 #endif /* __mcoldfire__ */
536
537 #endif /* L_udivsi3 */
538
539 #ifdef L_divsi3
540 .text
541 FUNC(__divsi3)
542 .globl SYM (__divsi3)
543 .globl SYM (__divsi3_internal)
544 .hidden SYM (__divsi3_internal)
545 SYM (__divsi3):
546 SYM (__divsi3_internal):
547 movel d2, sp@-
548
549 moveq IMM (1), d2 /* sign of result stored in d2 (=1 or =-1) */
550 movel sp@(12), d1 /* d1 = divisor */
551 jpl L1
552 negl d1
553 #ifndef __mcoldfire__
554 negb d2 /* change sign because divisor <0 */
555 #else
556 negl d2 /* change sign because divisor <0 */
557 #endif
558 L1: movel sp@(8), d0 /* d0 = dividend */
559 jpl L2
560 negl d0
561 #ifndef __mcoldfire__
562 negb d2
563 #else
564 negl d2
565 #endif
566
567 L2: movel d1, sp@-
568 movel d0, sp@-
569 PICCALL SYM (__udivsi3_internal) /* divide abs(dividend) by abs(divisor) */
570 addql IMM (8), sp
571
572 tstb d2
573 jpl L3
574 negl d0
575
576 L3: movel sp@+, d2
577 rts
578 #endif /* L_divsi3 */
579
580 #ifdef L_umodsi3
581 .text
582 FUNC(__umodsi3)
583 .globl SYM (__umodsi3)
584 SYM (__umodsi3):
585 movel sp@(8), d1 /* d1 = divisor */
586 movel sp@(4), d0 /* d0 = dividend */
587 movel d1, sp@-
588 movel d0, sp@-
589 PICCALL SYM (__udivsi3_internal)
590 addql IMM (8), sp
591 movel sp@(8), d1 /* d1 = divisor */
592 #ifndef __mcoldfire__
593 movel d1, sp@-
594 movel d0, sp@-
595 PICCALL SYM (__mulsi3_internal) /* d0 = (a/b)*b */
596 addql IMM (8), sp
597 #else
598 mulsl d1,d0
599 #endif
600 movel sp@(4), d1 /* d1 = dividend */
601 subl d0, d1 /* d1 = a - (a/b)*b */
602 movel d1, d0
603 rts
604 #endif /* L_umodsi3 */
605
606 #ifdef L_modsi3
607 .text
608 FUNC(__modsi3)
609 .globl SYM (__modsi3)
610 SYM (__modsi3):
611 movel sp@(8), d1 /* d1 = divisor */
612 movel sp@(4), d0 /* d0 = dividend */
613 movel d1, sp@-
614 movel d0, sp@-
615 PICCALL SYM (__divsi3_internal)
616 addql IMM (8), sp
617 movel sp@(8), d1 /* d1 = divisor */
618 #ifndef __mcoldfire__
619 movel d1, sp@-
620 movel d0, sp@-
621 PICCALL SYM (__mulsi3_internal) /* d0 = (a/b)*b */
622 addql IMM (8), sp
623 #else
624 mulsl d1,d0
625 #endif
626 movel sp@(4), d1 /* d1 = dividend */
627 subl d0, d1 /* d1 = a - (a/b)*b */
628 movel d1, d0
629 rts
630 #endif /* L_modsi3 */
631
632
633 #ifdef L_double
634
635 .globl SYM (_fpCCR)
636 .globl $_exception_handler
637
638 QUIET_NaN = 0x7fffffff
639
640 D_MAX_EXP = 0x07ff
641 D_BIAS = 1022
642 DBL_MAX_EXP = D_MAX_EXP - D_BIAS
643 DBL_MIN_EXP = 1 - D_BIAS
644 DBL_MANT_DIG = 53
645
646 INEXACT_RESULT = 0x0001
647 UNDERFLOW = 0x0002
648 OVERFLOW = 0x0004
649 DIVIDE_BY_ZERO = 0x0008
650 INVALID_OPERATION = 0x0010
651
652 DOUBLE_FLOAT = 2
653
654 NOOP = 0
655 ADD = 1
656 MULTIPLY = 2
657 DIVIDE = 3
658 NEGATE = 4
659 COMPARE = 5
660 EXTENDSFDF = 6
661 TRUNCDFSF = 7
662
663 UNKNOWN = -1
664 ROUND_TO_NEAREST = 0 | round result to nearest representable value
665 ROUND_TO_ZERO = 1 | round result towards zero
666 ROUND_TO_PLUS = 2 | round result towards plus infinity
667 ROUND_TO_MINUS = 3 | round result towards minus infinity
668
669 | Entry points:
670
671 .globl SYM (__adddf3)
672 .globl SYM (__subdf3)
673 .globl SYM (__muldf3)
674 .globl SYM (__divdf3)
675 .globl SYM (__negdf2)
676 .globl SYM (__cmpdf2)
677 .globl SYM (__cmpdf2_internal)
678 .hidden SYM (__cmpdf2_internal)
679
680 .text
681 .even
682
683 | These are common routines to return and signal exceptions.
684
685 Ld$den:
686 | Return and signal a denormalized number
687 orl d7,d0
688 movew IMM (INEXACT_RESULT+UNDERFLOW),d7
689 moveq IMM (DOUBLE_FLOAT),d6
690 PICJUMP $_exception_handler
691
692 Ld$infty:
693 Ld$overflow:
694 | Return a properly signed INFINITY and set the exception flags
695 movel IMM (0x7ff00000),d0
696 movel IMM (0),d1
697 orl d7,d0
698 movew IMM (INEXACT_RESULT+OVERFLOW),d7
699 moveq IMM (DOUBLE_FLOAT),d6
700 PICJUMP $_exception_handler
701
702 Ld$underflow:
703 | Return a properly signed 0 and set the exception flags
704 movel IMM (0),d0
705 movel d0,d1
706 orl d7,d0
707 movew IMM (INEXACT_RESULT+UNDERFLOW),d7
708 moveq IMM (DOUBLE_FLOAT),d6
709 PICJUMP $_exception_handler
710
711 Ld$inop:
712 | Return a quiet NaN and set the exception flags
713 movel IMM (QUIET_NaN),d0
714 movel d0,d1
715 bset IMM (31),d1
716 movew IMM (INEXACT_RESULT+INVALID_OPERATION),d7
717 moveq IMM (DOUBLE_FLOAT),d6
718 PICJUMP $_exception_handler
719
720 Ld$div$0:
721 | Return a properly signed INFINITY and set the exception flags
722 movel IMM (0x7ff00000),d0
723 movel IMM (0),d1
724 orl d7,d0
725 movew IMM (INEXACT_RESULT+DIVIDE_BY_ZERO),d7
726 moveq IMM (DOUBLE_FLOAT),d6
727 PICJUMP $_exception_handler
728
729 |=============================================================================
730 |=============================================================================
731 | double precision routines
732 |=============================================================================
733 |=============================================================================
734
735 | A double precision floating point number (double) has the format:
736 |
737 | struct _double {
738 | unsigned int sign : 1; /* sign bit */
739 | unsigned int exponent : 11; /* exponent, shifted by 126 */
740 | unsigned int fraction : 52; /* fraction */
741 | } double;
742 |
743 | Thus sizeof(double) = 8 (64 bits).
744 |
745 | All the routines are callable from C programs, and return the result
746 | in the register pair d0-d1. They also preserve all registers except
747 | d0-d1 and a0-a1.
748
749 |=============================================================================
750 | __subdf3
751 |=============================================================================
752
753 | double __subdf3(double, double);
754 FUNC(__subdf3)
755 SYM (__subdf3):
756 bchg IMM (31),sp@(12) | change sign of second operand
757 | and fall through, so we always add
758 |=============================================================================
759 | __adddf3
760 |=============================================================================
761
762 | double __adddf3(double, double);
763 FUNC(__adddf3)
764 SYM (__adddf3):
765 #ifndef __mcoldfire__
766 link a6,IMM (0) | everything will be done in registers
767 moveml d2-d7,sp@- | save all data registers and a2 (but d0-d1)
768 #else
769 link a6,IMM (-24)
770 moveml d2-d7,sp@
771 #endif
772 movel a6@(8),d0 | get first operand
773 movel a6@(12),d1 |
774 movel a6@(16),d2 | get second operand
775 movel a6@(20),d3 |
776
777 movel d0,d7 | get d0's sign bit in d7 '
778 addl d1,d1 | check and clear sign bit of a, and gain one
779 addxl d0,d0 | bit of extra precision
780 beq Ladddf$b | if zero return second operand
781
782 movel d2,d6 | save sign in d6
783 addl d3,d3 | get rid of sign bit and gain one bit of
784 addxl d2,d2 | extra precision
785 beq Ladddf$a | if zero return first operand
786
787 andl IMM (0x80000000),d7 | isolate a's sign bit '
788 swap d6 | and also b's sign bit '
789 #ifndef __mcoldfire__
790 andw IMM (0x8000),d6 |
791 orw d6,d7 | and combine them into d7, so that a's sign '
792 | bit is in the high word and b's is in the '
793 | low word, so d6 is free to be used
794 #else
795 andl IMM (0x8000),d6
796 orl d6,d7
797 #endif
798 movel d7,a0 | now save d7 into a0, so d7 is free to
799 | be used also
800
801 | Get the exponents and check for denormalized and/or infinity.
802
803 movel IMM (0x001fffff),d6 | mask for the fraction
804 movel IMM (0x00200000),d7 | mask to put hidden bit back
805
806 movel d0,d4 |
807 andl d6,d0 | get fraction in d0
808 notl d6 | make d6 into mask for the exponent
809 andl d6,d4 | get exponent in d4
810 beq Ladddf$a$den | branch if a is denormalized
811 cmpl d6,d4 | check for INFINITY or NaN
812 beq Ladddf$nf |
813 orl d7,d0 | and put hidden bit back
814 Ladddf$1:
815 swap d4 | shift right exponent so that it starts
816 #ifndef __mcoldfire__
817 lsrw IMM (5),d4 | in bit 0 and not bit 20
818 #else
819 lsrl IMM (5),d4 | in bit 0 and not bit 20
820 #endif
821 | Now we have a's exponent in d4 and fraction in d0-d1 '
822 movel d2,d5 | save b to get exponent
823 andl d6,d5 | get exponent in d5
824 beq Ladddf$b$den | branch if b is denormalized
825 cmpl d6,d5 | check for INFINITY or NaN
826 beq Ladddf$nf
827 notl d6 | make d6 into mask for the fraction again
828 andl d6,d2 | and get fraction in d2
829 orl d7,d2 | and put hidden bit back
830 Ladddf$2:
831 swap d5 | shift right exponent so that it starts
832 #ifndef __mcoldfire__
833 lsrw IMM (5),d5 | in bit 0 and not bit 20
834 #else
835 lsrl IMM (5),d5 | in bit 0 and not bit 20
836 #endif
837
838 | Now we have b's exponent in d5 and fraction in d2-d3. '
839
840 | The situation now is as follows: the signs are combined in a0, the
841 | numbers are in d0-d1 (a) and d2-d3 (b), and the exponents in d4 (a)
842 | and d5 (b). To do the rounding correctly we need to keep all the
843 | bits until the end, so we need to use d0-d1-d2-d3 for the first number
844 | and d4-d5-d6-d7 for the second. To do this we store (temporarily) the
845 | exponents in a2-a3.
846
847 #ifndef __mcoldfire__
848 moveml a2-a3,sp@- | save the address registers
849 #else
850 movel a2,sp@-
851 movel a3,sp@-
852 movel a4,sp@-
853 #endif
854
855 movel d4,a2 | save the exponents
856 movel d5,a3 |
857
858 movel IMM (0),d7 | and move the numbers around
859 movel d7,d6 |
860 movel d3,d5 |
861 movel d2,d4 |
862 movel d7,d3 |
863 movel d7,d2 |
864
865 | Here we shift the numbers until the exponents are the same, and put
866 | the largest exponent in a2.
867 #ifndef __mcoldfire__
868 exg d4,a2 | get exponents back
869 exg d5,a3 |
870 cmpw d4,d5 | compare the exponents
871 #else
872 movel d4,a4 | get exponents back
873 movel a2,d4
874 movel a4,a2
875 movel d5,a4
876 movel a3,d5
877 movel a4,a3
878 cmpl d4,d5 | compare the exponents
879 #endif
880 beq Ladddf$3 | if equal don't shift '
881 bhi 9f | branch if second exponent is higher
882
883 | Here we have a's exponent larger than b's, so we have to shift b. We do
884 | this by using as counter d2:
885 1: movew d4,d2 | move largest exponent to d2
886 #ifndef __mcoldfire__
887 subw d5,d2 | and subtract second exponent
888 exg d4,a2 | get back the longs we saved
889 exg d5,a3 |
890 #else
891 subl d5,d2 | and subtract second exponent
892 movel d4,a4 | get back the longs we saved
893 movel a2,d4
894 movel a4,a2
895 movel d5,a4
896 movel a3,d5
897 movel a4,a3
898 #endif
899 | if difference is too large we don't shift (actually, we can just exit) '
900 #ifndef __mcoldfire__
901 cmpw IMM (DBL_MANT_DIG+2),d2
902 #else
903 cmpl IMM (DBL_MANT_DIG+2),d2
904 #endif
905 bge Ladddf$b$small
906 #ifndef __mcoldfire__
907 cmpw IMM (32),d2 | if difference >= 32, shift by longs
908 #else
909 cmpl IMM (32),d2 | if difference >= 32, shift by longs
910 #endif
911 bge 5f
912 2:
913 #ifndef __mcoldfire__
914 cmpw IMM (16),d2 | if difference >= 16, shift by words
915 #else
916 cmpl IMM (16),d2 | if difference >= 16, shift by words
917 #endif
918 bge 6f
919 bra 3f | enter dbra loop
920
921 4:
922 #ifndef __mcoldfire__
923 lsrl IMM (1),d4
924 roxrl IMM (1),d5
925 roxrl IMM (1),d6
926 roxrl IMM (1),d7
927 #else
928 lsrl IMM (1),d7
929 btst IMM (0),d6
930 beq 10f
931 bset IMM (31),d7
932 10: lsrl IMM (1),d6
933 btst IMM (0),d5
934 beq 11f
935 bset IMM (31),d6
936 11: lsrl IMM (1),d5
937 btst IMM (0),d4
938 beq 12f
939 bset IMM (31),d5
940 12: lsrl IMM (1),d4
941 #endif
942 3:
943 #ifndef __mcoldfire__
944 dbra d2,4b
945 #else
946 subql IMM (1),d2
947 bpl 4b
948 #endif
949 movel IMM (0),d2
950 movel d2,d3
951 bra Ladddf$4
952 5:
953 movel d6,d7
954 movel d5,d6
955 movel d4,d5
956 movel IMM (0),d4
957 #ifndef __mcoldfire__
958 subw IMM (32),d2
959 #else
960 subl IMM (32),d2
961 #endif
962 bra 2b
963 6:
964 movew d6,d7
965 swap d7
966 movew d5,d6
967 swap d6
968 movew d4,d5
969 swap d5
970 movew IMM (0),d4
971 swap d4
972 #ifndef __mcoldfire__
973 subw IMM (16),d2
974 #else
975 subl IMM (16),d2
976 #endif
977 bra 3b
978
979 9:
980 #ifndef __mcoldfire__
981 exg d4,d5
982 movew d4,d6
983 subw d5,d6 | keep d5 (largest exponent) in d4
984 exg d4,a2
985 exg d5,a3
986 #else
987 movel d5,d6
988 movel d4,d5
989 movel d6,d4
990 subl d5,d6
991 movel d4,a4
992 movel a2,d4
993 movel a4,a2
994 movel d5,a4
995 movel a3,d5
996 movel a4,a3
997 #endif
998 | if difference is too large we don't shift (actually, we can just exit) '
999 #ifndef __mcoldfire__
1000 cmpw IMM (DBL_MANT_DIG+2),d6
1001 #else
1002 cmpl IMM (DBL_MANT_DIG+2),d6
1003 #endif
1004 bge Ladddf$a$small
1005 #ifndef __mcoldfire__
1006 cmpw IMM (32),d6 | if difference >= 32, shift by longs
1007 #else
1008 cmpl IMM (32),d6 | if difference >= 32, shift by longs
1009 #endif
1010 bge 5f
1011 2:
1012 #ifndef __mcoldfire__
1013 cmpw IMM (16),d6 | if difference >= 16, shift by words
1014 #else
1015 cmpl IMM (16),d6 | if difference >= 16, shift by words
1016 #endif
1017 bge 6f
1018 bra 3f | enter dbra loop
1019
1020 4:
1021 #ifndef __mcoldfire__
1022 lsrl IMM (1),d0
1023 roxrl IMM (1),d1
1024 roxrl IMM (1),d2
1025 roxrl IMM (1),d3
1026 #else
1027 lsrl IMM (1),d3
1028 btst IMM (0),d2
1029 beq 10f
1030 bset IMM (31),d3
1031 10: lsrl IMM (1),d2
1032 btst IMM (0),d1
1033 beq 11f
1034 bset IMM (31),d2
1035 11: lsrl IMM (1),d1
1036 btst IMM (0),d0
1037 beq 12f
1038 bset IMM (31),d1
1039 12: lsrl IMM (1),d0
1040 #endif
1041 3:
1042 #ifndef __mcoldfire__
1043 dbra d6,4b
1044 #else
1045 subql IMM (1),d6
1046 bpl 4b
1047 #endif
1048 movel IMM (0),d7
1049 movel d7,d6
1050 bra Ladddf$4
1051 5:
1052 movel d2,d3
1053 movel d1,d2
1054 movel d0,d1
1055 movel IMM (0),d0
1056 #ifndef __mcoldfire__
1057 subw IMM (32),d6
1058 #else
1059 subl IMM (32),d6
1060 #endif
1061 bra 2b
1062 6:
1063 movew d2,d3
1064 swap d3
1065 movew d1,d2
1066 swap d2
1067 movew d0,d1
1068 swap d1
1069 movew IMM (0),d0
1070 swap d0
1071 #ifndef __mcoldfire__
1072 subw IMM (16),d6
1073 #else
1074 subl IMM (16),d6
1075 #endif
1076 bra 3b
1077 Ladddf$3:
1078 #ifndef __mcoldfire__
1079 exg d4,a2
1080 exg d5,a3
1081 #else
1082 movel d4,a4
1083 movel a2,d4
1084 movel a4,a2
1085 movel d5,a4
1086 movel a3,d5
1087 movel a4,a3
1088 #endif
1089 Ladddf$4:
1090 | Now we have the numbers in d0--d3 and d4--d7, the exponent in a2, and
1091 | the signs in a4.
1092
1093 | Here we have to decide whether to add or subtract the numbers:
1094 #ifndef __mcoldfire__
1095 exg d7,a0 | get the signs
1096 exg d6,a3 | a3 is free to be used
1097 #else
1098 movel d7,a4
1099 movel a0,d7
1100 movel a4,a0
1101 movel d6,a4
1102 movel a3,d6
1103 movel a4,a3
1104 #endif
1105 movel d7,d6 |
1106 movew IMM (0),d7 | get a's sign in d7 '
1107 swap d6 |
1108 movew IMM (0),d6 | and b's sign in d6 '
1109 eorl d7,d6 | compare the signs
1110 bmi Lsubdf$0 | if the signs are different we have
1111 | to subtract
1112 #ifndef __mcoldfire__
1113 exg d7,a0 | else we add the numbers
1114 exg d6,a3 |
1115 #else
1116 movel d7,a4
1117 movel a0,d7
1118 movel a4,a0
1119 movel d6,a4
1120 movel a3,d6
1121 movel a4,a3
1122 #endif
1123 addl d7,d3 |
1124 addxl d6,d2 |
1125 addxl d5,d1 |
1126 addxl d4,d0 |
1127
1128 movel a2,d4 | return exponent to d4
1129 movel a0,d7 |
1130 andl IMM (0x80000000),d7 | d7 now has the sign
1131
1132 #ifndef __mcoldfire__
1133 moveml sp@+,a2-a3
1134 #else
1135 movel sp@+,a4
1136 movel sp@+,a3
1137 movel sp@+,a2
1138 #endif
1139
1140 | Before rounding normalize so bit #DBL_MANT_DIG is set (we will consider
1141 | the case of denormalized numbers in the rounding routine itself).
1142 | As in the addition (not in the subtraction!) we could have set
1143 | one more bit we check this:
1144 btst IMM (DBL_MANT_DIG+1),d0
1145 beq 1f
1146 #ifndef __mcoldfire__
1147 lsrl IMM (1),d0
1148 roxrl IMM (1),d1
1149 roxrl IMM (1),d2
1150 roxrl IMM (1),d3
1151 addw IMM (1),d4
1152 #else
1153 lsrl IMM (1),d3
1154 btst IMM (0),d2
1155 beq 10f
1156 bset IMM (31),d3
1157 10: lsrl IMM (1),d2
1158 btst IMM (0),d1
1159 beq 11f
1160 bset IMM (31),d2
1161 11: lsrl IMM (1),d1
1162 btst IMM (0),d0
1163 beq 12f
1164 bset IMM (31),d1
1165 12: lsrl IMM (1),d0
1166 addl IMM (1),d4
1167 #endif
1168 1:
1169 lea pc@(Ladddf$5),a0 | to return from rounding routine
1170 PICLEA SYM (_fpCCR),a1 | check the rounding mode
1171 #ifdef __mcoldfire__
1172 clrl d6
1173 #endif
1174 movew a1@(6),d6 | rounding mode in d6
1175 beq Lround$to$nearest
1176 #ifndef __mcoldfire__
1177 cmpw IMM (ROUND_TO_PLUS),d6
1178 #else
1179 cmpl IMM (ROUND_TO_PLUS),d6
1180 #endif
1181 bhi Lround$to$minus
1182 blt Lround$to$zero
1183 bra Lround$to$plus
1184 Ladddf$5:
1185 | Put back the exponent and check for overflow
1186 #ifndef __mcoldfire__
1187 cmpw IMM (0x7ff),d4 | is the exponent big?
1188 #else
1189 cmpl IMM (0x7ff),d4 | is the exponent big?
1190 #endif
1191 bge 1f
1192 bclr IMM (DBL_MANT_DIG-1),d0
1193 #ifndef __mcoldfire__
1194 lslw IMM (4),d4 | put exponent back into position
1195 #else
1196 lsll IMM (4),d4 | put exponent back into position
1197 #endif
1198 swap d0 |
1199 #ifndef __mcoldfire__
1200 orw d4,d0 |
1201 #else
1202 orl d4,d0 |
1203 #endif
1204 swap d0 |
1205 bra Ladddf$ret
1206 1:
1207 moveq IMM (ADD),d5
1208 bra Ld$overflow
1209
1210 Lsubdf$0:
1211 | Here we do the subtraction.
1212 #ifndef __mcoldfire__
1213 exg d7,a0 | put sign back in a0
1214 exg d6,a3 |
1215 #else
1216 movel d7,a4
1217 movel a0,d7
1218 movel a4,a0
1219 movel d6,a4
1220 movel a3,d6
1221 movel a4,a3
1222 #endif
1223 subl d7,d3 |
1224 subxl d6,d2 |
1225 subxl d5,d1 |
1226 subxl d4,d0 |
1227 beq Ladddf$ret$1 | if zero just exit
1228 bpl 1f | if positive skip the following
1229 movel a0,d7 |
1230 bchg IMM (31),d7 | change sign bit in d7
1231 movel d7,a0 |
1232 negl d3 |
1233 negxl d2 |
1234 negxl d1 | and negate result
1235 negxl d0 |
1236 1:
1237 movel a2,d4 | return exponent to d4
1238 movel a0,d7
1239 andl IMM (0x80000000),d7 | isolate sign bit
1240 #ifndef __mcoldfire__
1241 moveml sp@+,a2-a3 |
1242 #else
1243 movel sp@+,a4
1244 movel sp@+,a3
1245 movel sp@+,a2
1246 #endif
1247
1248 | Before rounding normalize so bit #DBL_MANT_DIG is set (we will consider
1249 | the case of denormalized numbers in the rounding routine itself).
1250 | As in the addition (not in the subtraction!) we could have set
1251 | one more bit we check this:
1252 btst IMM (DBL_MANT_DIG+1),d0
1253 beq 1f
1254 #ifndef __mcoldfire__
1255 lsrl IMM (1),d0
1256 roxrl IMM (1),d1
1257 roxrl IMM (1),d2
1258 roxrl IMM (1),d3
1259 addw IMM (1),d4
1260 #else
1261 lsrl IMM (1),d3
1262 btst IMM (0),d2
1263 beq 10f
1264 bset IMM (31),d3
1265 10: lsrl IMM (1),d2
1266 btst IMM (0),d1
1267 beq 11f
1268 bset IMM (31),d2
1269 11: lsrl IMM (1),d1
1270 btst IMM (0),d0
1271 beq 12f
1272 bset IMM (31),d1
1273 12: lsrl IMM (1),d0
1274 addl IMM (1),d4
1275 #endif
1276 1:
1277 lea pc@(Lsubdf$1),a0 | to return from rounding routine
1278 PICLEA SYM (_fpCCR),a1 | check the rounding mode
1279 #ifdef __mcoldfire__
1280 clrl d6
1281 #endif
1282 movew a1@(6),d6 | rounding mode in d6
1283 beq Lround$to$nearest
1284 #ifndef __mcoldfire__
1285 cmpw IMM (ROUND_TO_PLUS),d6
1286 #else
1287 cmpl IMM (ROUND_TO_PLUS),d6
1288 #endif
1289 bhi Lround$to$minus
1290 blt Lround$to$zero
1291 bra Lround$to$plus
1292 Lsubdf$1:
1293 | Put back the exponent and sign (we don't have overflow). '
1294 bclr IMM (DBL_MANT_DIG-1),d0
1295 #ifndef __mcoldfire__
1296 lslw IMM (4),d4 | put exponent back into position
1297 #else
1298 lsll IMM (4),d4 | put exponent back into position
1299 #endif
1300 swap d0 |
1301 #ifndef __mcoldfire__
1302 orw d4,d0 |
1303 #else
1304 orl d4,d0 |
1305 #endif
1306 swap d0 |
1307 bra Ladddf$ret
1308
1309 | If one of the numbers was too small (difference of exponents >=
1310 | DBL_MANT_DIG+1) we return the other (and now we don't have to '
1311 | check for finiteness or zero).
1312 Ladddf$a$small:
1313 #ifndef __mcoldfire__
1314 moveml sp@+,a2-a3
1315 #else
1316 movel sp@+,a4
1317 movel sp@+,a3
1318 movel sp@+,a2
1319 #endif
1320 movel a6@(16),d0
1321 movel a6@(20),d1
1322 PICLEA SYM (_fpCCR),a0
1323 movew IMM (0),a0@
1324 #ifndef __mcoldfire__
1325 moveml sp@+,d2-d7 | restore data registers
1326 #else
1327 moveml sp@,d2-d7
1328 | XXX if frame pointer is ever removed, stack pointer must
1329 | be adjusted here.
1330 #endif
1331 unlk a6 | and return
1332 rts
1333
1334 Ladddf$b$small:
1335 #ifndef __mcoldfire__
1336 moveml sp@+,a2-a3
1337 #else
1338 movel sp@+,a4
1339 movel sp@+,a3
1340 movel sp@+,a2
1341 #endif
1342 movel a6@(8),d0
1343 movel a6@(12),d1
1344 PICLEA SYM (_fpCCR),a0
1345 movew IMM (0),a0@
1346 #ifndef __mcoldfire__
1347 moveml sp@+,d2-d7 | restore data registers
1348 #else
1349 moveml sp@,d2-d7
1350 | XXX if frame pointer is ever removed, stack pointer must
1351 | be adjusted here.
1352 #endif
1353 unlk a6 | and return
1354 rts
1355
1356 Ladddf$a$den:
1357 movel d7,d4 | d7 contains 0x00200000
1358 bra Ladddf$1
1359
1360 Ladddf$b$den:
1361 movel d7,d5 | d7 contains 0x00200000
1362 notl d6
1363 bra Ladddf$2
1364
1365 Ladddf$b:
1366 | Return b (if a is zero)
1367 movel d2,d0
1368 movel d3,d1
1369 bne 1f | Check if b is -0
1370 cmpl IMM (0x80000000),d0
1371 bne 1f
1372 andl IMM (0x80000000),d7 | Use the sign of a
1373 clrl d0
1374 bra Ladddf$ret
1375 Ladddf$a:
1376 movel a6@(8),d0
1377 movel a6@(12),d1
1378 1:
1379 moveq IMM (ADD),d5
1380 | Check for NaN and +/-INFINITY.
1381 movel d0,d7 |
1382 andl IMM (0x80000000),d7 |
1383 bclr IMM (31),d0 |
1384 cmpl IMM (0x7ff00000),d0 |
1385 bge 2f |
1386 movel d0,d0 | check for zero, since we don't '
1387 bne Ladddf$ret | want to return -0 by mistake
1388 movel d1,d1 |
1389 bne Ladddf$ret |
1390 bclr IMM (31),d7 |
1391 bra Ladddf$ret |
1392 2:
1393 andl IMM (0x000fffff),d0 | check for NaN (nonzero fraction)
1394 orl d1,d0 |
1395 bne Ld$inop |
1396 bra Ld$infty |
1397
1398 Ladddf$ret$1:
1399 #ifndef __mcoldfire__
1400 moveml sp@+,a2-a3 | restore regs and exit
1401 #else
1402 movel sp@+,a4
1403 movel sp@+,a3
1404 movel sp@+,a2
1405 #endif
1406
1407 Ladddf$ret:
1408 | Normal exit.
1409 PICLEA SYM (_fpCCR),a0
1410 movew IMM (0),a0@
1411 orl d7,d0 | put sign bit back
1412 #ifndef __mcoldfire__
1413 moveml sp@+,d2-d7
1414 #else
1415 moveml sp@,d2-d7
1416 | XXX if frame pointer is ever removed, stack pointer must
1417 | be adjusted here.
1418 #endif
1419 unlk a6
1420 rts
1421
1422 Ladddf$ret$den:
1423 | Return a denormalized number.
1424 #ifndef __mcoldfire__
1425 lsrl IMM (1),d0 | shift right once more
1426 roxrl IMM (1),d1 |
1427 #else
1428 lsrl IMM (1),d1
1429 btst IMM (0),d0
1430 beq 10f
1431 bset IMM (31),d1
1432 10: lsrl IMM (1),d0
1433 #endif
1434 bra Ladddf$ret
1435
1436 Ladddf$nf:
1437 moveq IMM (ADD),d5
1438 | This could be faster but it is not worth the effort, since it is not
1439 | executed very often. We sacrifice speed for clarity here.
1440 movel a6@(8),d0 | get the numbers back (remember that we
1441 movel a6@(12),d1 | did some processing already)
1442 movel a6@(16),d2 |
1443 movel a6@(20),d3 |
1444 movel IMM (0x7ff00000),d4 | useful constant (INFINITY)
1445 movel d0,d7 | save sign bits
1446 movel d2,d6 |
1447 bclr IMM (31),d0 | clear sign bits
1448 bclr IMM (31),d2 |
1449 | We know that one of them is either NaN of +/-INFINITY
1450 | Check for NaN (if either one is NaN return NaN)
1451 cmpl d4,d0 | check first a (d0)
1452 bhi Ld$inop | if d0 > 0x7ff00000 or equal and
1453 bne 2f
1454 tstl d1 | d1 > 0, a is NaN
1455 bne Ld$inop |
1456 2: cmpl d4,d2 | check now b (d1)
1457 bhi Ld$inop |
1458 bne 3f
1459 tstl d3 |
1460 bne Ld$inop |
1461 3:
1462 | Now comes the check for +/-INFINITY. We know that both are (maybe not
1463 | finite) numbers, but we have to check if both are infinite whether we
1464 | are adding or subtracting them.
1465 eorl d7,d6 | to check sign bits
1466 bmi 1f
1467 andl IMM (0x80000000),d7 | get (common) sign bit
1468 bra Ld$infty
1469 1:
1470 | We know one (or both) are infinite, so we test for equality between the
1471 | two numbers (if they are equal they have to be infinite both, so we
1472 | return NaN).
1473 cmpl d2,d0 | are both infinite?
1474 bne 1f | if d0 <> d2 they are not equal
1475 cmpl d3,d1 | if d0 == d2 test d3 and d1
1476 beq Ld$inop | if equal return NaN
1477 1:
1478 andl IMM (0x80000000),d7 | get a's sign bit '
1479 cmpl d4,d0 | test now for infinity
1480 beq Ld$infty | if a is INFINITY return with this sign
1481 bchg IMM (31),d7 | else we know b is INFINITY and has
1482 bra Ld$infty | the opposite sign
1483
1484 |=============================================================================
1485 | __muldf3
1486 |=============================================================================
1487
1488 | double __muldf3(double, double);
1489 FUNC(__muldf3)
1490 SYM (__muldf3):
1491 #ifndef __mcoldfire__
1492 link a6,IMM (0)
1493 moveml d2-d7,sp@-
1494 #else
1495 link a6,IMM (-24)
1496 moveml d2-d7,sp@
1497 #endif
1498 movel a6@(8),d0 | get a into d0-d1
1499 movel a6@(12),d1 |
1500 movel a6@(16),d2 | and b into d2-d3
1501 movel a6@(20),d3 |
1502 movel d0,d7 | d7 will hold the sign of the product
1503 eorl d2,d7 |
1504 andl IMM (0x80000000),d7 |
1505 movel d7,a0 | save sign bit into a0
1506 movel IMM (0x7ff00000),d7 | useful constant (+INFINITY)
1507 movel d7,d6 | another (mask for fraction)
1508 notl d6 |
1509 bclr IMM (31),d0 | get rid of a's sign bit '
1510 movel d0,d4 |
1511 orl d1,d4 |
1512 beq Lmuldf$a$0 | branch if a is zero
1513 movel d0,d4 |
1514 bclr IMM (31),d2 | get rid of b's sign bit '
1515 movel d2,d5 |
1516 orl d3,d5 |
1517 beq Lmuldf$b$0 | branch if b is zero
1518 movel d2,d5 |
1519 cmpl d7,d0 | is a big?
1520 bhi Lmuldf$inop | if a is NaN return NaN
1521 beq Lmuldf$a$nf | we still have to check d1 and b ...
1522 cmpl d7,d2 | now compare b with INFINITY
1523 bhi Lmuldf$inop | is b NaN?
1524 beq Lmuldf$b$nf | we still have to check d3 ...
1525 | Here we have both numbers finite and nonzero (and with no sign bit).
1526 | Now we get the exponents into d4 and d5.
1527 andl d7,d4 | isolate exponent in d4
1528 beq Lmuldf$a$den | if exponent zero, have denormalized
1529 andl d6,d0 | isolate fraction
1530 orl IMM (0x00100000),d0 | and put hidden bit back
1531 swap d4 | I like exponents in the first byte
1532 #ifndef __mcoldfire__
1533 lsrw IMM (4),d4 |
1534 #else
1535 lsrl IMM (4),d4 |
1536 #endif
1537 Lmuldf$1:
1538 andl d7,d5 |
1539 beq Lmuldf$b$den |
1540 andl d6,d2 |
1541 orl IMM (0x00100000),d2 | and put hidden bit back
1542 swap d5 |
1543 #ifndef __mcoldfire__
1544 lsrw IMM (4),d5 |
1545 #else
1546 lsrl IMM (4),d5 |
1547 #endif
1548 Lmuldf$2: |
1549 #ifndef __mcoldfire__
1550 addw d5,d4 | add exponents
1551 subw IMM (D_BIAS+1),d4 | and subtract bias (plus one)
1552 #else
1553 addl d5,d4 | add exponents
1554 subl IMM (D_BIAS+1),d4 | and subtract bias (plus one)
1555 #endif
1556
1557 | We are now ready to do the multiplication. The situation is as follows:
1558 | both a and b have bit 52 ( bit 20 of d0 and d2) set (even if they were
1559 | denormalized to start with!), which means that in the product bit 104
1560 | (which will correspond to bit 8 of the fourth long) is set.
1561
1562 | Here we have to do the product.
1563 | To do it we have to juggle the registers back and forth, as there are not
1564 | enough to keep everything in them. So we use the address registers to keep
1565 | some intermediate data.
1566
1567 #ifndef __mcoldfire__
1568 moveml a2-a3,sp@- | save a2 and a3 for temporary use
1569 #else
1570 movel a2,sp@-
1571 movel a3,sp@-
1572 movel a4,sp@-
1573 #endif
1574 movel IMM (0),a2 | a2 is a null register
1575 movel d4,a3 | and a3 will preserve the exponent
1576
1577 | First, shift d2-d3 so bit 20 becomes bit 31:
1578 #ifndef __mcoldfire__
1579 rorl IMM (5),d2 | rotate d2 5 places right
1580 swap d2 | and swap it
1581 rorl IMM (5),d3 | do the same thing with d3
1582 swap d3 |
1583 movew d3,d6 | get the rightmost 11 bits of d3
1584 andw IMM (0x07ff),d6 |
1585 orw d6,d2 | and put them into d2
1586 andw IMM (0xf800),d3 | clear those bits in d3
1587 #else
1588 moveq IMM (11),d7 | left shift d2 11 bits
1589 lsll d7,d2
1590 movel d3,d6 | get a copy of d3
1591 lsll d7,d3 | left shift d3 11 bits
1592 andl IMM (0xffe00000),d6 | get the top 11 bits of d3
1593 moveq IMM (21),d7 | right shift them 21 bits
1594 lsrl d7,d6
1595 orl d6,d2 | stick them at the end of d2
1596 #endif
1597
1598 movel d2,d6 | move b into d6-d7
1599 movel d3,d7 | move a into d4-d5
1600 movel d0,d4 | and clear d0-d1-d2-d3 (to put result)
1601 movel d1,d5 |
1602 movel IMM (0),d3 |
1603 movel d3,d2 |
1604 movel d3,d1 |
1605 movel d3,d0 |
1606
1607 | We use a1 as counter:
1608 movel IMM (DBL_MANT_DIG-1),a1
1609 #ifndef __mcoldfire__
1610 exg d7,a1
1611 #else
1612 movel d7,a4
1613 movel a1,d7
1614 movel a4,a1
1615 #endif
1616
1617 1:
1618 #ifndef __mcoldfire__
1619 exg d7,a1 | put counter back in a1
1620 #else
1621 movel d7,a4
1622 movel a1,d7
1623 movel a4,a1
1624 #endif
1625 addl d3,d3 | shift sum once left
1626 addxl d2,d2 |
1627 addxl d1,d1 |
1628 addxl d0,d0 |
1629 addl d7,d7 |
1630 addxl d6,d6 |
1631 bcc 2f | if bit clear skip the following
1632 #ifndef __mcoldfire__
1633 exg d7,a2 |
1634 #else
1635 movel d7,a4
1636 movel a2,d7
1637 movel a4,a2
1638 #endif
1639 addl d5,d3 | else add a to the sum
1640 addxl d4,d2 |
1641 addxl d7,d1 |
1642 addxl d7,d0 |
1643 #ifndef __mcoldfire__
1644 exg d7,a2 |
1645 #else
1646 movel d7,a4
1647 movel a2,d7
1648 movel a4,a2
1649 #endif
1650 2:
1651 #ifndef __mcoldfire__
1652 exg d7,a1 | put counter in d7
1653 dbf d7,1b | decrement and branch
1654 #else
1655 movel d7,a4
1656 movel a1,d7
1657 movel a4,a1
1658 subql IMM (1),d7
1659 bpl 1b
1660 #endif
1661
1662 movel a3,d4 | restore exponent
1663 #ifndef __mcoldfire__
1664 moveml sp@+,a2-a3
1665 #else
1666 movel sp@+,a4
1667 movel sp@+,a3
1668 movel sp@+,a2
1669 #endif
1670
1671 | Now we have the product in d0-d1-d2-d3, with bit 8 of d0 set. The
1672 | first thing to do now is to normalize it so bit 8 becomes bit
1673 | DBL_MANT_DIG-32 (to do the rounding); later we will shift right.
1674 swap d0
1675 swap d1
1676 movew d1,d0
1677 swap d2
1678 movew d2,d1
1679 swap d3
1680 movew d3,d2
1681 movew IMM (0),d3
1682 #ifndef __mcoldfire__
1683 lsrl IMM (1),d0
1684 roxrl IMM (1),d1
1685 roxrl IMM (1),d2
1686 roxrl IMM (1),d3
1687 lsrl IMM (1),d0
1688 roxrl IMM (1),d1
1689 roxrl IMM (1),d2
1690 roxrl IMM (1),d3
1691 lsrl IMM (1),d0
1692 roxrl IMM (1),d1
1693 roxrl IMM (1),d2
1694 roxrl IMM (1),d3
1695 #else
1696 moveq IMM (29),d6
1697 lsrl IMM (3),d3
1698 movel d2,d7
1699 lsll d6,d7
1700 orl d7,d3
1701 lsrl IMM (3),d2
1702 movel d1,d7
1703 lsll d6,d7
1704 orl d7,d2
1705 lsrl IMM (3),d1
1706 movel d0,d7
1707 lsll d6,d7
1708 orl d7,d1
1709 lsrl IMM (3),d0
1710 #endif
1711
1712 | Now round, check for over- and underflow, and exit.
1713 movel a0,d7 | get sign bit back into d7
1714 moveq IMM (MULTIPLY),d5
1715
1716 btst IMM (DBL_MANT_DIG+1-32),d0
1717 beq Lround$exit
1718 #ifndef __mcoldfire__
1719 lsrl IMM (1),d0
1720 roxrl IMM (1),d1
1721 addw IMM (1),d4
1722 #else
1723 lsrl IMM (1),d1
1724 btst IMM (0),d0
1725 beq 10f
1726 bset IMM (31),d1
1727 10: lsrl IMM (1),d0
1728 addl IMM (1),d4
1729 #endif
1730 bra Lround$exit
1731
1732 Lmuldf$inop:
1733 moveq IMM (MULTIPLY),d5
1734 bra Ld$inop
1735
1736 Lmuldf$b$nf:
1737 moveq IMM (MULTIPLY),d5
1738 movel a0,d7 | get sign bit back into d7
1739 tstl d3 | we know d2 == 0x7ff00000, so check d3
1740 bne Ld$inop | if d3 <> 0 b is NaN
1741 bra Ld$overflow | else we have overflow (since a is finite)
1742
1743 Lmuldf$a$nf:
1744 moveq IMM (MULTIPLY),d5
1745 movel a0,d7 | get sign bit back into d7
1746 tstl d1 | we know d0 == 0x7ff00000, so check d1
1747 bne Ld$inop | if d1 <> 0 a is NaN
1748 bra Ld$overflow | else signal overflow
1749
1750 | If either number is zero return zero, unless the other is +/-INFINITY or
1751 | NaN, in which case we return NaN.
1752 Lmuldf$b$0:
1753 moveq IMM (MULTIPLY),d5
1754 #ifndef __mcoldfire__
1755 exg d2,d0 | put b (==0) into d0-d1
1756 exg d3,d1 | and a (with sign bit cleared) into d2-d3
1757 movel a0,d0 | set result sign
1758 #else
1759 movel d0,d2 | put a into d2-d3
1760 movel d1,d3
1761 movel a0,d0 | put result zero into d0-d1
1762 movq IMM(0),d1
1763 #endif
1764 bra 1f
1765 Lmuldf$a$0:
1766 movel a0,d0 | set result sign
1767 movel a6@(16),d2 | put b into d2-d3 again
1768 movel a6@(20),d3 |
1769 bclr IMM (31),d2 | clear sign bit
1770 1: cmpl IMM (0x7ff00000),d2 | check for non-finiteness
1771 bge Ld$inop | in case NaN or +/-INFINITY return NaN
1772 PICLEA SYM (_fpCCR),a0
1773 movew IMM (0),a0@
1774 #ifndef __mcoldfire__
1775 moveml sp@+,d2-d7
1776 #else
1777 moveml sp@,d2-d7
1778 | XXX if frame pointer is ever removed, stack pointer must
1779 | be adjusted here.
1780 #endif
1781 unlk a6
1782 rts
1783
1784 | If a number is denormalized we put an exponent of 1 but do not put the
1785 | hidden bit back into the fraction; instead we shift left until bit 21
1786 | (the hidden bit) is set, adjusting the exponent accordingly. We do this
1787 | to ensure that the product of the fractions is close to 1.
1788 Lmuldf$a$den:
1789 movel IMM (1),d4
1790 andl d6,d0
1791 1: addl d1,d1 | shift a left until bit 20 is set
1792 addxl d0,d0 |
1793 #ifndef __mcoldfire__
1794 subw IMM (1),d4 | and adjust exponent
1795 #else
1796 subl IMM (1),d4 | and adjust exponent
1797 #endif
1798 btst IMM (20),d0 |
1799 bne Lmuldf$1 |
1800 bra 1b
1801
1802 Lmuldf$b$den:
1803 movel IMM (1),d5
1804 andl d6,d2
1805 1: addl d3,d3 | shift b left until bit 20 is set
1806 addxl d2,d2 |
1807 #ifndef __mcoldfire__
1808 subw IMM (1),d5 | and adjust exponent
1809 #else
1810 subql IMM (1),d5 | and adjust exponent
1811 #endif
1812 btst IMM (20),d2 |
1813 bne Lmuldf$2 |
1814 bra 1b
1815
1816
1817 |=============================================================================
1818 | __divdf3
1819 |=============================================================================
1820
1821 | double __divdf3(double, double);
1822 FUNC(__divdf3)
1823 SYM (__divdf3):
1824 #ifndef __mcoldfire__
1825 link a6,IMM (0)
1826 moveml d2-d7,sp@-
1827 #else
1828 link a6,IMM (-24)
1829 moveml d2-d7,sp@
1830 #endif
1831 movel a6@(8),d0 | get a into d0-d1
1832 movel a6@(12),d1 |
1833 movel a6@(16),d2 | and b into d2-d3
1834 movel a6@(20),d3 |
1835 movel d0,d7 | d7 will hold the sign of the result
1836 eorl d2,d7 |
1837 andl IMM (0x80000000),d7
1838 movel d7,a0 | save sign into a0
1839 movel IMM (0x7ff00000),d7 | useful constant (+INFINITY)
1840 movel d7,d6 | another (mask for fraction)
1841 notl d6 |
1842 bclr IMM (31),d0 | get rid of a's sign bit '
1843 movel d0,d4 |
1844 orl d1,d4 |
1845 beq Ldivdf$a$0 | branch if a is zero
1846 movel d0,d4 |
1847 bclr IMM (31),d2 | get rid of b's sign bit '
1848 movel d2,d5 |
1849 orl d3,d5 |
1850 beq Ldivdf$b$0 | branch if b is zero
1851 movel d2,d5
1852 cmpl d7,d0 | is a big?
1853 bhi Ldivdf$inop | if a is NaN return NaN
1854 beq Ldivdf$a$nf | if d0 == 0x7ff00000 we check d1
1855 cmpl d7,d2 | now compare b with INFINITY
1856 bhi Ldivdf$inop | if b is NaN return NaN
1857 beq Ldivdf$b$nf | if d2 == 0x7ff00000 we check d3
1858 | Here we have both numbers finite and nonzero (and with no sign bit).
1859 | Now we get the exponents into d4 and d5 and normalize the numbers to
1860 | ensure that the ratio of the fractions is around 1. We do this by
1861 | making sure that both numbers have bit #DBL_MANT_DIG-32-1 (hidden bit)
1862 | set, even if they were denormalized to start with.
1863 | Thus, the result will satisfy: 2 > result > 1/2.
1864 andl d7,d4 | and isolate exponent in d4
1865 beq Ldivdf$a$den | if exponent is zero we have a denormalized
1866 andl d6,d0 | and isolate fraction
1867 orl IMM (0x00100000),d0 | and put hidden bit back
1868 swap d4 | I like exponents in the first byte
1869 #ifndef __mcoldfire__
1870 lsrw IMM (4),d4 |
1871 #else
1872 lsrl IMM (4),d4 |
1873 #endif
1874 Ldivdf$1: |
1875 andl d7,d5 |
1876 beq Ldivdf$b$den |
1877 andl d6,d2 |
1878 orl IMM (0x00100000),d2
1879 swap d5 |
1880 #ifndef __mcoldfire__
1881 lsrw IMM (4),d5 |
1882 #else
1883 lsrl IMM (4),d5 |
1884 #endif
1885 Ldivdf$2: |
1886 #ifndef __mcoldfire__
1887 subw d5,d4 | subtract exponents
1888 addw IMM (D_BIAS),d4 | and add bias
1889 #else
1890 subl d5,d4 | subtract exponents
1891 addl IMM (D_BIAS),d4 | and add bias
1892 #endif
1893
1894 | We are now ready to do the division. We have prepared things in such a way
1895 | that the ratio of the fractions will be less than 2 but greater than 1/2.
1896 | At this point the registers in use are:
1897 | d0-d1 hold a (first operand, bit DBL_MANT_DIG-32=0, bit
1898 | DBL_MANT_DIG-1-32=1)
1899 | d2-d3 hold b (second operand, bit DBL_MANT_DIG-32=1)
1900 | d4 holds the difference of the exponents, corrected by the bias
1901 | a0 holds the sign of the ratio
1902
1903 | To do the rounding correctly we need to keep information about the
1904 | nonsignificant bits. One way to do this would be to do the division
1905 | using four registers; another is to use two registers (as originally
1906 | I did), but use a sticky bit to preserve information about the
1907 | fractional part. Note that we can keep that info in a1, which is not
1908 | used.
1909 movel IMM (0),d6 | d6-d7 will hold the result
1910 movel d6,d7 |
1911 movel IMM (0),a1 | and a1 will hold the sticky bit
1912
1913 movel IMM (DBL_MANT_DIG-32+1),d5
1914
1915 1: cmpl d0,d2 | is a < b?
1916 bhi 3f | if b > a skip the following
1917 beq 4f | if d0==d2 check d1 and d3
1918 2: subl d3,d1 |
1919 subxl d2,d0 | a <-- a - b
1920 bset d5,d6 | set the corresponding bit in d6
1921 3: addl d1,d1 | shift a by 1
1922 addxl d0,d0 |
1923 #ifndef __mcoldfire__
1924 dbra d5,1b | and branch back
1925 #else
1926 subql IMM (1), d5
1927 bpl 1b
1928 #endif
1929 bra 5f
1930 4: cmpl d1,d3 | here d0==d2, so check d1 and d3
1931 bhi 3b | if d1 > d2 skip the subtraction
1932 bra 2b | else go do it
1933 5:
1934 | Here we have to start setting the bits in the second long.
1935 movel IMM (31),d5 | again d5 is counter
1936
1937 1: cmpl d0,d2 | is a < b?
1938 bhi 3f | if b > a skip the following
1939 beq 4f | if d0==d2 check d1 and d3
1940 2: subl d3,d1 |
1941 subxl d2,d0 | a <-- a - b
1942 bset d5,d7 | set the corresponding bit in d7
1943 3: addl d1,d1 | shift a by 1
1944 addxl d0,d0 |
1945 #ifndef __mcoldfire__
1946 dbra d5,1b | and branch back
1947 #else
1948 subql IMM (1), d5
1949 bpl 1b
1950 #endif
1951 bra 5f
1952 4: cmpl d1,d3 | here d0==d2, so check d1 and d3
1953 bhi 3b | if d1 > d2 skip the subtraction
1954 bra 2b | else go do it
1955 5:
1956 | Now go ahead checking until we hit a one, which we store in d2.
1957 movel IMM (DBL_MANT_DIG),d5
1958 1: cmpl d2,d0 | is a < b?
1959 bhi 4f | if b < a, exit
1960 beq 3f | if d0==d2 check d1 and d3
1961 2: addl d1,d1 | shift a by 1
1962 addxl d0,d0 |
1963 #ifndef __mcoldfire__
1964 dbra d5,1b | and branch back
1965 #else
1966 subql IMM (1), d5
1967 bpl 1b
1968 #endif
1969 movel IMM (0),d2 | here no sticky bit was found
1970 movel d2,d3
1971 bra 5f
1972 3: cmpl d1,d3 | here d0==d2, so check d1 and d3
1973 bhi 2b | if d1 > d2 go back
1974 4:
1975 | Here put the sticky bit in d2-d3 (in the position which actually corresponds
1976 | to it; if you don't do this the algorithm loses in some cases). '
1977 movel IMM (0),d2
1978 movel d2,d3
1979 #ifndef __mcoldfire__
1980 subw IMM (DBL_MANT_DIG),d5
1981 addw IMM (63),d5
1982 cmpw IMM (31),d5
1983 #else
1984 subl IMM (DBL_MANT_DIG),d5
1985 addl IMM (63),d5
1986 cmpl IMM (31),d5
1987 #endif
1988 bhi 2f
1989 1: bset d5,d3
1990 bra 5f
1991 #ifndef __mcoldfire__
1992 subw IMM (32),d5
1993 #else
1994 subl IMM (32),d5
1995 #endif
1996 2: bset d5,d2
1997 5:
1998 | Finally we are finished! Move the longs in the address registers to
1999 | their final destination:
2000 movel d6,d0
2001 movel d7,d1
2002 movel IMM (0),d3
2003
2004 | Here we have finished the division, with the result in d0-d1-d2-d3, with
2005 | 2^21 <= d6 < 2^23. Thus bit 23 is not set, but bit 22 could be set.
2006 | If it is not, then definitely bit 21 is set. Normalize so bit 22 is
2007 | not set:
2008 btst IMM (DBL_MANT_DIG-32+1),d0
2009 beq 1f
2010 #ifndef __mcoldfire__
2011 lsrl IMM (1),d0
2012 roxrl IMM (1),d1
2013 roxrl IMM (1),d2
2014 roxrl IMM (1),d3
2015 addw IMM (1),d4
2016 #else
2017 lsrl IMM (1),d3
2018 btst IMM (0),d2
2019 beq 10f
2020 bset IMM (31),d3
2021 10: lsrl IMM (1),d2
2022 btst IMM (0),d1
2023 beq 11f
2024 bset IMM (31),d2
2025 11: lsrl IMM (1),d1
2026 btst IMM (0),d0
2027 beq 12f
2028 bset IMM (31),d1
2029 12: lsrl IMM (1),d0
2030 addl IMM (1),d4
2031 #endif
2032 1:
2033 | Now round, check for over- and underflow, and exit.
2034 movel a0,d7 | restore sign bit to d7
2035 moveq IMM (DIVIDE),d5
2036 bra Lround$exit
2037
2038 Ldivdf$inop:
2039 moveq IMM (DIVIDE),d5
2040 bra Ld$inop
2041
2042 Ldivdf$a$0:
2043 | If a is zero check to see whether b is zero also. In that case return
2044 | NaN; then check if b is NaN, and return NaN also in that case. Else
2045 | return a properly signed zero.
2046 moveq IMM (DIVIDE),d5
2047 bclr IMM (31),d2 |
2048 movel d2,d4 |
2049 orl d3,d4 |
2050 beq Ld$inop | if b is also zero return NaN
2051 cmpl IMM (0x7ff00000),d2 | check for NaN
2052 bhi Ld$inop |
2053 blt 1f |
2054 tstl d3 |
2055 bne Ld$inop |
2056 1: movel a0,d0 | else return signed zero
2057 moveq IMM(0),d1 |
2058 PICLEA SYM (_fpCCR),a0 | clear exception flags
2059 movew IMM (0),a0@ |
2060 #ifndef __mcoldfire__
2061 moveml sp@+,d2-d7 |
2062 #else
2063 moveml sp@,d2-d7 |
2064 | XXX if frame pointer is ever removed, stack pointer must
2065 | be adjusted here.
2066 #endif
2067 unlk a6 |
2068 rts |
2069
2070 Ldivdf$b$0:
2071 moveq IMM (DIVIDE),d5
2072 | If we got here a is not zero. Check if a is NaN; in that case return NaN,
2073 | else return +/-INFINITY. Remember that a is in d0 with the sign bit
2074 | cleared already.
2075 movel a0,d7 | put a's sign bit back in d7 '
2076 cmpl IMM (0x7ff00000),d0 | compare d0 with INFINITY
2077 bhi Ld$inop | if larger it is NaN
2078 tstl d1 |
2079 bne Ld$inop |
2080 bra Ld$div$0 | else signal DIVIDE_BY_ZERO
2081
2082 Ldivdf$b$nf:
2083 moveq IMM (DIVIDE),d5
2084 | If d2 == 0x7ff00000 we have to check d3.
2085 tstl d3 |
2086 bne Ld$inop | if d3 <> 0, b is NaN
2087 movel a0,d7 | put a's sign
2088 bra Ld$underflow | else b is +/-INFINITY, so signal underflow
2089
2090 Ldivdf$a$nf:
2091 moveq IMM (DIVIDE),d5
2092 | If d0 == 0x7ff00000 we have to check d1.
2093 tstl d1 |
2094 bne Ld$inop | if d1 <> 0, a is NaN
2095 | If a is INFINITY we have to check b
2096 cmpl d7,d2 | compare b with INFINITY
2097 bge Ld$inop | if b is NaN or INFINITY return NaN
2098 movl a0,d7 | restore sign bit to d7
2099 bra Ld$overflow | else return overflow
2100
2101 | If a number is denormalized we put an exponent of 1 but do not put the
2102 | bit back into the fraction.
2103 Ldivdf$a$den:
2104 movel IMM (1),d4
2105 andl d6,d0
2106 1: addl d1,d1 | shift a left until bit 20 is set
2107 addxl d0,d0
2108 #ifndef __mcoldfire__
2109 subw IMM (1),d4 | and adjust exponent
2110 #else
2111 subl IMM (1),d4 | and adjust exponent
2112 #endif
2113 btst IMM (DBL_MANT_DIG-32-1),d0
2114 bne Ldivdf$1
2115 bra 1b
2116
2117 Ldivdf$b$den:
2118 movel IMM (1),d5
2119 andl d6,d2
2120 1: addl d3,d3 | shift b left until bit 20 is set
2121 addxl d2,d2
2122 #ifndef __mcoldfire__
2123 subw IMM (1),d5 | and adjust exponent
2124 #else
2125 subql IMM (1),d5 | and adjust exponent
2126 #endif
2127 btst IMM (DBL_MANT_DIG-32-1),d2
2128 bne Ldivdf$2
2129 bra 1b
2130
2131 Lround$exit:
2132 | This is a common exit point for __muldf3 and __divdf3. When they enter
2133 | this point the sign of the result is in d7, the result in d0-d1, normalized
2134 | so that 2^21 <= d0 < 2^22, and the exponent is in the lower byte of d4.
2135
2136 | First check for underlow in the exponent:
2137 #ifndef __mcoldfire__
2138 cmpw IMM (-DBL_MANT_DIG-1),d4
2139 #else
2140 cmpl IMM (-DBL_MANT_DIG-1),d4
2141 #endif
2142 blt Ld$underflow
2143 | It could happen that the exponent is less than 1, in which case the
2144 | number is denormalized. In this case we shift right and adjust the
2145 | exponent until it becomes 1 or the fraction is zero (in the latter case
2146 | we signal underflow and return zero).
2147 movel d7,a0 |
2148 movel IMM (0),d6 | use d6-d7 to collect bits flushed right
2149 movel d6,d7 | use d6-d7 to collect bits flushed right
2150 #ifndef __mcoldfire__
2151 cmpw IMM (1),d4 | if the exponent is less than 1 we
2152 #else
2153 cmpl IMM (1),d4 | if the exponent is less than 1 we
2154 #endif
2155 bge 2f | have to shift right (denormalize)
2156 1:
2157 #ifndef __mcoldfire__
2158 addw IMM (1),d4 | adjust the exponent
2159 lsrl IMM (1),d0 | shift right once
2160 roxrl IMM (1),d1 |
2161 roxrl IMM (1),d2 |
2162 roxrl IMM (1),d3 |
2163 roxrl IMM (1),d6 |
2164 roxrl IMM (1),d7 |
2165 cmpw IMM (1),d4 | is the exponent 1 already?
2166 #else
2167 addl IMM (1),d4 | adjust the exponent
2168 lsrl IMM (1),d7
2169 btst IMM (0),d6
2170 beq 13f
2171 bset IMM (31),d7
2172 13: lsrl IMM (1),d6
2173 btst IMM (0),d3
2174 beq 14f
2175 bset IMM (31),d6
2176 14: lsrl IMM (1),d3
2177 btst IMM (0),d2
2178 beq 10f
2179 bset IMM (31),d3
2180 10: lsrl IMM (1),d2
2181 btst IMM (0),d1
2182 beq 11f
2183 bset IMM (31),d2
2184 11: lsrl IMM (1),d1
2185 btst IMM (0),d0
2186 beq 12f
2187 bset IMM (31),d1
2188 12: lsrl IMM (1),d0
2189 cmpl IMM (1),d4 | is the exponent 1 already?
2190 #endif
2191 beq 2f | if not loop back
2192 bra 1b |
2193 movel a0,d7 | get back sign bit into d7
2194 bra Ld$underflow | safety check, shouldn't execute '
2195 2: orl d6,d2 | this is a trick so we don't lose '
2196 orl d7,d3 | the bits which were flushed right
2197 movel a0,d7 | get back sign bit into d7
2198 | Now call the rounding routine (which takes care of denormalized numbers):
2199 lea pc@(Lround$0),a0 | to return from rounding routine
2200 PICLEA SYM (_fpCCR),a1 | check the rounding mode
2201 #ifdef __mcoldfire__
2202 clrl d6
2203 #endif
2204 movew a1@(6),d6 | rounding mode in d6
2205 beq Lround$to$nearest
2206 #ifndef __mcoldfire__
2207 cmpw IMM (ROUND_TO_PLUS),d6
2208 #else
2209 cmpl IMM (ROUND_TO_PLUS),d6
2210 #endif
2211 bhi Lround$to$minus
2212 blt Lround$to$zero
2213 bra Lround$to$plus
2214 Lround$0:
2215 | Here we have a correctly rounded result (either normalized or denormalized).
2216
2217 | Here we should have either a normalized number or a denormalized one, and
2218 | the exponent is necessarily larger or equal to 1 (so we don't have to '
2219 | check again for underflow!). We have to check for overflow or for a
2220 | denormalized number (which also signals underflow).
2221 | Check for overflow (i.e., exponent >= 0x7ff).
2222 #ifndef __mcoldfire__
2223 cmpw IMM (0x07ff),d4
2224 #else
2225 cmpl IMM (0x07ff),d4
2226 #endif
2227 bge Ld$overflow
2228 | Now check for a denormalized number (exponent==0):
2229 movew d4,d4
2230 beq Ld$den
2231 1:
2232 | Put back the exponents and sign and return.
2233 #ifndef __mcoldfire__
2234 lslw IMM (4),d4 | exponent back to fourth byte
2235 #else
2236 lsll IMM (4),d4 | exponent back to fourth byte
2237 #endif
2238 bclr IMM (DBL_MANT_DIG-32-1),d0
2239 swap d0 | and put back exponent
2240 #ifndef __mcoldfire__
2241 orw d4,d0 |
2242 #else
2243 orl d4,d0 |
2244 #endif
2245 swap d0 |
2246 orl d7,d0 | and sign also
2247
2248 PICLEA SYM (_fpCCR),a0
2249 movew IMM (0),a0@
2250 #ifndef __mcoldfire__
2251 moveml sp@+,d2-d7
2252 #else
2253 moveml sp@,d2-d7
2254 | XXX if frame pointer is ever removed, stack pointer must
2255 | be adjusted here.
2256 #endif
2257 unlk a6
2258 rts
2259
2260 |=============================================================================
2261 | __negdf2
2262 |=============================================================================
2263
2264 | double __negdf2(double, double);
2265 FUNC(__negdf2)
2266 SYM (__negdf2):
2267 #ifndef __mcoldfire__
2268 link a6,IMM (0)
2269 moveml d2-d7,sp@-
2270 #else
2271 link a6,IMM (-24)
2272 moveml d2-d7,sp@
2273 #endif
2274 moveq IMM (NEGATE),d5
2275 movel a6@(8),d0 | get number to negate in d0-d1
2276 movel a6@(12),d1 |
2277 bchg IMM (31),d0 | negate
2278 movel d0,d2 | make a positive copy (for the tests)
2279 bclr IMM (31),d2 |
2280 movel d2,d4 | check for zero
2281 orl d1,d4 |
2282 beq 2f | if zero (either sign) return +zero
2283 cmpl IMM (0x7ff00000),d2 | compare to +INFINITY
2284 blt 1f | if finite, return
2285 bhi Ld$inop | if larger (fraction not zero) is NaN
2286 tstl d1 | if d2 == 0x7ff00000 check d1
2287 bne Ld$inop |
2288 movel d0,d7 | else get sign and return INFINITY
2289 andl IMM (0x80000000),d7
2290 bra Ld$infty
2291 1: PICLEA SYM (_fpCCR),a0
2292 movew IMM (0),a0@
2293 #ifndef __mcoldfire__
2294 moveml sp@+,d2-d7
2295 #else
2296 moveml sp@,d2-d7
2297 | XXX if frame pointer is ever removed, stack pointer must
2298 | be adjusted here.
2299 #endif
2300 unlk a6
2301 rts
2302 2: bclr IMM (31),d0
2303 bra 1b
2304
2305 |=============================================================================
2306 | __cmpdf2
2307 |=============================================================================
2308
2309 GREATER = 1
2310 LESS = -1
2311 EQUAL = 0
2312
2313 | int __cmpdf2_internal(double, double, int);
2314 SYM (__cmpdf2_internal):
2315 #ifndef __mcoldfire__
2316 link a6,IMM (0)
2317 moveml d2-d7,sp@- | save registers
2318 #else
2319 link a6,IMM (-24)
2320 moveml d2-d7,sp@
2321 #endif
2322 moveq IMM (COMPARE),d5
2323 movel a6@(8),d0 | get first operand
2324 movel a6@(12),d1 |
2325 movel a6@(16),d2 | get second operand
2326 movel a6@(20),d3 |
2327 | First check if a and/or b are (+/-) zero and in that case clear
2328 | the sign bit.
2329 movel d0,d6 | copy signs into d6 (a) and d7(b)
2330 bclr IMM (31),d0 | and clear signs in d0 and d2
2331 movel d2,d7 |
2332 bclr IMM (31),d2 |
2333 cmpl IMM (0x7ff00000),d0 | check for a == NaN
2334 bhi Lcmpd$inop | if d0 > 0x7ff00000, a is NaN
2335 beq Lcmpdf$a$nf | if equal can be INFINITY, so check d1
2336 movel d0,d4 | copy into d4 to test for zero
2337 orl d1,d4 |
2338 beq Lcmpdf$a$0 |
2339 Lcmpdf$0:
2340 cmpl IMM (0x7ff00000),d2 | check for b == NaN
2341 bhi Lcmpd$inop | if d2 > 0x7ff00000, b is NaN
2342 beq Lcmpdf$b$nf | if equal can be INFINITY, so check d3
2343 movel d2,d4 |
2344 orl d3,d4 |
2345 beq Lcmpdf$b$0 |
2346 Lcmpdf$1:
2347 | Check the signs
2348 eorl d6,d7
2349 bpl 1f
2350 | If the signs are not equal check if a >= 0
2351 tstl d6
2352 bpl Lcmpdf$a$gt$b | if (a >= 0 && b < 0) => a > b
2353 bmi Lcmpdf$b$gt$a | if (a < 0 && b >= 0) => a < b
2354 1:
2355 | If the signs are equal check for < 0
2356 tstl d6
2357 bpl 1f
2358 | If both are negative exchange them
2359 #ifndef __mcoldfire__
2360 exg d0,d2
2361 exg d1,d3
2362 #else
2363 movel d0,d7
2364 movel d2,d0
2365 movel d7,d2
2366 movel d1,d7
2367 movel d3,d1
2368 movel d7,d3
2369 #endif
2370 1:
2371 | Now that they are positive we just compare them as longs (does this also
2372 | work for denormalized numbers?).
2373 cmpl d0,d2
2374 bhi Lcmpdf$b$gt$a | |b| > |a|
2375 bne Lcmpdf$a$gt$b | |b| < |a|
2376 | If we got here d0 == d2, so we compare d1 and d3.
2377 cmpl d1,d3
2378 bhi Lcmpdf$b$gt$a | |b| > |a|
2379 bne Lcmpdf$a$gt$b | |b| < |a|
2380 | If we got here a == b.
2381 movel IMM (EQUAL),d0
2382 #ifndef __mcoldfire__
2383 moveml sp@+,d2-d7 | put back the registers
2384 #else
2385 moveml sp@,d2-d7
2386 | XXX if frame pointer is ever removed, stack pointer must
2387 | be adjusted here.
2388 #endif
2389 unlk a6
2390 rts
2391 Lcmpdf$a$gt$b:
2392 movel IMM (GREATER),d0
2393 #ifndef __mcoldfire__
2394 moveml sp@+,d2-d7 | put back the registers
2395 #else
2396 moveml sp@,d2-d7
2397 | XXX if frame pointer is ever removed, stack pointer must
2398 | be adjusted here.
2399 #endif
2400 unlk a6
2401 rts
2402 Lcmpdf$b$gt$a:
2403 movel IMM (LESS),d0
2404 #ifndef __mcoldfire__
2405 moveml sp@+,d2-d7 | put back the registers
2406 #else
2407 moveml sp@,d2-d7
2408 | XXX if frame pointer is ever removed, stack pointer must
2409 | be adjusted here.
2410 #endif
2411 unlk a6
2412 rts
2413
2414 Lcmpdf$a$0:
2415 bclr IMM (31),d6
2416 bra Lcmpdf$0
2417 Lcmpdf$b$0:
2418 bclr IMM (31),d7
2419 bra Lcmpdf$1
2420
2421 Lcmpdf$a$nf:
2422 tstl d1
2423 bne Ld$inop
2424 bra Lcmpdf$0
2425
2426 Lcmpdf$b$nf:
2427 tstl d3
2428 bne Ld$inop
2429 bra Lcmpdf$1
2430
2431 Lcmpd$inop:
2432 movl a6@(24),d0
2433 moveq IMM (INEXACT_RESULT+INVALID_OPERATION),d7
2434 moveq IMM (DOUBLE_FLOAT),d6
2435 PICJUMP $_exception_handler
2436
2437 | int __cmpdf2(double, double);
2438 FUNC(__cmpdf2)
2439 SYM (__cmpdf2):
2440 link a6,IMM (0)
2441 pea 1
2442 movl a6@(20),sp@-
2443 movl a6@(16),sp@-
2444 movl a6@(12),sp@-
2445 movl a6@(8),sp@-
2446 PICCALL SYM (__cmpdf2_internal)
2447 unlk a6
2448 rts
2449
2450 |=============================================================================
2451 | rounding routines
2452 |=============================================================================
2453
2454 | The rounding routines expect the number to be normalized in registers
2455 | d0-d1-d2-d3, with the exponent in register d4. They assume that the
2456 | exponent is larger or equal to 1. They return a properly normalized number
2457 | if possible, and a denormalized number otherwise. The exponent is returned
2458 | in d4.
2459
2460 Lround$to$nearest:
2461 | We now normalize as suggested by D. Knuth ("Seminumerical Algorithms"):
2462 | Here we assume that the exponent is not too small (this should be checked
2463 | before entering the rounding routine), but the number could be denormalized.
2464
2465 | Check for denormalized numbers:
2466 1: btst IMM (DBL_MANT_DIG-32),d0
2467 bne 2f | if set the number is normalized
2468 | Normalize shifting left until bit #DBL_MANT_DIG-32 is set or the exponent
2469 | is one (remember that a denormalized number corresponds to an
2470 | exponent of -D_BIAS+1).
2471 #ifndef __mcoldfire__
2472 cmpw IMM (1),d4 | remember that the exponent is at least one
2473 #else
2474 cmpl IMM (1),d4 | remember that the exponent is at least one
2475 #endif
2476 beq 2f | an exponent of one means denormalized
2477 addl d3,d3 | else shift and adjust the exponent
2478 addxl d2,d2 |
2479 addxl d1,d1 |
2480 addxl d0,d0 |
2481 #ifndef __mcoldfire__
2482 dbra d4,1b |
2483 #else
2484 subql IMM (1), d4
2485 bpl 1b
2486 #endif
2487 2:
2488 | Now round: we do it as follows: after the shifting we can write the
2489 | fraction part as f + delta, where 1 < f < 2^25, and 0 <= delta <= 2.
2490 | If delta < 1, do nothing. If delta > 1, add 1 to f.
2491 | If delta == 1, we make sure the rounded number will be even (odd?)
2492 | (after shifting).
2493 btst IMM (0),d1 | is delta < 1?
2494 beq 2f | if so, do not do anything
2495 orl d2,d3 | is delta == 1?
2496 bne 1f | if so round to even
2497 movel d1,d3 |
2498 andl IMM (2),d3 | bit 1 is the last significant bit
2499 movel IMM (0),d2 |
2500 addl d3,d1 |
2501 addxl d2,d0 |
2502 bra 2f |
2503 1: movel IMM (1),d3 | else add 1
2504 movel IMM (0),d2 |
2505 addl d3,d1 |
2506 addxl d2,d0
2507 | Shift right once (because we used bit #DBL_MANT_DIG-32!).
2508 2:
2509 #ifndef __mcoldfire__
2510 lsrl IMM (1),d0
2511 roxrl IMM (1),d1
2512 #else
2513 lsrl IMM (1),d1
2514 btst IMM (0),d0
2515 beq 10f
2516 bset IMM (31),d1
2517 10: lsrl IMM (1),d0
2518 #endif
2519
2520 | Now check again bit #DBL_MANT_DIG-32 (rounding could have produced a
2521 | 'fraction overflow' ...).
2522 btst IMM (DBL_MANT_DIG-32),d0
2523 beq 1f
2524 #ifndef __mcoldfire__
2525 lsrl IMM (1),d0
2526 roxrl IMM (1),d1
2527 addw IMM (1),d4
2528 #else
2529 lsrl IMM (1),d1
2530 btst IMM (0),d0
2531 beq 10f
2532 bset IMM (31),d1
2533 10: lsrl IMM (1),d0
2534 addl IMM (1),d4
2535 #endif
2536 1:
2537 | If bit #DBL_MANT_DIG-32-1 is clear we have a denormalized number, so we
2538 | have to put the exponent to zero and return a denormalized number.
2539 btst IMM (DBL_MANT_DIG-32-1),d0
2540 beq 1f
2541 jmp a0@
2542 1: movel IMM (0),d4
2543 jmp a0@
2544
2545 Lround$to$zero:
2546 Lround$to$plus:
2547 Lround$to$minus:
2548 jmp a0@
2549 #endif /* L_double */
2550
2551 #ifdef L_float
2552
2553 .globl SYM (_fpCCR)
2554 .globl $_exception_handler
2555
2556 QUIET_NaN = 0x7fffffff
2557 SIGNL_NaN = 0x7f800001
2558 INFINITY = 0x7f800000
2559
2560 F_MAX_EXP = 0xff
2561 F_BIAS = 126
2562 FLT_MAX_EXP = F_MAX_EXP - F_BIAS
2563 FLT_MIN_EXP = 1 - F_BIAS
2564 FLT_MANT_DIG = 24
2565
2566 INEXACT_RESULT = 0x0001
2567 UNDERFLOW = 0x0002
2568 OVERFLOW = 0x0004
2569 DIVIDE_BY_ZERO = 0x0008
2570 INVALID_OPERATION = 0x0010
2571
2572 SINGLE_FLOAT = 1
2573
2574 NOOP = 0
2575 ADD = 1
2576 MULTIPLY = 2
2577 DIVIDE = 3
2578 NEGATE = 4
2579 COMPARE = 5
2580 EXTENDSFDF = 6
2581 TRUNCDFSF = 7
2582
2583 UNKNOWN = -1
2584 ROUND_TO_NEAREST = 0 | round result to nearest representable value
2585 ROUND_TO_ZERO = 1 | round result towards zero
2586 ROUND_TO_PLUS = 2 | round result towards plus infinity
2587 ROUND_TO_MINUS = 3 | round result towards minus infinity
2588
2589 | Entry points:
2590
2591 .globl SYM (__addsf3)
2592 .globl SYM (__subsf3)
2593 .globl SYM (__mulsf3)
2594 .globl SYM (__divsf3)
2595 .globl SYM (__negsf2)
2596 .globl SYM (__cmpsf2)
2597 .globl SYM (__cmpsf2_internal)
2598 .hidden SYM (__cmpsf2_internal)
2599
2600 | These are common routines to return and signal exceptions.
2601
2602 .text
2603 .even
2604
2605 Lf$den:
2606 | Return and signal a denormalized number
2607 orl d7,d0
2608 moveq IMM (INEXACT_RESULT+UNDERFLOW),d7
2609 moveq IMM (SINGLE_FLOAT),d6
2610 PICJUMP $_exception_handler
2611
2612 Lf$infty:
2613 Lf$overflow:
2614 | Return a properly signed INFINITY and set the exception flags
2615 movel IMM (INFINITY),d0
2616 orl d7,d0
2617 moveq IMM (INEXACT_RESULT+OVERFLOW),d7
2618 moveq IMM (SINGLE_FLOAT),d6
2619 PICJUMP $_exception_handler
2620
2621 Lf$underflow:
2622 | Return a properly signed 0 and set the exception flags
2623 moveq IMM (0),d0
2624 orl d7,d0
2625 moveq IMM (INEXACT_RESULT+UNDERFLOW),d7
2626 moveq IMM (SINGLE_FLOAT),d6
2627 PICJUMP $_exception_handler
2628
2629 Lf$inop:
2630 | Return a quiet NaN and set the exception flags
2631 movel IMM (QUIET_NaN),d0
2632 moveq IMM (INEXACT_RESULT+INVALID_OPERATION),d7
2633 moveq IMM (SINGLE_FLOAT),d6
2634 PICJUMP $_exception_handler
2635
2636 Lf$div$0:
2637 | Return a properly signed INFINITY and set the exception flags
2638 movel IMM (INFINITY),d0
2639 orl d7,d0
2640 moveq IMM (INEXACT_RESULT+DIVIDE_BY_ZERO),d7
2641 moveq IMM (SINGLE_FLOAT),d6
2642 PICJUMP $_exception_handler
2643
2644 |=============================================================================
2645 |=============================================================================
2646 | single precision routines
2647 |=============================================================================
2648 |=============================================================================
2649
2650 | A single precision floating point number (float) has the format:
2651 |
2652 | struct _float {
2653 | unsigned int sign : 1; /* sign bit */
2654 | unsigned int exponent : 8; /* exponent, shifted by 126 */
2655 | unsigned int fraction : 23; /* fraction */
2656 | } float;
2657 |
2658 | Thus sizeof(float) = 4 (32 bits).
2659 |
2660 | All the routines are callable from C programs, and return the result
2661 | in the single register d0. They also preserve all registers except
2662 | d0-d1 and a0-a1.
2663
2664 |=============================================================================
2665 | __subsf3
2666 |=============================================================================
2667
2668 | float __subsf3(float, float);
2669 FUNC(__subsf3)
2670 SYM (__subsf3):
2671 bchg IMM (31),sp@(8) | change sign of second operand
2672 | and fall through
2673 |=============================================================================
2674 | __addsf3
2675 |=============================================================================
2676
2677 | float __addsf3(float, float);
2678 FUNC(__addsf3)
2679 SYM (__addsf3):
2680 #ifndef __mcoldfire__
2681 link a6,IMM (0) | everything will be done in registers
2682 moveml d2-d7,sp@- | save all data registers but d0-d1
2683 #else
2684 link a6,IMM (-24)
2685 moveml d2-d7,sp@
2686 #endif
2687 movel a6@(8),d0 | get first operand
2688 movel a6@(12),d1 | get second operand
2689 movel d0,a0 | get d0's sign bit '
2690 addl d0,d0 | check and clear sign bit of a
2691 beq Laddsf$b | if zero return second operand
2692 movel d1,a1 | save b's sign bit '
2693 addl d1,d1 | get rid of sign bit
2694 beq Laddsf$a | if zero return first operand
2695
2696 | Get the exponents and check for denormalized and/or infinity.
2697
2698 movel IMM (0x00ffffff),d4 | mask to get fraction
2699 movel IMM (0x01000000),d5 | mask to put hidden bit back
2700
2701 movel d0,d6 | save a to get exponent
2702 andl d4,d0 | get fraction in d0
2703 notl d4 | make d4 into a mask for the exponent
2704 andl d4,d6 | get exponent in d6
2705 beq Laddsf$a$den | branch if a is denormalized
2706 cmpl d4,d6 | check for INFINITY or NaN
2707 beq Laddsf$nf
2708 swap d6 | put exponent into first word
2709 orl d5,d0 | and put hidden bit back
2710 Laddsf$1:
2711 | Now we have a's exponent in d6 (second byte) and the mantissa in d0. '
2712 movel d1,d7 | get exponent in d7
2713 andl d4,d7 |
2714 beq Laddsf$b$den | branch if b is denormalized
2715 cmpl d4,d7 | check for INFINITY or NaN
2716 beq Laddsf$nf
2717 swap d7 | put exponent into first word
2718 notl d4 | make d4 into a mask for the fraction
2719 andl d4,d1 | get fraction in d1
2720 orl d5,d1 | and put hidden bit back
2721 Laddsf$2:
2722 | Now we have b's exponent in d7 (second byte) and the mantissa in d1. '
2723
2724 | Note that the hidden bit corresponds to bit #FLT_MANT_DIG-1, and we
2725 | shifted right once, so bit #FLT_MANT_DIG is set (so we have one extra
2726 | bit).
2727
2728 movel d1,d2 | move b to d2, since we want to use
2729 | two registers to do the sum
2730 movel IMM (0),d1 | and clear the new ones
2731 movel d1,d3 |
2732
2733 | Here we shift the numbers in registers d0 and d1 so the exponents are the
2734 | same, and put the largest exponent in d6. Note that we are using two
2735 | registers for each number (see the discussion by D. Knuth in "Seminumerical
2736 | Algorithms").
2737 #ifndef __mcoldfire__
2738 cmpw d6,d7 | compare exponents
2739 #else
2740 cmpl d6,d7 | compare exponents
2741 #endif
2742 beq Laddsf$3 | if equal don't shift '
2743 bhi 5f | branch if second exponent largest
2744 1:
2745 subl d6,d7 | keep the largest exponent
2746 negl d7
2747 #ifndef __mcoldfire__
2748 lsrw IMM (8),d7 | put difference in lower byte
2749 #else
2750 lsrl IMM (8),d7 | put difference in lower byte
2751 #endif
2752 | if difference is too large we don't shift (actually, we can just exit) '
2753 #ifndef __mcoldfire__
2754 cmpw IMM (FLT_MANT_DIG+2),d7
2755 #else
2756 cmpl IMM (FLT_MANT_DIG+2),d7
2757 #endif
2758 bge Laddsf$b$small
2759 #ifndef __mcoldfire__
2760 cmpw IMM (16),d7 | if difference >= 16 swap
2761 #else
2762 cmpl IMM (16),d7 | if difference >= 16 swap
2763 #endif
2764 bge 4f
2765 2:
2766 #ifndef __mcoldfire__
2767 subw IMM (1),d7
2768 #else
2769 subql IMM (1), d7
2770 #endif
2771 3:
2772 #ifndef __mcoldfire__
2773 lsrl IMM (1),d2 | shift right second operand
2774 roxrl IMM (1),d3
2775 dbra d7,3b
2776 #else
2777 lsrl IMM (1),d3
2778 btst IMM (0),d2
2779 beq 10f
2780 bset IMM (31),d3
2781 10: lsrl IMM (1),d2
2782 subql IMM (1), d7
2783 bpl 3b
2784 #endif
2785 bra Laddsf$3
2786 4:
2787 movew d2,d3
2788 swap d3
2789 movew d3,d2
2790 swap d2
2791 #ifndef __mcoldfire__
2792 subw IMM (16),d7
2793 #else
2794 subl IMM (16),d7
2795 #endif
2796 bne 2b | if still more bits, go back to normal case
2797 bra Laddsf$3
2798 5:
2799 #ifndef __mcoldfire__
2800 exg d6,d7 | exchange the exponents
2801 #else
2802 eorl d6,d7
2803 eorl d7,d6
2804 eorl d6,d7
2805 #endif
2806 subl d6,d7 | keep the largest exponent
2807 negl d7 |
2808 #ifndef __mcoldfire__
2809 lsrw IMM (8),d7 | put difference in lower byte
2810 #else
2811 lsrl IMM (8),d7 | put difference in lower byte
2812 #endif
2813 | if difference is too large we don't shift (and exit!) '
2814 #ifndef __mcoldfire__
2815 cmpw IMM (FLT_MANT_DIG+2),d7
2816 #else
2817 cmpl IMM (FLT_MANT_DIG+2),d7
2818 #endif
2819 bge Laddsf$a$small
2820 #ifndef __mcoldfire__
2821 cmpw IMM (16),d7 | if difference >= 16 swap
2822 #else
2823 cmpl IMM (16),d7 | if difference >= 16 swap
2824 #endif
2825 bge 8f
2826 6:
2827 #ifndef __mcoldfire__
2828 subw IMM (1),d7
2829 #else
2830 subl IMM (1),d7
2831 #endif
2832 7:
2833 #ifndef __mcoldfire__
2834 lsrl IMM (1),d0 | shift right first operand
2835 roxrl IMM (1),d1
2836 dbra d7,7b
2837 #else
2838 lsrl IMM (1),d1
2839 btst IMM (0),d0
2840 beq 10f
2841 bset IMM (31),d1
2842 10: lsrl IMM (1),d0
2843 subql IMM (1),d7
2844 bpl 7b
2845 #endif
2846 bra Laddsf$3
2847 8:
2848 movew d0,d1
2849 swap d1
2850 movew d1,d0
2851 swap d0
2852 #ifndef __mcoldfire__
2853 subw IMM (16),d7
2854 #else
2855 subl IMM (16),d7
2856 #endif
2857 bne 6b | if still more bits, go back to normal case
2858 | otherwise we fall through
2859
2860 | Now we have a in d0-d1, b in d2-d3, and the largest exponent in d6 (the
2861 | signs are stored in a0 and a1).
2862
2863 Laddsf$3:
2864 | Here we have to decide whether to add or subtract the numbers
2865 #ifndef __mcoldfire__
2866 exg d6,a0 | get signs back
2867 exg d7,a1 | and save the exponents
2868 #else
2869 movel d6,d4
2870 movel a0,d6
2871 movel d4,a0
2872 movel d7,d4
2873 movel a1,d7
2874 movel d4,a1
2875 #endif
2876 eorl d6,d7 | combine sign bits
2877 bmi Lsubsf$0 | if negative a and b have opposite
2878 | sign so we actually subtract the
2879 | numbers
2880
2881 | Here we have both positive or both negative
2882 #ifndef __mcoldfire__
2883 exg d6,a0 | now we have the exponent in d6
2884 #else
2885 movel d6,d4
2886 movel a0,d6
2887 movel d4,a0
2888 #endif
2889 movel a0,d7 | and sign in d7
2890 andl IMM (0x80000000),d7
2891 | Here we do the addition.
2892 addl d3,d1
2893 addxl d2,d0
2894 | Note: now we have d2, d3, d4 and d5 to play with!
2895
2896 | Put the exponent, in the first byte, in d2, to use the "standard" rounding
2897 | routines:
2898 movel d6,d2
2899 #ifndef __mcoldfire__
2900 lsrw IMM (8),d2
2901 #else
2902 lsrl IMM (8),d2
2903 #endif
2904
2905 | Before rounding normalize so bit #FLT_MANT_DIG is set (we will consider
2906 | the case of denormalized numbers in the rounding routine itself).
2907 | As in the addition (not in the subtraction!) we could have set
2908 | one more bit we check this:
2909 btst IMM (FLT_MANT_DIG+1),d0
2910 beq 1f
2911 #ifndef __mcoldfire__
2912 lsrl IMM (1),d0
2913 roxrl IMM (1),d1
2914 #else
2915 lsrl IMM (1),d1
2916 btst IMM (0),d0
2917 beq 10f
2918 bset IMM (31),d1
2919 10: lsrl IMM (1),d0
2920 #endif
2921 addl IMM (1),d2
2922 1:
2923 lea pc@(Laddsf$4),a0 | to return from rounding routine
2924 PICLEA SYM (_fpCCR),a1 | check the rounding mode
2925 #ifdef __mcoldfire__
2926 clrl d6
2927 #endif
2928 movew a1@(6),d6 | rounding mode in d6
2929 beq Lround$to$nearest
2930 #ifndef __mcoldfire__
2931 cmpw IMM (ROUND_TO_PLUS),d6
2932 #else
2933 cmpl IMM (ROUND_TO_PLUS),d6
2934 #endif
2935 bhi Lround$to$minus
2936 blt Lround$to$zero
2937 bra Lround$to$plus
2938 Laddsf$4:
2939 | Put back the exponent, but check for overflow.
2940 #ifndef __mcoldfire__
2941 cmpw IMM (0xff),d2
2942 #else
2943 cmpl IMM (0xff),d2
2944 #endif
2945 bge 1f
2946 bclr IMM (FLT_MANT_DIG-1),d0
2947 #ifndef __mcoldfire__
2948 lslw IMM (7),d2
2949 #else
2950 lsll IMM (7),d2
2951 #endif
2952 swap d2
2953 orl d2,d0
2954 bra Laddsf$ret
2955 1:
2956 moveq IMM (ADD),d5
2957 bra Lf$overflow
2958
2959 Lsubsf$0:
2960 | We are here if a > 0 and b < 0 (sign bits cleared).
2961 | Here we do the subtraction.
2962 movel d6,d7 | put sign in d7
2963 andl IMM (0x80000000),d7
2964
2965 subl d3,d1 | result in d0-d1
2966 subxl d2,d0 |
2967 beq Laddsf$ret | if zero just exit
2968 bpl 1f | if positive skip the following
2969 bchg IMM (31),d7 | change sign bit in d7
2970 negl d1
2971 negxl d0
2972 1:
2973 #ifndef __mcoldfire__
2974 exg d2,a0 | now we have the exponent in d2
2975 lsrw IMM (8),d2 | put it in the first byte
2976 #else
2977 movel d2,d4
2978 movel a0,d2
2979 movel d4,a0
2980 lsrl IMM (8),d2 | put it in the first byte
2981 #endif
2982
2983 | Now d0-d1 is positive and the sign bit is in d7.
2984
2985 | Note that we do not have to normalize, since in the subtraction bit
2986 | #FLT_MANT_DIG+1 is never set, and denormalized numbers are handled by
2987 | the rounding routines themselves.
2988 lea pc@(Lsubsf$1),a0 | to return from rounding routine
2989 PICLEA SYM (_fpCCR),a1 | check the rounding mode
2990 #ifdef __mcoldfire__
2991 clrl d6
2992 #endif
2993 movew a1@(6),d6 | rounding mode in d6
2994 beq Lround$to$nearest
2995 #ifndef __mcoldfire__
2996 cmpw IMM (ROUND_TO_PLUS),d6
2997 #else
2998 cmpl IMM (ROUND_TO_PLUS),d6
2999 #endif
3000 bhi Lround$to$minus
3001 blt Lround$to$zero
3002 bra Lround$to$plus
3003 Lsubsf$1:
3004 | Put back the exponent (we can't have overflow!). '
3005 bclr IMM (FLT_MANT_DIG-1),d0
3006 #ifndef __mcoldfire__
3007 lslw IMM (7),d2
3008 #else
3009 lsll IMM (7),d2
3010 #endif
3011 swap d2
3012 orl d2,d0
3013 bra Laddsf$ret
3014
3015 | If one of the numbers was too small (difference of exponents >=
3016 | FLT_MANT_DIG+2) we return the other (and now we don't have to '
3017 | check for finiteness or zero).
3018 Laddsf$a$small:
3019 movel a6@(12),d0
3020 PICLEA SYM (_fpCCR),a0
3021 movew IMM (0),a0@
3022 #ifndef __mcoldfire__
3023 moveml sp@+,d2-d7 | restore data registers
3024 #else
3025 moveml sp@,d2-d7
3026 | XXX if frame pointer is ever removed, stack pointer must
3027 | be adjusted here.
3028 #endif
3029 unlk a6 | and return
3030 rts
3031
3032 Laddsf$b$small:
3033 movel a6@(8),d0
3034 PICLEA SYM (_fpCCR),a0
3035 movew IMM (0),a0@
3036 #ifndef __mcoldfire__
3037 moveml sp@+,d2-d7 | restore data registers
3038 #else
3039 moveml sp@,d2-d7
3040 | XXX if frame pointer is ever removed, stack pointer must
3041 | be adjusted here.
3042 #endif
3043 unlk a6 | and return
3044 rts
3045
3046 | If the numbers are denormalized remember to put exponent equal to 1.
3047
3048 Laddsf$a$den:
3049 movel d5,d6 | d5 contains 0x01000000
3050 swap d6
3051 bra Laddsf$1
3052
3053 Laddsf$b$den:
3054 movel d5,d7
3055 swap d7
3056 notl d4 | make d4 into a mask for the fraction
3057 | (this was not executed after the jump)
3058 bra Laddsf$2
3059
3060 | The rest is mainly code for the different results which can be
3061 | returned (checking always for +/-INFINITY and NaN).
3062
3063 Laddsf$b:
3064 | Return b (if a is zero).
3065 movel a6@(12),d0
3066 cmpl IMM (0x80000000),d0 | Check if b is -0
3067 bne 1f
3068 movel a0,d7
3069 andl IMM (0x80000000),d7 | Use the sign of a
3070 clrl d0
3071 bra Laddsf$ret
3072 Laddsf$a:
3073 | Return a (if b is zero).
3074 movel a6@(8),d0
3075 1:
3076 moveq IMM (ADD),d5
3077 | We have to check for NaN and +/-infty.
3078 movel d0,d7
3079 andl IMM (0x80000000),d7 | put sign in d7
3080 bclr IMM (31),d0 | clear sign
3081 cmpl IMM (INFINITY),d0 | check for infty or NaN
3082 bge 2f
3083 movel d0,d0 | check for zero (we do this because we don't '
3084 bne Laddsf$ret | want to return -0 by mistake
3085 bclr IMM (31),d7 | if zero be sure to clear sign
3086 bra Laddsf$ret | if everything OK just return
3087 2:
3088 | The value to be returned is either +/-infty or NaN
3089 andl IMM (0x007fffff),d0 | check for NaN
3090 bne Lf$inop | if mantissa not zero is NaN
3091 bra Lf$infty
3092
3093 Laddsf$ret:
3094 | Normal exit (a and b nonzero, result is not NaN nor +/-infty).
3095 | We have to clear the exception flags (just the exception type).
3096 PICLEA SYM (_fpCCR),a0
3097 movew IMM (0),a0@
3098 orl d7,d0 | put sign bit
3099 #ifndef __mcoldfire__
3100 moveml sp@+,d2-d7 | restore data registers
3101 #else
3102 moveml sp@,d2-d7
3103 | XXX if frame pointer is ever removed, stack pointer must
3104 | be adjusted here.
3105 #endif
3106 unlk a6 | and return
3107 rts
3108
3109 Laddsf$ret$den:
3110 | Return a denormalized number (for addition we don't signal underflow) '
3111 lsrl IMM (1),d0 | remember to shift right back once
3112 bra Laddsf$ret | and return
3113
3114 | Note: when adding two floats of the same sign if either one is
3115 | NaN we return NaN without regard to whether the other is finite or
3116 | not. When subtracting them (i.e., when adding two numbers of
3117 | opposite signs) things are more complicated: if both are INFINITY
3118 | we return NaN, if only one is INFINITY and the other is NaN we return
3119 | NaN, but if it is finite we return INFINITY with the corresponding sign.
3120
3121 Laddsf$nf:
3122 moveq IMM (ADD),d5
3123 | This could be faster but it is not worth the effort, since it is not
3124 | executed very often. We sacrifice speed for clarity here.
3125 movel a6@(8),d0 | get the numbers back (remember that we
3126 movel a6@(12),d1 | did some processing already)
3127 movel IMM (INFINITY),d4 | useful constant (INFINITY)
3128 movel d0,d2 | save sign bits
3129 movel d0,d7 | into d7 as well as we may need the sign
3130 | bit before jumping to LfSinfty
3131 movel d1,d3
3132 bclr IMM (31),d0 | clear sign bits
3133 bclr IMM (31),d1
3134 | We know that one of them is either NaN of +/-INFINITY
3135 | Check for NaN (if either one is NaN return NaN)
3136 cmpl d4,d0 | check first a (d0)
3137 bhi Lf$inop
3138 cmpl d4,d1 | check now b (d1)
3139 bhi Lf$inop
3140 | Now comes the check for +/-INFINITY. We know that both are (maybe not
3141 | finite) numbers, but we have to check if both are infinite whether we
3142 | are adding or subtracting them.
3143 eorl d3,d2 | to check sign bits
3144 bmi 1f
3145 andl IMM (0x80000000),d7 | get (common) sign bit
3146 bra Lf$infty
3147 1:
3148 | We know one (or both) are infinite, so we test for equality between the
3149 | two numbers (if they are equal they have to be infinite both, so we
3150 | return NaN).
3151 cmpl d1,d0 | are both infinite?
3152 beq Lf$inop | if so return NaN
3153
3154 andl IMM (0x80000000),d7 | get a's sign bit '
3155 cmpl d4,d0 | test now for infinity
3156 beq Lf$infty | if a is INFINITY return with this sign
3157 bchg IMM (31),d7 | else we know b is INFINITY and has
3158 bra Lf$infty | the opposite sign
3159
3160 |=============================================================================
3161 | __mulsf3
3162 |=============================================================================
3163
3164 | float __mulsf3(float, float);
3165 FUNC(__mulsf3)
3166 SYM (__mulsf3):
3167 #ifndef __mcoldfire__
3168 link a6,IMM (0)
3169 moveml d2-d7,sp@-
3170 #else
3171 link a6,IMM (-24)
3172 moveml d2-d7,sp@
3173 #endif
3174 movel a6@(8),d0 | get a into d0
3175 movel a6@(12),d1 | and b into d1
3176 movel d0,d7 | d7 will hold the sign of the product
3177 eorl d1,d7 |
3178 andl IMM (0x80000000),d7
3179 movel IMM (INFINITY),d6 | useful constant (+INFINITY)
3180 movel d6,d5 | another (mask for fraction)
3181 notl d5 |
3182 movel IMM (0x00800000),d4 | this is to put hidden bit back
3183 bclr IMM (31),d0 | get rid of a's sign bit '
3184 movel d0,d2 |
3185 beq Lmulsf$a$0 | branch if a is zero
3186 bclr IMM (31),d1 | get rid of b's sign bit '
3187 movel d1,d3 |
3188 beq Lmulsf$b$0 | branch if b is zero
3189 cmpl d6,d0 | is a big?
3190 bhi Lmulsf$inop | if a is NaN return NaN
3191 beq Lmulsf$inf | if a is INFINITY we have to check b
3192 cmpl d6,d1 | now compare b with INFINITY
3193 bhi Lmulsf$inop | is b NaN?
3194 beq Lmulsf$overflow | is b INFINITY?
3195 | Here we have both numbers finite and nonzero (and with no sign bit).
3196 | Now we get the exponents into d2 and d3.
3197 andl d6,d2 | and isolate exponent in d2
3198 beq Lmulsf$a$den | if exponent is zero we have a denormalized
3199 andl d5,d0 | and isolate fraction
3200 orl d4,d0 | and put hidden bit back
3201 swap d2 | I like exponents in the first byte
3202 #ifndef __mcoldfire__
3203 lsrw IMM (7),d2 |
3204 #else
3205 lsrl IMM (7),d2 |
3206 #endif
3207 Lmulsf$1: | number
3208 andl d6,d3 |
3209 beq Lmulsf$b$den |
3210 andl d5,d1 |
3211 orl d4,d1 |
3212 swap d3 |
3213 #ifndef __mcoldfire__
3214 lsrw IMM (7),d3 |
3215 #else
3216 lsrl IMM (7),d3 |
3217 #endif
3218 Lmulsf$2: |
3219 #ifndef __mcoldfire__
3220 addw d3,d2 | add exponents
3221 subw IMM (F_BIAS+1),d2 | and subtract bias (plus one)
3222 #else
3223 addl d3,d2 | add exponents
3224 subl IMM (F_BIAS+1),d2 | and subtract bias (plus one)
3225 #endif
3226
3227 | We are now ready to do the multiplication. The situation is as follows:
3228 | both a and b have bit FLT_MANT_DIG-1 set (even if they were
3229 | denormalized to start with!), which means that in the product
3230 | bit 2*(FLT_MANT_DIG-1) (that is, bit 2*FLT_MANT_DIG-2-32 of the
3231 | high long) is set.
3232
3233 | To do the multiplication let us move the number a little bit around ...
3234 movel d1,d6 | second operand in d6
3235 movel d0,d5 | first operand in d4-d5
3236 movel IMM (0),d4
3237 movel d4,d1 | the sums will go in d0-d1
3238 movel d4,d0
3239
3240 | now bit FLT_MANT_DIG-1 becomes bit 31:
3241 lsll IMM (31-FLT_MANT_DIG+1),d6
3242
3243 | Start the loop (we loop #FLT_MANT_DIG times):
3244 moveq IMM (FLT_MANT_DIG-1),d3
3245 1: addl d1,d1 | shift sum
3246 addxl d0,d0
3247 lsll IMM (1),d6 | get bit bn
3248 bcc 2f | if not set skip sum
3249 addl d5,d1 | add a
3250 addxl d4,d0
3251 2:
3252 #ifndef __mcoldfire__
3253 dbf d3,1b | loop back
3254 #else
3255 subql IMM (1),d3
3256 bpl 1b
3257 #endif
3258
3259 | Now we have the product in d0-d1, with bit (FLT_MANT_DIG - 1) + FLT_MANT_DIG
3260 | (mod 32) of d0 set. The first thing to do now is to normalize it so bit
3261 | FLT_MANT_DIG is set (to do the rounding).
3262 #ifndef __mcoldfire__
3263 rorl IMM (6),d1
3264 swap d1
3265 movew d1,d3
3266 andw IMM (0x03ff),d3
3267 andw IMM (0xfd00),d1
3268 #else
3269 movel d1,d3
3270 lsll IMM (8),d1
3271 addl d1,d1
3272 addl d1,d1
3273 moveq IMM (22),d5
3274 lsrl d5,d3
3275 orl d3,d1
3276 andl IMM (0xfffffd00),d1
3277 #endif
3278 lsll IMM (8),d0
3279 addl d0,d0
3280 addl d0,d0
3281 #ifndef __mcoldfire__
3282 orw d3,d0
3283 #else
3284 orl d3,d0
3285 #endif
3286
3287 moveq IMM (MULTIPLY),d5
3288
3289 btst IMM (FLT_MANT_DIG+1),d0
3290 beq Lround$exit
3291 #ifndef __mcoldfire__
3292 lsrl IMM (1),d0
3293 roxrl IMM (1),d1
3294 addw IMM (1),d2
3295 #else
3296 lsrl IMM (1),d1
3297 btst IMM (0),d0
3298 beq 10f
3299 bset IMM (31),d1
3300 10: lsrl IMM (1),d0
3301 addql IMM (1),d2
3302 #endif
3303 bra Lround$exit
3304
3305 Lmulsf$inop:
3306 moveq IMM (MULTIPLY),d5
3307 bra Lf$inop
3308
3309 Lmulsf$overflow:
3310 moveq IMM (MULTIPLY),d5
3311 bra Lf$overflow
3312
3313 Lmulsf$inf:
3314 moveq IMM (MULTIPLY),d5
3315 | If either is NaN return NaN; else both are (maybe infinite) numbers, so
3316 | return INFINITY with the correct sign (which is in d7).
3317 cmpl d6,d1 | is b NaN?
3318 bhi Lf$inop | if so return NaN
3319 bra Lf$overflow | else return +/-INFINITY
3320
3321 | If either number is zero return zero, unless the other is +/-INFINITY,
3322 | or NaN, in which case we return NaN.
3323 Lmulsf$b$0:
3324 | Here d1 (==b) is zero.
3325 movel a6@(8),d1 | get a again to check for non-finiteness
3326 bra 1f
3327 Lmulsf$a$0:
3328 movel a6@(12),d1 | get b again to check for non-finiteness
3329 1: bclr IMM (31),d1 | clear sign bit
3330 cmpl IMM (INFINITY),d1 | and check for a large exponent
3331 bge Lf$inop | if b is +/-INFINITY or NaN return NaN
3332 movel d7,d0 | else return signed zero
3333 PICLEA SYM (_fpCCR),a0 |
3334 movew IMM (0),a0@ |
3335 #ifndef __mcoldfire__
3336 moveml sp@+,d2-d7 |
3337 #else
3338 moveml sp@,d2-d7
3339 | XXX if frame pointer is ever removed, stack pointer must
3340 | be adjusted here.
3341 #endif
3342 unlk a6 |
3343 rts |
3344
3345 | If a number is denormalized we put an exponent of 1 but do not put the
3346 | hidden bit back into the fraction; instead we shift left until bit 23
3347 | (the hidden bit) is set, adjusting the exponent accordingly. We do this
3348 | to ensure that the product of the fractions is close to 1.
3349 Lmulsf$a$den:
3350 movel IMM (1),d2
3351 andl d5,d0
3352 1: addl d0,d0 | shift a left (until bit 23 is set)
3353 #ifndef __mcoldfire__
3354 subw IMM (1),d2 | and adjust exponent
3355 #else
3356 subql IMM (1),d2 | and adjust exponent
3357 #endif
3358 btst IMM (FLT_MANT_DIG-1),d0
3359 bne Lmulsf$1 |
3360 bra 1b | else loop back
3361
3362 Lmulsf$b$den:
3363 movel IMM (1),d3
3364 andl d5,d1
3365 1: addl d1,d1 | shift b left until bit 23 is set
3366 #ifndef __mcoldfire__
3367 subw IMM (1),d3 | and adjust exponent
3368 #else
3369 subql IMM (1),d3 | and adjust exponent
3370 #endif
3371 btst IMM (FLT_MANT_DIG-1),d1
3372 bne Lmulsf$2 |
3373 bra 1b | else loop back
3374
3375 |=============================================================================
3376 | __divsf3
3377 |=============================================================================
3378
3379 | float __divsf3(float, float);
3380 FUNC(__divsf3)
3381 SYM (__divsf3):
3382 #ifndef __mcoldfire__
3383 link a6,IMM (0)
3384 moveml d2-d7,sp@-
3385 #else
3386 link a6,IMM (-24)
3387 moveml d2-d7,sp@
3388 #endif
3389 movel a6@(8),d0 | get a into d0
3390 movel a6@(12),d1 | and b into d1
3391 movel d0,d7 | d7 will hold the sign of the result
3392 eorl d1,d7 |
3393 andl IMM (0x80000000),d7 |
3394 movel IMM (INFINITY),d6 | useful constant (+INFINITY)
3395 movel d6,d5 | another (mask for fraction)
3396 notl d5 |
3397 movel IMM (0x00800000),d4 | this is to put hidden bit back
3398 bclr IMM (31),d0 | get rid of a's sign bit '
3399 movel d0,d2 |
3400 beq Ldivsf$a$0 | branch if a is zero
3401 bclr IMM (31),d1 | get rid of b's sign bit '
3402 movel d1,d3 |
3403 beq Ldivsf$b$0 | branch if b is zero
3404 cmpl d6,d0 | is a big?
3405 bhi Ldivsf$inop | if a is NaN return NaN
3406 beq Ldivsf$inf | if a is INFINITY we have to check b
3407 cmpl d6,d1 | now compare b with INFINITY
3408 bhi Ldivsf$inop | if b is NaN return NaN
3409 beq Ldivsf$underflow
3410 | Here we have both numbers finite and nonzero (and with no sign bit).
3411 | Now we get the exponents into d2 and d3 and normalize the numbers to
3412 | ensure that the ratio of the fractions is close to 1. We do this by
3413 | making sure that bit #FLT_MANT_DIG-1 (hidden bit) is set.
3414 andl d6,d2 | and isolate exponent in d2
3415 beq Ldivsf$a$den | if exponent is zero we have a denormalized
3416 andl d5,d0 | and isolate fraction
3417 orl d4,d0 | and put hidden bit back
3418 swap d2 | I like exponents in the first byte
3419 #ifndef __mcoldfire__
3420 lsrw IMM (7),d2 |
3421 #else
3422 lsrl IMM (7),d2 |
3423 #endif
3424 Ldivsf$1: |
3425 andl d6,d3 |
3426 beq Ldivsf$b$den |
3427 andl d5,d1 |
3428 orl d4,d1 |
3429 swap d3 |
3430 #ifndef __mcoldfire__
3431 lsrw IMM (7),d3 |
3432 #else
3433 lsrl IMM (7),d3 |
3434 #endif
3435 Ldivsf$2: |
3436 #ifndef __mcoldfire__
3437 subw d3,d2 | subtract exponents
3438 addw IMM (F_BIAS),d2 | and add bias
3439 #else
3440 subl d3,d2 | subtract exponents
3441 addl IMM (F_BIAS),d2 | and add bias
3442 #endif
3443
3444 | We are now ready to do the division. We have prepared things in such a way
3445 | that the ratio of the fractions will be less than 2 but greater than 1/2.
3446 | At this point the registers in use are:
3447 | d0 holds a (first operand, bit FLT_MANT_DIG=0, bit FLT_MANT_DIG-1=1)
3448 | d1 holds b (second operand, bit FLT_MANT_DIG=1)
3449 | d2 holds the difference of the exponents, corrected by the bias
3450 | d7 holds the sign of the ratio
3451 | d4, d5, d6 hold some constants
3452 movel d7,a0 | d6-d7 will hold the ratio of the fractions
3453 movel IMM (0),d6 |
3454 movel d6,d7
3455
3456 moveq IMM (FLT_MANT_DIG+1),d3
3457 1: cmpl d0,d1 | is a < b?
3458 bhi 2f |
3459 bset d3,d6 | set a bit in d6
3460 subl d1,d0 | if a >= b a <-- a-b
3461 beq 3f | if a is zero, exit
3462 2: addl d0,d0 | multiply a by 2
3463 #ifndef __mcoldfire__
3464 dbra d3,1b
3465 #else
3466 subql IMM (1),d3
3467 bpl 1b
3468 #endif
3469
3470 | Now we keep going to set the sticky bit ...
3471 moveq IMM (FLT_MANT_DIG),d3
3472 1: cmpl d0,d1
3473 ble 2f
3474 addl d0,d0
3475 #ifndef __mcoldfire__
3476 dbra d3,1b
3477 #else
3478 subql IMM(1),d3
3479 bpl 1b
3480 #endif
3481 movel IMM (0),d1
3482 bra 3f
3483 2: movel IMM (0),d1
3484 #ifndef __mcoldfire__
3485 subw IMM (FLT_MANT_DIG),d3
3486 addw IMM (31),d3
3487 #else
3488 subl IMM (FLT_MANT_DIG),d3
3489 addl IMM (31),d3
3490 #endif
3491 bset d3,d1
3492 3:
3493 movel d6,d0 | put the ratio in d0-d1
3494 movel a0,d7 | get sign back
3495
3496 | Because of the normalization we did before we are guaranteed that
3497 | d0 is smaller than 2^26 but larger than 2^24. Thus bit 26 is not set,
3498 | bit 25 could be set, and if it is not set then bit 24 is necessarily set.
3499 btst IMM (FLT_MANT_DIG+1),d0
3500 beq 1f | if it is not set, then bit 24 is set
3501 lsrl IMM (1),d0 |
3502 #ifndef __mcoldfire__
3503 addw IMM (1),d2 |
3504 #else
3505 addl IMM (1),d2 |
3506 #endif
3507 1:
3508 | Now round, check for over- and underflow, and exit.
3509 moveq IMM (DIVIDE),d5
3510 bra Lround$exit
3511
3512 Ldivsf$inop:
3513 moveq IMM (DIVIDE),d5
3514 bra Lf$inop
3515
3516 Ldivsf$overflow:
3517 moveq IMM (DIVIDE),d5
3518 bra Lf$overflow
3519
3520 Ldivsf$underflow:
3521 moveq IMM (DIVIDE),d5
3522 bra Lf$underflow
3523
3524 Ldivsf$a$0:
3525 moveq IMM (DIVIDE),d5
3526 | If a is zero check to see whether b is zero also. In that case return
3527 | NaN; then check if b is NaN, and return NaN also in that case. Else
3528 | return a properly signed zero.
3529 andl IMM (0x7fffffff),d1 | clear sign bit and test b
3530 beq Lf$inop | if b is also zero return NaN
3531 cmpl IMM (INFINITY),d1 | check for NaN
3532 bhi Lf$inop |
3533 movel d7,d0 | else return signed zero
3534 PICLEA SYM (_fpCCR),a0 |
3535 movew IMM (0),a0@ |
3536 #ifndef __mcoldfire__
3537 moveml sp@+,d2-d7 |
3538 #else
3539 moveml sp@,d2-d7 |
3540 | XXX if frame pointer is ever removed, stack pointer must
3541 | be adjusted here.
3542 #endif
3543 unlk a6 |
3544 rts |
3545
3546 Ldivsf$b$0:
3547 moveq IMM (DIVIDE),d5
3548 | If we got here a is not zero. Check if a is NaN; in that case return NaN,
3549 | else return +/-INFINITY. Remember that a is in d0 with the sign bit
3550 | cleared already.
3551 cmpl IMM (INFINITY),d0 | compare d0 with INFINITY
3552 bhi Lf$inop | if larger it is NaN
3553 bra Lf$div$0 | else signal DIVIDE_BY_ZERO
3554
3555 Ldivsf$inf:
3556 moveq IMM (DIVIDE),d5
3557 | If a is INFINITY we have to check b
3558 cmpl IMM (INFINITY),d1 | compare b with INFINITY
3559 bge Lf$inop | if b is NaN or INFINITY return NaN
3560 bra Lf$overflow | else return overflow
3561
3562 | If a number is denormalized we put an exponent of 1 but do not put the
3563 | bit back into the fraction.
3564 Ldivsf$a$den:
3565 movel IMM (1),d2
3566 andl d5,d0
3567 1: addl d0,d0 | shift a left until bit FLT_MANT_DIG-1 is set
3568 #ifndef __mcoldfire__
3569 subw IMM (1),d2 | and adjust exponent
3570 #else
3571 subl IMM (1),d2 | and adjust exponent
3572 #endif
3573 btst IMM (FLT_MANT_DIG-1),d0
3574 bne Ldivsf$1
3575 bra 1b
3576
3577 Ldivsf$b$den:
3578 movel IMM (1),d3
3579 andl d5,d1
3580 1: addl d1,d1 | shift b left until bit FLT_MANT_DIG is set
3581 #ifndef __mcoldfire__
3582 subw IMM (1),d3 | and adjust exponent
3583 #else
3584 subl IMM (1),d3 | and adjust exponent
3585 #endif
3586 btst IMM (FLT_MANT_DIG-1),d1
3587 bne Ldivsf$2
3588 bra 1b
3589
3590 Lround$exit:
3591 | This is a common exit point for __mulsf3 and __divsf3.
3592
3593 | First check for underlow in the exponent:
3594 #ifndef __mcoldfire__
3595 cmpw IMM (-FLT_MANT_DIG-1),d2
3596 #else
3597 cmpl IMM (-FLT_MANT_DIG-1),d2
3598 #endif
3599 blt Lf$underflow
3600 | It could happen that the exponent is less than 1, in which case the
3601 | number is denormalized. In this case we shift right and adjust the
3602 | exponent until it becomes 1 or the fraction is zero (in the latter case
3603 | we signal underflow and return zero).
3604 movel IMM (0),d6 | d6 is used temporarily
3605 #ifndef __mcoldfire__
3606 cmpw IMM (1),d2 | if the exponent is less than 1 we
3607 #else
3608 cmpl IMM (1),d2 | if the exponent is less than 1 we
3609 #endif
3610 bge 2f | have to shift right (denormalize)
3611 1:
3612 #ifndef __mcoldfire__
3613 addw IMM (1),d2 | adjust the exponent
3614 lsrl IMM (1),d0 | shift right once
3615 roxrl IMM (1),d1 |
3616 roxrl IMM (1),d6 | d6 collect bits we would lose otherwise
3617 cmpw IMM (1),d2 | is the exponent 1 already?
3618 #else
3619 addql IMM (1),d2 | adjust the exponent
3620 lsrl IMM (1),d6
3621 btst IMM (0),d1
3622 beq 11f
3623 bset IMM (31),d6
3624 11: lsrl IMM (1),d1
3625 btst IMM (0),d0
3626 beq 10f
3627 bset IMM (31),d1
3628 10: lsrl IMM (1),d0
3629 cmpl IMM (1),d2 | is the exponent 1 already?
3630 #endif
3631 beq 2f | if not loop back
3632 bra 1b |
3633 bra Lf$underflow | safety check, shouldn't execute '
3634 2: orl d6,d1 | this is a trick so we don't lose '
3635 | the extra bits which were flushed right
3636 | Now call the rounding routine (which takes care of denormalized numbers):
3637 lea pc@(Lround$0),a0 | to return from rounding routine
3638 PICLEA SYM (_fpCCR),a1 | check the rounding mode
3639 #ifdef __mcoldfire__
3640 clrl d6
3641 #endif
3642 movew a1@(6),d6 | rounding mode in d6
3643 beq Lround$to$nearest
3644 #ifndef __mcoldfire__
3645 cmpw IMM (ROUND_TO_PLUS),d6
3646 #else
3647 cmpl IMM (ROUND_TO_PLUS),d6
3648 #endif
3649 bhi Lround$to$minus
3650 blt Lround$to$zero
3651 bra Lround$to$plus
3652 Lround$0:
3653 | Here we have a correctly rounded result (either normalized or denormalized).
3654
3655 | Here we should have either a normalized number or a denormalized one, and
3656 | the exponent is necessarily larger or equal to 1 (so we don't have to '
3657 | check again for underflow!). We have to check for overflow or for a
3658 | denormalized number (which also signals underflow).
3659 | Check for overflow (i.e., exponent >= 255).
3660 #ifndef __mcoldfire__
3661 cmpw IMM (0x00ff),d2
3662 #else
3663 cmpl IMM (0x00ff),d2
3664 #endif
3665 bge Lf$overflow
3666 | Now check for a denormalized number (exponent==0).
3667 movew d2,d2
3668 beq Lf$den
3669 1:
3670 | Put back the exponents and sign and return.
3671 #ifndef __mcoldfire__
3672 lslw IMM (7),d2 | exponent back to fourth byte
3673 #else
3674 lsll IMM (7),d2 | exponent back to fourth byte
3675 #endif
3676 bclr IMM (FLT_MANT_DIG-1),d0
3677 swap d0 | and put back exponent
3678 #ifndef __mcoldfire__
3679 orw d2,d0 |
3680 #else
3681 orl d2,d0
3682 #endif
3683 swap d0 |
3684 orl d7,d0 | and sign also
3685
3686 PICLEA SYM (_fpCCR),a0
3687 movew IMM (0),a0@
3688 #ifndef __mcoldfire__
3689 moveml sp@+,d2-d7
3690 #else
3691 moveml sp@,d2-d7
3692 | XXX if frame pointer is ever removed, stack pointer must
3693 | be adjusted here.
3694 #endif
3695 unlk a6
3696 rts
3697
3698 |=============================================================================
3699 | __negsf2
3700 |=============================================================================
3701
3702 | This is trivial and could be shorter if we didn't bother checking for NaN '
3703 | and +/-INFINITY.
3704
3705 | float __negsf2(float);
3706 FUNC(__negsf2)
3707 SYM (__negsf2):
3708 #ifndef __mcoldfire__
3709 link a6,IMM (0)
3710 moveml d2-d7,sp@-
3711 #else
3712 link a6,IMM (-24)
3713 moveml d2-d7,sp@
3714 #endif
3715 moveq IMM (NEGATE),d5
3716 movel a6@(8),d0 | get number to negate in d0
3717 bchg IMM (31),d0 | negate
3718 movel d0,d1 | make a positive copy
3719 bclr IMM (31),d1 |
3720 tstl d1 | check for zero
3721 beq 2f | if zero (either sign) return +zero
3722 cmpl IMM (INFINITY),d1 | compare to +INFINITY
3723 blt 1f |
3724 bhi Lf$inop | if larger (fraction not zero) is NaN
3725 movel d0,d7 | else get sign and return INFINITY
3726 andl IMM (0x80000000),d7
3727 bra Lf$infty
3728 1: PICLEA SYM (_fpCCR),a0
3729 movew IMM (0),a0@
3730 #ifndef __mcoldfire__
3731 moveml sp@+,d2-d7
3732 #else
3733 moveml sp@,d2-d7
3734 | XXX if frame pointer is ever removed, stack pointer must
3735 | be adjusted here.
3736 #endif
3737 unlk a6
3738 rts
3739 2: bclr IMM (31),d0
3740 bra 1b
3741
3742 |=============================================================================
3743 | __cmpsf2
3744 |=============================================================================
3745
3746 GREATER = 1
3747 LESS = -1
3748 EQUAL = 0
3749
3750 | int __cmpsf2_internal(float, float, int);
3751 SYM (__cmpsf2_internal):
3752 #ifndef __mcoldfire__
3753 link a6,IMM (0)
3754 moveml d2-d7,sp@- | save registers
3755 #else
3756 link a6,IMM (-24)
3757 moveml d2-d7,sp@
3758 #endif
3759 moveq IMM (COMPARE),d5
3760 movel a6@(8),d0 | get first operand
3761 movel a6@(12),d1 | get second operand
3762 | Check if either is NaN, and in that case return garbage and signal
3763 | INVALID_OPERATION. Check also if either is zero, and clear the signs
3764 | if necessary.
3765 movel d0,d6
3766 andl IMM (0x7fffffff),d0
3767 beq Lcmpsf$a$0
3768 cmpl IMM (0x7f800000),d0
3769 bhi Lcmpf$inop
3770 Lcmpsf$1:
3771 movel d1,d7
3772 andl IMM (0x7fffffff),d1
3773 beq Lcmpsf$b$0
3774 cmpl IMM (0x7f800000),d1
3775 bhi Lcmpf$inop
3776 Lcmpsf$2:
3777 | Check the signs
3778 eorl d6,d7
3779 bpl 1f
3780 | If the signs are not equal check if a >= 0
3781 tstl d6
3782 bpl Lcmpsf$a$gt$b | if (a >= 0 && b < 0) => a > b
3783 bmi Lcmpsf$b$gt$a | if (a < 0 && b >= 0) => a < b
3784 1:
3785 | If the signs are equal check for < 0
3786 tstl d6
3787 bpl 1f
3788 | If both are negative exchange them
3789 #ifndef __mcoldfire__
3790 exg d0,d1
3791 #else
3792 movel d0,d7
3793 movel d1,d0
3794 movel d7,d1
3795 #endif
3796 1:
3797 | Now that they are positive we just compare them as longs (does this also
3798 | work for denormalized numbers?).
3799 cmpl d0,d1
3800 bhi Lcmpsf$b$gt$a | |b| > |a|
3801 bne Lcmpsf$a$gt$b | |b| < |a|
3802 | If we got here a == b.
3803 movel IMM (EQUAL),d0
3804 #ifndef __mcoldfire__
3805 moveml sp@+,d2-d7 | put back the registers
3806 #else
3807 moveml sp@,d2-d7
3808 #endif
3809 unlk a6
3810 rts
3811 Lcmpsf$a$gt$b:
3812 movel IMM (GREATER),d0
3813 #ifndef __mcoldfire__
3814 moveml sp@+,d2-d7 | put back the registers
3815 #else
3816 moveml sp@,d2-d7
3817 | XXX if frame pointer is ever removed, stack pointer must
3818 | be adjusted here.
3819 #endif
3820 unlk a6
3821 rts
3822 Lcmpsf$b$gt$a:
3823 movel IMM (LESS),d0
3824 #ifndef __mcoldfire__
3825 moveml sp@+,d2-d7 | put back the registers
3826 #else
3827 moveml sp@,d2-d7
3828 | XXX if frame pointer is ever removed, stack pointer must
3829 | be adjusted here.
3830 #endif
3831 unlk a6
3832 rts
3833
3834 Lcmpsf$a$0:
3835 bclr IMM (31),d6
3836 bra Lcmpsf$1
3837 Lcmpsf$b$0:
3838 bclr IMM (31),d7
3839 bra Lcmpsf$2
3840
3841 Lcmpf$inop:
3842 movl a6@(16),d0
3843 moveq IMM (INEXACT_RESULT+INVALID_OPERATION),d7
3844 moveq IMM (SINGLE_FLOAT),d6
3845 PICJUMP $_exception_handler
3846
3847 | int __cmpsf2(float, float);
3848 FUNC(__cmpsf2)
3849 SYM (__cmpsf2):
3850 link a6,IMM (0)
3851 pea 1
3852 movl a6@(12),sp@-
3853 movl a6@(8),sp@-
3854 PICCALL SYM (__cmpsf2_internal)
3855 unlk a6
3856 rts
3857
3858 |=============================================================================
3859 | rounding routines
3860 |=============================================================================
3861
3862 | The rounding routines expect the number to be normalized in registers
3863 | d0-d1, with the exponent in register d2. They assume that the
3864 | exponent is larger or equal to 1. They return a properly normalized number
3865 | if possible, and a denormalized number otherwise. The exponent is returned
3866 | in d2.
3867
3868 Lround$to$nearest:
3869 | We now normalize as suggested by D. Knuth ("Seminumerical Algorithms"):
3870 | Here we assume that the exponent is not too small (this should be checked
3871 | before entering the rounding routine), but the number could be denormalized.
3872
3873 | Check for denormalized numbers:
3874 1: btst IMM (FLT_MANT_DIG),d0
3875 bne 2f | if set the number is normalized
3876 | Normalize shifting left until bit #FLT_MANT_DIG is set or the exponent
3877 | is one (remember that a denormalized number corresponds to an
3878 | exponent of -F_BIAS+1).
3879 #ifndef __mcoldfire__
3880 cmpw IMM (1),d2 | remember that the exponent is at least one
3881 #else
3882 cmpl IMM (1),d2 | remember that the exponent is at least one
3883 #endif
3884 beq 2f | an exponent of one means denormalized
3885 addl d1,d1 | else shift and adjust the exponent
3886 addxl d0,d0 |
3887 #ifndef __mcoldfire__
3888 dbra d2,1b |
3889 #else
3890 subql IMM (1),d2
3891 bpl 1b
3892 #endif
3893 2:
3894 | Now round: we do it as follows: after the shifting we can write the
3895 | fraction part as f + delta, where 1 < f < 2^25, and 0 <= delta <= 2.
3896 | If delta < 1, do nothing. If delta > 1, add 1 to f.
3897 | If delta == 1, we make sure the rounded number will be even (odd?)
3898 | (after shifting).
3899 btst IMM (0),d0 | is delta < 1?
3900 beq 2f | if so, do not do anything
3901 tstl d1 | is delta == 1?
3902 bne 1f | if so round to even
3903 movel d0,d1 |
3904 andl IMM (2),d1 | bit 1 is the last significant bit
3905 addl d1,d0 |
3906 bra 2f |
3907 1: movel IMM (1),d1 | else add 1
3908 addl d1,d0 |
3909 | Shift right once (because we used bit #FLT_MANT_DIG!).
3910 2: lsrl IMM (1),d0
3911 | Now check again bit #FLT_MANT_DIG (rounding could have produced a
3912 | 'fraction overflow' ...).
3913 btst IMM (FLT_MANT_DIG),d0
3914 beq 1f
3915 lsrl IMM (1),d0
3916 #ifndef __mcoldfire__
3917 addw IMM (1),d2
3918 #else
3919 addql IMM (1),d2
3920 #endif
3921 1:
3922 | If bit #FLT_MANT_DIG-1 is clear we have a denormalized number, so we
3923 | have to put the exponent to zero and return a denormalized number.
3924 btst IMM (FLT_MANT_DIG-1),d0
3925 beq 1f
3926 jmp a0@
3927 1: movel IMM (0),d2
3928 jmp a0@
3929
3930 Lround$to$zero:
3931 Lround$to$plus:
3932 Lround$to$minus:
3933 jmp a0@
3934 #endif /* L_float */
3935
3936 | gcc expects the routines __eqdf2, __nedf2, __gtdf2, __gedf2,
3937 | __ledf2, __ltdf2 to all return the same value as a direct call to
3938 | __cmpdf2 would. In this implementation, each of these routines
3939 | simply calls __cmpdf2. It would be more efficient to give the
3940 | __cmpdf2 routine several names, but separating them out will make it
3941 | easier to write efficient versions of these routines someday.
3942 | If the operands recompare unordered unordered __gtdf2 and __gedf2 return -1.
3943 | The other routines return 1.
3944
3945 #ifdef L_eqdf2
3946 .text
3947 FUNC(__eqdf2)
3948 .globl SYM (__eqdf2)
3949 SYM (__eqdf2):
3950 link a6,IMM (0)
3951 pea 1
3952 movl a6@(20),sp@-
3953 movl a6@(16),sp@-
3954 movl a6@(12),sp@-
3955 movl a6@(8),sp@-
3956 PICCALL SYM (__cmpdf2_internal)
3957 unlk a6
3958 rts
3959 #endif /* L_eqdf2 */
3960
3961 #ifdef L_nedf2
3962 .text
3963 FUNC(__nedf2)
3964 .globl SYM (__nedf2)
3965 SYM (__nedf2):
3966 link a6,IMM (0)
3967 pea 1
3968 movl a6@(20),sp@-
3969 movl a6@(16),sp@-
3970 movl a6@(12),sp@-
3971 movl a6@(8),sp@-
3972 PICCALL SYM (__cmpdf2_internal)
3973 unlk a6
3974 rts
3975 #endif /* L_nedf2 */
3976
3977 #ifdef L_gtdf2
3978 .text
3979 FUNC(__gtdf2)
3980 .globl SYM (__gtdf2)
3981 SYM (__gtdf2):
3982 link a6,IMM (0)
3983 pea -1
3984 movl a6@(20),sp@-
3985 movl a6@(16),sp@-
3986 movl a6@(12),sp@-
3987 movl a6@(8),sp@-
3988 PICCALL SYM (__cmpdf2_internal)
3989 unlk a6
3990 rts
3991 #endif /* L_gtdf2 */
3992
3993 #ifdef L_gedf2
3994 .text
3995 FUNC(__gedf2)
3996 .globl SYM (__gedf2)
3997 SYM (__gedf2):
3998 link a6,IMM (0)
3999 pea -1
4000 movl a6@(20),sp@-
4001 movl a6@(16),sp@-
4002 movl a6@(12),sp@-
4003 movl a6@(8),sp@-
4004 PICCALL SYM (__cmpdf2_internal)
4005 unlk a6
4006 rts
4007 #endif /* L_gedf2 */
4008
4009 #ifdef L_ltdf2
4010 .text
4011 FUNC(__ltdf2)
4012 .globl SYM (__ltdf2)
4013 SYM (__ltdf2):
4014 link a6,IMM (0)
4015 pea 1
4016 movl a6@(20),sp@-
4017 movl a6@(16),sp@-
4018 movl a6@(12),sp@-
4019 movl a6@(8),sp@-
4020 PICCALL SYM (__cmpdf2_internal)
4021 unlk a6
4022 rts
4023 #endif /* L_ltdf2 */
4024
4025 #ifdef L_ledf2
4026 .text
4027 FUNC(__ledf2)
4028 .globl SYM (__ledf2)
4029 SYM (__ledf2):
4030 link a6,IMM (0)
4031 pea 1
4032 movl a6@(20),sp@-
4033 movl a6@(16),sp@-
4034 movl a6@(12),sp@-
4035 movl a6@(8),sp@-
4036 PICCALL SYM (__cmpdf2_internal)
4037 unlk a6
4038 rts
4039 #endif /* L_ledf2 */
4040
4041 | The comments above about __eqdf2, et. al., also apply to __eqsf2,
4042 | et. al., except that the latter call __cmpsf2 rather than __cmpdf2.
4043
4044 #ifdef L_eqsf2
4045 .text
4046 FUNC(__eqsf2)
4047 .globl SYM (__eqsf2)
4048 SYM (__eqsf2):
4049 link a6,IMM (0)
4050 pea 1
4051 movl a6@(12),sp@-
4052 movl a6@(8),sp@-
4053 PICCALL SYM (__cmpsf2_internal)
4054 unlk a6
4055 rts
4056 #endif /* L_eqsf2 */
4057
4058 #ifdef L_nesf2
4059 .text
4060 FUNC(__nesf2)
4061 .globl SYM (__nesf2)
4062 SYM (__nesf2):
4063 link a6,IMM (0)
4064 pea 1
4065 movl a6@(12),sp@-
4066 movl a6@(8),sp@-
4067 PICCALL SYM (__cmpsf2_internal)
4068 unlk a6
4069 rts
4070 #endif /* L_nesf2 */
4071
4072 #ifdef L_gtsf2
4073 .text
4074 FUNC(__gtsf2)
4075 .globl SYM (__gtsf2)
4076 SYM (__gtsf2):
4077 link a6,IMM (0)
4078 pea -1
4079 movl a6@(12),sp@-
4080 movl a6@(8),sp@-
4081 PICCALL SYM (__cmpsf2_internal)
4082 unlk a6
4083 rts
4084 #endif /* L_gtsf2 */
4085
4086 #ifdef L_gesf2
4087 .text
4088 FUNC(__gesf2)
4089 .globl SYM (__gesf2)
4090 SYM (__gesf2):
4091 link a6,IMM (0)
4092 pea -1
4093 movl a6@(12),sp@-
4094 movl a6@(8),sp@-
4095 PICCALL SYM (__cmpsf2_internal)
4096 unlk a6
4097 rts
4098 #endif /* L_gesf2 */
4099
4100 #ifdef L_ltsf2
4101 .text
4102 FUNC(__ltsf2)
4103 .globl SYM (__ltsf2)
4104 SYM (__ltsf2):
4105 link a6,IMM (0)
4106 pea 1
4107 movl a6@(12),sp@-
4108 movl a6@(8),sp@-
4109 PICCALL SYM (__cmpsf2_internal)
4110 unlk a6
4111 rts
4112 #endif /* L_ltsf2 */
4113
4114 #ifdef L_lesf2
4115 .text
4116 FUNC(__lesf2)
4117 .globl SYM (__lesf2)
4118 SYM (__lesf2):
4119 link a6,IMM (0)
4120 pea 1
4121 movl a6@(12),sp@-
4122 movl a6@(8),sp@-
4123 PICCALL SYM (__cmpsf2_internal)
4124 unlk a6
4125 rts
4126 #endif /* L_lesf2 */
4127
4128 #if defined (__ELF__) && defined (__linux__)
4129 /* Make stack non-executable for ELF linux targets. */
4130 .section .note.GNU-stack,"",@progbits
4131 #endif