2019-05-27 08:55:05 +02:00
;; SPDX-License-Identifier: GPL-2.0-or-later
2011-10-04 11:15:51 -04:00
;; Copyright 2010 Free Software Foundation, Inc.
;; Contributed by Bernd Schmidt <bernds@codesourcery.com>.
;;
# include < l i n u x / l i n k a g e . h >
;; ABI considerations for the divide functions
;; The following registers are call-used:
;; __c6xabi_divi A0,A1,A2,A4,A6,B0,B1,B2,B4,B5
;; __c6xabi_divu A0,A1,A2,A4,A6,B0,B1,B2,B4
;; __c6xabi_remi A1,A2,A4,A5,A6,B0,B1,B2,B4
;; __c6xabi_remu A1,A4,A5,A7,B0,B1,B2,B4
;;
;; In our implementation, divu and remu are leaf functions,
;; while both divi and remi call into divu.
;; A0 is not clobbered by any of the functions.
;; divu does not clobber B2 either, which is taken advantage of
;; in remi.
;; divi uses B5 to hold the original return address during
;; the call to divu.
;; remi uses B2 and A5 to hold the input values during the
;; call to divu. It stores B3 in on the stack.
.text
ENTRY( _ _ c6 x a b i _ r e m u )
;; The ABI seems designed to prevent these functions calling each other,
;; so we duplicate most of the divsi3 code here.
mv . s2 x A 4 , B 1
lmbd . l 2 1 , B 4 , B 1
| | [ ! B1 ] b . s2 B 3 ; RETURN A
| | [ ! B1 ] m v k . d2 1 , B 4
mv . l 1 x B 1 , A 7
| | shl . s2 B 4 , B 1 , B 4
cmpltu . l 1 x A 4 , B 4 , A 1
[ ! A1 ] s u b . l 1 x A 4 , B 4 , A 4
shru . s2 B 4 , 1 , B 4
_remu_loop :
cmpgt . l 2 B 1 , 7 , B 0
| | [ B1 ] s u b c . l 1 x A 4 ,B 4 ,A 4
| | [ B1 ] a d d . s2 - 1 , B 1 , B 1
;; RETURN A may happen here (note: must happen before the next branch)
[ B1 ] s u b c . l 1 x A 4 ,B 4 ,A 4
| | [ B1 ] a d d . s2 - 1 , B 1 , B 1
| | [ B0 ] b . s1 _ r e m u _ l o o p
[ B1 ] s u b c . l 1 x A 4 ,B 4 ,A 4
| | [ B1 ] a d d . s2 - 1 , B 1 , B 1
[ B1 ] s u b c . l 1 x A 4 ,B 4 ,A 4
| | [ B1 ] a d d . s2 - 1 , B 1 , B 1
[ B1 ] s u b c . l 1 x A 4 ,B 4 ,A 4
| | [ B1 ] a d d . s2 - 1 , B 1 , B 1
[ B1 ] s u b c . l 1 x A 4 ,B 4 ,A 4
| | [ B1 ] a d d . s2 - 1 , B 1 , B 1
[ B1 ] s u b c . l 1 x A 4 ,B 4 ,A 4
| | [ B1 ] a d d . s2 - 1 , B 1 , B 1
;; loop backwards branch happens here
ret . s2 B 3
[ B1 ] s u b c . l 1 x A 4 ,B 4 ,A 4
| | [ B1 ] a d d . s2 - 1 , B 1 , B 1
[ B1 ] s u b c . l 1 x A 4 ,B 4 ,A 4
extu . s1 A 4 , A 7 , A 4
nop 2
ENDPROC( _ _ c6 x a b i _ r e m u )