1 ; Low level integer divide, multiply, remainder, etc routines for the HPPA.
2 ; Copyright (C) 1995 Free Software Foundation, Inc.
4 ; This file is part of GNU CC.
6 ; GNU CC is free software; you can redistribute it and/or modify
7 ; it under the terms of the GNU General Public License as published by
8 ; the Free Software Foundation; either version 2, or (at your option)
11 ; In addition to the permissions in the GNU General Public License, the
12 ; Free Software Foundation gives you unlimited permission to link the
13 ; compiled version of this file with other programs, and to distribute
14 ; those programs without any restriction coming from the use of this
15 ; file. (The General Public License restrictions do apply in other
16 ; respects; for example, they cover modification of the file, and
17 ; distribution when not linked into another program.)
19 ; GNU CC is distributed in the hope that it will be useful,
20 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ; GNU General Public License for more details.
24 ; You should have received a copy of the GNU General Public License
25 ; along with GNU CC; see the file COPYING. If not, write to
26 ; the Free Software Foundation, 59 Temple Place - Suite 330,
27 ; Boston, MA 02111-1307, USA.
31 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
35 .callinfo frame=0,no_calls
37 bb,>=,n %r22,30,L$1 ; branch if not plabel address
38 depi 0,31,2,%r22 ; clear the two least significant bits
39 ldw 4(%sr0,%r22),%r19 ; load new LTP value
40 ldw 0(%sr0,%r22),%r22 ; load address of target
41 L$1 ldsid (%sr0,%r22),%r1 ; get the "space ident" selected by r22
42 mtsp %r1,%sr0 ; move that space identifier into sr0
43 be 0(%sr0,%r22) ; branch to the real target
44 stw %r2,-24(%sr0,%r30) ; save return address into frame marker
57 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
64 .callinfo frame=0,no_calls
66 addi,tr 0,%r0,res ; clear out res, skip next insn
67 L$loop zdep op1,26,27,op1 ; shift up op1 by 5
68 L$lo zdep op0,30,5,tmp ; extract next 5 bits and shift up
70 extru op0,26,27,op0 ; shift down op0 by 5
71 L$0 comib,<> 0,op0,L$lo
72 zdep op1,26,27,op1 ; shift up op1 by 5
83 L$3 sh1addl op1,op1,tmp ; 3x
91 L$5 sh2addl op1,op1,tmp ; 5x
95 L$6 sh1addl op1,op1,tmp ; 3x
99 L$7 zdep op1,28,29,tmp ; 8x
107 L$9 sh3addl op1,op1,tmp ; 9x
111 L$10 sh2addl op1,op1,tmp ; 5x
115 L$11 sh2addl op1,op1,tmp ; 5x
116 sh1addl tmp,op1,tmp ; 11x
119 L$12 sh1addl op1,op1,tmp ; 3x
123 L$13 sh1addl op1,op1,tmp ; 3x
124 sh2addl tmp,op1,tmp ; 13x
127 L$14 zdep op1,28,29,tmp ; 8x
131 L$15 zdep op1,27,28,tmp ; 16x
132 sub tmp,op1,tmp ; 15x
135 L$16 zdep op1,27,28,tmp ; 16x
139 L$17 zdep op1,27,28,tmp ; 16x
140 addl tmp,op1,tmp ; 17x
143 L$18 sh3addl op1,op1,tmp ; 9x
147 L$19 sh3addl op1,op1,tmp ; 9x
148 sh1addl tmp,op1,tmp ; 19x
151 L$20 sh2addl op1,op1,tmp ; 5x
155 L$21 sh2addl op1,op1,tmp ; 5x
156 sh2addl tmp,op1,tmp ; 21x
159 L$22 sh2addl op1,op1,tmp ; 5x
160 sh1addl tmp,op1,tmp ; 11x
163 L$23 sh1addl op1,op1,tmp ; 3x
164 sh3addl tmp,res,res ; += 8x3
166 sub res,op1,res ; -= x
167 L$24 sh1addl op1,op1,tmp ; 3x
169 sh3addl tmp,res,res ; += 8x3
171 L$25 sh2addl op1,op1,tmp ; 5x
172 sh2addl tmp,tmp,tmp ; 25x
175 L$26 sh1addl op1,op1,tmp ; 3x
176 sh2addl tmp,op1,tmp ; 13x
178 sh1addl tmp,res,res ; += 2x13
179 L$27 sh1addl op1,op1,tmp ; 3x
180 sh3addl tmp,tmp,tmp ; 27x
183 L$28 zdep op1,28,29,tmp ; 8x
186 sh2addl tmp,res,res ; += 4x7
187 L$29 sh1addl op1,op1,tmp ; 3x
188 sub res,tmp,res ; -= 3x
190 zdep op1,26,27,tmp ; 32x
191 L$30 zdep op1,27,28,tmp ; 16x
192 sub tmp,op1,tmp ; 15x
194 sh1addl tmp,res,res ; += 2x15
195 L$31 zdep op1,26,27,tmp ; 32x
196 sub tmp,op1,tmp ; 31x
205 #define dividend %r26
208 #define quotient %r29
211 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
216 .callinfo frame=0,no_calls
218 comb,< divisor,0,L$largedivisor
219 sub %r0,divisor,%r1 ; clear cy as side-effect
221 addc dividend,dividend,dividend
223 addc dividend,dividend,dividend
225 addc dividend,dividend,dividend
227 addc dividend,dividend,dividend
229 addc dividend,dividend,dividend
231 addc dividend,dividend,dividend
233 addc dividend,dividend,dividend
235 addc dividend,dividend,dividend
237 addc dividend,dividend,dividend
239 addc dividend,dividend,dividend
241 addc dividend,dividend,dividend
243 addc dividend,dividend,dividend
245 addc dividend,dividend,dividend
247 addc dividend,dividend,dividend
249 addc dividend,dividend,dividend
251 addc dividend,dividend,dividend
253 addc dividend,dividend,dividend
255 addc dividend,dividend,dividend
257 addc dividend,dividend,dividend
259 addc dividend,dividend,dividend
261 addc dividend,dividend,dividend
263 addc dividend,dividend,dividend
265 addc dividend,dividend,dividend
267 addc dividend,dividend,dividend
269 addc dividend,dividend,dividend
271 addc dividend,dividend,dividend
273 addc dividend,dividend,dividend
275 addc dividend,dividend,dividend
277 addc dividend,dividend,dividend
279 addc dividend,dividend,dividend
281 addc dividend,dividend,dividend
283 addc dividend,dividend,quotient
286 addc quotient,quotient,quotient
288 comclr,<< dividend,divisor,quotient
297 #define dividend %r26
299 #define quotient %r29
303 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
308 .callinfo frame=0,no_calls
310 comb,< divisor,0,L$largedivisor
311 sub %r0,divisor,%r1 ; clear cy as side-effect
313 addc dividend,dividend,dividend
315 addc dividend,dividend,dividend
317 addc dividend,dividend,dividend
319 addc dividend,dividend,dividend
321 addc dividend,dividend,dividend
323 addc dividend,dividend,dividend
325 addc dividend,dividend,dividend
327 addc dividend,dividend,dividend
329 addc dividend,dividend,dividend
331 addc dividend,dividend,dividend
333 addc dividend,dividend,dividend
335 addc dividend,dividend,dividend
337 addc dividend,dividend,dividend
339 addc dividend,dividend,dividend
341 addc dividend,dividend,dividend
343 addc dividend,dividend,dividend
345 addc dividend,dividend,dividend
347 addc dividend,dividend,dividend
349 addc dividend,dividend,dividend
351 addc dividend,dividend,dividend
353 addc dividend,dividend,dividend
355 addc dividend,dividend,dividend
357 addc dividend,dividend,dividend
359 addc dividend,dividend,dividend
361 addc dividend,dividend,dividend
363 addc dividend,dividend,dividend
365 addc dividend,dividend,dividend
367 addc dividend,dividend,dividend
369 addc dividend,dividend,dividend
371 addc dividend,dividend,dividend
373 addc dividend,dividend,dividend
375 addc dividend,dividend,quotient
377 comclr,>= %r1,%r0,%r0
382 sub,>>= dividend,divisor,quotient
383 copy dividend,quotient
391 #define dividend %r26
393 #define quotient %r29
397 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
402 .callinfo frame=0,no_calls
404 xor dividend,divisor,quotient ; result sign
405 comclr,>= divisor,%r0,%r0 ; get absolute values
406 sub %r0,divisor,divisor
407 comclr,>= dividend,%r0,%r0
408 sub %r0,dividend,dividend
410 comb,< divisor,0,L$largedivisor
411 sub %r0,divisor,%r1 ; clear cy as side-effect
413 addc dividend,dividend,dividend
415 addc dividend,dividend,dividend
417 addc dividend,dividend,dividend
419 addc dividend,dividend,dividend
421 addc dividend,dividend,dividend
423 addc dividend,dividend,dividend
425 addc dividend,dividend,dividend
427 addc dividend,dividend,dividend
429 addc dividend,dividend,dividend
431 addc dividend,dividend,dividend
433 addc dividend,dividend,dividend
435 addc dividend,dividend,dividend
437 addc dividend,dividend,dividend
439 addc dividend,dividend,dividend
441 addc dividend,dividend,dividend
443 addc dividend,dividend,dividend
445 addc dividend,dividend,dividend
447 addc dividend,dividend,dividend
449 addc dividend,dividend,dividend
451 addc dividend,dividend,dividend
453 addc dividend,dividend,dividend
455 addc dividend,dividend,dividend
457 addc dividend,dividend,dividend
459 addc dividend,dividend,dividend
461 addc dividend,dividend,dividend
463 addc dividend,dividend,dividend
465 addc dividend,dividend,dividend
467 addc dividend,dividend,dividend
469 addc dividend,dividend,dividend
471 addc dividend,dividend,dividend
473 addc dividend,dividend,dividend
475 addc dividend,dividend,dividend
477 addc dividend,dividend,dividend
478 comclr,>= %r1,%r0,%r0
480 comclr,>= quotient,%r0,%r0 ; skip of no need to negate
481 sub %r0,dividend,dividend
483 copy dividend,quotient
485 comclr,<< dividend,divisor,quotient
494 #define dividend %r26
496 #define quotient %r29
500 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
505 .callinfo frame=0,no_calls
507 xor dividend,%r0,quotient ; result sign
508 comclr,>= divisor,%r0,%r0 ; get absolute values
509 sub %r0,divisor,divisor
510 comclr,>= dividend,%r0,%r0
511 sub %r0,dividend,dividend
513 comb,< divisor,0,L$largedivisor
514 sub %r0,divisor,%r1 ; clear cy as side-effect
516 addc dividend,dividend,dividend
518 addc dividend,dividend,dividend
520 addc dividend,dividend,dividend
522 addc dividend,dividend,dividend
524 addc dividend,dividend,dividend
526 addc dividend,dividend,dividend
528 addc dividend,dividend,dividend
530 addc dividend,dividend,dividend
532 addc dividend,dividend,dividend
534 addc dividend,dividend,dividend
536 addc dividend,dividend,dividend
538 addc dividend,dividend,dividend
540 addc dividend,dividend,dividend
542 addc dividend,dividend,dividend
544 addc dividend,dividend,dividend
546 addc dividend,dividend,dividend
548 addc dividend,dividend,dividend
550 addc dividend,dividend,dividend
552 addc dividend,dividend,dividend
554 addc dividend,dividend,dividend
556 addc dividend,dividend,dividend
558 addc dividend,dividend,dividend
560 addc dividend,dividend,dividend
562 addc dividend,dividend,dividend
564 addc dividend,dividend,dividend
566 addc dividend,dividend,dividend
568 addc dividend,dividend,dividend
570 addc dividend,dividend,dividend
572 addc dividend,dividend,dividend
574 addc dividend,dividend,dividend
576 addc dividend,dividend,dividend
578 addc dividend,dividend,dividend
580 addc dividend,dividend,dividend
581 comclr,>= %r1,%r0,%r0
583 comclr,>= quotient,%r0,%r0 ; skip of no need to negate
588 sub,>>= dividend,divisor,quotient
589 copy dividend,quotient
596 #if defined (L_divU_3) && !defined (SMALL_LIB)
598 #define dividend %r26
604 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
609 .callinfo frame=0,no_calls
611 sh2add %r26,%r26,%r29 ; r29 = lo(101 x r)
612 shd %r0,%r26,30,%r1 ; r1 = hi(100 x r)
613 addc %r1,%r0,%r1 ; r1 = hi(101 x r)
615 zdep %r29,27,28,%r25 ; r25 = lo(10000 x r)
616 add %r25,%r29,%r25 ; r25 = lo(10001 x r)
617 shd %r1,%r29,28,%r29 ; r29 = hi(10000 x r)
618 addc %r29,%r1,%r29 ; r29 = hi(10001 x r)
620 zdep %r25,23,24,%r1 ; r1 = lo(100000000 x r)
621 add %r1,%r25,%r1 ; r1 = lo(100000001 x r)
622 shd %r29,%r25,24,%r25 ; r25 = hi(100000000 x r)
623 addc %r25,%r29,%r25 ; r25 = hi(100000001 x r)
630 sh1add %r29,%r26,%r0 ; r0 = lo(10 x r) + dividend
631 shd %r1,%r29,31,%r29 ; r29 = hi(10 x r)
634 extru %r29,30,31,result
640 #if defined (L_divU_5) && !defined (SMALL_LIB)
642 #define dividend %r26
648 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
653 .callinfo frame=0,no_calls
655 sh1add %r26,%r26,%r29 ; r29 = lo(11 x r)
656 shd %r0,%r26,31,%r1 ; r1 = hi(10 x r)
657 addc %r1,%r0,%r1 ; r1 = hi(11 x r)
659 zdep %r29,27,28,%r25 ; r25 = lo(10000 x r)
660 add %r25,%r29,%r25 ; r25 = lo(10001 x r)
661 shd %r1,%r29,28,%r29 ; r29 = hi(10000 x r)
662 addc %r29,%r1,%r29 ; r29 = hi(10001 x r)
664 zdep %r25,23,24,%r1 ; r1 = lo(100000000 x r)
665 add %r1,%r25,%r1 ; r1 = lo(100000001 x r)
666 shd %r29,%r25,24,%r25 ; r25 = hi(100000000 x r)
667 addc %r25,%r29,%r25 ; r25 = hi(100000001 x r)
674 sh2add %r29,%r26,%r0 ; r0 = lo(1000 x r) + dividend
675 shd %r1,%r29,30,%r29 ; r29 = hi(1000 x r)
678 extru %r29,29,30,result
684 #if defined (L_divU_6) && !defined (SMALL_LIB)
686 #define dividend %r26
692 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
697 .callinfo frame=0,no_calls
699 sh2add %r26,%r26,%r29 ; r29 = lo(101 x r)
700 shd %r0,%r26,30,%r1 ; r1 = hi(100 x r)
701 addc %r1,%r0,%r1 ; r1 = hi(101 x r)
703 zdep %r29,27,28,%r25 ; r25 = lo(10000 x r)
704 add %r25,%r29,%r25 ; r25 = lo(10001 x r)
705 shd %r1,%r29,28,%r29 ; r29 = hi(10000 x r)
706 addc %r29,%r1,%r29 ; r29 = hi(10001 x r)
708 zdep %r25,23,24,%r1 ; r1 = lo(100000000 x r)
709 add %r1,%r25,%r1 ; r1 = lo(100000001 x r)
710 shd %r29,%r25,24,%r25 ; r25 = hi(100000000 x r)
711 addc %r25,%r29,%r25 ; r25 = hi(100000001 x r)
718 sh1add %r29,%r26,%r0 ; r0 = lo(10 x r) + dividend
719 shd %r1,%r29,31,%r29 ; r29 = hi(10 x r)
722 extru %r29,29,30,result
728 #if defined (L_divU_9) && !defined (SMALL_LIB)
730 #define dividend %r26
736 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
741 .callinfo frame=0,no_calls
746 subb %r1,0,%r1 /* 111 */
751 addc %r29,%r1,%r29 /* 111000111 */
754 shd %r29,%r25,29,%r25
755 addc %r25,0,%r25 /* 111000111001 */
760 subb %r1,%r25,%r1 /* 111000111000111000111000111 */
764 addc %r29,0,%r29 /* 111000111000111000111000111001 */
766 extru %r29,30,31,result
772 #if defined (L_divU_10) && !defined (SMALL_LIB)
774 #define dividend %r26
780 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
785 .callinfo frame=0,no_calls
787 sh1add %r26,%r26,%r29 ; r29 = lo(11 x r)
788 shd %r0,%r26,31,%r1 ; r1 = hi(10 x r)
789 addc %r1,%r0,%r1 ; r1 = hi(11 x r)
791 zdep %r29,27,28,%r25 ; r25 = lo(10000 x r)
792 add %r25,%r29,%r25 ; r25 = lo(10001 x r)
793 shd %r1,%r29,28,%r29 ; r29 = hi(10000 x r)
794 addc %r29,%r1,%r29 ; r29 = hi(10001 x r)
796 zdep %r25,23,24,%r1 ; r1 = lo(100000000 x r)
797 add %r1,%r25,%r1 ; r1 = lo(100000001 x r)
798 shd %r29,%r25,24,%r25 ; r25 = hi(100000000 x r)
799 addc %r25,%r29,%r25 ; r25 = hi(100000001 x r)
806 sh2add %r29,%r26,%r0 ; r0 = lo(1000 x r) + dividend
807 shd %r1,%r29,30,%r29 ; r29 = hi(1000 x r)
810 extru %r29,28,29,result
816 #if defined (L_divU_12) && !defined (SMALL_LIB)
818 #define dividend %r26
824 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
829 .callinfo frame=0,no_calls
831 sh2add %r26,%r26,%r29 ; r29 = lo(101 x r)
832 shd %r0,%r26,30,%r1 ; r1 = hi(100 x r)
833 addc %r1,%r0,%r1 ; r1 = hi(101 x r)
835 zdep %r29,27,28,%r25 ; r25 = lo(10000 x r)
836 add %r25,%r29,%r25 ; r25 = lo(10001 x r)
837 shd %r1,%r29,28,%r29 ; r29 = hi(10000 x r)
838 addc %r29,%r1,%r29 ; r29 = hi(10001 x r)
840 zdep %r25,23,24,%r1 ; r1 = lo(100000000 x r)
841 add %r1,%r25,%r1 ; r1 = lo(100000001 x r)
842 shd %r29,%r25,24,%r25 ; r25 = hi(100000000 x r)
843 addc %r25,%r29,%r25 ; r25 = hi(100000001 x r)
850 sh1add %r29,%r26,%r0 ; r0 = lo(10 x r) + dividend
851 shd %r1,%r29,31,%r29 ; r29 = hi(10 x r)
854 extru %r29,28,29,result
862 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
867 .callinfo frame=0,no_calls
873 .import $$divU,MILLICODE
878 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
883 .callinfo frame=0,no_calls
889 .import $$divU,MILLICODE
894 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
899 .callinfo frame=0,no_calls
905 .import $$divU,MILLICODE
910 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
915 .callinfo frame=0,no_calls
921 .import $$divU,MILLICODE
926 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
931 .callinfo frame=0,no_calls
937 .import $$divU,MILLICODE
942 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
947 .callinfo frame=0,no_calls
953 .import $$divU,MILLICODE
958 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
963 .callinfo frame=0,no_calls
969 .import $$divU,MILLICODE
974 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
979 .callinfo frame=0,no_calls
985 .import $$divU,MILLICODE
990 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
995 .callinfo frame=0,no_calls
1001 .import $$divU,MILLICODE
1006 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
1011 .callinfo frame=0,no_calls
1017 .import $$divI,MILLICODE
1022 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
1027 .callinfo frame=0,no_calls
1033 .import $$divI,MILLICODE
1038 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
1043 .callinfo frame=0,no_calls
1049 .import $$divI,MILLICODE
1054 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
1059 .callinfo frame=0,no_calls
1065 .import $$divI,MILLICODE
1070 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
1075 .callinfo frame=0,no_calls
1081 .import $$divI,MILLICODE
1086 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
1091 .callinfo frame=0,no_calls
1097 .import $$divI,MILLICODE
1102 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
1107 .callinfo frame=0,no_calls
1113 .import $$divI,MILLICODE
1118 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
1123 .callinfo frame=0,no_calls
1129 .import $$divI,MILLICODE
1134 .subspa $MILLICODE$,quad=0,align=8,access=0x2c,sort=8
1139 .callinfo frame=0,no_calls
1145 .import $$divI,MILLICODE