added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / .unmaintained / m68k-native / utility / umult32.s
bloba614ee6740916317c813ce33a831542a789a2c85
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 #include "machine.i"
11 /* SMult32()/UMult32():
12 These are the signed/unsigned 32 bit multiplication routines.
13 I have two different possibilities here since I could be running
14 on a system without the corresponding muls.l/mulu.l calls.
16 After some soul searching I am happy that these routines don't
17 have to be separated between signed/unsigned since the sign is
18 correct, or the number overflows.
20 The native versions do make the difference however.
22 What I do is SetFunction() the correct function in later.
25 .balign 4
27 .globl AROS_SLIB_ENTRY(SMult32,Utility)
28 .globl AROS_SLIB_ENTRY(UMult32,Utility)
29 .globl AROS_SLIB_ENTRY(UMult32_020,Utility)
31 .type AROS_SLIB_ENTRY(SMult32,Utility),@function
32 .type AROS_SLIB_ENTRY(UMult32,Utility),@function
33 .type AROS_SLIB_ENTRY(UMult32_020,Utility),@function
35 AROS_SLIB_ENTRY(UMult32_020,Utility):
36 mulu.l d1,d0
37 rts
39 .balign 4
40 AROS_SLIB_ENTRY(SMult32,Utility):
41 AROS_SLIB_ENTRY(UMult32,Utility):
43 What do we have to do
44 d0 = (a^16 + b), d1 = (c^16 = d)
45 res = ac^32 + (ad + bc)^16 + bd
47 Now, ac^32 can be thrown away, as can the high 16 bits of ad + bd
49 movem.l d2/d3,-(sp)
50 moveq #0,d2
51 moveq #0,d3
53 /* ad */
54 move.w d1,d3
55 swap d0
56 mulu d0,d3
58 /* bc */
59 swap d0
60 move.w d0,d2
61 swap d1
62 mulu d1,d2
64 /* (ad + bc)^16 */
65 add.l d3,d2
66 swap d2
67 clr.w d2
69 /* bd + (ad + bc)^16 */
70 swap d1
71 mulu d1,d0
72 add.l d2,d0
73 movem.l (sp)+,d2/d3
74 rts