FreeCalypso > hg > gsm-codec-lib
annotate libgsmhr1/mathhalf.c @ 503:3654df24451f
libgsmhr1/mathdp31.[ch]: import original
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 19 Jun 2024 01:16:47 +0000 |
parents | b0333fa167c3 |
children |
rev | line source |
---|---|
500
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * File Name: mathhalf.c |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * Purpose: Contains functions which implement the primitive |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * arithmetic operations. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 * The functions in this file are listed below. Some of them are |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * defined in terms of other basic operations. One of the |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * routines, saturate() is static. This is not a basic |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * operation, and is not referenced outside the scope of this |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 * file. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 * abs_s() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 * add() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 * divide_s() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 * extract_h() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 * extract_l() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 * L_abs() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 * L_add() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 * L_deposit_h() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 * L_deposit_l() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 * L_mac() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 * L_msu() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 * L_mult() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 * L_negate() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 * L_shift_r() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 * L_shl() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 * L_shr() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 * L_sub() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 * mac_r() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 * msu_r() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 * mult() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 * mult_r() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 * negate() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 * norm_l() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 * norm_s() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 * round() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 * saturate() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 * shift_r() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 * shl() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 * shr() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 * sub() |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 **************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 /*_________________________________________________________________________ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 | | |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 | Include Files | |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 |_________________________________________________________________________| |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 #include "typedefs.h" |
502
b0333fa167c3
libgsmhr1: compile mathhalf.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
500
diff
changeset
|
55 #include "namespace.h" |
500
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 #include "mathhalf.h" |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 * FUNCTION NAME: saturate |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 * Limit the 32 bit input to the range of a 16 bit word. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 * L_var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 * swOut |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 * 0xffff 8000 <= swOut <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 * KEYWORDS: saturation, limiting, limit, saturate, 16 bits |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 static Shortword saturate(Longword L_var1) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 Shortword swOut; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 if (L_var1 > SW_MAX) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 swOut = SW_MAX; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 else if (L_var1 < SW_MIN) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 swOut = SW_MIN; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 swOut = (Shortword) L_var1; /* automatic type conversion */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 return (swOut); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 * FUNCTION NAME: abs_s |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 * Take the absolute value of the 16 bit input. An input of |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 * -0x8000 results in a return value of 0x7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 * var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 * swOut |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 * 0x0000 0000 <= swOut <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 * Take the absolute value of the 16 bit input. An input of |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 * -0x8000 results in a return value of 0x7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 * KEYWORDS: absolute value, abs |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 Shortword abs_s(Shortword var1) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 Shortword swOut; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 if (var1 == SW_MIN) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 swOut = SW_MAX; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 if (var1 < 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 swOut = -var1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 swOut = var1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 return (swOut); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 * FUNCTION NAME: add |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 * Perform the addition of the two 16 bit input variable with |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 * saturation. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 * var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 * var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 * swOut |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 * 0xffff 8000 <= swOut <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 * Perform the addition of the two 16 bit input variable with |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 * saturation. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 * swOut = var1 + var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 * swOut is set to 0x7fff if the operation results in an |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 * overflow. swOut is set to 0x8000 if the operation results |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 * in an underflow. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 * KEYWORDS: add, addition |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 Shortword add(Shortword var1, Shortword var2) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 Longword L_sum; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 Shortword swOut; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 L_sum = (Longword) var1 + var2; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 swOut = saturate(L_sum); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 return (swOut); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 * FUNCTION NAME: divide_s |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 * Divide var1 by var2. Note that both must be positive, and |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 * var1 >= var2. The output is set to 0 if invalid input is |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 * provided. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 * var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 * var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 * swOut |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 * 0xffff 8000 <= swOut <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
243 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
245 * In the case where var1==var2 the function returns 0x7fff. The output |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 * is undefined for invalid inputs. This implementation returns zero |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
247 * and issues a warning via stdio if invalid input is presented. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
248 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
249 * KEYWORDS: divide |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
250 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
251 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
252 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 Shortword divide_s(Shortword var1, Shortword var2) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 Longword L_div; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 Shortword swOut; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 if (var1 < 0 || var2 < 0 || var1 > var2) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
259 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 /* undefined output for invalid input into divide_s */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
261 return (0); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
262 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
263 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 if (var1 == var2) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 return (0x7fff); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
266 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 L_div = ((0x00008000L * (Longword) var1) / (Longword) var2); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
268 swOut = saturate(L_div); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
269 return (swOut); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
270 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
271 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
272 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
273 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
274 * FUNCTION NAME: extract_h |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
275 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
276 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
277 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
278 * Extract the 16 MS bits of a 32 bit Longword. Return the 16 bit |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
279 * number as a Shortword. This is used as a "truncation" of a fractional |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
280 * number. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
281 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
282 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
283 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
284 * L_var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
285 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
286 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
287 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
288 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
289 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
290 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
291 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
292 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
293 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
294 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
295 * swOut |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
296 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
297 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
298 * 0xffff 8000 <= swOut <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
299 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
300 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
301 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
302 * KEYWORDS: assign, truncate |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
303 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
304 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
305 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
306 Shortword extract_h(Longword L_var1) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
307 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
308 Shortword var2; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
309 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
310 var2 = (Shortword) (0x0000ffffL & (L_var1 >> 16)); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
311 return (var2); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
312 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
313 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
314 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
315 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
316 * FUNCTION NAME: extract_l |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
317 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
318 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
319 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
320 * Extract the 16 LS bits of a 32 bit Longword. Return the 16 bit |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
321 * number as a Shortword. The upper portion of the input Longword |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
322 * has no impact whatsoever on the output. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
323 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
324 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
325 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
326 * L_var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
327 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
328 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
329 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
330 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
331 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
332 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
333 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
334 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
335 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
336 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
337 * swOut |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
338 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
339 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
340 * 0xffff 8000 <= swOut <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
341 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
342 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
343 * KEYWORDS: extract, assign |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
344 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
345 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
346 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
347 Shortword extract_l(Longword L_var1) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
348 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
349 Shortword var2; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
350 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
351 var2 = (Shortword) (0x0000ffffL & L_var1); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
352 return (var2); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
353 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
354 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
355 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
356 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
357 * FUNCTION NAME: L_abs |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
358 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
359 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
360 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
361 * Take the absolute value of the 32 bit input. An input of |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
362 * -0x8000 0000 results in a return value of 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
363 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
364 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
365 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
366 * L_var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
367 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
368 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
369 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
370 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
371 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
372 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
373 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
374 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
375 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
376 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
377 * L_Out |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
378 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
379 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
380 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
381 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
382 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
383 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
384 * KEYWORDS: absolute value, abs |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
385 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
386 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
387 Longword L_abs(Longword L_var1) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
388 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
389 Longword L_Out; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
390 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
391 if (L_var1 == LW_MIN) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
392 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
393 L_Out = LW_MAX; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
394 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
395 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
396 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
397 if (L_var1 < 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
398 L_Out = -L_var1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
399 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
400 L_Out = L_var1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
401 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
402 return (L_Out); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
403 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
404 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
405 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
406 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
407 * FUNCTION NAME: L_add |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
408 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
409 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
410 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
411 * Perform the addition of the two 32 bit input variables with |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
412 * saturation. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
413 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
414 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
415 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
416 * L_var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
417 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
418 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
419 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
420 * L_var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
421 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
422 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
423 * 0x8000 0000 <= L_var2 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
424 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
425 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
426 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
427 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
428 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
429 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
430 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
431 * L_Out |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
432 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
433 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
434 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
435 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
436 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
437 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
438 * Perform the addition of the two 32 bit input variables with |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
439 * saturation. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
440 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
441 * L_Out = L_var1 + L_var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
442 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
443 * L_Out is set to 0x7fff ffff if the operation results in an |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
444 * overflow. L_Out is set to 0x8000 0000 if the operation |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
445 * results in an underflow. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
446 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
447 * KEYWORDS: add, addition |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
448 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
449 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
450 Longword L_add(Longword L_var1, Longword L_var2) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
451 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
452 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
453 Longword L_Sum, |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
454 L_SumLow, |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
455 L_SumHigh; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
456 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
457 L_Sum = L_var1 + L_var2; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
458 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
459 if ((L_var1 > 0 && L_var2 > 0) || (L_var1 < 0 && L_var2 < 0)) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
460 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
461 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
462 /* an overflow is possible */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
463 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
464 L_SumLow = (L_var1 & 0xffff) + (L_var2 & 0xffff); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
465 L_SumHigh = ((L_var1 >> 16) & 0xffff) + ((L_var2 >> 16) & 0xffff); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
466 if (L_SumLow & 0x10000) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
467 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
468 /* carry into high word is set */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
469 L_SumHigh += 1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
470 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
471 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
472 /* update sum only if there is an overflow or underflow */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
473 /*------------------------------------------------------*/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
474 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
475 if ((0x10000 & L_SumHigh) && !(0x8000 & L_SumHigh)) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
476 L_Sum = LW_MIN; /* underflow */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
477 else if (!(0x10000 & L_SumHigh) && (0x8000 & L_SumHigh)) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
478 L_Sum = LW_MAX; /* overflow */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
479 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
480 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
481 return (L_Sum); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
482 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
483 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
484 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
485 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
486 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
487 * FUNCTION NAME: L_deposit_h |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
488 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
489 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
490 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
491 * Put the 16 bit input into the 16 MSB's of the output Longword. The |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
492 * LS 16 bits are zeroed. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
493 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
494 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
495 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
496 * var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
497 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
498 * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
499 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
500 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
501 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
502 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
503 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
504 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
505 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
506 * L_Out |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
507 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
508 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
509 * 0x8000 0000 <= L_var1 <= 0x7fff 0000. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
510 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
511 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
512 * KEYWORDS: deposit, assign, fractional assign |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
513 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
514 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
515 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
516 Longword L_deposit_h(Shortword var1) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
517 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
518 Longword L_var2; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
519 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
520 L_var2 = (Longword) var1 << 16; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
521 return (L_var2); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
522 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
523 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
524 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
525 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
526 * FUNCTION NAME: L_deposit_l |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
527 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
528 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
529 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
530 * Put the 16 bit input into the 16 LSB's of the output Longword with |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
531 * sign extension i.e. the top 16 bits are set to either 0 or 0xffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
532 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
533 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
534 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
535 * var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
536 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
537 * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
538 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
539 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
540 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
541 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
542 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
543 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
544 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
545 * L_Out |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
546 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
547 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
548 * 0xffff 8000 <= L_var1 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
549 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
550 * KEYWORDS: deposit, assign |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
551 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
552 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
553 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
554 Longword L_deposit_l(Shortword var1) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
555 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
556 Longword L_Out; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
557 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
558 L_Out = var1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
559 return (L_Out); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
560 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
561 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
562 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
563 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
564 * FUNCTION NAME: L_mac |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
565 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
566 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
567 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
568 * Multiply accumulate. Fractionally multiply two 16 bit |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
569 * numbers together with saturation. Add that result to the |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
570 * 32 bit input with saturation. Return the 32 bit result. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
571 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
572 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
573 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
574 * var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
575 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
576 * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
577 * var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
578 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
579 * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
580 * L_var3 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
581 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
582 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
583 * 0x8000 0000 <= L_var2 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
584 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
585 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
586 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
587 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
588 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
589 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
590 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
591 * L_Out |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
592 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
593 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
594 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
595 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
596 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
597 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
598 * Fractionally multiply two 16 bit numbers together with |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
599 * saturation. The only numbers which will cause saturation on |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
600 * the multiply are 0x8000 * 0x8000. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
601 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
602 * Add that result to the 32 bit input with saturation. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
603 * Return the 32 bit result. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
604 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
605 * Please note that this is not a true multiply accumulate as |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
606 * most processors would implement it. The 0x8000*0x8000 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
607 * causes and overflow for this instruction. On most |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
608 * processors this would cause an overflow only if the 32 bit |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
609 * input added to it were positive or zero. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
610 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
611 * KEYWORDS: mac, multiply accumulate |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
612 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
613 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
614 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
615 Longword L_mac(Longword L_var3, Shortword var1, Shortword var2) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
616 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
617 return (L_add(L_var3, L_mult(var1, var2))); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
618 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
619 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
620 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
621 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
622 * FUNCTION NAME: L_msu |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
623 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
624 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
625 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
626 * Multiply and subtract. Fractionally multiply two 16 bit |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
627 * numbers together with saturation. Subtract that result from |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
628 * the 32 bit input with saturation. Return the 32 bit result. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
629 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
630 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
631 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
632 * var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
633 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
634 * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
635 * var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
636 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
637 * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
638 * L_var3 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
639 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
640 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
641 * 0x8000 0000 <= L_var2 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
642 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
643 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
644 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
645 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
646 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
647 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
648 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
649 * L_Out |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
650 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
651 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
652 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
653 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
654 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
655 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
656 * Fractionally multiply two 16 bit numbers together with |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
657 * saturation. The only numbers which will cause saturation on |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
658 * the multiply are 0x8000 * 0x8000. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
659 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
660 * Subtract that result from the 32 bit input with saturation. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
661 * Return the 32 bit result. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
662 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
663 * Please note that this is not a true multiply accumulate as |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
664 * most processors would implement it. The 0x8000*0x8000 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
665 * causes and overflow for this instruction. On most |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
666 * processors this would cause an overflow only if the 32 bit |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
667 * input added to it were negative or zero. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
668 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
669 * KEYWORDS: mac, multiply accumulate, msu |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
670 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
671 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
672 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
673 Longword L_msu(Longword L_var3, Shortword var1, Shortword var2) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
674 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
675 return (L_sub(L_var3, L_mult(var1, var2))); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
676 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
677 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
678 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
679 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
680 * FUNCTION NAME: L_mult |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
681 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
682 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
683 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
684 * Perform a fractional multipy of the two 16 bit input numbers |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
685 * with saturation. Output a 32 bit number. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
686 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
687 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
688 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
689 * var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
690 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
691 * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
692 * var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
693 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
694 * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
695 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
696 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
697 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
698 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
699 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
700 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
701 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
702 * L_Out |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
703 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
704 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
705 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
706 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
707 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
708 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
709 * Multiply the two the two 16 bit input numbers. If the |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
710 * result is within this range, left shift the result by one |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
711 * and output the 32 bit number. The only possible overflow |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
712 * occurs when var1==var2==-0x8000. In this case output |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
713 * 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
714 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
715 * KEYWORDS: multiply, mult, mpy |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
716 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
717 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
718 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
719 Longword L_mult(Shortword var1, Shortword var2) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
720 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
721 Longword L_product; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
722 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
723 if (var1 == SW_MIN && var2 == SW_MIN) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
724 L_product = LW_MAX; /* overflow */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
725 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
726 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
727 L_product = (Longword) var1 *var2; /* integer multiply */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
728 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
729 L_product = L_product << 1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
730 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
731 return (L_product); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
732 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
733 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
734 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
735 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
736 * FUNCTION NAME: L_negate |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
737 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
738 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
739 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
740 * Negate the 32 bit input. 0x8000 0000's negated value is |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
741 * 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
742 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
743 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
744 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
745 * L_var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
746 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
747 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
748 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
749 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
750 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
751 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
752 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
753 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
754 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
755 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
756 * L_Out |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
757 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
758 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
759 * 0x8000 0001 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
760 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
761 * KEYWORDS: negate, negative |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
762 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
763 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
764 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
765 Longword L_negate(Longword L_var1) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
766 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
767 Longword L_Out; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
768 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
769 if (L_var1 == LW_MIN) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
770 L_Out = LW_MAX; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
771 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
772 L_Out = -L_var1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
773 return (L_Out); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
774 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
775 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
776 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
777 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
778 * FUNCTION NAME: L_shift_r |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
779 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
780 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
781 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
782 * Shift and round. Perform a shift right. After shifting, use |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
783 * the last bit shifted out of the LSB to round the result up |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
784 * or down. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
785 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
786 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
787 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
788 * L_var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
789 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
790 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
791 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
792 * var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
793 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
794 * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
795 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
796 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
797 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
798 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
799 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
800 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
801 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
802 * L_var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
803 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
804 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
805 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
806 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
807 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
808 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
809 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
810 * Shift and round. Perform a shift right. After shifting, use |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
811 * the last bit shifted out of the LSB to round the result up |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
812 * or down. This is just like shift_r above except that the |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
813 * input/output is 32 bits as opposed to 16. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
814 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
815 * if var2 is positve perform a arithmetic left shift |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
816 * with saturation (see L_shl() above). |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
817 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
818 * If var2 is zero simply return L_var1. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
819 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
820 * If var2 is negative perform a arithmetic right shift (L_shr) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
821 * of L_var1 by (-var2)+1. Add the LS bit of the result to |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
822 * L_var1 shifted right (L_shr) by -var2. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
823 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
824 * Note that there is no constraint on var2, so if var2 is |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
825 * -0xffff 8000 then -var2 is 0x0000 8000, not 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
826 * This is the reason the L_shl function is used. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
827 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
828 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
829 * KEYWORDS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
830 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
831 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
832 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
833 Longword L_shift_r(Longword L_var1, Shortword var2) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
834 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
835 Longword L_Out, |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
836 L_rnd; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
837 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
838 if (var2 < -31) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
839 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
840 L_Out = 0; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
841 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
842 else if (var2 < 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
843 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
844 /* right shift */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
845 L_rnd = L_shl(L_var1, var2 + 1) & 0x1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
846 L_Out = L_add(L_shl(L_var1, var2), L_rnd); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
847 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
848 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
849 L_Out = L_shl(L_var1, var2); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
850 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
851 return (L_Out); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
852 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
853 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
854 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
855 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
856 * FUNCTION NAME: L_shl |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
857 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
858 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
859 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
860 * Arithmetic shift left (or right). |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
861 * Arithmetically shift the input left by var2. If var2 is |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
862 * negative then an arithmetic shift right (L_shr) of L_var1 by |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
863 * -var2 is performed. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
864 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
865 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
866 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
867 * var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
868 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
869 * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
870 * L_var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
871 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
872 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
873 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
874 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
875 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
876 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
877 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
878 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
879 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
880 * L_Out |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
881 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
882 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
883 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
884 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
885 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
886 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
887 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
888 * Arithmetically shift the 32 bit input left by var2. This |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
889 * operation maintains the sign of the input number. If var2 is |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
890 * negative then an arithmetic shift right (L_shr) of L_var1 by |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
891 * -var2 is performed. See description of L_shr for details. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
892 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
893 * Equivalent to the Full-Rate GSM ">> n" operation. Note that |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
894 * ANSI-C does not guarantee operation of the C ">>" or "<<" |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
895 * operator for negative numbers. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
896 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
897 * KEYWORDS: shift, arithmetic shift left, |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
898 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
899 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
900 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
901 Longword L_shl(Longword L_var1, Shortword var2) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
902 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
903 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
904 Longword L_Mask, |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
905 L_Out; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
906 int i, |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
907 iOverflow = 0; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
908 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
909 if (var2 == 0 || L_var1 == 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
910 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
911 L_Out = L_var1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
912 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
913 else if (var2 < 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
914 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
915 if (var2 <= -31) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
916 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
917 if (L_var1 > 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
918 L_Out = 0; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
919 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
920 L_Out = 0xffffffffL; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
921 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
922 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
923 L_Out = L_shr(L_var1, -var2); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
924 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
925 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
926 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
927 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
928 if (var2 >= 31) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
929 iOverflow = 1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
930 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
931 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
932 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
933 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
934 if (L_var1 < 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
935 L_Mask = LW_SIGN; /* sign bit mask */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
936 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
937 L_Mask = 0x0; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
938 L_Out = L_var1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
939 for (i = 0; i < var2 && !iOverflow; i++) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
940 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
941 /* check the sign bit */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
942 L_Out = (L_Out & 0x7fffffffL) << 1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
943 if ((L_Mask ^ L_Out) & LW_SIGN) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
944 iOverflow = 1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
945 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
946 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
947 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
948 if (iOverflow) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
949 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
950 /* saturate */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
951 if (L_var1 > 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
952 L_Out = LW_MAX; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
953 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
954 L_Out = LW_MIN; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
955 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
956 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
957 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
958 return (L_Out); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
959 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
960 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
961 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
962 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
963 * FUNCTION NAME: L_shr |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
964 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
965 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
966 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
967 * Arithmetic shift right (or left). |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
968 * Arithmetically shift the input right by var2. If var2 is |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
969 * negative then an arithmetic shift left (shl) of var1 by |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
970 * -var2 is performed. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
971 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
972 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
973 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
974 * var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
975 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
976 * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
977 * L_var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
978 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
979 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
980 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
981 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
982 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
983 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
984 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
985 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
986 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
987 * L_Out |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
988 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
989 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
990 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
991 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
992 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
993 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
994 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
995 * Arithmetically shift the input right by var2. This |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
996 * operation maintains the sign of the input number. If var2 is |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
997 * negative then an arithmetic shift left (shl) of L_var1 by |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
998 * -var2 is performed. See description of L_shl for details. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
999 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1000 * The input is a 32 bit number, as is the output. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1001 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1002 * Equivalent to the Full-Rate GSM ">> n" operation. Note that |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1003 * ANSI-C does not guarantee operation of the C ">>" or "<<" |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1004 * operator for negative numbers. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1005 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1006 * KEYWORDS: shift, arithmetic shift right, |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1007 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1008 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1009 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1010 Longword L_shr(Longword L_var1, Shortword var2) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1011 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1012 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1013 Longword L_Mask, |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1014 L_Out; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1015 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1016 if (var2 == 0 || L_var1 == 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1017 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1018 L_Out = L_var1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1019 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1020 else if (var2 < 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1021 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1022 /* perform a left shift */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1023 /*----------------------*/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1024 if (var2 <= -31) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1025 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1026 /* saturate */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1027 if (L_var1 > 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1028 L_Out = LW_MAX; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1029 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1030 L_Out = LW_MIN; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1031 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1032 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1033 L_Out = L_shl(L_var1, -var2); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1034 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1035 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1036 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1037 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1038 if (var2 >= 31) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1039 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1040 if (L_var1 > 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1041 L_Out = 0; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1042 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1043 L_Out = 0xffffffffL; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1044 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1045 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1046 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1047 L_Mask = 0; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1048 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1049 if (L_var1 < 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1050 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1051 L_Mask = ~L_Mask << (32 - var2); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1052 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1053 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1054 L_var1 >>= var2; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1055 L_Out = L_Mask | L_var1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1056 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1057 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1058 return (L_Out); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1059 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1060 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1061 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1062 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1063 * FUNCTION NAME: L_sub |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1064 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1065 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1066 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1067 * Perform the subtraction of the two 32 bit input variables with |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1068 * saturation. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1069 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1070 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1071 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1072 * L_var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1073 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1074 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1075 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1076 * L_var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1077 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1078 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1079 * 0x8000 0000 <= L_var2 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1080 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1081 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1082 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1083 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1084 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1085 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1086 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1087 * L_Out |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1088 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1089 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1090 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1091 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1092 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1093 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1094 * Perform the subtraction of the two 32 bit input variables with |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1095 * saturation. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1096 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1097 * L_Out = L_var1 - L_var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1098 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1099 * L_Out is set to 0x7fff ffff if the operation results in an |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1100 * overflow. L_Out is set to 0x8000 0000 if the operation |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1101 * results in an underflow. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1102 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1103 * KEYWORDS: sub, subtraction |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1104 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1105 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1106 Longword L_sub(Longword L_var1, Longword L_var2) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1107 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1108 Longword L_Sum; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1109 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1110 /* check for overflow */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1111 if ((L_var1 > 0 && L_var2 < 0) || (L_var1 < 0 && L_var2 > 0)) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1112 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1113 if (L_var2 == LW_MIN) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1114 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1115 L_Sum = L_add(L_var1, LW_MAX); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1116 L_Sum = L_add(L_Sum, 1); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1117 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1118 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1119 L_Sum = L_add(L_var1, -L_var2); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1120 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1121 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1122 { /* no overflow possible */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1123 L_Sum = L_var1 - L_var2; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1124 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1125 return (L_Sum); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1126 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1127 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1128 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1129 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1130 * FUNCTION NAME:mac_r |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1131 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1132 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1133 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1134 * Multiply accumulate and round. Fractionally multiply two 16 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1135 * bit numbers together with saturation. Add that result to |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1136 * the 32 bit input with saturation. Finally round the result |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1137 * into a 16 bit number. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1138 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1139 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1140 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1141 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1142 * var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1143 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1144 * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1145 * var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1146 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1147 * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1148 * L_var3 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1149 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1150 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1151 * 0x8000 0000 <= L_var2 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1152 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1153 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1154 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1155 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1156 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1157 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1158 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1159 * swOut |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1160 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1161 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1162 * 0xffff 8000 <= swOut <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1163 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1164 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1165 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1166 * Fractionally multiply two 16 bit numbers together with |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1167 * saturation. The only numbers which will cause saturation on |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1168 * the multiply are 0x8000 * 0x8000. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1169 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1170 * Add that result to the 32 bit input with saturation. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1171 * Round the 32 bit result by adding 0x0000 8000 to the input. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1172 * The result may overflow due to the add. If so, the result |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1173 * is saturated. The 32 bit rounded number is then shifted |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1174 * down 16 bits and returned as a Shortword. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1175 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1176 * Please note that this is not a true multiply accumulate as |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1177 * most processors would implement it. The 0x8000*0x8000 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1178 * causes and overflow for this instruction. On most |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1179 * processors this would cause an overflow only if the 32 bit |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1180 * input added to it were positive or zero. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1181 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1182 * KEYWORDS: mac, multiply accumulate, macr |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1183 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1184 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1185 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1186 Shortword mac_r(Longword L_var3, Shortword var1, Shortword var2) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1187 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1188 return (round(L_add(L_var3, L_mult(var1, var2)))); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1189 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1190 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1191 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1192 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1193 * FUNCTION NAME: msu_r |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1194 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1195 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1196 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1197 * Multiply subtract and round. Fractionally multiply two 16 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1198 * bit numbers together with saturation. Subtract that result from |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1199 * the 32 bit input with saturation. Finally round the result |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1200 * into a 16 bit number. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1201 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1202 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1203 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1204 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1205 * var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1206 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1207 * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1208 * var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1209 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1210 * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1211 * L_var3 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1212 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1213 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1214 * 0x8000 0000 <= L_var2 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1215 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1216 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1217 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1218 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1219 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1220 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1221 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1222 * swOut |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1223 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1224 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1225 * 0xffff 8000 <= swOut <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1226 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1227 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1228 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1229 * Fractionally multiply two 16 bit numbers together with |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1230 * saturation. The only numbers which will cause saturation on |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1231 * the multiply are 0x8000 * 0x8000. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1232 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1233 * Subtract that result from the 32 bit input with saturation. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1234 * Round the 32 bit result by adding 0x0000 8000 to the input. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1235 * The result may overflow due to the add. If so, the result |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1236 * is saturated. The 32 bit rounded number is then shifted |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1237 * down 16 bits and returned as a Shortword. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1238 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1239 * Please note that this is not a true multiply accumulate as |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1240 * most processors would implement it. The 0x8000*0x8000 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1241 * causes and overflow for this instruction. On most |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1242 * processors this would cause an overflow only if the 32 bit |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1243 * input added to it were positive or zero. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1244 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1245 * KEYWORDS: mac, multiply accumulate, macr |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1246 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1247 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1248 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1249 Shortword msu_r(Longword L_var3, Shortword var1, Shortword var2) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1250 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1251 return (round(L_sub(L_var3, L_mult(var1, var2)))); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1252 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1253 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1254 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1255 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1256 * FUNCTION NAME: mult |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1257 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1258 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1259 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1260 * Perform a fractional multipy of the two 16 bit input numbers |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1261 * with saturation and truncation. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1262 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1263 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1264 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1265 * var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1266 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1267 * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1268 * var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1269 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1270 * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1271 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1272 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1273 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1274 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1275 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1276 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1277 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1278 * swOut |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1279 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1280 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1281 * 0xffff 8000 <= swOut <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1282 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1283 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1284 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1285 * Perform a fractional multipy of the two 16 bit input |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1286 * numbers. If var1 == var2 == -0x8000, output 0x7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1287 * Otherwise output var1*var2 >> 15. The output is a |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1288 * 16 bit number. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1289 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1290 * KEYWORDS: mult, mulitply, mpy |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1291 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1292 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1293 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1294 Shortword mult(Shortword var1, Shortword var2) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1295 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1296 Longword L_product; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1297 Shortword swOut; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1298 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1299 L_product = L_mult(var1, var2); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1300 swOut = extract_h(L_product); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1301 return (swOut); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1302 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1303 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1304 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1305 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1306 * FUNCTION NAME: mult_r |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1307 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1308 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1309 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1310 * Perform a fractional multipy and round of the two 16 bit |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1311 * input numbers with saturation. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1312 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1313 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1314 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1315 * var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1316 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1317 * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1318 * var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1319 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1320 * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1321 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1322 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1323 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1324 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1325 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1326 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1327 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1328 * swOut |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1329 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1330 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1331 * 0xffff 8000 <= swOut <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1332 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1333 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1334 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1335 * This routine is defined as the concatenation of the multiply |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1336 * operation and the round operation. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1337 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1338 * The fractional multiply (L_mult) produces a saturated 32 bit |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1339 * output. This is followed by a an add of 0x0000 8000 to the |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1340 * 32 bit result. The result may overflow due to the add. If |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1341 * so, the result is saturated. The 32 bit rounded number is |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1342 * then shifted down 16 bits and returned as a Shortword. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1343 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1344 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1345 * KEYWORDS: multiply and round, round, mult_r, mpyr |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1346 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1347 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1348 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1349 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1350 Shortword mult_r(Shortword var1, Shortword var2) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1351 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1352 Shortword swOut; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1353 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1354 swOut = round(L_mult(var1, var2)); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1355 return (swOut); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1356 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1357 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1358 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1359 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1360 * FUNCTION NAME: negate |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1361 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1362 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1363 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1364 * Negate the 16 bit input. 0x8000's negated value is 0x7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1365 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1366 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1367 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1368 * var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1369 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1370 * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1371 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1372 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1373 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1374 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1375 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1376 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1377 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1378 * swOut |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1379 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1380 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1381 * 0xffff 8001 <= swOut <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1382 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1383 * KEYWORDS: negate, negative, invert |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1384 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1385 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1386 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1387 Shortword negate(Shortword var1) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1388 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1389 Shortword swOut; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1390 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1391 if (var1 == SW_MIN) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1392 swOut = SW_MAX; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1393 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1394 swOut = -var1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1395 return (swOut); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1396 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1397 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1398 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1399 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1400 * FUNCTION NAME: norm_l |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1401 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1402 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1403 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1404 * Get normalize shift count: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1405 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1406 * A 32 bit number is input (possiblly unnormalized). Output |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1407 * the positive (or zero) shift count required to normalize the |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1408 * input. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1409 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1410 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1411 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1412 * L_var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1413 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1414 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1415 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1416 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1417 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1418 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1419 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1420 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1421 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1422 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1423 * swOut |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1424 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1425 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1426 * 0 <= swOut <= 31 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1427 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1428 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1429 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1430 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1431 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1432 * Get normalize shift count: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1433 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1434 * A 32 bit number is input (possiblly unnormalized). Output |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1435 * the positive (or zero) shift count required to normalize the |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1436 * input. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1437 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1438 * If zero in input, return 0 as the shift count. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1439 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1440 * For non-zero numbers, count the number of left shift |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1441 * required to get the number to fall into the range: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1442 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1443 * 0x4000 0000 >= normlzd number >= 0x7fff ffff (positive number) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1444 * or |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1445 * 0x8000 0000 <= normlzd number < 0xc000 0000 (negative number) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1446 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1447 * Return the number of shifts. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1448 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1449 * This instruction corresponds exactly to the Full-Rate "norm" |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1450 * instruction. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1451 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1452 * KEYWORDS: norm, normalization |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1453 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1454 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1455 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1456 Shortword norm_l(Longword L_var1) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1457 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1458 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1459 Shortword swShiftCnt; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1460 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1461 if (L_var1 != 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1462 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1463 if (!(L_var1 & LW_SIGN)) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1464 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1465 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1466 /* positive input */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1467 for (swShiftCnt = 0; !(L_var1 <= LW_MAX && L_var1 >= 0x40000000L); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1468 swShiftCnt++) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1469 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1470 L_var1 = L_var1 << 1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1471 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1472 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1473 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1474 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1475 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1476 /* negative input */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1477 for (swShiftCnt = 0; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1478 !(L_var1 >= LW_MIN && L_var1 < (Longword) 0xc0000000L); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1479 swShiftCnt++) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1480 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1481 L_var1 = L_var1 << 1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1482 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1483 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1484 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1485 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1486 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1487 swShiftCnt = 0; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1488 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1489 return (swShiftCnt); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1490 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1491 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1492 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1493 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1494 * FUNCTION NAME: norm_s |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1495 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1496 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1497 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1498 * Get normalize shift count: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1499 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1500 * A 16 bit number is input (possiblly unnormalized). Output |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1501 * the positive (or zero) shift count required to normalize the |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1502 * input. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1503 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1504 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1505 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1506 * var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1507 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1508 * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1509 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1510 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1511 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1512 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1513 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1514 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1515 * swOut |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1516 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1517 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1518 * 0 <= swOut <= 15 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1519 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1520 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1521 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1522 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1523 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1524 * Get normalize shift count: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1525 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1526 * A 16 bit number is input (possiblly unnormalized). Output |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1527 * the positive (or zero) shift count required to normalize the |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1528 * input. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1529 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1530 * If zero in input, return 0 as the shift count. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1531 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1532 * For non-zero numbers, count the number of left shift |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1533 * required to get the number to fall into the range: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1534 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1535 * 0x4000 >= normlzd number >= 0x7fff (positive number) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1536 * or |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1537 * 0x8000 <= normlzd number < 0xc000 (negative number) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1538 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1539 * Return the number of shifts. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1540 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1541 * This instruction corresponds exactly to the Full-Rate "norm" |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1542 * instruction. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1543 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1544 * KEYWORDS: norm, normalization |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1545 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1546 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1547 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1548 Shortword norm_s(Shortword var1) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1549 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1550 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1551 short swShiftCnt; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1552 Longword L_var1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1553 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1554 L_var1 = L_deposit_h(var1); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1555 swShiftCnt = norm_l(L_var1); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1556 return (swShiftCnt); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1557 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1558 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1559 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1560 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1561 * FUNCTION NAME: round |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1562 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1563 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1564 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1565 * Round the 32 bit Longword into a 16 bit shortword with saturation. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1566 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1567 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1568 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1569 * L_var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1570 * 32 bit long signed integer (Longword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1571 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1572 * 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1573 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1574 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1575 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1576 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1577 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1578 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1579 * swOut |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1580 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1581 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1582 * 0xffff 8000 <= swOut <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1583 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1584 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1585 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1586 * Perform a two's complement round on the input Longword with |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1587 * saturation. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1588 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1589 * This is equivalent to adding 0x0000 8000 to the input. The |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1590 * result may overflow due to the add. If so, the result is |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1591 * saturated. The 32 bit rounded number is then shifted down |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1592 * 16 bits and returned as a Shortword. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1593 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1594 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1595 * KEYWORDS: round |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1596 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1597 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1598 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1599 Shortword round(Longword L_var1) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1600 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1601 Longword L_Prod; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1602 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1603 L_Prod = L_add(L_var1, 0x00008000L); /* round MSP */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1604 return (extract_h(L_Prod)); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1605 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1606 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1607 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1608 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1609 * FUNCTION NAME: shift_r |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1610 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1611 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1612 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1613 * Shift and round. Perform a shift right. After shifting, use |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1614 * the last bit shifted out of the LSB to round the result up |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1615 * or down. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1616 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1617 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1618 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1619 * var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1620 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1621 * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1622 * var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1623 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1624 * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1625 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1626 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1627 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1628 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1629 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1630 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1631 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1632 * swOut |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1633 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1634 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1635 * 0xffff 8000 <= swOut <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1636 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1637 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1638 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1639 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1640 * Shift and round. Perform a shift right. After shifting, use |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1641 * the last bit shifted out of the LSB to round the result up |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1642 * or down. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1643 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1644 * If var2 is positive perform a arithmetic left shift |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1645 * with saturation (see shl() above). |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1646 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1647 * If var2 is zero simply return var1. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1648 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1649 * If var2 is negative perform a arithmetic right shift (shr) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1650 * of var1 by (-var2)+1. Add the LS bit of the result to var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1651 * shifted right (shr) by -var2. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1652 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1653 * Note that there is no constraint on var2, so if var2 is |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1654 * -0xffff 8000 then -var2 is 0x0000 8000, not 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1655 * This is the reason the shl function is used. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1656 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1657 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1658 * KEYWORDS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1659 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1660 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1661 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1662 Shortword shift_r(Shortword var1, Shortword var2) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1663 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1664 Shortword swOut, |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1665 swRnd; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1666 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1667 if (var2 >= 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1668 swOut = shl(var1, var2); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1669 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1670 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1671 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1672 /* right shift */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1673 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1674 if (var2 < -15) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1675 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1676 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1677 swOut = 0; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1678 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1679 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1680 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1681 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1682 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1683 swRnd = shl(var1, var2 + 1) & 0x1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1684 swOut = add(shl(var1, var2), swRnd); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1685 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1686 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1687 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1688 return (swOut); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1689 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1690 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1691 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1692 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1693 * FUNCTION NAME: shl |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1694 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1695 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1696 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1697 * Arithmetically shift the input left by var2. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1698 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1699 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1700 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1701 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1702 * var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1703 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1704 * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1705 * var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1706 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1707 * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1708 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1709 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1710 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1711 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1712 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1713 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1714 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1715 * swOut |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1716 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1717 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1718 * 0xffff 8000 <= swOut <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1719 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1720 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1721 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1722 * If Arithmetically shift the input left by var2. If var2 is |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1723 * negative then an arithmetic shift right (shr) of var1 by |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1724 * -var2 is performed. See description of shr for details. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1725 * When an arithmetic shift left is performed the var2 LS bits |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1726 * are zero filled. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1727 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1728 * The only exception is if the left shift causes an overflow |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1729 * or underflow. In this case the LS bits are not modified. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1730 * The number returned is 0x8000 in the case of an underflow or |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1731 * 0x7fff in the case of an overflow. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1732 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1733 * The shl is equivalent to the Full-Rate GSM "<< n" operation. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1734 * Note that ANSI-C does not guarantee operation of the C ">>" |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1735 * or "<<" operator for negative numbers - it is not specified |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1736 * whether this shift is an arithmetic or logical shift. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1737 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1738 * KEYWORDS: asl, arithmetic shift left, shift |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1739 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1740 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1741 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1742 Shortword shl(Shortword var1, Shortword var2) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1743 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1744 Shortword swOut; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1745 Longword L_Out; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1746 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1747 if (var2 == 0 || var1 == 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1748 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1749 swOut = var1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1750 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1751 else if (var2 < 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1752 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1753 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1754 /* perform a right shift */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1755 /*-----------------------*/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1756 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1757 if (var2 <= -15) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1758 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1759 if (var1 < 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1760 swOut = (Shortword) 0xffff; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1761 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1762 swOut = 0x0; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1763 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1764 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1765 swOut = shr(var1, -var2); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1766 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1767 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1768 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1769 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1770 /* var2 > 0 */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1771 if (var2 >= 15) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1772 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1773 /* saturate */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1774 if (var1 > 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1775 swOut = SW_MAX; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1776 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1777 swOut = SW_MIN; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1778 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1779 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1780 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1781 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1782 L_Out = (Longword) var1 *(1 << var2); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1783 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1784 swOut = (Shortword) L_Out; /* copy low portion to swOut, overflow |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1785 * could have hpnd */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1786 if (swOut != L_Out) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1787 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1788 /* overflow */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1789 if (var1 > 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1790 swOut = SW_MAX; /* saturate */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1791 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1792 swOut = SW_MIN; /* saturate */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1793 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1794 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1795 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1796 return (swOut); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1797 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1798 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1799 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1800 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1801 * FUNCTION NAME: shr |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1802 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1803 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1804 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1805 * Arithmetic shift right (or left). |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1806 * Arithmetically shift the input right by var2. If var2 is |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1807 * negative then an arithmetic shift left (shl) of var1 by |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1808 * -var2 is performed. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1809 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1810 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1811 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1812 * var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1813 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1814 * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1815 * var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1816 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1817 * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1818 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1819 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1820 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1821 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1822 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1823 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1824 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1825 * swOut |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1826 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1827 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1828 * 0xffff 8000 <= swOut <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1829 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1830 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1831 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1832 * Arithmetically shift the input right by var2. This |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1833 * operation maintains the sign of the input number. If var2 is |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1834 * negative then an arithmetic shift left (shl) of var1 by |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1835 * -var2 is performed. See description of shl for details. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1836 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1837 * Equivalent to the Full-Rate GSM ">> n" operation. Note that |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1838 * ANSI-C does not guarantee operation of the C ">>" or "<<" |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1839 * operator for negative numbers. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1840 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1841 * KEYWORDS: shift, arithmetic shift right, |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1842 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1843 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1844 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1845 Shortword shr(Shortword var1, Shortword var2) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1846 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1847 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1848 Shortword swMask, |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1849 swOut; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1850 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1851 if (var2 == 0 || var1 == 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1852 swOut = var1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1853 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1854 else if (var2 < 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1855 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1856 /* perform an arithmetic left shift */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1857 /*----------------------------------*/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1858 if (var2 <= -15) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1859 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1860 /* saturate */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1861 if (var1 > 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1862 swOut = SW_MAX; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1863 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1864 swOut = SW_MIN; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1865 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1866 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1867 swOut = shl(var1, -var2); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1868 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1869 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1870 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1871 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1872 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1873 /* positive shift count */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1874 /*----------------------*/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1875 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1876 if (var2 >= 15) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1877 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1878 if (var1 < 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1879 swOut = (Shortword) 0xffff; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1880 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1881 swOut = 0x0; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1882 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1883 else |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1884 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1885 /* take care of sign extension */ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1886 /*-----------------------------*/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1887 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1888 swMask = 0; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1889 if (var1 < 0) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1890 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1891 swMask = ~swMask << (16 - var2); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1892 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1893 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1894 var1 >>= var2; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1895 swOut = swMask | var1; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1896 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1897 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1898 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1899 return (swOut); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1900 } |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1901 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1902 /*************************************************************************** |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1903 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1904 * FUNCTION NAME: sub |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1905 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1906 * PURPOSE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1907 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1908 * Perform the subtraction of the two 16 bit input variable with |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1909 * saturation. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1910 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1911 * INPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1912 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1913 * var1 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1914 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1915 * falls in the range 0xffff 8000 <= var1 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1916 * var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1917 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1918 * falls in the range 0xffff 8000 <= var2 <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1919 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1920 * OUTPUTS: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1921 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1922 * none |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1923 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1924 * RETURN VALUE: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1925 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1926 * swOut |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1927 * 16 bit short signed integer (Shortword) whose value |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1928 * falls in the range |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1929 * 0xffff 8000 <= swOut <= 0x0000 7fff. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1930 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1931 * IMPLEMENTATION: |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1932 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1933 * Perform the subtraction of the two 16 bit input variable with |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1934 * saturation. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1935 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1936 * swOut = var1 - var2 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1937 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1938 * swOut is set to 0x7fff if the operation results in an |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1939 * overflow. swOut is set to 0x8000 if the operation results |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1940 * in an underflow. |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1941 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1942 * KEYWORDS: sub, subtraction |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1943 * |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1944 *************************************************************************/ |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1945 Shortword sub(Shortword var1, Shortword var2) |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1946 { |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1947 Longword L_diff; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1948 Shortword swOut; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1949 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1950 L_diff = (Longword) var1 - var2; |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1951 swOut = saturate(L_diff); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1952 |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1953 return (swOut); |
66fb1fd032e6
libgsmhr1/mathhalf.[ch]: import original
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1954 } |