1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
23 ------------------------------------------------------------------------------
30 ------------------------------------------------------------------------------
31 INPUT AND OUTPUT DEFINITIONS
34 Int32 x 32-bit integer input Q27
37 Int32 32-bit integer in Q25
40 ------------------------------------------------------------------------------
43 Implement the power base 2 for positive numbers lesser than 5.999999
44 ------------------------------------------------------------------------------
48 ------------------------------------------------------------------------------
51 ------------------------------------------------------------------------------
54 ------------------------------------------------------------------------------
58 /*----------------------------------------------------------------------------
60 ----------------------------------------------------------------------------*/
62 #include "fxp_mul32.h"
64 /*----------------------------------------------------------------------------
66 ; Define module specific macros here
67 ----------------------------------------------------------------------------*/
70 /*----------------------------------------------------------------------------
72 ; Include all pre-processor statements here. Include conditional
73 ; compile variables also.
74 ----------------------------------------------------------------------------*/
76 /*----------------------------------------------------------------------------
77 ; LOCAL FUNCTION DEFINITIONS
78 ; Function Prototype declaration
79 ----------------------------------------------------------------------------*/
80 #define POW_2_TABLE_LENGTH 6
81 #define POW_2_TABLE_LENGTH_m_2 (POW_2_TABLE_LENGTH - 2)
83 /*----------------------------------------------------------------------------
84 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
85 ; Variable declaration - defined here and used outside this module
86 ----------------------------------------------------------------------------*/
89 #define Q_fmt(x) (Int32)(x*((Int32)1<<R_SHIFT) + (x>=0?0.5F:-0.5F))
91 #define Q27fmt(x) (Int32)(x*((Int32)1<<27) + (x>=0?0.5F:-0.5F))
93 const Int32 pow2_table[6] =
95 Q_fmt(0.00224510927441F), Q_fmt(0.00777943379416F),
96 Q_fmt(0.05737929218747F), Q_fmt(0.23918017179889F),
97 Q_fmt(0.69345251849351F), Q_fmt(0.99996347120248F)
101 /*----------------------------------------------------------------------------
102 ; EXTERNAL FUNCTION REFERENCES
103 ; Declare functions defined elsewhere and referenced in this module
104 ----------------------------------------------------------------------------*/
106 /*----------------------------------------------------------------------------
107 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
108 ; Declare variables used in this module but defined elsewhere
109 ----------------------------------------------------------------------------*/
111 /*----------------------------------------------------------------------------
113 ----------------------------------------------------------------------------*/
120 Int32 pv_pow2(Int32 z)
122 const Int32 *pt_table = pow2_table;
123 Int32 multiplier = 0;
130 if (z > Q27fmt(1.0f))
132 v_q = z - (z & 0xF8000000);
133 shift_factor = z >> 27;
141 if (v_q < Q27fmt(0.5f))
144 multiplier = Q_fmt(0.70710678118655F);
149 y = fxp_mul32_Q29(*(pt_table++), v_q);
151 for (i = POW_2_TABLE_LENGTH_m_2; i != 0; i--)
154 y = fxp_mul32_Q29(y, v_q);
160 y = fxp_mul32_Q29(y, multiplier);
164 * returns number on Q25
166 return (y >> (4 - shift_factor));