Path: blob/main/contrib/llvm-project/compiler-rt/lib/builtins/avr/udivmodhi4.S
35290 views
//===------------ udivmodhi4.S - uint16 div & mod -------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// As described at9// https://gcc.gnu.org/wiki/avr-gcc#Exceptions_to_the_Calling_Convention, the10// prototype is `struct {uint16, uint16} __udivmodhi4(uint16, uint16)`.11// The uint16 quotient is returned via R23:R22, and the uint16 remainder is12// returned via R25:R24, while R21/R26/R27 are clobbered.13//14//===----------------------------------------------------------------------===//1516.text17.align 21819.globl __udivmodhi420.type __udivmodhi4, @function2122__udivmodhi4:23sub r26, r2624sub r27, r27 ; Initialize the remainder to zero.25ldi r21, 17 ; Only loop 16 rounds for uint16.2627__udivmodhi4_loop:28adc r24, r2429adc r25, r2530dec r2131breq __udivmodhi4_end32adc r26, r2633adc r27, r2734cp r26, r2235cpc r27, r23 ; Compare with the divisor.36brcs __udivmodhi4_loop37sub r26, r2238sbc r27, r23 ; Subtract the divisor.39rjmp __udivmodhi4_loop4041__udivmodhi4_end:42com r2443com r2544mov r22, r2445mov r23, r25 ; The quotient is returned in R23:R22.46mov r24, r2647mov r25, r27 ; The remainder is returned in in R25:R24.48ret495051