annotate libgsmefr/oper_32b.c @ 55:92dc7f0082a3

libgsmefr: autocorr.c compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 25 Nov 2022 16:38:54 +0000
parents 49dd1ac8e75b
children 92479d9a8e38
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
53
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*****************************************************************************
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * This file contains operations in double precision. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * These operations are not standard double precision operations. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * They are used where single precision is not enough but the full 32 bits *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * precision is not necessary. For example, the function Div_32() has a *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * 24 bits precision which is enough for our purposes. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 * The double precision numbers use a special representation: *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 * L_32 = hi<<16 + lo<<1 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 * L_32 is a 32 bit integer. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 * hi and lo are 16 bit signed integers. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 * As the low part also contains the sign, this allows fast multiplication. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 * 0x8000 0000 <= L_32 <= 0x7fff fffe. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 * We will use DPF (Double Precision Format )in this file to specify *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 * this special format. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 *****************************************************************************
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 #include "typedef.h"
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 #include "basic_op.h"
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 #include "oper_32b.h"
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 #include "count.h"
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 /*****************************************************************************
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 * Function L_Extract() *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 * Extract from a 32 bit integer two 16 bit DPF. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 * Arguments: *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 * L_32 : 32 bit integer. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 * 0x8000 0000 <= L_32 <= 0x7fff ffff. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 * hi : b16 to b31 of L_32 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 * lo : (L_32 - hi<<16)>>1 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 *****************************************************************************
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 void L_Extract (Word32 L_32, Word16 *hi, Word16 *lo)
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 {
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 *hi = extract_h (L_32);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 *lo = extract_l (L_msu (L_shr (L_32, 1), *hi, 16384));
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 return;
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 /*****************************************************************************
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 * Function L_Comp() *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 * Compose from two 16 bit DPF a 32 bit integer. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 * L_32 = hi<<16 + lo<<1 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 * Arguments: *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 * hi msb *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 * lo lsf (with sign) *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 * Return Value : *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 * 32 bit long signed integer (Word32) whose value falls in the *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 * range : 0x8000 0000 <= L_32 <= 0x7fff fff0. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 *****************************************************************************
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 Word32 L_Comp (Word16 hi, Word16 lo)
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 {
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 Word32 L_32;
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 L_32 = L_deposit_h (hi);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 return (L_mac (L_32, lo, 1)); /* = hi<<16 + lo<<1 */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 }
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 /*****************************************************************************
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 * Function Mpy_32() *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 * Multiply two 32 bit integers (DPF). The result is divided by 2**31 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 * L_32 = (hi1*hi2)<<1 + ( (hi1*lo2)>>15 + (lo1*hi2)>>15 )<<1 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 * This operation can also be viewed as the multiplication of two Q31 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 * number and the result is also in Q31. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 * Arguments: *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 * hi1 hi part of first number *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 * lo1 lo part of first number *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 * hi2 hi part of second number *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 * lo2 lo part of second number *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 *****************************************************************************
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 Word32 Mpy_32 (Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2)
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 {
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 Word32 L_32;
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 L_32 = L_mult (hi1, hi2);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 L_32 = L_mac (L_32, mult (hi1, lo2), 1);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 L_32 = L_mac (L_32, mult (lo1, hi2), 1);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 return (L_32);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 }
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 /*****************************************************************************
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 * Function Mpy_32_16() *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 * Multiply a 16 bit integer by a 32 bit (DPF). The result is divided *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 * by 2**15 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 * L_32 = (hi1*lo2)<<1 + ((lo1*lo2)>>15)<<1 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 * Arguments: *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 * hi hi part of 32 bit number. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 * lo lo part of 32 bit number. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 * n 16 bit number. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 *****************************************************************************
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 Word32 Mpy_32_16 (Word16 hi, Word16 lo, Word16 n)
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 {
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 Word32 L_32;
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 L_32 = L_mult (hi, n);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 L_32 = L_mac (L_32, mult (lo, n), 1);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 return (L_32);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 }
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 /*****************************************************************************
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 * Function Name : Div_32 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 * Purpose : *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 * Fractional integer division of two 32 bit numbers. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 * L_num / L_denom. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 * L_num and L_denom must be positive and L_num < L_denom. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 * L_denom = denom_hi<<16 + denom_lo<<1 *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 * denom_hi is a normalize number. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 * Inputs : *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 * L_num *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 * 32 bit long signed integer (Word32) whose value falls in the *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 * range : 0x0000 0000 < L_num < L_denom *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 * L_denom = denom_hi<<16 + denom_lo<<1 (DPF) *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 * denom_hi *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 * 16 bit positive normalized integer whose value falls in the *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 * range : 0x4000 < hi < 0x7fff *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 * denom_lo *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 * 16 bit positive integer whose value falls in the *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 * range : 0 < lo < 0x7fff *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 * Return Value : *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 * L_div *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 * 32 bit long signed integer (Word32) whose value falls in the *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 * range : 0x0000 0000 <= L_div <= 0x7fff ffff. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 * Algorithm: *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 * - find = 1/L_denom. *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 * First approximation: approx = 1 / denom_hi *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 * 1/L_denom = approx * (2.0 - L_denom * approx ) *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 * *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 * - result = L_num * (1/L_denom) *
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 *****************************************************************************
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 Word32 Div_32 (Word32 L_num, Word16 denom_hi, Word16 denom_lo)
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 {
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 Word16 approx, hi, lo, n_hi, n_lo;
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 Word32 L_32;
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 /* First approximation: 1 / L_denom = 1/denom_hi */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 approx = div_s ((Word16) 0x3fff, denom_hi);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 /* 1/L_denom = approx * (2.0 - L_denom * approx) */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 L_32 = Mpy_32_16 (denom_hi, denom_lo, approx);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 L_32 = L_sub ((Word32) 0x7fffffffL, L_32);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 L_Extract (L_32, &hi, &lo);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 L_32 = Mpy_32_16 (hi, lo, approx);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 /* L_num * (1/L_denom) */
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 L_Extract (L_32, &hi, &lo);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 L_Extract (L_num, &n_hi, &n_lo);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 L_32 = Mpy_32 (n_hi, n_lo, hi, lo);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 L_32 = L_shl (L_32, 2);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 return (L_32);
49dd1ac8e75b libgsmefr: import most *.c files from ETSI source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 }