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