58 lines · plain
1//===------------- divmodhi4.S - sint16 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-exception6//7//===----------------------------------------------------------------------===//8//9// As described at10// https://gcc.gnu.org/wiki/avr-gcc#Exceptions_to_the_Calling_Convention, the11// prototype is `struct {sint16, sint16} __divmodhi4(sint16, sint16)`.12// The sint16 quotient is returned via R23:R22, and the sint16 remainder is13// returned via R25:R24, while registers R21/R26/27/Rtmp and bit T in SREG14// are clobbered.15//16//===----------------------------------------------------------------------===//17 18 .text19 .align 220 21#ifdef __AVR_TINY__22 .set __tmp_reg__, 1623#else24 .set __tmp_reg__, 025#endif26 27 .globl __divmodhi428 .type __divmodhi4, @function29 30__divmodhi4:31 bst r25, 732 mov __tmp_reg__, r2333 brtc __divmodhi4_a34 com __tmp_reg__35 rcall __divmodhi4_b36 37__divmodhi4_a:38 sbrc r23, 739 rcall __divmodhi4_c40 rcall __udivmodhi4 ; Call __udivmodhi4 to do real calculation.41 sbrc __tmp_reg__, 742 rcall __divmodhi4_c43 brtc __divmodhi4_exit44 45__divmodhi4_b:46 com r2547 neg r2448 sbci r25, 25549 ret ; Return quotient via R23:R22 and remainder via R25:R24.50 51__divmodhi4_c:52 com r2353 neg r2254 sbci r23, 25555 56__divmodhi4_exit:57 ret ; Return quotient via R23:R22 and remainder via R25:r24.58