2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / config / ip2k / libgcc.S
blob5be482f9ca763a6cec5886bfaf8788e536bb3f0c
2 ; Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
3 ; Contributed by Red Hat, Inc and Ubicom, Inc.
5 ; This file is part of GCC.
7 ; GCC is free software; you can redistribute it and/or modify
8 ; it under the terms of the GNU General Public License as published by
9 ; the Free Software Foundation; either version 2, or (at your option)
10 ; any later version.
12 ; In addition to the permissions in the GNU General Public License, the
13 ; Free Software Foundation gives you unlimited permission to link the
14 ; compiled version of this file with other programs, and to distribute
15 ; those programs without any restriction coming from the use of this
16 ; file.  (The General Public License restrictions do apply in other
17 ; respects; for example, they cover modification of the file, and
18 ; distribution when not linked into another program.)
20 ; GCC is distributed in the hope that it will be useful,
21 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 ; GNU General Public License for more details.
25 ; You should have received a copy of the GNU General Public License
26 ; along with GCC; see the file COPYING.  If not, write to
27 ; the Free Software Foundation, 59 Temple Place - Suite 330,
28 ; Boston, MA 02111-1307, USA.  */
30 /*******************************************************
31         load byte from arbitrary memory
32         address passed in first bank register, result in W
34 *******************************************************/
35         .macro  movb    to, from
36         mov     w, \from
37         mov     \to, w
38         .endm
41 #if defined (L_indcall)
42 /* __indcall - given register containing an address, call the function
43  *      at that address.
44  */
46         .sect   .pram.libgcc,"ax"
47         .global __indcall
48         .func   _indcall,__indcall
50 __indcall:
51         page    1f
52         call    1f
53 1:      pop     callh                   ; Get the call target
54         pop     calll
55         ret                             ; Transfer to new function
57         .endfunc
58 #endif
61 #if defined (L_mulhi3)
62         .sect   .pram.libgcc,"ax"
63         .global __mulhi3
64         .func   _mulhi3, __mulhi3
66 __mulhi3:
67         mov     w, 2(SP)                ; First upper half partial product
68         mulu    w, 3(SP)
69         mov     3(SP), w
70         mov     w, 1(SP)                ; Second upper half partial product
71         mulu    w, 4(SP)
72         add     3(SP), w
73         mov     w, 2(SP)                ; Lower half partial product
74         mulu    w, 4(SP)
75         mov     4(SP), w
76         mov     w, MULH
77         add     3(SP), w
79         mov     w, #2                   ; Adjust the stack leaving the result to
80         add     spl, w                  ; be popped off later.
81         ret
83         .endfunc
85 #endif /* defined (L_mulhi3) */
87 #if defined (L_mulsi3)
88 /*******************************************************
89                Multiplication  32 x 32
90 *******************************************************/
91         
92         .sect   .text.libgcc,"ax"
93         .global __mulsi3
94         .func   _mulsi3, __mulsi3
96 __mulsi3:
97         clr     $80                     ; Assume zero result
98         clr     $81
99         clr     $82
100         clr     $83
102 2:      mov     w, 1(sp)
103         or      w, 2(sp)
104         or      w, 3(sp)
105         or      w, 4(sp)
106         snz                             ; Any more significant bits to multiply?
107         page    3f
108         jmp     3f
110         sb      4(sp), 0                ; Check LSB of multiplier
111         page    1f                      ; zero => scale multiplicand & multiplier
112         jmp     1f
114         mov     w, 8(sp)                ; Accumulate product
115         add     $83, w
116         mov     w, 7(sp)
117         addc    $82, w
118         mov     w, 6(sp)
119         addc    $81, w
120         mov     w, 5(sp)
121         addc    $80, w
122 1:      clrb    status, 0               ; scale multiplier down
123         rr      1(sp)   
124         rr      2(sp)
125         rr      3(sp)
126         rr      4(sp)
127         clrb    status, 0
128         rl      8(sp)
129         rl      7(sp)
130         rl      6(sp)
131         rl      5(sp)
132         page    2b
133         jmp     2b
135 3:      mov     w, #8
136         add     spl ,w
137         ret
139         .endfunc
141 #endif /* defined (L_mulsi3) */
142         
143 #if defined (L_muldi3)
144 /*******************************************************
145                Multiplication  64 x 64
146 *******************************************************/
147         
148         .sect   .text.libgcc,"ax"
149         .global __muldi3
150         .func   _muldi3, __muldi3
152 __muldi3:
153         clr     $80                     ; Assume zero result
154         clr     $81
155         clr     $82
156         clr     $83
157         clr     $84
158         clr     $85
159         clr     $86
160         clr     $87
162 2:      mov     w, 1(sp)
163         or      w, 2(sp)
164         or      w, 3(sp)
165         or      w, 4(sp)
166         or      w, 5(sp)
167         or      w, 6(sp)
168         or      w, 7(sp)
169         or      w, 8(sp)
170         snz                             ; Any more significant bits to multiply?
171         page    3f
172         jmp     3f
174         sb      8(sp), 0                ; Check LSB of multiplier
175         page    1f                      ; zero => scale multiplicand & multiplier
176         jmp     1f
178         mov     w, 16(sp)               ; Accumulate product
179         add     $87, w
180         mov     w, 15(sp)
181         addc    $86, w
182         mov     w, 14(sp)
183         addc    $85, w
184         mov     w, 13(sp)
185         addc    $84, w
186         mov     w, 12(sp)
187         addc    $83, w
188         mov     w, 11(sp)
189         addc    $82, w
190         mov     w, 10(sp)
191         addc    $81, w
192         mov     w, 9(sp)
193         addc    $80, w
195 1:      clrb    status, 0               ; scale multiplier down
196         rr      1(sp)   
197         rr      2(sp)
198         rr      3(sp)
199         rr      4(sp)
200         rr      5(sp)
201         rr      6(sp)
202         rr      7(sp)
203         rr      8(sp)
204         clrb    status, 0
205         rl      16(sp)
206         rl      15(sp)
207         rl      14(sp)
208         rl      13(sp)
209         rl      12(sp)
210         rl      11(sp)
211         rl      10(sp)
212         rl      9(sp)
213         page    2b
214         jmp     2b
216 3:      mov     w, #16
217         add     spl, w
218         ret
220         .endfunc
222 #endif /* defined (L_muldi3) */
224 #if defined (L_divmodhi4)
225 #define arg1h 1(SP)
226 #define arg1l 2(SP)
227 #define arg2h 3(SP)
228 #define arg2l 4(SP)
229 #define resl $81
230 #define resh $80
231 #define reml $83
232 #define remh $82
233 #define tmp_var $84
234 #define cnt $85
235 #define arg1_sign $86
236 #define res_sign $87
238         .sect   .text.libgcc,"ax"
239         .global __divmodhi4
240         .func   _divmodhi4, __divmodhi4
242 __divmodhi4:
243         mov     w,arg2h
244         mov     res_sign,w
245         mov     w,arg1h
246         mov     arg1_sign,w
247         xor     res_sign,w
249         sb      arg1h,7
250         page    1f
251         jmp     1f
253         not     arg1h
254         not     arg1l
255         incsnz  arg1l
256         inc     arg1h
258 1:      sb      arg2h, 7
259         page    1f
260         jmp     1f
262         not     arg2h
263         not     arg2l
264         incsnz  arg2l
265         inc     arg2h
267 1:      page    __udivmodhi4            ; Do the unsigned div/mod
268         call    __udivmodhi4
270         sb      arg1_sign, 7
271         page    1f
272         jmp     1f
274         not     reml
275         not     remh
276         incsnz  reml
277         inc     remh
279 1:      sb      res_sign, 7
280         ret
282         not     resl
283         not     resh
284         incsnz  resl
285         inc     resh
286         ret
288         .endfunc
290 #undef arg1h
291 #undef arg1l
292 #undef arg2h
293 #undef arg2l
294 #undef resl
295 #undef resh
296 #undef reml
297 #undef remh
298 #undef tmp_var
299 #undef cnt
300 #undef arg1_sign
301 #undef res_sign
303 #endif /* defined (L_divmodhi4) */
304         
305 #if defined (L_udivmodhi4)
307 #define arg1h 1(SP)
308 #define arg1l 2(SP)
309 #define arg2h 3(SP)
310 #define arg2l 4(SP)
311 #define resl $81
312 #define resh $80
313 #define reml $83
314 #define remh $82
315 #define tmp_var $84
316 #define cnt $85
318         .sect   .text.libgcc,"ax"
319         .global __udivmodhi4
320         .func   _udivmodhi4, __udivmodhi4
322 __udivmodhi4:
323         clr     reml
324         clr     remh
325         mov     w, #17
326         mov     cnt,w
327         clrb    status, 0
328         page    1f
329         jmp     1f
331 2:      rl      reml
332         rl      remh
333         mov     w, arg2l
334         sub     w, reml
335         mov     tmp_var, w
336         mov     w, arg2h
337         subc    w, remh
338         sc
339         page    1f
340         jmp     1f
341         mov     remh, w
342         mov     w, tmp_var
343         mov     reml, w
345 1:      rl      arg1l
346         rl      arg1h
347         decsz   cnt
348         page    2b
349         jmp     2b
350         
351         pop     resh
352         pop     resl    
353         mov     w, #2
354         add     spl, w
355         ret
357         .endfunc
359 #undef arg1h
360 #undef arg1l
361 #undef arg2h
362 #undef arg2l
363 #undef resl
364 #undef resh
365 #undef reml
366 #undef remh
367 #undef tmp_var
368 #undef cnt
370 #endif  /* defined (L_udivmodhi4) */
372 #if defined (L_divmodsi4)
374 #define arg1a 1(SP)
375 #define arg1b 2(SP)
376 #define arg1c 3(SP)
377 #define arg1d 4(SP)
379 #define arg2a 5(SP)
380 #define arg2b 6(SP)
381 #define arg2c 7(SP)
382 #define arg2d 8(SP)
383         
384 #define resa $80
385 #define resb $81
386 #define resc $82
387 #define resd $83
389 #define rema $84
390 #define remb $85
391 #define remc $86
392 #define remd $87
394 #define tmp_var $88
395 #define tmp_var1 $89
396 #define tmp_var2 $8a
397 #define cnt $8b
398 #define arg1_sign $8c
399 #define res_sign $8d
401         .sect   .text.libgcc,"ax"
402         .global __divmodsi4
403         .func   _divmodsi4, __divmodsi4
405 __divmodsi4:
406         mov     w, arg2a
407         mov     res_sign, w
408         mov     w, arg1a
409         mov     arg1_sign, w
410         xor     res_sign, w
412         sb      arg1a, 7
413         page    1f
414         jmp     1f
416         not     arg1d
417         not     arg1c
418         not     arg1b
419         not     arg1a
420         incsnz  arg1d
421         incsz   arg1c
422         page    1f
423         jmp     1f
424         incsnz  arg1b
425         inc     arg1a
427 1:      sb      arg2a, 7
428         page    1f
429         jmp     1f
431         not     arg2d
432         not     arg2c
433         not     arg2b
434         not     arg2a
435         incsnz  arg2d
436         incsz   arg2c
437         page    1f
438         jmp     1f
439         incsnz  arg2b
440         inc     arg2a
442 1:      page    __udivmodsi4            ; Do the unsigned div/mod.
443         call    __udivmodsi4
445         sb      arg1_sign, 7
446         page    1f
447         jmp     1f
449         not     remd
450         not     remc
451         not     remb
452         not     rema
453         incsnz  remd
454         incsz   remc
455         page    1f
456         jmp     1f
457         incsnz  remb
458         inc     rema
460 1:      sb      res_sign, 7
461         ret
463         not     resd
464         not     resc
465         not     resb
466         not     resa
467         incsnz  resd
468         incsz   resc
469         ret
470         incsnz  resb
471         inc     resa
472         ret
474         .endfunc
476 #undef arg1a
477 #undef arg1b
478 #undef arg1c
479 #undef arg1d
481 #undef arg2a
482 #undef arg2b
483 #undef arg2c
484 #undef arg2d
485         
486 #undef resa
487 #undef resb
488 #undef resc
489 #undef resd
491 #undef rema
492 #undef remb
493 #undef remc
494 #undef remd
496 #undef tmp_var
497 #undef tmp_var1
498 #undef tmp_var2
499 #undef cnt
500 #undef arg1_sign
501 #undef res_sign
503 #endif /* defined (L_divmodsi4) */
505 #if defined (L_udivmodsi4)              
506 #define arg1a 1(SP)
507 #define arg1b 2(SP)
508 #define arg1c 3(SP)
509 #define arg1d 4(SP)
511 #define arg2a 5(SP)
512 #define arg2b 6(SP)
513 #define arg2c 7(SP)
514 #define arg2d 8(SP)
515         
516 #define resa $80
517 #define resb $81
518 #define resc $82
519 #define resd $83
521 #define rema $84
522 #define remb $85
523 #define remc $86
524 #define remd $87
526 #define tmp_var $88
527 #define tmp_var1 $89
528 #define tmp_var2 $8a
529 #define cnt $8b
531         .sect   .text.libgcc,"ax"
532         .global __udivmodsi4
533         .func   _udivmodsi4, __udivmodsi4
535 __udivmodsi4:
536         clr     remd
537         clr     remc
538         clr     remb
539         clr     rema
540         mov     w, #33
541         mov     cnt, w
542         clrb    status, 0
543         page    1f
544         jmp     1f
546 2:      rl      remd
547         rl      remc
548         rl      remb
549         rl      rema
550         mov     w, arg2d
551         sub     w, remd
552         mov     tmp_var, w
553         mov     w, arg2c
554         subc    w, remc
555         mov     tmp_var1, w
556         mov     w, arg2b
557         subc    w, remb
558         mov     tmp_var2, w
559         mov     w, arg2a
560         subc    w, rema
561         sc
562         page    1f
563         jmp     1f
565         mov     rema, w
566         mov     w, tmp_var2
567         mov     remb, w
568         mov     w, tmp_var1
569         mov     remc, w
570         mov     w, tmp_var
571         mov     remd, w
573 1:      rl      arg1d
574         rl      arg1c
575         rl      arg1b
576         rl      arg1a
577         decsz   cnt
578         page    2b
579         jmp     2b
581         pop     resa
582         pop     resb
583         pop     resc
584         pop     resd
585         mov     w, #4
586         add     spl, w
587         ret
589         .endfunc
591 #undef arg1a
592 #undef arg1b
593 #undef arg1c
594 #undef arg1d
596 #undef arg2a
597 #undef arg2b
598 #undef arg2c
599 #undef arg2d
600         
601 #undef resa
602 #undef resb
603 #undef resc
604 #undef resd
606 #undef rema
607 #undef remb
608 #undef remc
609 #undef remd
611 #undef tmp_var
612 #undef tmp_var1
613 #undef tmp_var2
614 #undef cnt
616 #endif /* defined (L_udivmodsi4) */
618 #if defined (L_divmoddi4)
620 #define arg1s 1(SP)
621 #define arg1t 2(SP)
622 #define arg1u 3(SP)
623 #define arg1v 4(SP)
624 #define arg1w 5(SP)
625 #define arg1x 6(SP)
626 #define arg1y 7(SP)
627 #define arg1z 8(SP)
629 #define arg2s 9(SP)
630 #define arg2t 10(SP)
631 #define arg2u 11(SP)
632 #define arg2v 12(SP)
633 #define arg2w 13(SP)
634 #define arg2x 14(SP)
635 #define arg2y 15(SP)
636 #define arg2z 16(SP)
637         
638 #define ress $80
639 #define rest $81
640 #define resu $82
641 #define resv $83
642 #define resw $84
643 #define resx $85
644 #define resy $86
645 #define resz $87
647 #define rems $88
648 #define remt $89
649 #define remu $8a
650 #define remv $8b
651 #define remw $8c
652 #define remx $8d
653 #define remy $8e
654 #define remz $8f
656 #define tmp_var $90
657 #define tmp_var1 $91
658 #define tmp_var2 $92
659 #define tmp_var3 $93
660 #define tmp_var4 $94
661 #define tmp_var5 $95
662 #define tmp_var6 $96
663 #define cnt $97
665         .sect   .text.libgcc,"ax"
666         .global __divmoddi4
667         .func   _divmoddi4, __divmoddi4
669 __divmoddi4:
670         rl      w, arg2s                ; Use MULH to track sign bits.
671         rl      MULH
672         rl      w, arg1s
673         rl      WREG
674         xor     MULH, w
675         rl      w, arg1s
676         rl      MULH
678         sb      arg1s, 7
679         page    1f
680         jmp     1f
682         not     arg1s
683         not     arg1t
684         not     arg1u
685         not     arg1v
686         not     arg1w
687         not     arg1x
688         not     arg1y
689         not     arg1z
690         incsnz  arg1z
691         incsz   arg1y
692         page    1f
693         jmp     1f
694         incsnz  arg1x
695         incsz   arg1w
696         page    1f
697         jmp     1f
698         incsnz  arg1v
699         incsz   arg1u
700         page    1f
701         jmp     1f
702         incsnz  arg1t
703         inc     arg1s
705 1:      sb      arg2s, 7
706         page    1f
707         jmp     1f
709         not     arg2s
710         not     arg2t
711         not     arg2u
712         not     arg2v
713         not     arg2w
714         not     arg2x
715         not     arg2y
716         not     arg2z
717         incsnz  arg2z
718         incsz   arg2y
719         page    1f
720         jmp     1f
721         incsnz  arg2x
722         incsz   arg2w
723         page    1f
724         jmp     1f
725         incsnz  arg2v
726         incsz   arg2u
727         page    1f
728         jmp     1f
729         incsnz  arg2t
730         inc     arg2s
732 1:      page    __udivmoddi4            ; Do the unsigned div/mod.
733         call    __udivmoddi4
735         sb      MULH, 0                 ; Look at the save sign bit for arg 1.
736         page    1f
737         jmp     1f
739         not     rems
740         not     remt
741         not     remu
742         not     remv
743         not     remw
744         not     remx
745         not     remy
746         not     remz
747         incsnz  remz
748         incsz   remy
749         page    1f
750         jmp     1f
751         incsnz  remx
752         incsz   remw
753         page    1f
754         jmp     1f
755         incsnz  remv
756         incsz   remu
757         page    1f
758         jmp     1f
759         incsnz  remt
760         inc     rems
762 1:      sb      MULH, 1
763         ret
765         not     ress
766         not     rest
767         not     resu
768         not     resv
769         not     resw
770         not     resx
771         not     resy
772         not     resz
773         incsnz  resz
774         incsz   resy
775         ret
776         incsnz  resx
777         incsz   resw
778         ret
779         incsnz  resv
780         incsz   resu
781         ret
782         incsnz  rest
783         inc     ress
784         ret
786         .endfunc
788 #undef arg1s
789 #undef arg1t
790 #undef arg1u
791 #undef arg1v
792 #undef arg1w
793 #undef arg1x
794 #undef arg1y
795 #undef arg1z
797 #undef arg2s
798 #undef arg2t
799 #undef arg2u
800 #undef arg2v
801 #undef arg2w
802 #undef arg2x
803 #undef arg2y
804 #undef arg2z
805         
806 #undef ress
807 #undef rest
808 #undef resu
809 #undef resv
810 #undef resw
811 #undef resx
812 #undef resy
813 #undef resz
815 #undef rems
816 #undef remt
817 #undef remu
818 #undef remv
819 #undef remw
820 #undef remx
821 #undef remy
822 #undef remz
824 #undef tmp_var
825 #undef tmp_var1
826 #undef tmp_var2
827 #undef tmp_var3
828 #undef tmp_var4
829 #undef tmp_var5
830 #undef tmp_var6
831 #undef cnt
833 #endif /* defined (L_divmoddi4) */
835 #if defined (L_udivmoddi4)              
836 #define arg1s 1(SP)
837 #define arg1t 2(SP)
838 #define arg1u 3(SP)
839 #define arg1v 4(SP)
840 #define arg1w 5(SP)
841 #define arg1x 6(SP)
842 #define arg1y 7(SP)
843 #define arg1z 8(SP)
845 #define arg2s 9(SP)
846 #define arg2t 10(SP)
847 #define arg2u 11(SP)
848 #define arg2v 12(SP)
849 #define arg2w 13(SP)
850 #define arg2x 14(SP)
851 #define arg2y 15(SP)
852 #define arg2z 16(SP)
853         
854 #define ress $80
855 #define rest $81
856 #define resu $82
857 #define resv $83
858 #define resw $84
859 #define resx $85
860 #define resy $86
861 #define resz $87
863 #define rems $88
864 #define remt $89
865 #define remu $8a
866 #define remv $8b
867 #define remw $8c
868 #define remx $8d
869 #define remy $8e
870 #define remz $8f
872 #define tmp_var $90
873 #define tmp_var1 $91
874 #define tmp_var2 $92
875 #define tmp_var3 $93
876 #define tmp_var4 $94
877 #define tmp_var5 $95
878 #define tmp_var6 $96
879 #define cnt $97
881         .sect   .text.libgcc,"ax"
882         .global __udivmoddi4
883         .func   _udivmoddi4, __udivmoddi4
885 __udivmoddi4:
886         clr     rems
887         clr     remt
888         clr     remu
889         clr     remv
890         clr     remw
891         clr     remx
892         clr     remy
893         clr     remz
894         mov     w, #65
895         mov     cnt, w
896         clrb    status, 0
897         page    1f
898         jmp     1f
900 2:      rl      remz
901         rl      remy
902         rl      remx
903         rl      remw
904         rl      remv
905         rl      remu
906         rl      remt
907         rl      rems
908         mov     w, arg2z
909         sub     w, remz
910         mov     tmp_var, w
911         mov     w, arg2y
912         subc    w, remy
913         mov     tmp_var1, w
914         mov     w, arg2x
915         subc    w, remx
916         mov     tmp_var2, w
917         mov     w, arg2w
918         subc    w, remw
919         mov     tmp_var3, w
920         mov     w, arg2v
921         subc    w, remv
922         mov     tmp_var4, w
923         mov     w, arg2u
924         subc    w, remu
925         mov     tmp_var5, w
926         mov     w, arg2t
927         subc    w, remt
928         mov     tmp_var6, w
929         mov     w, arg2s
930         subc    w, rems
931         sc
932         page    1f
933         jmp     1f
935         mov     rems, w
936         mov     w, tmp_var6
937         mov     remt, w
938         mov     w, tmp_var5
939         mov     remu, w
940         mov     w, tmp_var4
941         mov     remv, w
942         mov     w, tmp_var3
943         mov     remw, w
944         mov     w, tmp_var2
945         mov     remx, w
946         mov     w, tmp_var1
947         mov     remy, w
948         mov     w, tmp_var
949         mov     remz, w
951 1:      rl      arg1z
952         rl      arg1y
953         rl      arg1x
954         rl      arg1w
955         rl      arg1v
956         rl      arg1u
957         rl      arg1t
958         rl      arg1s
959         decsz   cnt
960         page    2b
961         jmp     2b
963         pop     ress
964         pop     rest
965         pop     resu
966         pop     resv
967         pop     resw
968         pop     resx
969         pop     resy
970         pop     resz
971         mov     w, #8
972         add     spl, w
973         ret
975         .endfunc
977 #undef arg1s
978 #undef arg1t
979 #undef arg1u
980 #undef arg1v
981 #undef arg1w
982 #undef arg1x
983 #undef arg1y
984 #undef arg1z
986 #undef arg2s
987 #undef arg2t
988 #undef arg2u
989 #undef arg2v
990 #undef arg2w
991 #undef arg2x
992 #undef arg2y
993 #undef arg2z
994         
995 #undef ress
996 #undef rest
997 #undef resu
998 #undef resv
999 #undef resw
1000 #undef resx
1001 #undef resy
1002 #undef resz
1004 #undef rems
1005 #undef remt
1006 #undef remu
1007 #undef remv
1008 #undef remw
1009 #undef remx
1010 #undef remy
1011 #undef remz
1013 #undef tmp_var
1014 #undef tmp_var1
1015 #undef tmp_var2
1016 #undef tmp_var3
1017 #undef tmp_var4
1018 #undef tmp_var5
1019 #undef tmp_var6
1020 #undef cnt
1022 #endif /* defined (L_udivmoddi4) */
1024 #define LT      #0
1025 #define EQ      #1
1026 #define GT      #2
1028 #if defined(L_cmphi2)
1029 #define arg1l 2(sp)
1030 #define arg1h 1(sp)
1031 #define arg2l 4(sp)
1032 #define arg2h 3(sp)
1034         .sect   .text.libgcc,"ax"
1035         .global __cmphi2
1036         .global __cmp_ret
1037         .global __cmpqi_ret
1038         .func   _cmphi2, __cmphi2
1040 __cmphi2:
1041         mov     w,arg1l 
1042         sub     w,arg2l
1043         snz
1044         page    2f
1045         jmp     2f
1046         mov     w,arg1h
1048         subc    w,arg2h
1049         clr     arg2l
1050         rl      arg2l
1051         snb     arg1h,7
1052         setb    arg2l,2
1053         snb     arg2h,7
1054         setb    arg2l,1
1055         mov     w,#3
1057 __cmp_ret:
1058         add     spl,w                   ;  sign1
1059         pop     wreg                    ;   sign2
1061 __cmpqi_ret:
1062         add     pcl,w                   ;    carry of arg1 - arg2
1063         retw    GT                      ; [000] arg1 > arg2
1064         retw    LT                      ; [001] arg1 < arg2
1065         retw    GT                      ; [010] arg1 > arg2
1066         retw    GT                      ; [011] arg1 > arg2
1067         retw    LT                      ; [100] arg1 < arg2
1068         retw    LT                      ; [101] arg1 < arg2
1069         retw    GT                      ; [110] arg1 > arg2
1070         retw    LT                      ; [111] arg1 < arg2
1072         mov     w,arg1h
1073         cse     w,arg2h
1074         page    1b
1075         jmp     1b
1076         mov     w,#4
1077         add     spl,w
1078         retw    EQ
1080         .endfunc
1081 #undef arg1l
1082 #undef arg1h
1083 #undef arg2l
1084 #undef arg2h
1085 #endif  /* L_cmphi2 */
1087 #if defined(L_cmpqi2)
1088 #define arg1 1(sp)
1089 #define arg2 2(sp)
1091         .sect   .text.libgcc,"ax"
1092         .global __cmpqi2
1093         .func   _cmpqi2, __cmpqi2
1095 __cmpqi2:
1096         mov     w, arg1
1097         sub     w, arg2
1098         snz
1099         page    2f
1100         jmp     2f
1102         clr     wreg
1103         rl      wreg
1104         snb     arg1, 7
1105         setb    wreg, 2
1106         snb     arg2, 7
1107         setb    wreg, 1
1108         inc     spl
1109         inc     spl
1110         page    __cmpqi_ret
1111         jmp     __cmpqi_ret
1113 2:      mov     w, #2
1114         add     spl, w
1115         retw    EQ
1117         .endfunc
1118 #undef arg1l
1119 #undef arg2l
1120 #endif  /* L_cmpqi2 */
1122 #if defined(L_cmpsi2)
1123 #define arg1d 4(sp)
1124 #define arg1c 3(sp)
1125 #define arg1b 2(sp)
1126 #define arg1a 1(sp)
1127 #define arg2d 8(sp)
1128 #define arg2c 7(sp)
1129 #define arg2b 6(sp)
1130 #define arg2a 5(sp)
1131         
1132         .sect   .text.libgcc,"ax"
1133         .global __cmpsi2
1134         .func   _cmpsi2, __cmpsi2
1136 __cmpsi2:
1137         mov     w, arg1d
1138         sub     w, arg2d
1139         snz
1140         page    2f
1141         jmp     2f
1143 1:      mov     w, arg1c
1144         subc    w, arg2c
1145         mov     w, arg1b
1146         subc    w, arg2b
1147         mov     w, arg1a
1148         subc    w, arg2a
1150         clr     arg2d
1151         rl      arg2d
1152         snb     arg1a, 7
1153         setb    arg2d, 2
1154         snb     arg2a, 7
1155         setb    arg2d, 1
1156         mov     w, #7
1157         page    __cmp_ret
1158         jmp     __cmp_ret
1160 2:      mov     w, arg1c
1161         cse     w, arg2c
1162         page    1b
1163         jmp     1b
1165         mov     w, arg1b
1166         cse     w, arg2b
1167         page    1b
1168         jmp     1b
1170         mov     w, arg1a
1171         cse     w, arg2a
1172         page    1b
1173         jmp     1b
1175         mov     w, #8
1176         add     spl, w
1177         retw    EQ
1179         .endfunc
1181 #undef arg1d
1182 #undef arg1c
1183 #undef arg1b
1184 #undef arg1a
1185 #undef arg2d
1186 #undef arg2c
1187 #undef arg2b
1188 #undef arg2a
1189 #endif  /* L_cmpsi2 */
1191 #if defined(L_cmpdi2)
1192 #define arg1z 8(sp)
1193 #define arg1y 7(sp)
1194 #define arg1x 6(sp)
1195 #define arg1w 5(sp)
1196 #define arg1v 4(sp)
1197 #define arg1u 3(sp)
1198 #define arg1t 2(sp)
1199 #define arg1s 1(sp)
1201 #define arg2z 16(sp)
1202 #define arg2y 15(sp)
1203 #define arg2x 14(sp)
1204 #define arg2w 13(sp)
1205 #define arg2v 12(sp)
1206 #define arg2u 11(sp)
1207 #define arg2t 10(sp)
1208 #define arg2s 9(sp)
1209         
1210         .sect   .text.libgcc,"ax"
1211         .global __cmpdi2
1212         .func   _cmpdi2, __cmpdi2
1214 __cmpdi2:
1215         mov     w, arg1z
1216         sub     w, arg2z
1217         snz
1218         page    2f
1219         jmp     2f
1221 1:      mov     w, arg1y
1222         subc    w, arg2y
1223         mov     w, arg1x
1224         subc    w, arg2x
1225         mov     w, arg1w
1226         subc    w, arg2w
1227         mov     w, arg1v
1228         subc    w, arg2v
1229         mov     w, arg1u
1230         subc    w, arg2u
1231         mov     w, arg1t
1232         subc    w, arg2t
1233         mov     w, arg1s
1234         subc    w, arg2s
1235         clr     arg2z
1236         rl      arg2z
1237         snb     arg1s, 7
1238         setb    arg2z, 2
1239         snb     arg2s, 7
1240         setb    arg2z, 1
1241         mov     w, #15
1242         page    __cmp_ret
1243         jmp     __cmp_ret
1245 2:      mov     w, arg1y
1246         cse     w, arg2y
1247         page    1b
1248         jmp     1b
1250         mov     w, arg1x
1251         cse     w, arg2x
1252         page    1b
1253         jmp     1b
1255         mov     w, arg1w
1256         cse     w, arg2w
1257         page    1b
1258         jmp     1b
1260         mov     w, arg1v
1261         cse     w, arg2v
1262         page    1b
1263         jmp     1b
1265         mov     w, arg1u
1266         cse     w, arg2u
1267         page    1b
1268         jmp     1b
1270         mov     w, arg1t
1271         cse     w, arg2t
1272         page    1b
1273         jmp     1b
1275         mov     w, arg1s
1276         cse     w, arg2s
1277         page    1b
1278         jmp     1b
1280         mov     w, #16
1281         add     spl, w
1282         retw    EQ
1284         .endfunc
1285         
1286 #undef arg1z
1287 #undef arg1y
1288 #undef arg1x
1289 #undef arg1w
1290 #undef arg1v
1291 #undef arg1u
1292 #undef arg1t
1293 #undef arg1s
1294 #undef arg2z
1295 #undef arg2y
1296 #undef arg2x
1297 #undef arg2w
1298 #undef arg2v
1299 #undef arg2u
1300 #undef arg2t
1301 #undef arg2s
1303 #endif  /* L_cmpdi2 */
1304         
1305 #if defined(L_cmpdi2_dp)
1306         .sect   .text.libgcc,"ax"
1307         .global __cmpdi2_dp
1308         .func   _cmpdi2_dp, __cmpdi2_dp
1310 __cmpdi2_dp:
1311         push    7(dp)
1312         push    6(dp)
1313         push    5(dp)
1314         push    4(dp)
1315         push    3(dp)
1316         push    2(dp)
1317         push    1(dp)
1318         push    (dp)
1319         page    __cmpdi2
1320         jmp     __cmpdi2
1322         .endfunc
1323 #endif  /* L_cmpdi2_dp */
1325 #if defined(L_fp_pop_args_ret)
1326         .sect   .pram.libgcc,"ax"
1327         .global __fp_pop_args_ret
1328         .global __pop_args_ret
1329         .global __pop2_args_ret
1330         .func   __fp_pop2_args_ret, __fp_pop2_args_ret
1332 __fp_pop2_args_ret:
1333         mov     w, #2
1334 __fp_pop_args_ret:
1335         pop     0xfd
1336         pop     0xfe
1337 __pop_args_ret:
1338         pop     callh
1339         pop     calll
1340         add     spl, w
1341         ret
1343         .endfunc
1344 #endif /* L_fp_pop_args_ret */
1346 #if defined(L__pop2_args_ret)
1347         .sect   .pram.libgcc,"ax"
1348         .global __pop2_args_ret
1349         .func   __pop2_args_ret, __pop2_args_ret
1351 __pop2_args_ret:
1352         mov     w, #2
1353         pop     callh
1354         pop     calll
1355         add     spl, w
1356         ret
1358         .endfunc
1359 #endif /* L__pop2_args_ret */
1361 #if defined(L_leaf_fp_pop_args_ret)
1362         .sect   .pram.libgcc,"ax"
1363         .global __leaf_fp_pop_args_ret, __leaf_fp_pop2_args_ret
1364         .func   __leaf_fp2_pop_args_ret, __leaf_fp_pop2_args_ret
1366 __leaf_fp_pop2_args_ret:
1367         mov     w, #2
1368 __leaf_fp_pop_args_ret:
1369         pop     0xfd
1370         pop     0xfe
1371         add     spl, w
1372         ret
1374         .endfunc
1375 #endif /* L_leaf_fp_pop_args_ret */
1377 #if defined(L_movstrhi_countqi)
1378         .sect   .pram.libgcc,"ax"
1379         .global __movstrhi_countqi
1380         .func   _movstrhi_countqi, __movstrhi_countqi
1382 __movstrhi_countqi:
1383         push    dph                     ; Save our pointer regs
1384         push    dpl
1385         push    iph
1386         push    ipl
1388         mov     w, 5(SP)                ; Get our dest pointer
1389         mov     dph, w
1390         mov     w, 6(SP)
1391         mov     dpl, w
1392         mov     w, 7(SP)                ; And our source pointer
1393         mov     iph, w
1394         mov     w, 8(SP)
1395         mov     ipl, w
1397 1:      push    (IP)                    ; *dest++ = *src++
1398         pop     0(DP)
1399         inc     ipl
1400         inc     dpl
1401         decsz   9(SP)                   ; Loop until completed
1402         page    1b
1403         jmp     1b
1405         pop     ipl                     ; Restore our pointer regs
1406         pop     iph
1407         pop     dpl
1408         pop     dph
1410         mov     w, #5                   ; Tidy up our stack args
1411         add     spl, w
1412         ret
1414         .endfunc
1415 #endif
1417 #if defined(L_movstrhi_counthi)
1418         .sect   .text.libgcc,"ax"
1419         .global __movstrhi_counthi
1420         .func   _movstrhi_counthi, __movstrhi_counthi
1422 __movstrhi_counthi:
1423         push    dph                     ; Save our pointer regs
1424         push    dpl
1425         push    iph
1426         push    ipl
1428         mov     w, 5(SP)                ; Get our dest pointer
1429         mov     dph, w
1430         mov     w, 6(SP)
1431         mov     dpl, w
1432         mov     w, 7(SP)                ; And our source pointer
1433         mov     iph, w
1434         mov     w, 8(SP)
1435         mov     ipl, w
1437         test    10(SP)                  ; If we have a nonzero LSB then adjust the
1438         sz                              ; MSB of the loop count to allow us to use
1439         inc     9(SP)                   ; skip tricks!
1441 1:      push    (IP)                    ; *dest++ = *src++
1442         pop     0(DP)
1443         inc     ipl
1444         inc     dpl
1445         decsnz  10(SP)                  ; Loop until completed - note the skip trick
1446         decsz   9(SP)                   ; on the MSB!
1447         page    1b
1448         jmp     1b
1450         pop     ipl                     ; Restore our pointer regs
1451         pop     iph
1452         pop     dpl
1453         pop     dph
1455         mov     w, #6                   ; Tidy up our stacked args.
1456         add     spl, w
1457         ret
1459         .endfunc
1460 #endif
1462 #if defined(L_exit)
1463         .sect   .text.libgcc,"ax"
1464         .global __exit
1465         .global _exit
1466         .func   _exit, __exit
1467         .weak   __exit
1468         .weak   _exit
1470 _exit:          
1471 __exit:
1472         pop     $88
1473         pop     wreg
1474         or      w, $88
1475         push    wreg
1476         push    #0
1477         push    #1
1478         system                          ; Exit wreg
1479         page    __exit                  ; Never return
1480         jmp     __exit
1482         .endfunc
1483 #endif
1485 #if defined(Labort)
1486         .sect   .text.libgcc,"ax"
1487         .global _abort
1488         .func   abort, _abort
1490 _abort:
1491         push    #1
1492         push    #0
1493         push    #1
1494         system                          ; Exit 1
1495         ret
1497         .endfunc
1498 #endif
1500 #if defined(Lwrite)
1501         /* Dummy entrypoint to suppress problems with glue code. */
1502         .sect   .text.libgcc,"ax"
1503         .global _write
1504         .func   write, _write
1506 ;; write (fil,buf,len) - say that write succeeds....
1507 ;; 
1508 _write:
1509         movb    $80, 5(SP)
1510         movb    $81, 6(SP)              ; Return length written
1511         mov     w, #6
1512         add     spl, w
1513         ret
1514         
1515         .endfunc
1516 #endif