📄 libgcc.s
字号:
/* -*- Mode: Asm -*- *//* Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. Contributed by Denis Chertykov <denisc@overta.ru>This file is free software; you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by theFree Software Foundation; either version 2, or (at your option) anylater version.In addition to the permissions in the GNU General Public License, theFree Software Foundation gives you unlimited permission to link thecompiled version of this file into combinations with other programs,and to distribute those combinations without any restriction comingfrom the use of this file. (The General Public License restrictionsdo apply in other respects; for example, they cover modification ofthe file, and distribution when not linked into a combineexecutable.)This file is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; see the file COPYING. If not, write tothe Free Software Foundation, 59 Temple Place - Suite 330,Boston, MA 02111-1307, USA. */#define __zero_reg__ r1#define __tmp_reg__ r0#define __SREG__ 0x3f#define __SP_H__ 0x3e#define __SP_L__ 0x3d/* Most of the functions here are called directly from avr.md patterns, instead of using the standard libcall mechanisms. This can make better code because GCC knows exactly which of the call-used registers (not all of them) are clobbered. */ .section .text.libgcc, "ax", @progbits .macro mov_l r_dest, r_src#if defined (__AVR_ENHANCED__) movw \r_dest, \r_src#else mov \r_dest, \r_src#endif .endm .macro mov_h r_dest, r_src#if defined (__AVR_ENHANCED__) ; empty#else mov \r_dest, \r_src#endif .endm/* Note: mulqi3, mulhi3 are open-coded on the enhanced core. */#if !defined (__AVR_ENHANCED__)/******************************************************* Multiplication 8 x 8*******************************************************/#if defined (L_mulqi3)#define r_arg2 r22 /* multiplicand */#define r_arg1 r24 /* multiplier */#define r_res __tmp_reg__ /* result */ .global __mulqi3 .func __mulqi3__mulqi3: clr r_res ; clear result__mulqi3_loop: sbrc r_arg1,0 add r_res,r_arg2 add r_arg2,r_arg2 ; shift multiplicand breq __mulqi3_exit ; while multiplicand != 0 lsr r_arg1 ; brne __mulqi3_loop ; exit if multiplier = 0__mulqi3_exit: mov r_arg1,r_res ; result to return register ret#undef r_arg2 #undef r_arg1 #undef r_res .endfunc#endif /* defined (L_mulqi3) */#if defined (L_mulqihi3) .global __mulqihi3 .func __mulqihi3__mulqihi3: clr r25 sbrc r24, 7 dec r25 clr r23 sbrc r22, 7 dec r22 rjmp __mulhi3 .endfunc#endif /* defined (L_mulqihi3) */#if defined (L_umulqihi3) .global __umulqihi3 .func __umulqihi3__umulqihi3: clr r25 clr r23 rjmp __mulhi3 .endfunc#endif /* defined (L_umulqihi3) *//******************************************************* Multiplication 16 x 16*******************************************************/#if defined (L_mulhi3)#define r_arg1L r24 /* multiplier Low */#define r_arg1H r25 /* multiplier High */#define r_arg2L r22 /* multiplicand Low */#define r_arg2H r23 /* multiplicand High */#define r_resL __tmp_reg__ /* result Low */#define r_resH r21 /* result High */ .global __mulhi3 .func __mulhi3__mulhi3: clr r_resH ; clear result clr r_resL ; clear result__mulhi3_loop: sbrs r_arg1L,0 rjmp __mulhi3_skip1 add r_resL,r_arg2L ; result + multiplicand adc r_resH,r_arg2H__mulhi3_skip1: add r_arg2L,r_arg2L ; shift multiplicand adc r_arg2H,r_arg2H cp r_arg2L,__zero_reg__ cpc r_arg2H,__zero_reg__ breq __mulhi3_exit ; while multiplicand != 0 lsr r_arg1H ; gets LSB of multiplier ror r_arg1L sbiw r_arg1L,0 brne __mulhi3_loop ; exit if multiplier = 0__mulhi3_exit: mov r_arg1H,r_resH ; result to return register mov r_arg1L,r_resL ret#undef r_arg1L#undef r_arg1H#undef r_arg2L#undef r_arg2H#undef r_resL #undef r_resH .endfunc#endif /* defined (L_mulhi3) */#endif /* !defined (__AVR_ENHANCED__) */#if defined (L_mulhisi3) .global __mulhisi3 .func __mulhisi3__mulhisi3: mov_l r18, r24 mov_h r19, r25 clr r24 sbrc r23, 7 dec r24 mov r25, r24 clr r20 sbrc r19, 7 dec r20 mov r21, r20 rjmp __mulsi3 .endfunc#endif /* defined (L_mulhisi3) */#if defined (L_umulhisi3) .global __umulhisi3 .func __umulhisi3__umulhisi3: mov_l r18, r24 mov_h r19, r25 clr r24 clr r25 clr r20 clr r21 rjmp __mulsi3 .endfunc#endif /* defined (L_umulhisi3) */#if defined (L_mulsi3)/******************************************************* Multiplication 32 x 32*******************************************************/#define r_arg1L r22 /* multiplier Low */#define r_arg1H r23#define r_arg1HL r24#define r_arg1HH r25 /* multiplier High */#define r_arg2L r18 /* multiplicand Low */#define r_arg2H r19 #define r_arg2HL r20#define r_arg2HH r21 /* multiplicand High */ #define r_resL r26 /* result Low */#define r_resH r27#define r_resHL r30#define r_resHH r31 /* result High */ .global __mulsi3 .func __mulsi3__mulsi3:#if defined (__AVR_ENHANCED__) mul r_arg1L, r_arg2L movw r_resL, r0 mul r_arg1H, r_arg2H movw r_resHL, r0 mul r_arg1HL, r_arg2L add r_resHL, r0 adc r_resHH, r1 mul r_arg1L, r_arg2HL add r_resHL, r0 adc r_resHH, r1 mul r_arg1HH, r_arg2L add r_resHH, r0 mul r_arg1HL, r_arg2H add r_resHH, r0 mul r_arg1H, r_arg2HL add r_resHH, r0 mul r_arg1L, r_arg2HH add r_resHH, r0 clr r_arg1HH ; use instead of __zero_reg__ to add carry mul r_arg1H, r_arg2L add r_resH, r0 adc r_resHL, r1 adc r_resHH, r_arg1HH ; add carry mul r_arg1L, r_arg2H add r_resH, r0 adc r_resHL, r1 adc r_resHH, r_arg1HH ; add carry movw r_arg1L, r_resL movw r_arg1HL, r_resHL clr r1 ; __zero_reg__ clobbered by "mul" ret#else clr r_resHH ; clear result clr r_resHL ; clear result clr r_resH ; clear result clr r_resL ; clear result__mulsi3_loop: sbrs r_arg1L,0 rjmp __mulsi3_skip1 add r_resL,r_arg2L ; result + multiplicand adc r_resH,r_arg2H adc r_resHL,r_arg2HL adc r_resHH,r_arg2HH__mulsi3_skip1: add r_arg2L,r_arg2L ; shift multiplicand adc r_arg2H,r_arg2H adc r_arg2HL,r_arg2HL adc r_arg2HH,r_arg2HH lsr r_arg1HH ; gets LSB of multiplier ror r_arg1HL ror r_arg1H ror r_arg1L brne __mulsi3_loop sbiw r_arg1HL,0 cpc r_arg1H,r_arg1L brne __mulsi3_loop ; exit if multiplier = 0__mulsi3_exit: mov r_arg1HH,r_resHH ; result to return register mov r_arg1HL,r_resHL mov r_arg1H,r_resH mov r_arg1L,r_resL ret#endif /* !defined (__AVR_ENHANCED__) */#undef r_arg1L #undef r_arg1H #undef r_arg1HL#undef r_arg1HH #undef r_arg2L #undef r_arg2H #undef r_arg2HL#undef r_arg2HH #undef r_resL #undef r_resH #undef r_resHL #undef r_resHH .endfunc#endif /* defined (L_mulsi3) */ /******************************************************* Division 8 / 8 => (result + remainder)*******************************************************/#define r_rem r25 /* remainder */#define r_arg1 r24 /* dividend, quotient */#define r_arg2 r22 /* divisor */#define r_cnt r23 /* loop count */#if defined (L_udivmodqi4) .global __udivmodqi4 .func __udivmodqi4__udivmodqi4: sub r_rem,r_rem ; clear remainder and carry ldi r_cnt,9 ; init loop counter rjmp __udivmodqi4_ep ; jump to entry point__udivmodqi4_loop: rol r_rem ; shift dividend into remainder cp r_rem,r_arg2 ; compare remainder & divisor brcs __udivmodqi4_ep ; remainder <= divisor sub r_rem,r_arg2 ; restore remainder__udivmodqi4_ep: rol r_arg1 ; shift dividend (with CARRY) dec r_cnt ; decrement loop counter brne __udivmodqi4_loop com r_arg1 ; complement result ; because C flag was complemented in loop ret .endfunc#endif /* defined (L_udivmodqi4) */#if defined (L_divmodqi4) .global __divmodqi4 .func __divmodqi4__divmodqi4: bst r_arg1,7 ; store sign of dividend mov __tmp_reg__,r_arg1 eor __tmp_reg__,r_arg2; r0.7 is sign of result sbrc r_arg1,7 neg r_arg1 ; dividend negative : negate sbrc r_arg2,7 neg r_arg2 ; divisor negative : negate rcall __udivmodqi4 ; do the unsigned div/mod brtc __divmodqi4_1 neg r_rem ; correct remainder sign__divmodqi4_1: sbrc __tmp_reg__,7 neg r_arg1 ; correct result sign__divmodqi4_exit: ret .endfunc#endif /* defined (L_divmodqi4) */#undef r_rem#undef r_arg1#undef r_arg2#undef r_cnt /******************************************************* Division 16 / 16 => (result + remainder)*******************************************************/#define r_remL r26 /* remainder Low */#define r_remH r27 /* remainder High *//* return: remainder */#define r_arg1L r24 /* dividend Low */#define r_arg1H r25 /* dividend High *//* return: quotient */#define r_arg2L r22 /* divisor Low */#define r_arg2H r23 /* divisor High */ #define r_cnt r21 /* loop count */#if defined (L_udivmodhi4) .global __udivmodhi4 .func __udivmodhi4__udivmodhi4: sub r_remL,r_remL sub r_remH,r_remH ; clear remainder and carry ldi r_cnt,17 ; init loop counter rjmp __udivmodhi4_ep ; jump to entry point__udivmodhi4_loop: rol r_remL ; shift dividend into remainder rol r_remH cp r_remL,r_arg2L ; compare remainder & divisor cpc r_remH,r_arg2H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -