Finalize muluint/mulsint and mululong/mulslong merging
[fw/sdcc] / device / lib / _mullong.c
index 8ced7e575587281d884f78162bf13878257d2776..6b40ea6fb1f9f66f34e6afa331ad46d0b5dedff0 100644 (file)
@@ -8,28 +8,24 @@
    under the terms of the GNU Library General Public License as published by the
    Free Software Foundation; either version 2, or (at your option) any
    later version.
    under the terms of the GNU Library General Public License as published by the
    Free Software Foundation; either version 2, or (at your option) any
    later version.
-   
+
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Library General Public License for more details.
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Library General Public License for more details.
-   
+
    You should have received a copy of the GNU Library General Public License
    along with this program; if not, write to the Free Software
    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    You should have received a copy of the GNU Library General Public License
    along with this program; if not, write to the Free Software
    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-   
+
    In other words, you are welcome to use, share and improve this program.
    You are forbidden to forbid anyone else to use, share and improve
    In other words, you are welcome to use, share and improve this program.
    You are forbidden to forbid anyone else to use, share and improve
-   what you give them.   Help stamp out software-hoarding!  
+   what you give them.   Help stamp out software-hoarding!
 -------------------------------------------------------------------------*/
 
 /* Signed and unsigned multiplication are the same - as long as the output
    has the same precision as the input.
 
 -------------------------------------------------------------------------*/
 
 /* Signed and unsigned multiplication are the same - as long as the output
    has the same precision as the input.
 
-   To do: _mululong and _mulslong should be replaced by _mullong.
-
-   bernhard@bernhardheld.de
-
    Assembler-functions are provided for:
      mcs51 small
      mcs51 small stack-auto
    Assembler-functions are provided for:
      mcs51 small
      mcs51 small stack-auto
@@ -38,7 +34,7 @@
 #if !defined(SDCC_USE_XSTACK) && !defined(_SDCC_NO_ASM_LIB_FUNCS)
 #  if defined(SDCC_mcs51)
 #    if defined(SDCC_MODEL_SMALL)
 #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)
+#      if defined(SDCC_STACK_AUTO) && !defined(SDCC_PARMS_IN_BANK1)
 #        define _MULLONG_ASM_SMALL_AUTO
 #      else
 #        define _MULLONG_ASM_SMALL
 #        define _MULLONG_ASM_SMALL_AUTO
 #      else
 #        define _MULLONG_ASM_SMALL
@@ -51,7 +47,7 @@
 #  endif
 #endif
 
 #  endif
 #endif
 
-#if defined _MULLONG_ASM_SMALL || defined _MULLONG_ASM_SMALL_AUTO
+#if defined(_MULLONG_ASM_SMALL) || defined(_MULLONG_ASM_SMALL_AUTO)
 
 void
 _mullong_dummy (void) _naked
 
 void
 _mullong_dummy (void) _naked
@@ -59,12 +55,8 @@ _mullong_dummy (void) _naked
        _asm
 
        __mullong:
        _asm
 
        __mullong:
-       __mululong:                     ; obsolete
-       __mulslong:                     ; obsolete
 
                .globl __mullong
 
                .globl __mullong
-               .globl __mululong       ; obsolete
-               .globl __mulslong       ; obsolete
 
                                        ; the result c will be stored in r4...r7
                #define c0 r4
 
                                        ; the result c will be stored in r4...r7
                #define c0 r4
@@ -72,45 +64,47 @@ _mullong_dummy (void) _naked
                #define c2 r6
                #define c3 r7
 
                #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
 
        ; 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
-
-#if defined(SDCC_NOOVERLAY)            // BUG SDCC_NOOVERLAY is not set by -no-overlay
+#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:
                .area DSEG    (DATA)
 #else
                .area OSEG    (OVR,DATA)
 #endif
 
        __mullong_PARM_2:
-       __mululong_PARM_2:                      ; obsolete
-       __mulslong_PARM_2:                      ; obsolete
 
                .globl __mullong_PARM_2
 
                .globl __mullong_PARM_2
-               .globl __mululong_PARM_2        ; obsolete
-               .globl __mulslong_PARM_2        ; obsolete
 
                .ds     4
 
 
                .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
 
                .area CSEG    (CODE)
 
                                        ; 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
-
-               b0 =  __mullong_PARM_2
-               b1 = (__mullong_PARM_2+1)
-               b2 = (__mullong_PARM_2+2)
-               b3 = (__mullong_PARM_2+3)
-
                                        ;       Byte 0
                mov     a,a0
                mov     b,b0
                                        ;       Byte 0
                mov     a,a0
                mov     b,b0
@@ -127,7 +121,7 @@ _mullong_dummy (void) _naked
                clr     a
                addc    a,b
                mov     c2,a
                clr     a
                addc    a,b
                mov     c2,a
-               
+
 
                mov     a,a0
                mov     b,b1
 
                mov     a,a0
                mov     b,b1
@@ -233,7 +227,7 @@ _mullong_dummy (void) _naked
                clr     a
                addc    a,b
                mov     c2,a
                clr     a
                addc    a,b
                mov     c2,a
-               
+
 
                mov     a,a0
                mov     b,@r0           ; b1
 
                mov     a,a0
                mov     b,@r0           ; b1
@@ -315,7 +309,7 @@ _mullong_dummy (void) _naked
 }
 
 
 }
 
 
-#elif defined _MULLONG_ASM_LARGE
+#elif defined(_MULLONG_ASM_LARGE)
 
 void
 _mullong_dummy (void) _naked
 
 void
 _mullong_dummy (void) _naked
@@ -323,12 +317,8 @@ _mullong_dummy (void) _naked
        _asm
 
        __mullong:
        _asm
 
        __mullong:
-       __mululong:                     ; obsolete
-       __mulslong:                     ; obsolete
 
                .globl __mullong
 
                .globl __mullong
-               .globl __mululong       ; obsolete
-               .globl __mulslong       ; obsolete
 
                                        ; the result c will be stored in r4...r7
                #define c0 r4
 
                                        ; the result c will be stored in r4...r7
                #define c0 r4
@@ -341,18 +331,15 @@ _mullong_dummy (void) _naked
        ; c2  a2 * b0 + a1 * b1 + a0 * b2
        ; c3  a3 * b0 + a2 * b1 + a1 * b2 + a0 * b3
 
        ; 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:
                .area XSEG    (XDATA)
 
        __mullong_PARM_2:
-       __mululong_PARM_2:                      ; obsolete
-       __mulslong_PARM_2:                      ; obsolete
 
                .globl __mullong_PARM_2
 
                .globl __mullong_PARM_2
-               .globl __mululong_PARM_2        ; obsolete
-               .globl __mulslong_PARM_2        ; obsolete
 
                .ds     4
 
                .ds     4
-
+#endif
                .area CSEG    (CODE)
 
                                        ; parameter a comes in a, b, dph, dpl
                .area CSEG    (CODE)
 
                                        ; parameter a comes in a, b, dph, dpl
@@ -368,26 +355,38 @@ _mullong_dummy (void) _naked
 
                                        ;       Byte 0
                mov     b,a0
 
                                        ;       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
                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
                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
                movx    a,@dptr         ; b0
+#endif
                mul     ab              ; a1 * b0
                add     a,c1
                mov     c1,a
                clr     a
                addc    a,b
                mov     c2,a
                mul     ab              ; a1 * b0
                add     a,c1
                mov     c1,a
                clr     a
                addc    a,b
                mov     c2,a
-               
+
 
                mov     b,a0
 
                mov     b,a0
+#if defined(SDCC_PARMS_IN_BANK1)
+               mov     a,b1_1          ; b1
+#else
                inc     dptr            ; b1
                movx    a,@dptr
                inc     dptr            ; b1
                movx    a,@dptr
+#endif
                mul     ab              ; a0 * b1
                add     a,c1
                mov     c1,a
                mul     ab              ; a0 * b1
                add     a,c1
                mov     c1,a
@@ -400,7 +399,11 @@ _mullong_dummy (void) _naked
 
                                        ;       Byte 2
                mov     b,a1
 
                                        ;       Byte 2
                mov     b,a1
+#if defined(SDCC_PARMS_IN_BANK1)
+               mov     a,b1_1          ; b1
+#else
                movx    a,@dptr         ; b1
                movx    a,@dptr         ; b1
+#endif
                mul     ab              ; a1 * b1
                add     a,c2
                mov     c2,a
                mul     ab              ; a1 * b1
                add     a,c2
                mov     c2,a
@@ -409,8 +412,12 @@ _mullong_dummy (void) _naked
                mov     c3,a
 
                mov     b,a0
                mov     c3,a
 
                mov     b,a0
+#if defined(SDCC_PARMS_IN_BANK1)
+               mov     a,b1_2          ; b2
+#else
                inc     dptr            ; b2
                movx    a,@dptr
                inc     dptr            ; b2
                movx    a,@dptr
+#endif
                mul     ab              ; a0 * b2
                add     a,c2
                mov     c2,a
                mul     ab              ; a0 * b2
                add     a,c2
                mov     c2,a
@@ -419,8 +426,12 @@ _mullong_dummy (void) _naked
                mov     c3,a
 
                mov     b,a2
                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
                mov     dptr,#__mullong_PARM_2
                movx    a,@dptr         ; b0
+#endif
                mul     ab              ; a2 * b0
                add     a,c2
                mov     c2,a
                mul     ab              ; a2 * b0
                add     a,c2
                mov     c2,a
@@ -430,28 +441,44 @@ _mullong_dummy (void) _naked
 
                                        ;       Byte 3
                mov     b,a3
 
                                        ;       Byte 3
                mov     b,a3
+#if defined(SDCC_PARMS_IN_BANK1)
+               mov     a,b1_0          ; b0
+#else
                movx    a,@dptr         ; b0
                movx    a,@dptr         ; b0
+#endif
                mul     ab              ; a3 * b0
                add     a,c3
                mov     c3,a
 
                mov     b,a2
                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
                inc     dptr            ; b1
                movx    a,@dptr
+#endif
                mul     ab              ; a2 * b1
                add     a,c3
                mov     c3,a
 
                mov     b,a1
                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
                inc     dptr            ; b2
                movx    a,@dptr
+#endif
                mul     ab              ; a1 * b2
                add     a,c3
                mov     c3,a
 
                mov     b,a0
                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
                inc     dptr            ; b3
                movx    a,@dptr
+#endif
                mul     ab              ; a0 * b3
                add     a,c3
 
                mul     ab              ; a0 * b3
                add     a,c3
 
@@ -476,21 +503,21 @@ union bil {
         struct { unsigned char b0; unsigned int i12; unsigned char b3;} bi;
 } ;
 #if defined(SDCC_MODEL_LARGE) || defined (SDCC_ds390)
         struct { unsigned char b0; unsigned int i12; unsigned char b3;} bi;
 } ;
 #if defined(SDCC_MODEL_LARGE) || defined (SDCC_ds390)
-#define bcast(x) ((union bil xdata *)&(x))
+#  define bcast(x) ((union bil xdata *)&(x))
 #elif defined(__z80) || defined(__gbz80)
 #elif defined(__z80) || defined(__gbz80)
-#define bcast(x) ((union bil *)&(x))
+#  define bcast(x) ((union bil *)&(x))
 #else
 #else
-#define bcast(x) ((union bil near *)&(x))
+#  define bcast(x) ((union bil near  *)&(x))
 #endif
 
 /*
                      3   2   1   0
        X             3   2   1   0
        ----------------------------
 #endif
 
 /*
                      3   2   1   0
        X             3   2   1   0
        ----------------------------
-                   0.3 0.2 0.1 0.0 
-               1.3 1.2 1.1 1.0 
-           2.3 2.2 2.1 2.0 
-       3.3 3.2 3.1 3.0 
+                   0.3 0.2 0.1 0.0
+               1.3 1.2 1.1 1.0
+           2.3 2.2 2.1 2.0
+       3.3 3.2 3.1 3.0
        ----------------------------
                   |3.3|1.3|0.2|0.0|   A
                     |2.3|0.3|0.1|     B
        ----------------------------
                   |3.3|1.3|0.2|0.0|   A
                     |2.3|0.3|0.1|     B
@@ -501,14 +528,13 @@ union bil {
                         |3.0|         G
                           |-------> only this side 32 x 32 -> 32
 */
                         |3.0|         G
                           |-------> only this side 32 x 32 -> 32
 */
-unsigned long
-_mululong (unsigned long a, unsigned long b)   // in future: _mullong
+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
 {
         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
-       _asm ;johan _endasm;
         t.b.b3 += bcast(a)->b.b3 *
                                   bcast(b)->b.b0;       // G
         t.b.b3 += bcast(a)->b.b2 *
         t.b.b3 += bcast(a)->b.b3 *
                                   bcast(b)->b.b0;       // G
         t.b.b3 += bcast(a)->b.b2 *
@@ -533,10 +559,4 @@ _mululong (unsigned long a, unsigned long b)       // in future: _mullong
         return t.l + b;
 }
 
         return t.l + b;
 }
 
-long
-_mulslong (long a, long b)     // obsolete
-{
-  return _mululong (a, b);
-}
-
 #endif // _MULLONG_ASM
 #endif // _MULLONG_ASM