xref: /openbsd-src/gnu/llvm/compiler-rt/lib/builtins/avr/divmodqi4.S (revision 810390e339a5425391477d5d41c78d7cab2424ac)
1*810390e3Srobert//===------------- divmodqi4.S - sint8 div & mod --------------------------===//
2*810390e3Srobert//
3*810390e3Srobert// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*810390e3Srobert// See https://llvm.org/LICENSE.txt for license information.
5*810390e3Srobert// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*810390e3Srobert//
7*810390e3Srobert//===----------------------------------------------------------------------===//
8*810390e3Srobert//
9*810390e3Srobert// As described at
10*810390e3Srobert// https://gcc.gnu.org/wiki/avr-gcc#Exceptions_to_the_Calling_Convention, the
11*810390e3Srobert// prototype is `struct {sint8, sint8}  __divmodqi4(sint8, sint8)`.
12*810390e3Srobert// The sint8 quotient is returned via R24, and the sint8 remainder is returned
13*810390e3Srobert// via R25, while registers R23/Rtmp and bit T in SREG are clobbered.
14*810390e3Srobert//
15*810390e3Srobert//===----------------------------------------------------------------------===//
16*810390e3Srobert
17*810390e3Srobert	.text
18*810390e3Srobert	.align 2
19*810390e3Srobert
20*810390e3Srobert#ifdef __AVR_TINY__
21*810390e3Srobert	.set __tmp_reg__, 16
22*810390e3Srobert#else
23*810390e3Srobert	.set __tmp_reg__, 0
24*810390e3Srobert#endif
25*810390e3Srobert
26*810390e3Srobert	.globl __divmodqi4
27*810390e3Srobert	.type  __divmodqi4, @function
28*810390e3Srobert
29*810390e3Srobert__divmodqi4:
30*810390e3Srobert	bst     r24, 7
31*810390e3Srobert	mov     __tmp_reg__, r24
32*810390e3Srobert	eor     __tmp_reg__, r22
33*810390e3Srobert	sbrc    r24, 7
34*810390e3Srobert	neg     r24
35*810390e3Srobert	sbrc    r22, 7
36*810390e3Srobert	neg     r22
37*810390e3Srobert	rcall   __udivmodqi4   ; Call __udivmodqi4 to do real calculation.
38*810390e3Srobert	brtc    __divmodqi4_1
39*810390e3Srobert	neg     r25
40*810390e3Srobert
41*810390e3Srobert__divmodqi4_1:
42*810390e3Srobert	sbrc    __tmp_reg__, 7
43*810390e3Srobert	neg     r24
44*810390e3Srobert	ret                    ; Return quotient via R24 and remainder via R25.
45