lin
2025-03-21 36aaa54056c4f4e150f6ee0636610d9a68470a08
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/******************************************************************************
 *
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *****************************************************************************
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/
/*!
******************************************************************************
* \file var_q_operator.c
*
* \brief
*    This files to be used for basic fixed Q-point functions
*
* \date
*
* \author
*    ittiam
*
******************************************************************************
*/
/*****************************************************************************/
/* File Includes                                                             */
/*****************************************************************************/
/* User include files */
#include "ia_type_def.h"
#include "defs.h"
#include "ia_basic_ops32.h"
#include "ia_basic_ops40.h"
/* #include "num_struct.h" */
#include "var_q_operator.h"
#include "sqrt_interp.h"
#include "common_rom.h"
 
#define NUM_BITS_MAG 32
 
/************************************************************************************/
/* The files to be used for basic fixed Q-point functions :                         */
/*                                                                                  */
/* audio/ia_standards/c64x/include/ia_basic_ops32.h        cvs_version : FULL_V1_16 */
/* audio/ia_standards/c64x/include/ia_basic_ops40.h     cvs_version : FULL_V1_16    */
/*                                                                                  */
/************************************************************************************/
 
/* Multiply */
 
void mult32_var_q(number_t a, number_t b, number_t *c)
{
    WORD32 Q_a;
    WORD32 Q_b;
    /* WORD32 final_Q; */
    WORD32 norm_a;
    WORD32 norm_b;
 
    norm_a = norm32(a.sm); /* norm32 defined in ia_basic_ops32.h */
    norm_b = norm32(b.sm);
 
    Q_a = norm_a + a.e;
    Q_b = norm_b + b.e;
 
    a.sm = shl32_sat(a.sm, norm_a);
    b.sm = shl32_sat(b.sm, norm_b);
 
    c->sm = mult32(a.sm, b.sm); /* mult32 defined in ia_basic_ops40.h */
    c->e = a.e + b.e + norm_a + norm_b - 32; /* mult32 decreases the Q-format by 32 */
}
 
/* Division */
 
void div32_var_q(number_t a, number_t b, number_t *c)
{
    WORD32 qoutient_q_format;
 
    c->sm = div32(a.sm, b.sm, &qoutient_q_format); /* div32 defined in ia_basic_ops32.h */
    c->e = (a.e - b.e) + qoutient_q_format;
}
 
/* Addition */
 
void add32_var_q(number_t a, number_t b, number_t *c)
{
    WORD32 Q_a;
    WORD32 Q_b;
    WORD32 final_Q;
    WORD32 norm_a;
    WORD32 norm_b;
 
    norm_a = norm32(a.sm) - 1; /* norm32 defined in ia_basic_ops32.h */
    norm_b = norm32(b.sm) - 1; /* we normalise a & b only to 30t bit
                                        instead of to 31st bit
                                        */
 
    Q_a = norm_a + a.e;
    Q_b = norm_b + b.e;
 
    if(Q_b < Q_a)
    {
        b.sm = shl32_dir_sat(b.sm, norm_b);
        a.sm = shr32_dir_sat(a.sm, ((a.e - b.e) - norm_b));
        final_Q = Q_b;
    }
    else if(Q_a < Q_b)
    {
        a.sm = shl32_dir_sat(a.sm, norm_a);
        b.sm = shr32_dir_sat(b.sm, ((b.e - a.e) - norm_a));
        final_Q = Q_a;
    }
    else
    {
        a.sm = shl32_dir_sat(a.sm, norm_a);
        b.sm = shl32_dir_sat(b.sm, norm_b);
        final_Q = Q_a;
    }
 
    c->sm = add32(a.sm, b.sm); /* add32_shr defined in ia_basic_ops32.h */
    c->e = final_Q; /* because add32_shr does right shift
                                            by 1 before adding */
}
 
/* Subtraction */
 
void sub32_var_q(number_t a, number_t b, number_t *c)
{
    WORD32 Q_a;
    WORD32 Q_b;
    WORD32 final_Q;
    WORD32 norm_a;
    WORD32 norm_b;
 
    norm_a = norm32(a.sm) - 1; /* norm32 defined in ia_basic_ops32.h */
    norm_b = norm32(b.sm) - 1; /* we normalise a & b only to 30t bit
                                        instead of to 31st bit
                                        */
 
    Q_a = norm_a + a.e;
    Q_b = norm_b + b.e;
 
    if(Q_b < Q_a)
    {
        b.sm = shl32_dir_sat(b.sm, norm_b);
        a.sm = shr32_dir_sat(a.sm, ((a.e - b.e) - norm_b));
        final_Q = Q_b;
    }
    else if(Q_a < Q_b)
    {
        a.sm = shl32_dir_sat(a.sm, norm_a);
        b.sm = shr32_dir_sat(b.sm, ((b.e - a.e) - norm_a));
        final_Q = Q_a;
    }
    else
    {
        a.sm = shl32_dir_sat(a.sm, norm_a);
        b.sm = shl32_dir_sat(b.sm, norm_b);
        final_Q = Q_a;
    }
 
    c->sm = sub32(a.sm, b.sm); /* add32_shr defined in ia_basic_ops32.h */
    c->e = final_Q; /* because add32_shr does right shift
                                            by 1 before adding */
}
 
/* square root */
 
void sqrt32_var_q(number_t a, number_t *c)
{
    WORD32 q_temp;
    q_temp = a.e;
    c->sm = sqrtFix_interpolate(a.sm, &q_temp, gi4_sqrt_tab);
    /* c->sm = sqrtFix(a.sm, &q_temp, gi4_sqrt_tab); */
    c->e = q_temp;
}
 
void number_t_to_word32(number_t num_a, WORD32 *a)
{
    *a = shr32_dir_sat(num_a.sm, num_a.e);
}
 
/*
convert_float_to_fix(float a_f,
                     number_t *a)
{
            double log_a_f;
            log_a_f = log(ABS(a_f))/log(2);
 
            a->e = 30 - (WORD32)ceil(log_a_f);
            a->sm = (WORD32) (a_f * pow(2, a->e));
}
*/
 
#ifdef ITT_C6678
#pragma CODE_SECTION(number_t_to_word32, "itt_varq_l1pram");
#pragma CODE_SECTION(sqrt32_var_q, "itt_varq_l1pram");
#pragma CODE_SECTION(sub32_var_q, "itt_varq_l1pram");
#pragma CODE_SECTION(add32_var_q, "itt_varq_l1pram");
#pragma CODE_SECTION(div32_var_q, "itt_varq_l1pram");
#pragma CODE_SECTION(mult32_var_q, "itt_varq_l1pram");
#endif