Fix IO memory access .. SB128 driver makes noises in VMWare - CMI is untested (Curren...
[AROS.git] / arch / m68k-all / utility / umult32.s
blob4d5bce69d2c6d0a7dce9887dda98b2dc2a656b0c
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Utility 32 bit multiplication routines. m68k version.
6 Lang: english
7 */
9 /* SMult32()/UMult32():
10 These are the signed/unsigned 32 bit multiplication routines.
11 I have two different possibilities here since I could be running
12 on a system without the corresponding muls.l/mulu.l calls.
14 After some soul searching I am happy that these routines don't
15 have to be separated between signed/unsigned since the sign is
16 correct, or the number overflows.
18 The native versions do make the difference however.
20 What I do is SetFunction() the correct function in later.
23 #include "aros/m68k/asm.h"
25 .text
26 .balign 4
28 .globl AROS_SLIB_ENTRY(SMult32,Utility,23)
29 .globl AROS_SLIB_ENTRY(UMult32,Utility,24)
30 .globl AROS_SLIB_ENTRY(UMult32_020,Utility,24)
32 .type AROS_SLIB_ENTRY(SMult32,Utility,23),@function
33 .type AROS_SLIB_ENTRY(UMult32,Utility,24),@function
34 .type AROS_SLIB_ENTRY(UMult32_020,Utility,24),@function
36 AROS_SLIB_ENTRY(UMult32_020,Utility,24):
37 mulu.l %d1,%d0
38 rts
40 .balign 4
41 AROS_SLIB_ENTRY(SMult32,Utility,23):
42 AROS_SLIB_ENTRY(UMult32,Utility,24):
44 What do we have to do
45 d0 = (a^16 + b), d1 = (c^16 = d)
46 res = ac^32 + (ad + bc)^16 + bd
48 Now, ac^32 can be thrown away, as can the high 16 bits of ad + bd
50 movem.l %d2/%d3,-(%sp)
51 moveq #0,%d2
52 moveq #0,%d3
54 /* ad */
55 move.w %d1,%d3
56 swap %d0
57 mulu %d0,%d3
59 /* bc */
60 swap %d0
61 move.w %d0,%d2
62 swap %d1
63 mulu %d1,%d2
65 /* (ad + bc)^16 */
66 add.l %d3,%d2
67 swap %d2
68 clr.w %d2
70 /* bd + (ad + bc)^16 */
71 swap %d1
72 mulu %d1,%d0
73 add.l %d2,%d0
74 movem.l (%sp)+,%d2/%d3
75 rts