FreeCalypso > hg > gsm-codec-lib
annotate libgsmhr1/mathdp31.c @ 503:3654df24451f
libgsmhr1/mathdp31.[ch]: import original
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 19 Jun 2024 01:16:47 +0000 |
parents | |
children | 024615de06fe |
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 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 #include "mathhalf.h" |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 #include "typedefs.h" |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 /**************************************************************************** |
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 * FUNCTION NAME: isLwLimit |
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 * PURPOSE: |
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 * Check to see if the input Longword is at the |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 * upper or lower limit of its range. i.e. |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 * 0x7fff ffff or -0x8000 0000 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 * |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 * Ostensibly this is a check for an overflow. |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 * This does not truly mean an overflow occurred, |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 * it means the value reached is the |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 * maximum/minimum value representable. It may |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 * have come about due to an overflow. |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 * |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 * INPUTS: |
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 * L_In A Longword input variable |
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 * |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 * OUTPUTS: none |
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 * RETURN VALUE: 1 if input == 0x7fff ffff or -0x8000 0000 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 * 0 otherwise |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 * |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 * KEYWORDS: saturation, limit |
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 ***************************************************************************/ |
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 short isLwLimit(Longword L_In) |
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 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 Longword L_ls; |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 short siOut; |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 if (L_In != 0) |
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 L_ls = L_shl(L_In, 1); |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (L_sub(L_In, L_ls) == 0) |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 siOut = 1; |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 else |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 siOut = 0; |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 } |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 else |
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 siOut = 0; |
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 return (siOut); |
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 |
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 * FUNCTION NAME: isSwLimit |
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 * PURPOSE: |
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 * Check to see if the input Shortword is at the |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 * upper or lower limit of its range. i.e. |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 * 0x7fff or -0x8000 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 * |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 * Ostensibly this is a check for an overflow. |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 * This does not truly mean an overflow occurred, |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 * it means the value reached is the |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 * maximum/minimum value representable. It may |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 * have come about due to an overflow. |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 * |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 * INPUTS: |
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 * swIn A Shortword input variable |
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 * |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 * OUTPUTS: none |
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 * RETURN VALUE: 1 if input == 0x7fff or -0x8000 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 * 0 otherwise |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 * |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 * KEYWORDS: saturation, limit |
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 ***************************************************************************/ |
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 short isSwLimit(Shortword swIn) |
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 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 Shortword swls; |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 short siOut; |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 if (swIn != 0) |
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 swls = shl(swIn, 1); |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 if (sub(swIn, swls) == 0) /* logical compare outputs 1/0 */ |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 siOut = 1; |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 else |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 siOut = 0; |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 } |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 else |
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 siOut = 0; |
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 return (siOut); |
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 } |
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 * FUNCTION NAME: L_mpy_ll |
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 * 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
|
133 * (L_var2), and return a 32 bit result. |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 * |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 * INPUTS: |
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 * L_var1 A Longword input variable |
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_var2 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 * OUTPUTS: none |
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 * IMPLEMENTATION: |
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 * Performs a 31x31 bit multiply, Complexity=24 Ops. |
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 * Let x1x0, or y1y0, be the two constituent halves |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 * of a 32 bit number. This function performs the |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 * following: |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 * |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 * low = ((x0 >> 1)*(y0 >> 1)) >> 16 (low * low) |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 * mid1 = [(x1 * (y0 >> 1)) >> 1 ] (high * low) |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 * mid2 = [(y1 * (x0 >> 1)) >> 1] (high * low) |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 * mid = (mid1 + low + mid2) >> 14 (sum so far) |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 * output = (y1*x1) + mid (high * high) |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 * |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 * |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 * RETURN VALUE: A Longword value |
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 * KEYWORDS: mult,mpy,multiplication |
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 ***************************************************************************/ |
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 Longword L_mpy_ll(Longword L_var1, Longword L_var2) |
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 Shortword swLow1, |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 swLow2, |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 swHigh1, |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 swHigh2; |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 Longword L_varOut, |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 L_low, |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 L_mid1, |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 L_mid2, |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 L_mid; |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 swLow1 = shr(extract_l(L_var1), 1); |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 swLow1 = SW_MAX & swLow1; |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 swLow2 = shr(extract_l(L_var2), 1); |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 swLow2 = SW_MAX & swLow2; |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 swHigh1 = extract_h(L_var1); |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 swHigh2 = extract_h(L_var2); |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 L_low = L_mult(swLow1, swLow2); |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 L_low = L_shr(L_low, 16); |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 L_mid1 = L_mult(swHigh1, swLow2); |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 L_mid1 = L_shr(L_mid1, 1); |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 L_mid = L_add(L_mid1, L_low); |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 L_mid2 = L_mult(swHigh2, swLow1); |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 L_mid2 = L_shr(L_mid2, 1); |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 L_mid = L_add(L_mid, L_mid2); |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 L_mid = L_shr(L_mid, 14); |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 L_varOut = L_mac(L_mid, swHigh1, swHigh2); |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 return (L_varOut); |
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 |
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 * FUNCTION NAME: L_mpy_ls |
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 * 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
|
207 * number (var1) returning a 32 bit result. L_var2 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 * is truncated to 31 bits prior to executing the |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 * multiply. |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 * |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 * INPUTS: |
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 * L_var2 A Longword input variable |
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 * var1 A Shortword 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 * OUTPUTS: none |
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 * RETURN VALUE: A Longword value |
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 * KEYWORDS: mult,mpy,multiplication |
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 ***************************************************************************/ |
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 Longword L_mpy_ls(Longword L_var2, Shortword var1) |
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_varOut; |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 Shortword swtemp; |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 swtemp = shr(extract_l(L_var2), 1); |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 swtemp = (short) 32767 & (short) swtemp; |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 L_varOut = L_mult(var1, swtemp); |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 L_varOut = L_shr(L_varOut, 15); |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 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
|
236 return (L_varOut); |
3654df24451f
libgsmhr1/mathdp31.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 } |