Add new strings.
[AROS.git] / rom / utility / smult32.c
blob618c333386b7da2958c87affb53a8ebb5161974d
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Signed 32 bit multiplication function.
6 Lang: english
7 */
8 #include "intern.h"
10 /*****************************************************************************
12 NAME */
13 #include <proto/utility.h>
15 AROS_LH2(LONG, SMult32,
17 /* SYNOPSIS */
18 AROS_LHA(LONG, arg1, D0),
19 AROS_LHA(LONG, arg2, D1),
21 /* LOCATION */
22 struct UtilityBase *, UtilityBase, 23, Utility)
24 /* FUNCTION
25 Performs the signed 32-bit multiplication of arg1 * arg2 and
26 returns a signed 32 bit value.
28 INPUTS
29 arg1, arg2 - 32 bit signed longs
31 RESULT
32 arg1 * arg2
34 NOTES
35 This can perform the multiplication either using the machines
36 native instructions (if they exist), or in software using a
37 simple algorithm based on expanding algebraic products.
39 The utility.library math functions are unlike all other utility
40 functions in that they don't require the library base to be
41 loaded in register A6, and they also save the values of the
42 address registers A0/A1.
44 This function is mainly to support assembly programers, and is
45 probably of limited use to higher-level language programmers.
47 EXAMPLE
49 LONG a = 352543;
50 LONG b = -52464;
51 LONG c = SMult32(a,b);
52 c == -1315946768
54 BUGS
55 Of limited use to C programmers.
57 SEE ALSO
58 UMult32(), UMult64(), SMult64()
60 INTERNALS
61 May be handled by code in config/$(KERNEL), may not be...
62 It is for m68k-native.
64 For emulation we are performing the operation:
66 (2^16 * a + b) * (2^16 * c + d)
67 = 2^32 * ab + 2^16 * ad + 2^16 * bc + bd
68 = 2^32 * ab + 2^16 ( ad + bc ) + bd
70 Now since the result is a 32-bit number, the 2^32 term will have
71 no effect. (Since 2^32 > max (32-bit number)), as will the
72 high part of ad + bc.
74 Therefore:
75 product = 2^16( ad + bc ) + bd
77 HISTORY
78 29-10-95 digulla automatically created from
79 utility_lib.fd and clib/utility_protos.h
80 18-08-96 iaint Implemented as described above.
82 *****************************************************************************/
84 AROS_LIBFUNC_INIT
86 /* If we have native support for 32 * 32 -> 32, use that. */
88 return arg1 * arg2;
90 #if 0
91 /* This is effectively what the emulation does, see also
92 config/m68k-native/sumult32.s
95 UWORD a1, b1, a0, b0;
97 a1 = (arg1 >> 16) & 0xffff;
98 a0 = arg1 & 0xffff;
99 b1 = (arg2 >> 16) & 0xffff;
100 b0 = arg2 & 0xffff;
102 return ((a0 * b1) + (a1 * b0)) << 16 + (b0 * a0);
103 #endif
105 AROS_LIBFUNC_EXIT
106 } /* SMult32 */