1 /****************************************************************************** 2 * 3 * Copyright (C) 2018 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ***************************************************************************** 18 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore 19 */ 20 #ifndef VAR_Q_OPERATOR_H 21 #define VAR_Q_OPERATOR_H 22 23 typedef struct 24 { 25 WORD32 sm; /* MSB 1 bit sign & rest magnitude */ 26 WORD32 e; /* Q-format */ 27 } number_t; 28 29 void mult32_var_q(number_t a, number_t b, number_t *c); 30 31 void div32_var_q(number_t a, number_t b, number_t *c); 32 33 void add32_var_q(number_t a, number_t b, number_t *c); 34 35 void sub32_var_q(number_t a, number_t b, number_t *c); 36 37 void sqrt32_var_q(number_t a, number_t *c); 38 39 void number_t_to_word32(number_t num_a, WORD32 *a); 40 41 void convert_float_to_fix(float a_f, number_t *a); 42 43 void convert_fix_to_float(number_t a, float *a_f); 44 45 #define SET_VAR_Q(a, b, c) \ 46 { \ 47 (a).sm = (b); \ 48 (a).e = (c); \ 49 } 50 51 /*right shift greated than 32 bit for word32 variable is undefined*/ 52 #define convert_varq_to_fixq(varq, a, q_fact) \ 53 { \ 54 if((varq).e > q_fact) \ 55 { \ 56 if(((varq).e - q_fact) >= (WORD32)(sizeof(WORD32) * 8)) \ 57 { \ 58 *a = 0; \ 59 } \ 60 else \ 61 { \ 62 *a = (varq).sm >> ((varq).e - q_fact); \ 63 } \ 64 } \ 65 else \ 66 *a = (varq).sm << (q_fact - (varq).e); \ 67 } 68 69 #define SET_VARQ_FRM_FIXQ(fixq, var_q, q_fact) \ 70 { \ 71 (var_q).sm = fixq; \ 72 (var_q).e = q_fact; \ 73 } 74 #endif 75