added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / .unmaintained / m68k-native / utility / umult64.s
blobe6ad62da959d54496d9b5be32abbf48b29a68231
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Utility 64 bit multiplication routines. m68k version.
6 Lang: english
7 */
9 #include "machine.i"
11 /* SMult64()/UMult64():
12 These are the signed/unsigned 64 bit multiplication routines.
13 There are two possibilities here because as of the 060 the
14 32*32->64 bit result instructions are not supported, and I haven't
15 quite figured out how to do this using the 32 bit ops yet (can't be
16 that hard though).
18 Still, emulating is faster than a unsup integer instruction except.
22 .balign 4
24 .globl AROS_SLIB_ENTRY(UMult64,Utility)
25 .globl AROS_SLIB_ENTRY(UMult64_020,Utility)
27 .type AROS_SLIB_ENTRY(UMult64,Utility),@function
28 .type AROS_SLIB_ENTRY(UMult64_020,Utility),@function
31 AROS_SLIB_ENTRY(UMult64_020,Utility):
32 mulu.l d0,d0:d1
33 rts
35 /* How do I do this, again consider:
36 (a^16 + b) * (c^16 + d)
37 = ac^32 + (ad + bc)^16 + bd
39 I tried to think of a way of doing this with the mulu.l instr,
40 but I couldn't so I'll just use the mulu.w. Its quicker than
41 an unsupp integer instruction anyway :)
44 .balign 4
45 AROS_SLIB_ENTRY(UMult64,Utility):
46 movem.l d2-d5,-(sp)
47 /* Set up some registers */
48 move.l d0,d2
49 move.l d1,d3
50 move.l d0,d4 /* d */
51 move.l d1,d5 /* b */
52 swap d2 /* a */
53 swap d3 /* c */
56 /* Firstly, find the product bd */
57 mulu d5,d1 /* d1 = bd */
58 swap d1 /* d1 = (bd)^16 */
60 /* Then find ac, put in d0 */
61 mulu d3,d0 /* d0 = ac */
63 /* Next find ad, bc, and add together */
64 mulu d2,d4
65 mulu d3,d5
66 add.l d5,d4
69 Add the low 16 bits to d1, then add upper 16 bits to d0
70 But make sure we carry the 1...
72 Apparently swap doesn't affect the X bit.
74 add.w d4,d1
75 swap d4
76 addx.w d4,d0
78 /* All that remains to do is to flip d1 around the right way */
79 swap d1
80 movem.l (sp)+,d2-d5
82 rts