Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/llvm-project/compiler-rt/lib/builtins/avr/udivmodqi4.S
35290 views
1
//===------------ udivmodqi4.S - uint8 div & mod --------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// As described at
10
// https://gcc.gnu.org/wiki/avr-gcc#Exceptions_to_the_Calling_Convention, the
11
// prototype is `struct {uint8, uint8} __udivmodqi4(uint8, uint8)`.
12
// The uint8 quotient is returned via R24, and the uint8 remainder is returned
13
// via R25, while R23 is clobbered.
14
//
15
//===----------------------------------------------------------------------===//
16
17
.text
18
.align 2
19
20
.globl __udivmodqi4
21
.type __udivmodqi4, @function
22
23
__udivmodqi4:
24
sub r25, r25 ; Initialize the remainder to zero.
25
ldi r23, 9 ; Only loop 8 rounds for uint8.
26
27
__udivmodqi4_loop:
28
adc r24, r24
29
dec r23
30
breq __udivmodqi4_end
31
adc r25, r25
32
cp r25, r22 ; Compare with the divisor.
33
brcs __udivmodqi4_loop
34
sub r25, r22 ; Subtract the divisor.
35
rjmp __udivmodqi4_loop
36
37
__udivmodqi4_end:
38
com r24 ; The uint8 quotient is returned via R24.
39
ret ; The uint8 remainder is returned via R25.
40
41