xref: /linux/arch/sparc/lib/divdi3.S (revision 03c11eb3b16dc0058589751dfd91f254be2be613)
1f8739b71SThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-or-later */
21da177e4SLinus Torvalds/* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
31da177e4SLinus Torvalds
41da177e4SLinus TorvaldsThis file is part of GNU CC.
51da177e4SLinus Torvalds
6f8739b71SThomas Gleixner */
71da177e4SLinus Torvalds
8*4cdb71b6SMasahiro Yamada#include <linux/export.h>
91da177e4SLinus Torvalds	.text
101da177e4SLinus Torvalds	.align 4
111da177e4SLinus Torvalds	.globl __divdi3
121da177e4SLinus Torvalds__divdi3:
131da177e4SLinus Torvalds	save %sp,-104,%sp
141da177e4SLinus Torvalds	cmp %i0,0
151da177e4SLinus Torvalds	bge .LL40
161da177e4SLinus Torvalds	mov 0,%l4
171da177e4SLinus Torvalds	mov -1,%l4
181da177e4SLinus Torvalds	sub %g0,%i1,%o0
191da177e4SLinus Torvalds	mov %o0,%o5
201da177e4SLinus Torvalds	subcc %g0,%o0,%g0
211da177e4SLinus Torvalds	sub %g0,%i0,%o0
221da177e4SLinus Torvalds	subx %o0,0,%o4
231da177e4SLinus Torvalds	mov %o4,%i0
241da177e4SLinus Torvalds	mov %o5,%i1
251da177e4SLinus Torvalds.LL40:
261da177e4SLinus Torvalds	cmp %i2,0
271da177e4SLinus Torvalds	bge .LL84
281da177e4SLinus Torvalds	mov %i3,%o4
291da177e4SLinus Torvalds	xnor %g0,%l4,%l4
301da177e4SLinus Torvalds	sub %g0,%i3,%o0
311da177e4SLinus Torvalds	mov %o0,%o3
321da177e4SLinus Torvalds	subcc %g0,%o0,%g0
331da177e4SLinus Torvalds	sub %g0,%i2,%o0
341da177e4SLinus Torvalds	subx %o0,0,%o2
351da177e4SLinus Torvalds	mov %o2,%i2
361da177e4SLinus Torvalds	mov %o3,%i3
371da177e4SLinus Torvalds	mov %i3,%o4
381da177e4SLinus Torvalds.LL84:
391da177e4SLinus Torvalds	cmp %i2,0
401da177e4SLinus Torvalds	bne .LL45
411da177e4SLinus Torvalds	mov %i1,%i3
421da177e4SLinus Torvalds	cmp %o4,%i0
431da177e4SLinus Torvalds	bleu .LL46
441da177e4SLinus Torvalds	mov %i3,%o1
451da177e4SLinus Torvalds	mov	32,%g1
461da177e4SLinus Torvalds	subcc	%i0,%o4,%g0
471da177e4SLinus Torvalds1:	bcs	5f
481da177e4SLinus Torvalds	 addxcc %o1,%o1,%o1	! shift n1n0 and a q-bit in lsb
491da177e4SLinus Torvalds	sub	%i0,%o4,%i0	! this kills msb of n
501da177e4SLinus Torvalds	addx	%i0,%i0,%i0	! so this cannot give carry
511da177e4SLinus Torvalds	subcc	%g1,1,%g1
521da177e4SLinus Torvalds2:	bne	1b
531da177e4SLinus Torvalds	 subcc	%i0,%o4,%g0
541da177e4SLinus Torvalds	bcs	3f
551da177e4SLinus Torvalds	 addxcc %o1,%o1,%o1	! shift n1n0 and a q-bit in lsb
561da177e4SLinus Torvalds	b	3f
571da177e4SLinus Torvalds	 sub	%i0,%o4,%i0	! this kills msb of n
581da177e4SLinus Torvalds4:	sub	%i0,%o4,%i0
591da177e4SLinus Torvalds5:	addxcc	%i0,%i0,%i0
601da177e4SLinus Torvalds	bcc	2b
611da177e4SLinus Torvalds	 subcc	%g1,1,%g1
621da177e4SLinus Torvalds! Got carry from n.  Subtract next step to cancel this carry.
631da177e4SLinus Torvalds	bne	4b
641da177e4SLinus Torvalds	 addcc	%o1,%o1,%o1	! shift n1n0 and a 0-bit in lsb
651da177e4SLinus Torvalds	sub	%i0,%o4,%i0
661da177e4SLinus Torvalds3:	xnor	%o1,0,%o1
671da177e4SLinus Torvalds	b .LL50
681da177e4SLinus Torvalds	mov 0,%o2
691da177e4SLinus Torvalds.LL46:
701da177e4SLinus Torvalds	cmp %o4,0
711da177e4SLinus Torvalds	bne .LL85
721da177e4SLinus Torvalds	mov %i0,%o2
731da177e4SLinus Torvalds	mov 1,%o0
741da177e4SLinus Torvalds	mov 0,%o1
751b35a57bSDavid S. Miller	wr %g0, 0, %y
761b35a57bSDavid S. Miller	udiv %o0, %o1, %o0
771da177e4SLinus Torvalds	mov %o0,%o4
781da177e4SLinus Torvalds	mov %i0,%o2
791da177e4SLinus Torvalds.LL85:
801da177e4SLinus Torvalds	mov 0,%g3
811da177e4SLinus Torvalds	mov	32,%g1
821da177e4SLinus Torvalds	subcc	%g3,%o4,%g0
831da177e4SLinus Torvalds1:	bcs	5f
841da177e4SLinus Torvalds	 addxcc %o2,%o2,%o2	! shift n1n0 and a q-bit in lsb
851da177e4SLinus Torvalds	sub	%g3,%o4,%g3	! this kills msb of n
861da177e4SLinus Torvalds	addx	%g3,%g3,%g3	! so this cannot give carry
871da177e4SLinus Torvalds	subcc	%g1,1,%g1
881da177e4SLinus Torvalds2:	bne	1b
891da177e4SLinus Torvalds	 subcc	%g3,%o4,%g0
901da177e4SLinus Torvalds	bcs	3f
911da177e4SLinus Torvalds	 addxcc %o2,%o2,%o2	! shift n1n0 and a q-bit in lsb
921da177e4SLinus Torvalds	b	3f
931da177e4SLinus Torvalds	 sub	%g3,%o4,%g3	! this kills msb of n
941da177e4SLinus Torvalds4:	sub	%g3,%o4,%g3
951da177e4SLinus Torvalds5:	addxcc	%g3,%g3,%g3
961da177e4SLinus Torvalds	bcc	2b
971da177e4SLinus Torvalds	 subcc	%g1,1,%g1
981da177e4SLinus Torvalds! Got carry from n.  Subtract next step to cancel this carry.
991da177e4SLinus Torvalds	bne	4b
1001da177e4SLinus Torvalds	 addcc	%o2,%o2,%o2	! shift n1n0 and a 0-bit in lsb
1011da177e4SLinus Torvalds	sub	%g3,%o4,%g3
1021da177e4SLinus Torvalds3:	xnor	%o2,0,%o2
1031da177e4SLinus Torvalds	mov %g3,%i0
1041da177e4SLinus Torvalds	mov %i3,%o1
1051da177e4SLinus Torvalds	mov	32,%g1
1061da177e4SLinus Torvalds	subcc	%i0,%o4,%g0
1071da177e4SLinus Torvalds1:	bcs	5f
1081da177e4SLinus Torvalds	 addxcc %o1,%o1,%o1	! shift n1n0 and a q-bit in lsb
1091da177e4SLinus Torvalds	sub	%i0,%o4,%i0	! this kills msb of n
1101da177e4SLinus Torvalds	addx	%i0,%i0,%i0	! so this cannot give carry
1111da177e4SLinus Torvalds	subcc	%g1,1,%g1
1121da177e4SLinus Torvalds2:	bne	1b
1131da177e4SLinus Torvalds	 subcc	%i0,%o4,%g0
1141da177e4SLinus Torvalds	bcs	3f
1151da177e4SLinus Torvalds	 addxcc %o1,%o1,%o1	! shift n1n0 and a q-bit in lsb
1161da177e4SLinus Torvalds	b	3f
1171da177e4SLinus Torvalds	 sub	%i0,%o4,%i0	! this kills msb of n
1181da177e4SLinus Torvalds4:	sub	%i0,%o4,%i0
1191da177e4SLinus Torvalds5:	addxcc	%i0,%i0,%i0
1201da177e4SLinus Torvalds	bcc	2b
1211da177e4SLinus Torvalds	 subcc	%g1,1,%g1
1221da177e4SLinus Torvalds! Got carry from n.  Subtract next step to cancel this carry.
1231da177e4SLinus Torvalds	bne	4b
1241da177e4SLinus Torvalds	 addcc	%o1,%o1,%o1	! shift n1n0 and a 0-bit in lsb
1251da177e4SLinus Torvalds	sub	%i0,%o4,%i0
1261da177e4SLinus Torvalds3:	xnor	%o1,0,%o1
1271da177e4SLinus Torvalds	b .LL86
1281da177e4SLinus Torvalds	mov %o1,%l1
1291da177e4SLinus Torvalds.LL45:
1301da177e4SLinus Torvalds	cmp %i2,%i0
1311da177e4SLinus Torvalds	bleu .LL51
1321da177e4SLinus Torvalds	sethi %hi(65535),%o0
1331da177e4SLinus Torvalds	b .LL78
1341da177e4SLinus Torvalds	mov 0,%o1
1351da177e4SLinus Torvalds.LL51:
1361da177e4SLinus Torvalds	or %o0,%lo(65535),%o0
1371da177e4SLinus Torvalds	cmp %i2,%o0
1381da177e4SLinus Torvalds	bgu .LL58
1391da177e4SLinus Torvalds	mov %i2,%o1
1401da177e4SLinus Torvalds	cmp %i2,256
1411da177e4SLinus Torvalds	addx %g0,-1,%o0
1421da177e4SLinus Torvalds	b .LL64
1431da177e4SLinus Torvalds	and %o0,8,%o2
1441da177e4SLinus Torvalds.LL58:
1451da177e4SLinus Torvalds	sethi %hi(16777215),%o0
1461da177e4SLinus Torvalds	or %o0,%lo(16777215),%o0
1471da177e4SLinus Torvalds	cmp %i2,%o0
1481da177e4SLinus Torvalds	bgu .LL64
1491da177e4SLinus Torvalds	mov 24,%o2
1501da177e4SLinus Torvalds	mov 16,%o2
1511da177e4SLinus Torvalds.LL64:
1521da177e4SLinus Torvalds	srl %o1,%o2,%o0
1531da177e4SLinus Torvalds	sethi %hi(__clz_tab),%o1
1541da177e4SLinus Torvalds	or %o1,%lo(__clz_tab),%o1
1551da177e4SLinus Torvalds	ldub [%o0+%o1],%o0
1561da177e4SLinus Torvalds	add %o0,%o2,%o0
1571da177e4SLinus Torvalds	mov 32,%o1
1581da177e4SLinus Torvalds	subcc %o1,%o0,%o3
1591da177e4SLinus Torvalds	bne,a .LL72
1601da177e4SLinus Torvalds	sub %o1,%o3,%o1
1611da177e4SLinus Torvalds	cmp %i0,%i2
1621da177e4SLinus Torvalds	bgu .LL74
1631da177e4SLinus Torvalds	cmp %i3,%o4
1641da177e4SLinus Torvalds	blu .LL78
1651da177e4SLinus Torvalds	mov 0,%o1
1661da177e4SLinus Torvalds.LL74:
1671da177e4SLinus Torvalds	b .LL78
1681da177e4SLinus Torvalds	mov 1,%o1
1691da177e4SLinus Torvalds.LL72:
1701da177e4SLinus Torvalds	sll %i2,%o3,%o2
1711da177e4SLinus Torvalds	srl %o4,%o1,%o0
1721da177e4SLinus Torvalds	or %o2,%o0,%i2
1731da177e4SLinus Torvalds	sll %o4,%o3,%o4
1741da177e4SLinus Torvalds	srl %i0,%o1,%o2
1751da177e4SLinus Torvalds	sll %i0,%o3,%o0
1761da177e4SLinus Torvalds	srl %i3,%o1,%o1
1771da177e4SLinus Torvalds	or %o0,%o1,%i0
1781da177e4SLinus Torvalds	sll %i3,%o3,%i3
1791da177e4SLinus Torvalds	mov %i0,%o1
1801da177e4SLinus Torvalds	mov	32,%g1
1811da177e4SLinus Torvalds	subcc	%o2,%i2,%g0
1821da177e4SLinus Torvalds1:	bcs	5f
1831da177e4SLinus Torvalds	 addxcc %o1,%o1,%o1	! shift n1n0 and a q-bit in lsb
1841da177e4SLinus Torvalds	sub	%o2,%i2,%o2	! this kills msb of n
1851da177e4SLinus Torvalds	addx	%o2,%o2,%o2	! so this cannot give carry
1861da177e4SLinus Torvalds	subcc	%g1,1,%g1
1871da177e4SLinus Torvalds2:	bne	1b
1881da177e4SLinus Torvalds	 subcc	%o2,%i2,%g0
1891da177e4SLinus Torvalds	bcs	3f
1901da177e4SLinus Torvalds	 addxcc %o1,%o1,%o1	! shift n1n0 and a q-bit in lsb
1911da177e4SLinus Torvalds	b	3f
1921da177e4SLinus Torvalds	 sub	%o2,%i2,%o2	! this kills msb of n
1931da177e4SLinus Torvalds4:	sub	%o2,%i2,%o2
1941da177e4SLinus Torvalds5:	addxcc	%o2,%o2,%o2
1951da177e4SLinus Torvalds	bcc	2b
1961da177e4SLinus Torvalds	 subcc	%g1,1,%g1
1971da177e4SLinus Torvalds! Got carry from n.  Subtract next step to cancel this carry.
1981da177e4SLinus Torvalds	bne	4b
1991da177e4SLinus Torvalds	 addcc	%o1,%o1,%o1	! shift n1n0 and a 0-bit in lsb
2001da177e4SLinus Torvalds	sub	%o2,%i2,%o2
2011da177e4SLinus Torvalds3:	xnor	%o1,0,%o1
2021da177e4SLinus Torvalds	mov %o2,%i0
2031da177e4SLinus Torvalds	wr	%g0,%o1,%y	! SPARC has 0-3 delay insn after a wr
2041da177e4SLinus Torvalds	sra	%o4,31,%g2	! Do not move this insn
2051da177e4SLinus Torvalds	and	%o1,%g2,%g2	! Do not move this insn
2061da177e4SLinus Torvalds	andcc	%g0,0,%g1	! Do not move this insn
2071da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2081da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2091da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2101da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2111da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2121da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2131da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2141da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2151da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2161da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2171da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2181da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2191da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2201da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2211da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2221da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2231da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2241da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2251da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2261da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2271da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2281da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2291da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2301da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2311da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2321da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2331da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2341da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2351da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2361da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2371da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2381da177e4SLinus Torvalds	mulscc	%g1,%o4,%g1
2391da177e4SLinus Torvalds	mulscc	%g1,0,%g1
2401da177e4SLinus Torvalds	add	%g1,%g2,%o0
2411da177e4SLinus Torvalds	rd	%y,%o2
2421da177e4SLinus Torvalds	cmp %o0,%i0
2431da177e4SLinus Torvalds	bgu,a .LL78
2441da177e4SLinus Torvalds	add %o1,-1,%o1
2451da177e4SLinus Torvalds	bne,a .LL50
2461da177e4SLinus Torvalds	mov 0,%o2
2471da177e4SLinus Torvalds	cmp %o2,%i3
2481da177e4SLinus Torvalds	bleu .LL50
2491da177e4SLinus Torvalds	mov 0,%o2
2501da177e4SLinus Torvalds	add %o1,-1,%o1
2511da177e4SLinus Torvalds.LL78:
2521da177e4SLinus Torvalds	mov 0,%o2
2531da177e4SLinus Torvalds.LL50:
2541da177e4SLinus Torvalds	mov %o1,%l1
2551da177e4SLinus Torvalds.LL86:
2561da177e4SLinus Torvalds	mov %o2,%l0
2571da177e4SLinus Torvalds	mov %l0,%i0
2581da177e4SLinus Torvalds	mov %l1,%i1
2591da177e4SLinus Torvalds	cmp %l4,0
2601da177e4SLinus Torvalds	be .LL81
2611da177e4SLinus Torvalds	sub %g0,%i1,%o0
2621da177e4SLinus Torvalds	mov %o0,%l3
2631da177e4SLinus Torvalds	subcc %g0,%o0,%g0
2641da177e4SLinus Torvalds	sub %g0,%i0,%o0
2651da177e4SLinus Torvalds	subx %o0,0,%l2
2661da177e4SLinus Torvalds	mov %l2,%i0
2671da177e4SLinus Torvalds	mov %l3,%i1
2681da177e4SLinus Torvalds.LL81:
2691da177e4SLinus Torvalds	ret
2701da177e4SLinus Torvalds	restore
271d3867f04SAl ViroEXPORT_SYMBOL(__divdi3)
272