annotate libgsmhr1/mathdp31.c @ 529:79cd992de3ad

libgsmfr2: API definitions for TFO transform
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 19 Sep 2024 08:07:26 +0000
parents 024615de06fe
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
503
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /***************************************************************************
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * File Name: mathdp31.c
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * Purpose: Contains functions increased-precision arithmetic operations.
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * Below is a listing of all the functions in this file. There
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 * is no interdependence among the functions.
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * L_mpy_ls()
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 * L_mpy_ll()
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 * isLwLimit()
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 * isSwLimit()
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 ***************************************************************************/
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 /*_________________________________________________________________________
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 | |
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 | Include Files |
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 |_________________________________________________________________________|
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 */
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
504
024615de06fe libgsmhr1: compile mathdp31.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 503
diff changeset
22 #include "typedefs.h"
024615de06fe libgsmhr1: compile mathdp31.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 503
diff changeset
23 #include "namespace.h"
503
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 #include "mathhalf.h"
504
024615de06fe libgsmhr1: compile mathdp31.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 503
diff changeset
25 #include "mathdp31.h"
503
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 /****************************************************************************
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 * FUNCTION NAME: isLwLimit
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 * PURPOSE:
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 * Check to see if the input Longword is at the
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 * upper or lower limit of its range. i.e.
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 * 0x7fff ffff or -0x8000 0000
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 * Ostensibly this is a check for an overflow.
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 * This does not truly mean an overflow occurred,
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 * it means the value reached is the
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 * maximum/minimum value representable. It may
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 * have come about due to an overflow.
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 * INPUTS:
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 * L_In A Longword input variable
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 * OUTPUTS: none
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 * RETURN VALUE: 1 if input == 0x7fff ffff or -0x8000 0000
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 * 0 otherwise
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 * KEYWORDS: saturation, limit
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 ***************************************************************************/
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 short isLwLimit(Longword L_In)
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 {
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 Longword L_ls;
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 short siOut;
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 if (L_In != 0)
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 {
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 L_ls = L_shl(L_In, 1);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 if (L_sub(L_In, L_ls) == 0)
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 siOut = 1;
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 else
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 siOut = 0;
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 else
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 {
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 siOut = 0;
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 return (siOut);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 }
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 /****************************************************************************
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 * FUNCTION NAME: isSwLimit
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 * PURPOSE:
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 * Check to see if the input Shortword is at the
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 * upper or lower limit of its range. i.e.
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 * 0x7fff or -0x8000
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 * Ostensibly this is a check for an overflow.
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 * This does not truly mean an overflow occurred,
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 * it means the value reached is the
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 * maximum/minimum value representable. It may
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 * have come about due to an overflow.
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 * INPUTS:
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 * swIn A Shortword input variable
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 * OUTPUTS: none
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 * RETURN VALUE: 1 if input == 0x7fff or -0x8000
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 * 0 otherwise
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 * KEYWORDS: saturation, limit
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 ***************************************************************************/
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 short isSwLimit(Shortword swIn)
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 {
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 Shortword swls;
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 short siOut;
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 if (swIn != 0)
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 {
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 swls = shl(swIn, 1);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 if (sub(swIn, swls) == 0) /* logical compare outputs 1/0 */
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 siOut = 1;
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 else
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 siOut = 0;
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 }
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 else
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 {
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 siOut = 0;
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 }
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 return (siOut);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 }
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 /****************************************************************************
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 * FUNCTION NAME: L_mpy_ll
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 * PURPOSE: Multiply a 32 bit number (L_var1) and a 32 bit number
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 * (L_var2), and return a 32 bit result.
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 * INPUTS:
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 * L_var1 A Longword input variable
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 * L_var2 A Longword input variable
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 * OUTPUTS: none
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 * IMPLEMENTATION:
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 * Performs a 31x31 bit multiply, Complexity=24 Ops.
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 * Let x1x0, or y1y0, be the two constituent halves
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 * of a 32 bit number. This function performs the
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 * following:
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 * low = ((x0 >> 1)*(y0 >> 1)) >> 16 (low * low)
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 * mid1 = [(x1 * (y0 >> 1)) >> 1 ] (high * low)
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 * mid2 = [(y1 * (x0 >> 1)) >> 1] (high * low)
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 * mid = (mid1 + low + mid2) >> 14 (sum so far)
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 * output = (y1*x1) + mid (high * high)
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 * RETURN VALUE: A Longword value
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 * KEYWORDS: mult,mpy,multiplication
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 ***************************************************************************/
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 Longword L_mpy_ll(Longword L_var1, Longword L_var2)
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 {
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 Shortword swLow1,
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 swLow2,
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 swHigh1,
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 swHigh2;
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 Longword L_varOut,
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 L_low,
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 L_mid1,
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 L_mid2,
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 L_mid;
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 swLow1 = shr(extract_l(L_var1), 1);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 swLow1 = SW_MAX & swLow1;
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 swLow2 = shr(extract_l(L_var2), 1);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 swLow2 = SW_MAX & swLow2;
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 swHigh1 = extract_h(L_var1);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 swHigh2 = extract_h(L_var2);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 L_low = L_mult(swLow1, swLow2);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 L_low = L_shr(L_low, 16);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 L_mid1 = L_mult(swHigh1, swLow2);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 L_mid1 = L_shr(L_mid1, 1);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 L_mid = L_add(L_mid1, L_low);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 L_mid2 = L_mult(swHigh2, swLow1);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 L_mid2 = L_shr(L_mid2, 1);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 L_mid = L_add(L_mid, L_mid2);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 L_mid = L_shr(L_mid, 14);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 L_varOut = L_mac(L_mid, swHigh1, swHigh2);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 return (L_varOut);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 }
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 /****************************************************************************
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 * FUNCTION NAME: L_mpy_ls
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 * PURPOSE: Multiply a 32 bit number (L_var2) and a 16 bit
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 * number (var1) returning a 32 bit result. L_var2
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 * is truncated to 31 bits prior to executing the
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 * multiply.
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 * INPUTS:
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 * L_var2 A Longword input variable
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 * var1 A Shortword input variable
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 * OUTPUTS: none
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 * RETURN VALUE: A Longword value
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 * KEYWORDS: mult,mpy,multiplication
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 *
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 ***************************************************************************/
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 Longword L_mpy_ls(Longword L_var2, Shortword var1)
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 {
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 Longword L_varOut;
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 Shortword swtemp;
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 swtemp = shr(extract_l(L_var2), 1);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 swtemp = (short) 32767 & (short) swtemp;
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 L_varOut = L_mult(var1, swtemp);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 L_varOut = L_shr(L_varOut, 15);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 L_varOut = L_mac(L_varOut, var1, extract_h(L_var2));
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 return (L_varOut);
3654df24451f libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 }