18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ciThis file is part of GNU CC.
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <asm/export.h>
98c2ecf20Sopenharmony_ci	.text
108c2ecf20Sopenharmony_ci	.align 4
118c2ecf20Sopenharmony_ci	.globl __divdi3
128c2ecf20Sopenharmony_ci__divdi3:
138c2ecf20Sopenharmony_ci	save %sp,-104,%sp
148c2ecf20Sopenharmony_ci	cmp %i0,0
158c2ecf20Sopenharmony_ci	bge .LL40
168c2ecf20Sopenharmony_ci	mov 0,%l4
178c2ecf20Sopenharmony_ci	mov -1,%l4
188c2ecf20Sopenharmony_ci	sub %g0,%i1,%o0
198c2ecf20Sopenharmony_ci	mov %o0,%o5
208c2ecf20Sopenharmony_ci	subcc %g0,%o0,%g0
218c2ecf20Sopenharmony_ci	sub %g0,%i0,%o0
228c2ecf20Sopenharmony_ci	subx %o0,0,%o4
238c2ecf20Sopenharmony_ci	mov %o4,%i0
248c2ecf20Sopenharmony_ci	mov %o5,%i1
258c2ecf20Sopenharmony_ci.LL40:
268c2ecf20Sopenharmony_ci	cmp %i2,0
278c2ecf20Sopenharmony_ci	bge .LL84
288c2ecf20Sopenharmony_ci	mov %i3,%o4
298c2ecf20Sopenharmony_ci	xnor %g0,%l4,%l4
308c2ecf20Sopenharmony_ci	sub %g0,%i3,%o0
318c2ecf20Sopenharmony_ci	mov %o0,%o3
328c2ecf20Sopenharmony_ci	subcc %g0,%o0,%g0
338c2ecf20Sopenharmony_ci	sub %g0,%i2,%o0
348c2ecf20Sopenharmony_ci	subx %o0,0,%o2
358c2ecf20Sopenharmony_ci	mov %o2,%i2
368c2ecf20Sopenharmony_ci	mov %o3,%i3
378c2ecf20Sopenharmony_ci	mov %i3,%o4
388c2ecf20Sopenharmony_ci.LL84:
398c2ecf20Sopenharmony_ci	cmp %i2,0
408c2ecf20Sopenharmony_ci	bne .LL45
418c2ecf20Sopenharmony_ci	mov %i1,%i3
428c2ecf20Sopenharmony_ci	cmp %o4,%i0
438c2ecf20Sopenharmony_ci	bleu .LL46
448c2ecf20Sopenharmony_ci	mov %i3,%o1
458c2ecf20Sopenharmony_ci	mov	32,%g1
468c2ecf20Sopenharmony_ci	subcc	%i0,%o4,%g0
478c2ecf20Sopenharmony_ci1:	bcs	5f
488c2ecf20Sopenharmony_ci	 addxcc %o1,%o1,%o1	! shift n1n0 and a q-bit in lsb
498c2ecf20Sopenharmony_ci	sub	%i0,%o4,%i0	! this kills msb of n
508c2ecf20Sopenharmony_ci	addx	%i0,%i0,%i0	! so this cannot give carry
518c2ecf20Sopenharmony_ci	subcc	%g1,1,%g1
528c2ecf20Sopenharmony_ci2:	bne	1b
538c2ecf20Sopenharmony_ci	 subcc	%i0,%o4,%g0
548c2ecf20Sopenharmony_ci	bcs	3f
558c2ecf20Sopenharmony_ci	 addxcc %o1,%o1,%o1	! shift n1n0 and a q-bit in lsb
568c2ecf20Sopenharmony_ci	b	3f
578c2ecf20Sopenharmony_ci	 sub	%i0,%o4,%i0	! this kills msb of n
588c2ecf20Sopenharmony_ci4:	sub	%i0,%o4,%i0
598c2ecf20Sopenharmony_ci5:	addxcc	%i0,%i0,%i0
608c2ecf20Sopenharmony_ci	bcc	2b
618c2ecf20Sopenharmony_ci	 subcc	%g1,1,%g1
628c2ecf20Sopenharmony_ci! Got carry from n.  Subtract next step to cancel this carry.
638c2ecf20Sopenharmony_ci	bne	4b
648c2ecf20Sopenharmony_ci	 addcc	%o1,%o1,%o1	! shift n1n0 and a 0-bit in lsb
658c2ecf20Sopenharmony_ci	sub	%i0,%o4,%i0
668c2ecf20Sopenharmony_ci3:	xnor	%o1,0,%o1
678c2ecf20Sopenharmony_ci	b .LL50
688c2ecf20Sopenharmony_ci	mov 0,%o2
698c2ecf20Sopenharmony_ci.LL46:
708c2ecf20Sopenharmony_ci	cmp %o4,0
718c2ecf20Sopenharmony_ci	bne .LL85
728c2ecf20Sopenharmony_ci	mov %i0,%o2
738c2ecf20Sopenharmony_ci	mov 1,%o0
748c2ecf20Sopenharmony_ci	mov 0,%o1
758c2ecf20Sopenharmony_ci	wr %g0, 0, %y
768c2ecf20Sopenharmony_ci	udiv %o0, %o1, %o0
778c2ecf20Sopenharmony_ci	mov %o0,%o4
788c2ecf20Sopenharmony_ci	mov %i0,%o2
798c2ecf20Sopenharmony_ci.LL85:
808c2ecf20Sopenharmony_ci	mov 0,%g3
818c2ecf20Sopenharmony_ci	mov	32,%g1
828c2ecf20Sopenharmony_ci	subcc	%g3,%o4,%g0
838c2ecf20Sopenharmony_ci1:	bcs	5f
848c2ecf20Sopenharmony_ci	 addxcc %o2,%o2,%o2	! shift n1n0 and a q-bit in lsb
858c2ecf20Sopenharmony_ci	sub	%g3,%o4,%g3	! this kills msb of n
868c2ecf20Sopenharmony_ci	addx	%g3,%g3,%g3	! so this cannot give carry
878c2ecf20Sopenharmony_ci	subcc	%g1,1,%g1
888c2ecf20Sopenharmony_ci2:	bne	1b
898c2ecf20Sopenharmony_ci	 subcc	%g3,%o4,%g0
908c2ecf20Sopenharmony_ci	bcs	3f
918c2ecf20Sopenharmony_ci	 addxcc %o2,%o2,%o2	! shift n1n0 and a q-bit in lsb
928c2ecf20Sopenharmony_ci	b	3f
938c2ecf20Sopenharmony_ci	 sub	%g3,%o4,%g3	! this kills msb of n
948c2ecf20Sopenharmony_ci4:	sub	%g3,%o4,%g3
958c2ecf20Sopenharmony_ci5:	addxcc	%g3,%g3,%g3
968c2ecf20Sopenharmony_ci	bcc	2b
978c2ecf20Sopenharmony_ci	 subcc	%g1,1,%g1
988c2ecf20Sopenharmony_ci! Got carry from n.  Subtract next step to cancel this carry.
998c2ecf20Sopenharmony_ci	bne	4b
1008c2ecf20Sopenharmony_ci	 addcc	%o2,%o2,%o2	! shift n1n0 and a 0-bit in lsb
1018c2ecf20Sopenharmony_ci	sub	%g3,%o4,%g3
1028c2ecf20Sopenharmony_ci3:	xnor	%o2,0,%o2
1038c2ecf20Sopenharmony_ci	mov %g3,%i0
1048c2ecf20Sopenharmony_ci	mov %i3,%o1
1058c2ecf20Sopenharmony_ci	mov	32,%g1
1068c2ecf20Sopenharmony_ci	subcc	%i0,%o4,%g0
1078c2ecf20Sopenharmony_ci1:	bcs	5f
1088c2ecf20Sopenharmony_ci	 addxcc %o1,%o1,%o1	! shift n1n0 and a q-bit in lsb
1098c2ecf20Sopenharmony_ci	sub	%i0,%o4,%i0	! this kills msb of n
1108c2ecf20Sopenharmony_ci	addx	%i0,%i0,%i0	! so this cannot give carry
1118c2ecf20Sopenharmony_ci	subcc	%g1,1,%g1
1128c2ecf20Sopenharmony_ci2:	bne	1b
1138c2ecf20Sopenharmony_ci	 subcc	%i0,%o4,%g0
1148c2ecf20Sopenharmony_ci	bcs	3f
1158c2ecf20Sopenharmony_ci	 addxcc %o1,%o1,%o1	! shift n1n0 and a q-bit in lsb
1168c2ecf20Sopenharmony_ci	b	3f
1178c2ecf20Sopenharmony_ci	 sub	%i0,%o4,%i0	! this kills msb of n
1188c2ecf20Sopenharmony_ci4:	sub	%i0,%o4,%i0
1198c2ecf20Sopenharmony_ci5:	addxcc	%i0,%i0,%i0
1208c2ecf20Sopenharmony_ci	bcc	2b
1218c2ecf20Sopenharmony_ci	 subcc	%g1,1,%g1
1228c2ecf20Sopenharmony_ci! Got carry from n.  Subtract next step to cancel this carry.
1238c2ecf20Sopenharmony_ci	bne	4b
1248c2ecf20Sopenharmony_ci	 addcc	%o1,%o1,%o1	! shift n1n0 and a 0-bit in lsb
1258c2ecf20Sopenharmony_ci	sub	%i0,%o4,%i0
1268c2ecf20Sopenharmony_ci3:	xnor	%o1,0,%o1
1278c2ecf20Sopenharmony_ci	b .LL86
1288c2ecf20Sopenharmony_ci	mov %o1,%l1
1298c2ecf20Sopenharmony_ci.LL45:
1308c2ecf20Sopenharmony_ci	cmp %i2,%i0
1318c2ecf20Sopenharmony_ci	bleu .LL51
1328c2ecf20Sopenharmony_ci	sethi %hi(65535),%o0
1338c2ecf20Sopenharmony_ci	b .LL78
1348c2ecf20Sopenharmony_ci	mov 0,%o1
1358c2ecf20Sopenharmony_ci.LL51:
1368c2ecf20Sopenharmony_ci	or %o0,%lo(65535),%o0
1378c2ecf20Sopenharmony_ci	cmp %i2,%o0
1388c2ecf20Sopenharmony_ci	bgu .LL58
1398c2ecf20Sopenharmony_ci	mov %i2,%o1
1408c2ecf20Sopenharmony_ci	cmp %i2,256
1418c2ecf20Sopenharmony_ci	addx %g0,-1,%o0
1428c2ecf20Sopenharmony_ci	b .LL64
1438c2ecf20Sopenharmony_ci	and %o0,8,%o2
1448c2ecf20Sopenharmony_ci.LL58:
1458c2ecf20Sopenharmony_ci	sethi %hi(16777215),%o0
1468c2ecf20Sopenharmony_ci	or %o0,%lo(16777215),%o0
1478c2ecf20Sopenharmony_ci	cmp %i2,%o0
1488c2ecf20Sopenharmony_ci	bgu .LL64
1498c2ecf20Sopenharmony_ci	mov 24,%o2
1508c2ecf20Sopenharmony_ci	mov 16,%o2
1518c2ecf20Sopenharmony_ci.LL64:
1528c2ecf20Sopenharmony_ci	srl %o1,%o2,%o0
1538c2ecf20Sopenharmony_ci	sethi %hi(__clz_tab),%o1
1548c2ecf20Sopenharmony_ci	or %o1,%lo(__clz_tab),%o1
1558c2ecf20Sopenharmony_ci	ldub [%o0+%o1],%o0
1568c2ecf20Sopenharmony_ci	add %o0,%o2,%o0
1578c2ecf20Sopenharmony_ci	mov 32,%o1
1588c2ecf20Sopenharmony_ci	subcc %o1,%o0,%o3
1598c2ecf20Sopenharmony_ci	bne,a .LL72
1608c2ecf20Sopenharmony_ci	sub %o1,%o3,%o1
1618c2ecf20Sopenharmony_ci	cmp %i0,%i2
1628c2ecf20Sopenharmony_ci	bgu .LL74
1638c2ecf20Sopenharmony_ci	cmp %i3,%o4
1648c2ecf20Sopenharmony_ci	blu .LL78
1658c2ecf20Sopenharmony_ci	mov 0,%o1
1668c2ecf20Sopenharmony_ci.LL74:
1678c2ecf20Sopenharmony_ci	b .LL78
1688c2ecf20Sopenharmony_ci	mov 1,%o1
1698c2ecf20Sopenharmony_ci.LL72:
1708c2ecf20Sopenharmony_ci	sll %i2,%o3,%o2
1718c2ecf20Sopenharmony_ci	srl %o4,%o1,%o0
1728c2ecf20Sopenharmony_ci	or %o2,%o0,%i2
1738c2ecf20Sopenharmony_ci	sll %o4,%o3,%o4
1748c2ecf20Sopenharmony_ci	srl %i0,%o1,%o2
1758c2ecf20Sopenharmony_ci	sll %i0,%o3,%o0
1768c2ecf20Sopenharmony_ci	srl %i3,%o1,%o1
1778c2ecf20Sopenharmony_ci	or %o0,%o1,%i0
1788c2ecf20Sopenharmony_ci	sll %i3,%o3,%i3
1798c2ecf20Sopenharmony_ci	mov %i0,%o1
1808c2ecf20Sopenharmony_ci	mov	32,%g1
1818c2ecf20Sopenharmony_ci	subcc	%o2,%i2,%g0
1828c2ecf20Sopenharmony_ci1:	bcs	5f
1838c2ecf20Sopenharmony_ci	 addxcc %o1,%o1,%o1	! shift n1n0 and a q-bit in lsb
1848c2ecf20Sopenharmony_ci	sub	%o2,%i2,%o2	! this kills msb of n
1858c2ecf20Sopenharmony_ci	addx	%o2,%o2,%o2	! so this cannot give carry
1868c2ecf20Sopenharmony_ci	subcc	%g1,1,%g1
1878c2ecf20Sopenharmony_ci2:	bne	1b
1888c2ecf20Sopenharmony_ci	 subcc	%o2,%i2,%g0
1898c2ecf20Sopenharmony_ci	bcs	3f
1908c2ecf20Sopenharmony_ci	 addxcc %o1,%o1,%o1	! shift n1n0 and a q-bit in lsb
1918c2ecf20Sopenharmony_ci	b	3f
1928c2ecf20Sopenharmony_ci	 sub	%o2,%i2,%o2	! this kills msb of n
1938c2ecf20Sopenharmony_ci4:	sub	%o2,%i2,%o2
1948c2ecf20Sopenharmony_ci5:	addxcc	%o2,%o2,%o2
1958c2ecf20Sopenharmony_ci	bcc	2b
1968c2ecf20Sopenharmony_ci	 subcc	%g1,1,%g1
1978c2ecf20Sopenharmony_ci! Got carry from n.  Subtract next step to cancel this carry.
1988c2ecf20Sopenharmony_ci	bne	4b
1998c2ecf20Sopenharmony_ci	 addcc	%o1,%o1,%o1	! shift n1n0 and a 0-bit in lsb
2008c2ecf20Sopenharmony_ci	sub	%o2,%i2,%o2
2018c2ecf20Sopenharmony_ci3:	xnor	%o1,0,%o1
2028c2ecf20Sopenharmony_ci	mov %o2,%i0
2038c2ecf20Sopenharmony_ci	wr	%g0,%o1,%y	! SPARC has 0-3 delay insn after a wr
2048c2ecf20Sopenharmony_ci	sra	%o4,31,%g2	! Do not move this insn
2058c2ecf20Sopenharmony_ci	and	%o1,%g2,%g2	! Do not move this insn
2068c2ecf20Sopenharmony_ci	andcc	%g0,0,%g1	! Do not move this insn
2078c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2088c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2098c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2108c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2118c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2128c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2138c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2148c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2158c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2168c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2178c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2188c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2198c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2208c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2218c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2228c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2238c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2248c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2258c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2268c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2278c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2288c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2298c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2308c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2318c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2328c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2338c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2348c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2358c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2368c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2378c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2388c2ecf20Sopenharmony_ci	mulscc	%g1,%o4,%g1
2398c2ecf20Sopenharmony_ci	mulscc	%g1,0,%g1
2408c2ecf20Sopenharmony_ci	add	%g1,%g2,%o0
2418c2ecf20Sopenharmony_ci	rd	%y,%o2
2428c2ecf20Sopenharmony_ci	cmp %o0,%i0
2438c2ecf20Sopenharmony_ci	bgu,a .LL78
2448c2ecf20Sopenharmony_ci	add %o1,-1,%o1
2458c2ecf20Sopenharmony_ci	bne,a .LL50
2468c2ecf20Sopenharmony_ci	mov 0,%o2
2478c2ecf20Sopenharmony_ci	cmp %o2,%i3
2488c2ecf20Sopenharmony_ci	bleu .LL50
2498c2ecf20Sopenharmony_ci	mov 0,%o2
2508c2ecf20Sopenharmony_ci	add %o1,-1,%o1
2518c2ecf20Sopenharmony_ci.LL78:
2528c2ecf20Sopenharmony_ci	mov 0,%o2
2538c2ecf20Sopenharmony_ci.LL50:
2548c2ecf20Sopenharmony_ci	mov %o1,%l1
2558c2ecf20Sopenharmony_ci.LL86:
2568c2ecf20Sopenharmony_ci	mov %o2,%l0
2578c2ecf20Sopenharmony_ci	mov %l0,%i0
2588c2ecf20Sopenharmony_ci	mov %l1,%i1
2598c2ecf20Sopenharmony_ci	cmp %l4,0
2608c2ecf20Sopenharmony_ci	be .LL81
2618c2ecf20Sopenharmony_ci	sub %g0,%i1,%o0
2628c2ecf20Sopenharmony_ci	mov %o0,%l3
2638c2ecf20Sopenharmony_ci	subcc %g0,%o0,%g0
2648c2ecf20Sopenharmony_ci	sub %g0,%i0,%o0
2658c2ecf20Sopenharmony_ci	subx %o0,0,%l2
2668c2ecf20Sopenharmony_ci	mov %l2,%i0
2678c2ecf20Sopenharmony_ci	mov %l3,%i1
2688c2ecf20Sopenharmony_ci.LL81:
2698c2ecf20Sopenharmony_ci	ret
2708c2ecf20Sopenharmony_ci	restore
2718c2ecf20Sopenharmony_ciEXPORT_SYMBOL(__divdi3)
272