xref: /kernel/linux/linux-5.10/arch/c6x/lib/remu.S (revision 8c2ecf20)
18c2ecf20Sopenharmony_ci;; SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci;;  Copyright 2010  Free Software Foundation, Inc.
38c2ecf20Sopenharmony_ci;;  Contributed by Bernd Schmidt <bernds@codesourcery.com>.
48c2ecf20Sopenharmony_ci;;
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include <linux/linkage.h>
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci	;; ABI considerations for the divide functions
98c2ecf20Sopenharmony_ci	;; The following registers are call-used:
108c2ecf20Sopenharmony_ci	;; __c6xabi_divi A0,A1,A2,A4,A6,B0,B1,B2,B4,B5
118c2ecf20Sopenharmony_ci	;; __c6xabi_divu A0,A1,A2,A4,A6,B0,B1,B2,B4
128c2ecf20Sopenharmony_ci	;; __c6xabi_remi A1,A2,A4,A5,A6,B0,B1,B2,B4
138c2ecf20Sopenharmony_ci	;; __c6xabi_remu A1,A4,A5,A7,B0,B1,B2,B4
148c2ecf20Sopenharmony_ci	;;
158c2ecf20Sopenharmony_ci	;; In our implementation, divu and remu are leaf functions,
168c2ecf20Sopenharmony_ci	;; while both divi and remi call into divu.
178c2ecf20Sopenharmony_ci	;; A0 is not clobbered by any of the functions.
188c2ecf20Sopenharmony_ci	;; divu does not clobber B2 either, which is taken advantage of
198c2ecf20Sopenharmony_ci	;; in remi.
208c2ecf20Sopenharmony_ci	;; divi uses B5 to hold the original return address during
218c2ecf20Sopenharmony_ci	;; the call to divu.
228c2ecf20Sopenharmony_ci	;; remi uses B2 and A5 to hold the input values during the
238c2ecf20Sopenharmony_ci	;; call to divu.  It stores B3 in on the stack.
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci	.text
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ciENTRY(__c6xabi_remu)
298c2ecf20Sopenharmony_ci	;; The ABI seems designed to prevent these functions calling each other,
308c2ecf20Sopenharmony_ci	;; so we duplicate most of the divsi3 code here.
318c2ecf20Sopenharmony_ci	 mv	.s2x	A4, B1
328c2ecf20Sopenharmony_ci	 lmbd	.l2	1, B4, B1
338c2ecf20Sopenharmony_ci|| [!B1] b	.s2	B3	; RETURN A
348c2ecf20Sopenharmony_ci|| [!B1] mvk	.d2	1, B4
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	 mv	.l1x	B1, A7
378c2ecf20Sopenharmony_ci||	 shl	.s2	B4, B1, B4
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	 cmpltu	.l1x	A4, B4, A1
408c2ecf20Sopenharmony_ci   [!A1] sub	.l1x	A4, B4, A4
418c2ecf20Sopenharmony_ci	 shru	.s2	B4, 1, B4
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci_remu_loop:
448c2ecf20Sopenharmony_ci	 cmpgt	.l2	B1, 7, B0
458c2ecf20Sopenharmony_ci|| [B1]	 subc	.l1x	A4,B4,A4
468c2ecf20Sopenharmony_ci|| [B1]	 add	.s2	-1, B1, B1
478c2ecf20Sopenharmony_ci	;; RETURN A may happen here (note: must happen before the next branch)
488c2ecf20Sopenharmony_ci   [B1]	 subc	.l1x	A4,B4,A4
498c2ecf20Sopenharmony_ci|| [B1]	 add	.s2	-1, B1, B1
508c2ecf20Sopenharmony_ci|| [B0]	 b	.s1	_remu_loop
518c2ecf20Sopenharmony_ci   [B1]	 subc	.l1x	A4,B4,A4
528c2ecf20Sopenharmony_ci|| [B1]	 add	.s2	-1, B1, B1
538c2ecf20Sopenharmony_ci   [B1]	 subc	.l1x	A4,B4,A4
548c2ecf20Sopenharmony_ci|| [B1]	 add	.s2	-1, B1, B1
558c2ecf20Sopenharmony_ci   [B1]	 subc	.l1x	A4,B4,A4
568c2ecf20Sopenharmony_ci|| [B1]	 add	.s2	-1, B1, B1
578c2ecf20Sopenharmony_ci   [B1]	 subc	.l1x	A4,B4,A4
588c2ecf20Sopenharmony_ci|| [B1]	 add	.s2	-1, B1, B1
598c2ecf20Sopenharmony_ci   [B1]	 subc	.l1x	A4,B4,A4
608c2ecf20Sopenharmony_ci|| [B1]	 add	.s2	-1, B1, B1
618c2ecf20Sopenharmony_ci	;; loop backwards branch happens here
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	 ret	.s2	B3
648c2ecf20Sopenharmony_ci   [B1]	 subc	.l1x	A4,B4,A4
658c2ecf20Sopenharmony_ci|| [B1]	 add	.s2	-1, B1, B1
668c2ecf20Sopenharmony_ci   [B1]	 subc	.l1x	A4,B4,A4
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	 extu	.s1	A4, A7, A4
698c2ecf20Sopenharmony_ci	 nop	2
708c2ecf20Sopenharmony_ciENDPROC(__c6xabi_remu)
71