gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 3ef4db914e2c9ddea0ba22020bdac4fd2f951362 parent f2f7d3e29025d37b1fb30859681daf235a034c20 Author: Toxa <untoxa@mail.ru> Date: Thu, 1 Jul 2021 01:12:34 +0300 cleanup SDCC native library artifacts Diffstat:
| M | gbdk-lib/libc/_divslong.c | 229 | +------------------------------------------------------------------------------ |
| M | gbdk-lib/libc/_memmove.c | 1 | - |
| M | gbdk-lib/libc/_modslong.c | 234 | +------------------------------------------------------------------------------ |
| M | gbdk-lib/libc/_modulong.c | 310 | +------------------------------------------------------------------------------ |
| M | gbdk-lib/libc/_mullong.c | 673 | +------------------------------------------------------------------------------ |
5 files changed, 5 insertions(+), 1442 deletions(-)
diff --git a/gbdk-lib/libc/_divslong.c b/gbdk-lib/libc/_divslong.c @@ -26,234 +26,9 @@ might be covered by the GNU General Public License. -------------------------------------------------------------------------*/ -#ifndef GBDK -#include <sdcc-lib.h> -#endif - -#if _SDCC_MANGLES_SUPPORT_FUNS || GBDK unsigned long _divulong (unsigned long a, unsigned long b); -#endif - -/* Assembler-functions are provided for: - mcs51 small - mcs51 small stack-auto -*/ - -#if !defined(SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS) -# if defined(SDCC_mcs51) -# if defined(SDCC_MODEL_SMALL) -# if defined(SDCC_STACK_AUTO) -# define _DIVSLONG_ASM_SMALL_AUTO -# else -# define _DIVSLONG_ASM_SMALL -# endif -# endif -# endif -#endif - -#if defined _DIVSLONG_ASM_SMALL - -static void -_divslong_dummy (void) _naked -{ - _asm - - #define a0 dpl - #define a1 dph - #define a2 b - #define a3 r3 - - .globl __divslong - - // _divslong_PARM_2 shares the same memory with _divulong_PARM_2 - // and is defined in _divulong.c - #define b0 (__divslong_PARM_2) - #define b1 (__divslong_PARM_2 + 1) - #define b2 (__divslong_PARM_2 + 2) - #define b3 (__divslong_PARM_2 + 3) - - __divslong: - ; a3 in acc - ; b3 in (__divslong_PARM_2 + 3) - mov a3,a ; save a3 - - clr F0 ; Flag 0 in PSW - ; available to user for general purpose - jnb acc.7,a_not_negative - - setb F0 - - clr a - clr c - subb a,a0 - mov a0,a - clr a - subb a,a1 - mov a1,a - clr a - subb a,a2 - mov a2,a - clr a - subb a,a3 - mov a3,a - - a_not_negative: - - mov a,b3 - jnb acc.7,b_not_negative - - cpl F0 - - clr a - clr c - subb a,b0 - mov b0,a - clr a - subb a,b1 - mov b1,a - clr a - subb a,b2 - mov b2,a - clr a - subb a,b3 - mov b3,a - - b_not_negative: - - mov a,a3 ; restore a3 in acc - - lcall __divulong - - jnb F0,not_negative - - mov a3,a ; save a3 - - clr a - clr c - subb a,a0 - mov a0,a - clr a - subb a,a1 - mov a1,a - clr a - subb a,a2 - mov a2,a - clr a - subb a,a3 - mov a3,a - - not_negative: - ret - - _endasm ; -} -#elif defined _DIVSLONG_ASM_SMALL_AUTO - -static void -_divslong_dummy (void) _naked -{ - _asm - - #define a0 dpl - #define a1 dph - #define a2 b - #define a3 r3 - - .globl __divslong - - __divslong: - - ; a3 in acc - mov a3,a ; save a3 - - clr F0 ; Flag 0 in PSW - ; available to user for general purpose - jnb acc.7,a_not_negative - - setb F0 - - clr a - clr c - subb a,a0 - mov a0,a - clr a - subb a,a1 - mov a1,a - clr a - subb a,a2 - mov a2,a - clr a - subb a,a3 - mov a3,a - - a_not_negative: - - mov a,sp - add a,#-2 ; 2 bytes return address - mov r0,a ; r0 points to b3 - mov a,@r0 ; b3 - - jnb acc.7,b_not_negative - - cpl F0 - - dec r0 - dec r0 - dec r0 - - clr a - clr c - subb a,@r0 ; b0 - mov @r0,a - clr a - inc r0 - subb a,@r0 ; b1 - mov @r0,a - clr a - inc r0 - subb a,@r0 ; b2 - mov @r0,a - clr a - inc r0 - subb a,@r0 ; b3 - mov @r0,a - - b_not_negative: - dec r0 - dec r0 - dec r0 ; r0 points to b0 - - lcall __divlong - - jnb F0,not_negative - - mov a3,a ; save a3 - - clr a - clr c - subb a,a0 - mov a0,a - clr a - subb a,a1 - mov a1,a - clr a - subb a,a2 - mov a2,a - clr a - subb a,a3 - mov a3,a - - not_negative: - ret - - _endasm ; -} - -#else // _DIVSLONG_ASM - -long -_divslong (long a, long b) +long _divslong (long a, long b) { long r; @@ -264,5 +39,3 @@ _divslong (long a, long b) else return r; } - -#endif // _DIVSLONG_ASM diff --git a/gbdk-lib/libc/_memmove.c b/gbdk-lib/libc/_memmove.c @@ -29,7 +29,6 @@ -------------------------------------------------------------------------*/ #include <string.h> #include <stdint.h> -#include <sdcc-lib.h> void *memmove (void *dst, const void *src, size_t size) { diff --git a/gbdk-lib/libc/_modslong.c b/gbdk-lib/libc/_modslong.c @@ -26,239 +26,9 @@ might be covered by the GNU General Public License. -------------------------------------------------------------------------*/ -#ifndef GBDK -#include <sdcc-lib.h> -#endif - -#if _SDCC_MANGLES_SUPPORT_FUNS || GBDK unsigned long _modulong (unsigned long a, unsigned long b); -#endif - -/* Assembler-functions are provided for: - mcs51 small - mcs51 small stack-auto -*/ - -#if !defined(SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS) -# if defined(SDCC_mcs51) -# if defined(SDCC_MODEL_SMALL) -# if defined(SDCC_STACK_AUTO) -# define _MODSLONG_ASM_SMALL_AUTO -# else -# define _MODSLONG_ASM_SMALL -# endif -# endif -# endif -#endif - -#if defined _MODSLONG_ASM_SMALL - -static void -_modslong_dummy (void) _naked -{ - _asm - - #define a0 dpl - #define a1 dph - #define a2 b - #define a3 r1 - - .globl __modslong - - // _modslong_PARM_2 shares the same memory with _modulong_PARM_2 - // and is defined in _modulong.c - #define b0 (__modslong_PARM_2) - #define b1 (__modslong_PARM_2 + 1) - #define b2 (__modslong_PARM_2 + 2) - #define b3 (__modslong_PARM_2 + 3) - - __modslong: - ; a3 in acc - ; b3 in (__modslong_PARM_2 + 3) - mov a3,a ; save a3 - - clr F0 ; Flag 0 in PSW - ; available to user for general purpose - jnb acc.7,a_not_negative - - setb F0 - - clr a ; a = -a; - clr c - subb a,a0 - mov a0,a - clr a - subb a,a1 - mov a1,a - clr a - subb a,a2 - mov a2,a - clr a - subb a,a3 - mov a3,a - - a_not_negative: - - mov a,b3 - jnb acc.7,b_not_negative - - cpl F0 - - clr a ; b = -b; - clr c - subb a,b0 - mov b0,a - clr a - subb a,b1 - mov b1,a - clr a - subb a,b2 - mov b2,a - clr a - subb a,b3 - mov b3,a - - b_not_negative: - - mov a,a3 ; restore a3 in acc - - lcall __modulong - - jnb F0,not_negative - - ; result in (a == r1), b, dph, dpl - clr a - clr c - subb a,a0 - mov a0,a - clr a - subb a,a1 - mov a1,a - clr a - subb a,a2 - mov a2,a - clr a - subb a,a3 - ; result in a, b, dph, dpl - not_negative: - ret - - _endasm ; -} - -#elif defined _MODSLONG_ASM_SMALL_AUTO - -static void -_modslong_dummy (void) _naked -{ - _asm - - #define a0 dpl - #define a1 dph - #define a2 b - #define a3 r1 - - #define b0 r2 - #define b1 r3 - #define b2 r4 - #define b3 r5 - - ar2 = 2 ; BUG register set is not considered - ar3 = 3 - ar4 = 4 - ar5 = 5 - - .globl __modslong - - __modslong: - - ; a3 in acc - mov a3,a ; save a3 - - clr F0 ; F0 (Flag 0) - ; available to user for general purpose - jnb acc.7,a_not_negative - - setb F0 - - clr a ; a = -a; - clr c - subb a,a0 - mov a0,a - clr a - subb a,a1 - mov a1,a - clr a - subb a,a2 - mov a2,a - clr a - subb a,a3 - mov a3,a - - a_not_negative: - - mov a,sp - add a,#-2-3 ; 2 bytes return address, 3 bytes param b - mov r0,a ; r1 points to b0 - - mov ar2,@r0 ; load b0 - inc r0 ; r0 points to b1 - mov ar3,@r0 ; b1 - inc r0 - mov ar4,@r0 ; b2 - inc r0 - mov a,@r0 ; b3 - mov b3,a - - jnb acc.7,b_not_negative - - cpl F0 - - clr a ; b = -b; - clr c - subb a,b0 - mov b0,a - clr a - subb a,b1 - mov b1,a - clr a - subb a,b2 - mov b2,a - clr a - subb a,b3 - mov b3,a - - b_not_negative: - - lcall __modlong - - jnb F0,not_negative - - ; result in (a == r1), b, dph, dpl - clr a - clr c - subb a,a0 - mov a0,a - clr a - subb a,a1 - mov a1,a - clr a - subb a,a2 - mov a2,a - clr a - subb a,a3 ; result in a, b, dph, dpl - - not_negative: - ret - - _endasm ; -} - -#else // _MODSLONG_ASM - -long -_modslong (long a, long b) +long _modslong (long a, long b) { long r; @@ -269,5 +39,3 @@ _modslong (long a, long b) else return r; } - -#endif // _MODSLONG_ASM diff --git a/gbdk-lib/libc/_modulong.c b/gbdk-lib/libc/_modulong.c @@ -27,315 +27,9 @@ might be covered by the GNU General Public License. -------------------------------------------------------------------------*/ -/* Assembler-functions are provided for: - mcs51 small - mcs51 small stack-auto -*/ - -#if !defined(SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS) -# if defined(SDCC_mcs51) -# if defined(SDCC_MODEL_SMALL) -# if defined(SDCC_STACK_AUTO) -# define _MODULONG_ASM_SMALL_AUTO -# else -# define _MODULONG_ASM_SMALL -# endif -# endif -# endif -#endif - -#if defined _MODULONG_ASM_SMALL - -static void -_modlong_dummy (void) _naked -{ - _asm - - .globl __modulong - - __modulong: - -#if defined(SDCC_NOOVERLAY) - .area DSEG (DATA) -#else - .area OSEG (OVR,DATA) -#endif - - .globl __modulong_PARM_2 - .globl __modslong_PARM_2 - - __modulong_PARM_2: - __modslong_PARM_2: - .ds 4 - - .area CSEG (CODE) - - #define count r0 - - #define a0 dpl - #define a1 dph - #define a2 b - #define a3 r1 - - #define b0 (__modulong_PARM_2) - #define b1 (__modulong_PARM_2 + 1) - #define b2 (__modulong_PARM_2 + 2) - #define b3 (__modulong_PARM_2 + 3) - - ; parameter a comes in a, b, dph, dpl - mov a3,a ; save parameter a3 - - mov a,b0 ; b == 0? avoid endless loop - orl a,b1 - orl a,b2 - orl a,b3 - jz div_by_0 - - mov count,#0 - clr c ; when loop1 jumps immediately to loop2 - - loop1: inc count - - mov a,b3 ; if (!MSB_SET(b)) - jb acc.7,loop2 - - mov a,b0 ; b <<= 1 - add a,acc - mov b0,a - mov a,b1 - rlc a - mov b1,a - mov a,b2 - rlc a - mov b2,a - mov a,b3 - rlc a - mov b3,a - - mov a,a0 ; a - b - subb a,b0 ; here carry is always clear - mov a,a1 - subb a,b1 - mov a,a2 - subb a,b2 - mov a,a3 - subb a,b3 - - jnc loop1 - - - clr c - mov a,b3 ; b >>= 1; - rrc a - mov b3,a - mov a,b2 - rrc a - mov b2,a - mov a,b1 - rrc a - mov b1,a - mov a,b0 - rrc a - mov b0,a - - loop2: ; clr c never set - mov a,a0 ; a - b - subb a,b0 - mov r4,a - mov a,a1 - subb a,b1 - mov r5,a - mov a,a2 - subb a,b2 - mov r6,a - mov a,a3 - subb a,b3 - - jc smaller ; a >= b? - - mov a3,a ; -> yes; a = a - b; - mov a2,r6 - mov a1,r5 - mov a0,r4 - smaller: ; -> no - clr c - mov a,b3 ; b >>= 1; - rrc a - mov b3,a - mov a,b2 - rrc a - mov b2,a - mov a,b1 - rrc a - mov b1,a - mov a,b0 - rrc a - mov b0,a - - djnz count,loop2 - - mov a,a3 ; prepare the return value - div_by_0: - ret - - _endasm ; -} - -#elif defined _MODULONG_ASM_SMALL_AUTO - -static void -_modlong_dummy (void) _naked -{ - _asm - - .globl __modulong - - __modulong: - - #define count r0 - - #define a0 dpl - #define a1 dph - #define a2 b - #define a3 r1 - - #define b0 r2 - #define b1 r3 - #define b2 r4 - #define b3 r5 - - ar2 = 2 ; BUG register set is not considered - ar3 = 3 - ar4 = 4 - ar5 = 5 - - .globl __modlong ; entry point for __modslong - - ; parameter a comes in a, b, dph, dpl - mov a3,a ; save parameter a3 - - mov a,sp - add a,#-2-3 ; 2 bytes return address, 3 bytes param b - mov r0,a ; r1 points to b0 - - - mov ar2,@r0 ; load b0 - inc r0 ; r0 points to b1 - mov ar3,@r0 ; b1 - inc r0 - mov ar4,@r0 ; b2 - inc r0 - mov ar5,@r0 ; b3 - - __modlong: ; entry point for __modslong - ; a in r1, b, dph, dpl - ; b in r5, r4, r3, r2 - - mov count,#0 - - mov a,b0 ; b == 0? avoid endless loop - orl a,b1 - orl a,b2 - orl a,b3 - jz div_by_0 - - mov count,#0 - clr c ; when loop1 jumps immediately to loop2 - - loop1: inc count - - mov a,b3 ; if (!MSB_SET(b)) - jb acc.7,loop2 - - mov a,b0 ; b <<= 1 - add a,acc - mov b0,a - mov a,b1 - rlc a - mov b1,a - mov a,b2 - rlc a - mov b2,a - mov a,b3 - rlc a - mov b3,a - - mov a,a0 ; a - b - subb a,b0 ; here carry is always clear - mov a,a1 - subb a,b1 - mov a,a2 - subb a,b2 - mov a,a3 - subb a,b3 - - jnc loop1 - - - clr c - mov a,b3 ; b >>= 1; - rrc a - mov b3,a - mov a,b2 - rrc a - mov b2,a - mov a,b1 - rrc a - mov b1,a - mov a,b0 - rrc a - mov b0,a - - loop2: ; clr c never set - mov a,a0 ; a - b - subb a,b0 - mov a,a1 - subb a,b1 - mov r6,a ; d1 - mov a,a2 - subb a,b2 - mov r7,a ; d2 - mov a,a3 - subb a,b3 - - jc smaller ; a >= b? - - mov a3,a ; -> yes; a = a - b; - mov a2,r7 - mov a1,r6 - mov a,a0 - subb a,b0 - mov a0,a - smaller: ; -> no - clr c - mov a,b3 ; b >>= 1; - rrc a - mov b3,a - mov a,b2 - rrc a - mov b2,a - mov a,b1 - rrc a - mov b1,a - mov a,b0 - rrc a - mov b0,a - - djnz count,loop2 - - mov a,a3 ; prepare the return value - div_by_0: - ret - - _endasm ; -} - -#else // _MODULONG_ASM - #define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1) -unsigned long -_modulong (unsigned long a, unsigned long b) +unsigned long _modulong (unsigned long a, unsigned long b) { unsigned char count = 0; @@ -359,5 +53,3 @@ _modulong (unsigned long a, unsigned long b) return a; } - -#endif // _MODULONG_ASM diff --git a/gbdk-lib/libc/_mullong.c b/gbdk-lib/libc/_mullong.c @@ -27,631 +27,19 @@ might be covered by the GNU General Public License. -------------------------------------------------------------------------*/ -/* Signed and unsigned multiplication are the same - as long as the output - has the same precision as the input. - - Assembler-functions are provided for: - mcs51 small - mcs51 small stack-auto -*/ - -#if !defined(__SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS) -# if defined(__SDCC_mcs51) -# if defined(__SDCC_MODEL_SMALL) -# if defined(__SDCC_STACK_AUTO) && !defined(__SDCC_PARMS_IN_BANK1) -# define _MULLONG_ASM_SMALL_AUTO -# else -# define _MULLONG_ASM_SMALL -# endif -# elif defined(__SDCC_MODEL_LARGE) -# if !defined(__SDCC_STACK_AUTO) -# define _MULLONG_ASM_LARGE -# endif -# endif -# endif -#endif - -#if defined(_MULLONG_ASM_SMALL) || defined(_MULLONG_ASM_SMALL_AUTO) - -void -_mullong_dummy (void) __naked -{ - __asm - -__mullong: - - .globl __mullong - - ; the result c will be stored in r4...r7 - #define c0 r4 - #define c1 r5 - #define c2 r6 - #define c3 r7 - - #define a0 dpl - #define a1 dph - #define a2 r2 - #define a3 r3 - - ; c0 a0 * b0 - ; c1 a1 * b0 + a0 * b1 - ; c2 a2 * b0 + a1 * b1 + a0 * b2 - ; c3 a3 * b0 + a2 * b1 + a1 * b2 + a0 * b3 - -#if !defined(__SDCC_STACK_AUTO) || defined(__SDCC_PARMS_IN_BANK1) -#if defined(__SDCC_PARMS_IN_BANK1) - #define b0 (b1_0) - #define b1 (b1_1) - #define b2 (b1_2) - #define b3 (b1_3) -#else -#if defined(__SDCC_NOOVERLAY) - .area DSEG (DATA) -#else - .area OSEG (OVR,DATA) -#endif - -__mullong_PARM_2: - - .globl __mullong_PARM_2 - - .ds 4 - - b0 = __mullong_PARM_2 - b1 = (__mullong_PARM_2+1) - b2 = (__mullong_PARM_2+2) - b3 = (__mullong_PARM_2+3) - -#endif - .area CSEG (CODE) - - ; parameter a comes in a, b, dph, dpl - mov r2,b ; save parameter a - mov r3,a - - ; Byte 0 - mov a,a0 - mov b,b0 - mul ab ; a0 * b0 - mov c0,a - mov c1,b - - ; Byte 1 - mov a,a1 - mov b,b0 - mul ab ; a1 * b0 - add a,c1 - mov c1,a - clr a - addc a,b - mov c2,a - - mov a,a0 - mov b,b1 - mul ab ; a0 * b1 - add a,c1 - mov c1,a - mov a,b - addc a,c2 - mov c2,a - clr a - rlc a - mov c3,a - - ; Byte 2 - mov a,a2 - mov b,b0 - mul ab ; a2 * b0 - add a,c2 - mov c2,a - mov a,b - addc a,c3 - mov c3,a - - mov a,a1 - mov b,b1 - mul ab ; a1 * b1 - add a,c2 - mov c2,a - mov a,b - addc a,c3 - mov c3,a - - mov a,a0 - mov b,b2 - mul ab ; a0 * b2 - add a,c2 - mov c2,a - mov a,b - addc a,c3 - mov c3,a - - ; Byte 3 - mov a,a3 - mov b,b0 - mul ab ; a3 * b0 - add a,c3 - mov c3,a - - mov a,a2 - mov b,b1 - mul ab ; a2 * b1 - add a,c3 - mov c3,a - - mov a,a1 - mov b,b2 - mul ab ; a1 * b2 - add a,c3 - mov c3,a - - mov a,a0 - mov b,b3 - mul ab ; a0 * b3 - add a,c3 - - mov b,c2 - mov dph,c1 - mov dpl,c0 - ret - -#else // __SDCC_STACK_AUTO - - ; parameter a comes in a, b, dph, dpl - mov r2,b ; save parameter a - mov r3,a - - #define a0 dpl - #define a1 dph - #define a2 r2 - #define a3 r3 - - #define b0 r1 - - mov a,#-2-3 ; 1 return address 2 bytes, b 4 bytes - add a,sp ; 1 - mov r0,a ; 1 r0 points to b0 - - ; Byte 0 - mov a,a0 - mov b,@r0 ; b0 - mov b0,b ; we need b0 several times - inc r0 ; r0 points to b1 - mul ab ; a0 * b0 - mov c0,a - mov c1,b - - ; Byte 1 - mov a,a1 - mov b,b0 - mul ab ; a1 * b0 - add a,c1 - mov c1,a - clr a - addc a,b - mov c2,a - - mov a,a0 - mov b,@r0 ; b1 - mul ab ; a0 * b1 - add a,c1 - mov c1,a - mov a,b - addc a,c2 - mov c2,a - clr a - rlc a - mov c3,a - - ; Byte 2 - mov a,a2 - mov b,b0 - mul ab ; a2 * b0 - add a,c2 - mov c2,a - mov a,b - addc a,c3 - mov c3,a - - mov a,a1 - mov b,@r0 ; b1 - mul ab ; a1 * b1 - add a,c2 - mov c2,a - mov a,b - addc a,c3 - mov c3,a - - mov a,a0 - inc r0 - mov b,@r0 ; b2 - mul ab ; a0 * b2 - add a,c2 - mov c2,a - mov a,b - addc a,c3 - mov c3,a - - ; Byte 3 - mov a,a3 - mov b,b0 - mul ab ; a3 * b0 - add a,c3 - mov c3,a - - mov a,a1 - mov b,@r0 ; b2 - mul ab ; a1 * b2 - add a,c3 - mov c3,a - - mov a,a2 - dec r0 - mov b,@r0 ; b1 - mul ab ; a2 * b1 - add a,c3 - mov c3,a - - mov a,a0 - inc r0 - inc r0 - mov b,@r0 ; b3 - mul ab ; a0 * b3 - add a,c3 - - mov b,c2 - mov dph,c1 - mov dpl,c0 - - ret - -#endif // __SDCC_STACK_AUTO - - __endasm; -} - -#elif defined(_MULLONG_ASM_LARGE) - -void -_mullong_dummy (void) __naked -{ - __asm - -__mullong: - - .globl __mullong - - ; the result c will be stored in r4...r7 - #define c0 r4 - #define c1 r5 - #define c2 r6 - #define c3 r7 - - ; c0 a0 * b0 - ; c1 a1 * b0 + a0 * b1 - ; c2 a2 * b0 + a1 * b1 + a0 * b2 - ; c3 a3 * b0 + a2 * b1 + a1 * b2 + a0 * b3 - -#if !defined(__SDCC_PARMS_IN_BANK1) - .area XSEG (XDATA) - -__mullong_PARM_2: - - .globl __mullong_PARM_2 - - .ds 4 -#endif - .area CSEG (CODE) - - ; parameter a comes in a, b, dph, dpl - mov r0,dpl ; save parameter a - mov r1,dph - mov r2,b - mov r3,a - - #define a0 r0 - #define a1 r1 - #define a2 r2 - #define a3 r3 - - ; Byte 0 - mov b,a0 -#if defined(__SDCC_PARMS_IN_BANK1) - mov a,b1_0 ; b0 -#else - mov dptr,#__mullong_PARM_2 - movx a,@dptr ; b0 -#endif - mul ab ; a0 * b0 - mov c0,a - mov c1,b - - ; Byte 1 - mov b,a1 -#if defined(__SDCC_PARMS_IN_BANK1) - mov a,b1_0 ; b0 -#else - movx a,@dptr ; b0 -#endif - mul ab ; a1 * b0 - add a,c1 - mov c1,a - clr a - addc a,b - mov c2,a - - mov b,a0 -#if defined(__SDCC_PARMS_IN_BANK1) - mov a,b1_1 ; b1 -#else - inc dptr ; b1 - movx a,@dptr -#endif - mul ab ; a0 * b1 - add a,c1 - mov c1,a - mov a,b - addc a,c2 - mov c2,a - clr a - rlc a - mov c3,a - - ; Byte 2 - mov b,a1 -#if defined(__SDCC_PARMS_IN_BANK1) - mov a,b1_1 ; b1 -#else - movx a,@dptr ; b1 -#endif - mul ab ; a1 * b1 - add a,c2 - mov c2,a - mov a,b - addc a,c3 - mov c3,a - - mov b,a0 -#if defined(__SDCC_PARMS_IN_BANK1) - mov a,b1_2 ; b2 -#else - inc dptr ; b2 - movx a,@dptr -#endif - mul ab ; a0 * b2 - add a,c2 - mov c2,a - mov a,b - addc a,c3 - mov c3,a - - mov b,a2 -#if defined(__SDCC_PARMS_IN_BANK1) - mov a,b1_0 ; b0 -#else - mov dptr,#__mullong_PARM_2 - movx a,@dptr ; b0 -#endif - mul ab ; a2 * b0 - add a,c2 - mov c2,a - mov a,b - addc a,c3 - mov c3,a - - ; Byte 3 - mov b,a3 -#if defined(__SDCC_PARMS_IN_BANK1) - mov a,b1_0 ; b0 -#else - movx a,@dptr ; b0 -#endif - mul ab ; a3 * b0 - add a,c3 - mov c3,a - - mov b,a2 -#if defined(__SDCC_PARMS_IN_BANK1) - mov a,b1_1 ; b1 -#else - inc dptr ; b1 - movx a,@dptr -#endif - mul ab ; a2 * b1 - add a,c3 - mov c3,a - - mov b,a1 -#if defined(__SDCC_PARMS_IN_BANK1) - mov a,b1_2 ; b2 -#else - inc dptr ; b2 - movx a,@dptr -#endif - mul ab ; a1 * b2 - add a,c3 - mov c3,a - - mov b,a0 -#if defined(__SDCC_PARMS_IN_BANK1) - mov a,b1_3 ; b3 -#else - inc dptr ; b3 - movx a,@dptr -#endif - mul ab ; a0 * b3 - add a,c3 - - mov b,c2 - mov dph,c1 - mov dpl,c0 - ret - - __endasm; -} - -#elif defined(__SDCC_USE_XSTACK) && defined(__SDCC_STACK_AUTO) - -void -_mullong_dummy (void) __naked -{ - __asm - -__mullong: - - .globl __mullong - - ; the result c will be stored in r4...r7 - #define c0 r4 - #define c1 r5 - #define c2 r6 - #define c3 r7 - - #define a0 dpl - #define a1 dph - #define a2 r2 - #define a3 r3 - - #define b0 r1 - - ; c0 a0 * b0 - ; c1 a1 * b0 + a0 * b1 - ; c2 a2 * b0 + a1 * b1 + a0 * b2 - ; c3 a3 * b0 + a2 * b1 + a1 * b2 + a0 * b3 - - ; parameter a comes in a, b, dph, dpl - mov r2,b ; save parameter a - mov r3,a - - mov a,#-4 ; 1 b 4 bytes - add a,_spx ; 1 - mov r0,a ; 1 r0 points to b0 - - ; Byte 0 - movx a,@r0 ; b0 - mov b0,a ; we need b0 several times - inc r0 ; r0 points to b1 - mov b,a0 - mul ab ; a0 * b0 - mov c0,a - mov c1,b - - ; Byte 1 - mov a,a1 - mov b,b0 - mul ab ; a1 * b0 - add a,c1 - mov c1,a - clr a - addc a,b - mov c2,a - - mov b,a0 - movx a,@r0 ; b1 - mul ab ; a0 * b1 - add a,c1 - mov c1,a - mov a,b - addc a,c2 - mov c2,a - clr a - rlc a - mov c3,a - - ; Byte 2 - mov a,a2 - mov b,b0 - mul ab ; a2 * b0 - add a,c2 - mov c2,a - mov a,b - addc a,c3 - mov c3,a - - mov b,a1 - movx a,@r0 ; b1 - mul ab ; a1 * b1 - add a,c2 - mov c2,a - mov a,b - addc a,c3 - mov c3,a - - mov b,a0 - inc r0 - movx a,@r0 ; b2 - mul ab ; a0 * b2 - add a,c2 - mov c2,a - mov a,b - addc a,c3 - mov c3,a - - ; Byte 3 - mov a,a3 - mov b,b0 - mul ab ; a3 * b0 - add a,c3 - mov c3,a - - mov b,a1 - movx a,@r0 ; b2 - mul ab ; a1 * b2 - add a,c3 - mov c3,a - - mov b,a2 - dec r0 - movx a,@r0 ; b1 - mul ab ; a2 * b1 - add a,c3 - mov c3,a - - mov b,a0 - inc r0 - inc r0 - movx a,@r0 ; b3 - mul ab ; a0 * b3 - add a,c3 - - mov b,c2 - mov dph,c1 - mov dpl,c0 - - ret - - __endasm; -} - -#else // _MULLONG_ASM struct some_struct { short a ; char b; long c ;}; -#if defined(__SDCC_hc08) || defined(__SDCC_s08) || defined(__SDCC_stm8) -/* big endian order */ -union bil { - struct {unsigned char b3,b2,b1,b0 ;} b; - struct {unsigned short hi,lo ;} i; - unsigned long l; - struct { unsigned char b3; unsigned short i12; unsigned char b0;} bi; -} ; -#else -/* little endian order */ union bil { struct {unsigned char b0,b1,b2,b3 ;} b; struct {unsigned short lo,hi ;} i; unsigned long l; struct { unsigned char b0; unsigned short i12; unsigned char b3;} bi; } ; -#endif -#if defined(__SDCC) - #include <sdcc-lib.h> -#endif - -#define bcast(x) ((union bil _AUTOMEM *)&(x)) +#define bcast(x) ((union bil *)&(x)) /* 3 2 1 0 @@ -671,34 +59,7 @@ union bil { |3.0| G |-------> only this side 32 x 32 -> 32 */ -#if defined(__SDCC_USE_XSTACK) -// currently the original code without u fails with --xstack -// it runs out of pointer registers -long -_mullong (long a, long b) -{ - union bil t, u; - - t.i.hi = bcast(a)->b.b0 * bcast(b)->b.b2; // A - t.i.lo = bcast(a)->b.b0 * bcast(b)->b.b0; // A - u.bi.b3 = bcast(a)->b.b0 * bcast(b)->b.b3; // B - u.bi.i12 = bcast(a)->b.b0 * bcast(b)->b.b1; // B - u.bi.b0 = 0; // B - t.l += u.l; - - t.b.b3 += bcast(a)->b.b3 * bcast(b)->b.b0; // G - t.b.b3 += bcast(a)->b.b2 * bcast(b)->b.b1; // F - t.i.hi += bcast(a)->b.b2 * bcast(b)->b.b0; // E - t.i.hi += bcast(a)->b.b1 * bcast(b)->b.b1; // D - u.bi.b3 = bcast(a)->b.b1 * bcast(b)->b.b2; // C - u.bi.i12 = bcast(a)->b.b1 * bcast(b)->b.b0; // C - u.bi.b0 = 0; // C - t.l += u.l; - - return t.l; -} -#elif defined(__SDCC_z80) || defined(__SDCC_gbz80) || defined(__SDCC_r2k) || defined(__SDCC_r3k) /* 32x32->32 multiplication to be used if 16x16->16 is faster than three 8x8->16. 2009, by M.Bodrato ( http://bodrato.it/ ) @@ -706,8 +67,7 @@ _mullong (long a, long b) z80 and gbz80 don't have any hardware multiplication. r2k and r3k have 16x16 hardware multiplication. */ -long -_mullong (long a, long b) +long _mullong (long a, long b) { unsigned short i12; @@ -729,32 +89,3 @@ _mullong (long a, long b) return a + b; } -#else -long -_mullong (long a, long b) -{ - union bil t; - - t.i.hi = bcast(a)->b.b0 * bcast(b)->b.b2; // A - t.i.lo = bcast(a)->b.b0 * bcast(b)->b.b0; // A - t.b.b3 += bcast(a)->b.b3 * bcast(b)->b.b0; // G - t.b.b3 += bcast(a)->b.b2 * bcast(b)->b.b1; // F - t.i.hi += bcast(a)->b.b2 * bcast(b)->b.b0; // E <- b lost in .lst - // bcast(a)->i.hi is free ! - t.i.hi += bcast(a)->b.b1 * bcast(b)->b.b1; // D <- b lost in .lst - - bcast(a)->bi.b3 = bcast(a)->b.b1 * bcast(b)->b.b2; // C - bcast(a)->bi.i12 = bcast(a)->b.b1 * bcast(b)->b.b0; // C - - bcast(b)->bi.b3 = bcast(a)->b.b0 * bcast(b)->b.b3; // B - bcast(b)->bi.i12 = bcast(a)->b.b0 * bcast(b)->b.b1; // B - - bcast(b)->bi.b0 = 0; // B - bcast(a)->bi.b0 = 0; // C - t.l += a; - - return t.l + b; -} -#endif - -#endif // _MULLONG_ASM
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.