summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/codecs/aacenc/basic_op
diff options
context:
space:
mode:
authorMans Rullgard <mans@mansr.com>2011-04-22 09:22:33 +0300
committerJames Dong <jdong@google.com>2011-05-21 09:39:22 -0700
commite2e838afcf03e603a41a0455846eaf9614537c16 (patch)
treeb6c2eedacc690a2c5514ac33dea7267cb38744bf /media/libstagefright/codecs/aacenc/basic_op
parent8294aac281863e584027c3f2c7d2007c4140bf24 (diff)
downloadframeworks_av-e2e838afcf03e603a41a0455846eaf9614537c16.zip
frameworks_av-e2e838afcf03e603a41a0455846eaf9614537c16.tar.gz
frameworks_av-e2e838afcf03e603a41a0455846eaf9614537c16.tar.bz2
Convert line breaks to Unix style
Change-Id: I6219725a9fbd72432bad71a176c14f26fabdbd5f
Diffstat (limited to 'media/libstagefright/codecs/aacenc/basic_op')
-rw-r--r--media/libstagefright/codecs/aacenc/basic_op/basic_op.h2308
-rw-r--r--media/libstagefright/codecs/aacenc/basic_op/basicop2.c3240
-rw-r--r--media/libstagefright/codecs/aacenc/basic_op/oper_32b.c358
-rw-r--r--media/libstagefright/codecs/aacenc/basic_op/oper_32b.h138
-rw-r--r--media/libstagefright/codecs/aacenc/basic_op/typedef.h42
-rw-r--r--media/libstagefright/codecs/aacenc/basic_op/typedefs.h262
6 files changed, 3174 insertions, 3174 deletions
diff --git a/media/libstagefright/codecs/aacenc/basic_op/basic_op.h b/media/libstagefright/codecs/aacenc/basic_op/basic_op.h
index 5457f33..8291684 100644
--- a/media/libstagefright/codecs/aacenc/basic_op/basic_op.h
+++ b/media/libstagefright/codecs/aacenc/basic_op/basic_op.h
@@ -1,27 +1,27 @@
-/*
- ** Copyright 2003-2010, VisualOn, Inc.
- **
- ** 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.
- */
-/*******************************************************************************
- File: basicop2.h
-
- Content: Constants , Globals and Basic arithmetic operators.
-
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** 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.
+ */
+/*******************************************************************************
+ File: basicop2.h
+
+ Content: Constants , Globals and Basic arithmetic operators.
+
*******************************************************************************/
#ifndef __BASIC_OP_H
-#define __BASIC_OP_H
+#define __BASIC_OP_H
#include "typedef.h"
@@ -30,1137 +30,1137 @@
#define MAX_16 (Word16)0x7fff
#define MIN_16 (Word16)0x8000
-#define ABS(a) ((a) >= 0) ? (a) : (-(a))
-
-/* Short abs, 1 */
-#define abs_s(x) ((Word16)(((x) != MIN_16) ? (((x) >= 0) ? (x) : (-(x))) : MAX_16))
-
-/* 16 bit var1 -> MSB, 2 */
-#define L_deposit_h(x) (((Word32)(x)) << 16)
-
-
-/* 16 bit var1 -> LSB, 2 */
-#define L_deposit_l(x) ((Word32)(x))
-
-
-/* Long abs, 3 */
-#define L_abs(x) (((x) != MIN_32) ? (((x) >= 0) ? (x) : (-(x))) : MAX_32)
-
-
-/* Short negate, 1 */
-#define negate(var1) ((Word16)(((var1) == MIN_16) ? MAX_16 : (-(var1))))
-
-
-/* Long negate, 2 */
-#define L_negate(L_var1) (((L_var1) == (MIN_32)) ? (MAX_32) : (-(L_var1)))
-
-
-#define MULHIGH(A,B) (int)(((Word64)(A)*(Word64)(B)) >> 32)
-#define fixmul(a, b) (int)((((Word64)(a)*(Word64)(b)) >> 32) << 1)
-
-
-#if (SATRUATE_IS_INLINE)
-__inline Word16 saturate(Word32 L_var1);
-#else
-Word16 saturate(Word32 L_var1);
-#endif
-
-/* Short shift left, 1 */
-#if (SHL_IS_INLINE)
-__inline Word16 shl (Word16 var1, Word16 var2);
-#else
-Word16 shl (Word16 var1, Word16 var2);
-#endif
-
-/* Short shift right, 1 */
-#if (SHR_IS_INLINE)
-__inline Word16 shr (Word16 var1, Word16 var2);
-#else
-Word16 shr (Word16 var1, Word16 var2);
-#endif
-
-#if (L_MULT_IS_INLINE)
-__inline Word32 L_mult(Word16 var1, Word16 var2);
-#else
-Word32 L_mult(Word16 var1, Word16 var2);
-#endif
-
-/* Msu, 1 */
-#if (L_MSU_IS_INLINE)
-__inline Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2);
-#else
-Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2);
-#endif
-
-/* Long sub, 2 */
-#if (L_SUB_IS_INLINE)
-__inline Word32 L_sub(Word32 L_var1, Word32 L_var2);
-#else
-Word32 L_sub(Word32 L_var1, Word32 L_var2);
-#endif
-
-/* Long shift left, 2 */
-#if (L_SHL_IS_INLINE)
-__inline Word32 L_shl (Word32 L_var1, Word16 var2);
-#else
-Word32 L_shl (Word32 L_var1, Word16 var2);
-#endif
-
-/* Long shift right, 2*/
-#if (L_SHR_IS_INLINE)
-__inline Word32 L_shr (Word32 L_var1, Word16 var2);
-#else
-Word32 L_shr (Word32 L_var1, Word16 var2);
-#endif
-
-/* Short add, 1 */
-#if (ADD_IS_INLINE)
-__inline Word16 add (Word16 var1, Word16 var2);
-#else
-Word16 add (Word16 var1, Word16 var2);
-#endif
-
-/* Short sub, 1 */
-#if (SUB_IS_INLINE)
-__inline Word16 sub(Word16 var1, Word16 var2);
-#else
-Word16 sub(Word16 var1, Word16 var2);
-#endif
-
-/* Short division, 18 */
-#if (DIV_S_IS_INLINE)
-__inline Word16 div_s (Word16 var1, Word16 var2);
-#else
-Word16 div_s (Word16 var1, Word16 var2);
-#endif
-
-/* Short mult, 1 */
-#if (MULT_IS_INLINE)
-__inline Word16 mult (Word16 var1, Word16 var2);
-#else
-Word16 mult (Word16 var1, Word16 var2);
-#endif
-
-/* Short norm, 15 */
-#if (NORM_S_IS_INLINE)
-__inline Word16 norm_s (Word16 var1);
-#else
-Word16 norm_s (Word16 var1);
-#endif
-
-/* Long norm, 30 */
-#if (NORM_L_IS_INLINE)
-__inline Word16 norm_l (Word32 L_var1);
-#else
-Word16 norm_l (Word32 L_var1);
-#endif
-
-/* Round, 1 */
-#if (ROUND_IS_INLINE)
-__inline Word16 round16(Word32 L_var1);
-#else
-Word16 round16(Word32 L_var1);
-#endif
-
-/* Mac, 1 */
-#if (L_MAC_IS_INLINE)
-__inline Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2);
-#else
-Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2);
-#endif
-
-#if (L_ADD_IS_INLINE)
-__inline Word32 L_add (Word32 L_var1, Word32 L_var2);
-#else
-Word32 L_add (Word32 L_var1, Word32 L_var2);
-#endif
-
-/* Extract high, 1 */
-#if (EXTRACT_H_IS_INLINE)
-__inline Word16 extract_h (Word32 L_var1);
-#else
-Word16 extract_h (Word32 L_var1);
-#endif
-
-/* Extract low, 1 */
-#if (EXTRACT_L_IS_INLINE)
-__inline Word16 extract_l(Word32 L_var1);
-#else
-Word16 extract_l(Word32 L_var1);
-#endif
-
-/* Mult with round, 2 */
-#if (MULT_R_IS_INLINE)
-__inline Word16 mult_r(Word16 var1, Word16 var2);
-#else
-Word16 mult_r(Word16 var1, Word16 var2);
-#endif
-
-/* Shift right with round, 2 */
-#if (SHR_R_IS_INLINE)
-__inline Word16 shr_r (Word16 var1, Word16 var2);
-#else
-Word16 shr_r (Word16 var1, Word16 var2);
-#endif
-
-/* Mac with rounding,2 */
-#if (MAC_R_IS_INLINE)
-__inline Word16 mac_r (Word32 L_var3, Word16 var1, Word16 var2);
-#else
-Word16 mac_r (Word32 L_var3, Word16 var1, Word16 var2);
-#endif
-
-/* Msu with rounding,2 */
-#if (MSU_R_IS_INLINE)
-__inline Word16 msu_r (Word32 L_var3, Word16 var1, Word16 var2);
-#else
-Word16 msu_r (Word32 L_var3, Word16 var1, Word16 var2);
-#endif
-
-/* Long shift right with round, 3 */
-#if (L_SHR_R_IS_INLINE)
-__inline Word32 L_shr_r (Word32 L_var1, Word16 var2);
-#else
-Word32 L_shr_r (Word32 L_var1, Word16 var2);
-#endif
-
-#if ARMV4_INASM
-__inline Word32 ASM_L_shr(Word32 L_var1, Word16 var2)
-{
- Word32 result;
- asm volatile(
- "MOV %[result], %[L_var1], ASR %[var2] \n"
- :[result]"=r"(result)
- :[L_var1]"r"(L_var1), [var2]"r"(var2)
- );
- return result;
-}
-
-__inline Word32 ASM_L_shl(Word32 L_var1, Word16 var2)
-{
- Word32 result;
- asm volatile(
- "MOV r2, %[L_var1] \n"
- "MOV r3, #0x7fffffff\n"
- "MOV %[result], %[L_var1], ASL %[var2] \n"
- "TEQ r2, %[result], ASR %[var2]\n"
- "EORNE %[result],r3,r2,ASR#31\n"
- :[result]"+r"(result)
- :[L_var1]"r"(L_var1), [var2]"r"(var2)
- :"r2", "r3"
- );
- return result;
-}
-
-__inline Word32 ASM_shr(Word32 L_var1, Word16 var2)
-{
- Word32 result;
- asm volatile(
- "CMP %[var2], #15\n"
- "MOVGE %[var2], #15\n"
- "MOV %[result], %[L_var1], ASR %[var2]\n"
- :[result]"=r"(result)
- :[L_var1]"r"(L_var1), [var2]"r"(var2)
- );
- return result;
-}
-
-__inline Word32 ASM_shl(Word32 L_var1, Word16 var2)
-{
- Word32 result;
- asm volatile(
- "CMP %[var2], #16\n"
- "MOVGE %[var2], #16\n"
- "MOV %[result], %[L_var1], ASL %[var2]\n"
- "MOV r3, #1\n"
- "MOV r2, %[result], ASR #15\n"
- "RSB r3,r3,r3,LSL #15 \n"
- "TEQ r2, %[result], ASR #31 \n"
- "EORNE %[result], r3, %[result],ASR #31"
- :[result]"+r"(result)
- :[L_var1]"r"(L_var1), [var2]"r"(var2)
- :"r2", "r3"
- );
- return result;
-}
-#endif
-
-/*___________________________________________________________________________
- | |
- | definitions for inline basic arithmetic operators |
- |___________________________________________________________________________|
-*/
-#if (SATRUATE_IS_INLINE)
-__inline Word16 saturate(Word32 L_var1)
-{
-#if ARMV5TE_SAT
- Word16 result;
- asm volatile (
- "MOV %[result], %[L_var1]\n"
- "MOV r3, #1\n"
- "MOV r2,%[L_var1],ASR#15\n"
- "RSB r3, r3, r3, LSL #15\n"
- "TEQ r2,%[L_var1],ASR#31\n"
- "EORNE %[result],r3,%[L_var1],ASR#31\n"
- :[result]"+r"(result)
- :[L_var1]"r"(L_var1)
- :"r2", "r3"
- );
-
- return result;
-#else
- Word16 var_out;
-
- //var_out = (L_var1 > (Word32)0X00007fffL) ? (MAX_16) : ((L_var1 < (Word32)0xffff8000L) ? (MIN_16) : ((Word16)L_var1));
-
- if (L_var1 > 0X00007fffL)
- {
- var_out = MAX_16;
- }
- else if (L_var1 < (Word32) 0xffff8000L)
- {
- var_out = MIN_16;
- }
- else
- {
- var_out = extract_l(L_var1);
- }
-
- return (var_out);
-#endif
-}
-#endif
-
-/* Short shift left, 1 */
-#if (SHL_IS_INLINE)
-__inline Word16 shl (Word16 var1, Word16 var2)
-{
-#if ARMV5TE_SHL
- if(var2>=0)
- {
- return ASM_shl( var1, var2);
- }
- else
- {
- return ASM_shr( var1, -var2);
- }
-#else
- Word16 var_out;
- Word32 result;
-
- if (var2 < 0)
- {
- var_out = shr (var1, (Word16)-var2);
- }
- else
- {
- result = (Word32) var1 *((Word32) 1 << var2);
-
- if ((var2 > 15 && var1 != 0) || (result != (Word32) ((Word16) result)))
- {
- var_out = (Word16)((var1 > 0) ? MAX_16 : MIN_16);
- }
- else
- {
- var_out = extract_l(result);
- }
- }
- return (var_out);
-#endif
-}
-#endif
-
-/* Short shift right, 1 */
-#if (SHR_IS_INLINE)
-__inline Word16 shr (Word16 var1, Word16 var2)
-{
-#if ARMV5TE_SHR
- if(var2>=0)
- {
- return ASM_shr( var1, var2);
- }
- else
- {
- return ASM_shl( var1, -var2);
- }
-#else
- Word16 var_out;
-
- if (var2 < 0)
- {
- var_out = shl (var1, (Word16)-var2);
- }
- else
- {
- if (var2 >= 15)
- {
- var_out = (Word16)((var1 < 0) ? -1 : 0);
- }
- else
- {
- if (var1 < 0)
- {
- var_out = (Word16)(~((~var1) >> var2));
- }
- else
- {
- var_out = (Word16)(var1 >> var2);
- }
- }
- }
-
- return (var_out);
-#endif
-}
-#endif
-
-
-#if (L_MULT_IS_INLINE)
-__inline Word32 L_mult(Word16 var1, Word16 var2)
-{
-#if ARMV5TE_L_MULT
- Word32 result;
- asm volatile(
- "SMULBB %[result], %[var1], %[var2] \n"
- "QADD %[result], %[result], %[result] \n"
- :[result]"+r"(result)
- :[var1]"r"(var1), [var2]"r"(var2)
- );
- return result;
-#else
- Word32 L_var_out;
-
- L_var_out = (Word32) var1 *(Word32) var2;
-
- if (L_var_out != (Word32) 0x40000000L)
- {
- L_var_out <<= 1;
- }
- else
- {
- L_var_out = MAX_32;
- }
- return (L_var_out);
-#endif
-}
-#endif
-
-#if (L_MSU_IS_INLINE)
-__inline Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2)
-{
-#if ARMV5TE_L_MSU
- Word32 result;
- asm volatile(
- "SMULBB %[result], %[var1], %[var2] \n"
- "QADD %[result], %[result], %[result] \n"
- "QSUB %[result], %[L_var3], %[result]\n"
- :[result]"+r"(result)
- :[L_var3]"r"(L_var3), [var1]"r"(var1), [var2]"r"(var2)
- );
- return result;
-#else
- Word32 L_var_out;
- Word32 L_product;
-
- L_product = L_mult(var1, var2);
- L_var_out = L_sub(L_var3, L_product);
- return (L_var_out);
-#endif
-}
-#endif
-
-#if (L_SUB_IS_INLINE)
-__inline Word32 L_sub(Word32 L_var1, Word32 L_var2)
-{
-#if ARMV5TE_L_SUB
- Word32 result;
- asm volatile(
- "QSUB %[result], %[L_var1], %[L_var2]\n"
- :[result]"+r"(result)
- :[L_var1]"r"(L_var1), [L_var2]"r"(L_var2)
- );
- return result;
-#else
- Word32 L_var_out;
-
- L_var_out = L_var1 - L_var2;
-
- if (((L_var1 ^ L_var2) & MIN_32) != 0)
- {
- if ((L_var_out ^ L_var1) & MIN_32)
- {
- L_var_out = (L_var1 < 0L) ? MIN_32 : MAX_32;
- }
- }
-
- return (L_var_out);
-#endif
-}
-#endif
-
-#if (L_SHL_IS_INLINE)
-__inline Word32 L_shl(Word32 L_var1, Word16 var2)
-{
-#if ARMV5TE_L_SHL
- if(var2>=0)
- {
- return ASM_L_shl( L_var1, var2);
- }
- else
- {
- return ASM_L_shr( L_var1, -var2);
- }
-#else
- Word32 L_var_out = 0L;
-
- if (var2 <= 0)
- {
- L_var1 = L_shr(L_var1, (Word16)-var2);
- }
- else
- {
- for (; var2 > 0; var2--)
- {
- if (L_var1 > (Word32) 0X3fffffffL)
- {
- return MAX_32;
- }
- else
- {
- if (L_var1 < (Word32) 0xc0000000L)
- {
- return MIN_32;
- }
- }
- L_var1 <<= 1;
- L_var_out = L_var1;
- }
- }
- return (L_var1);
-#endif
-}
-#endif
-
-#if (L_SHR_IS_INLINE)
-__inline Word32 L_shr (Word32 L_var1, Word16 var2)
-{
-#if ARMV5TE_L_SHR
- if(var2>=0)
- {
- return ASM_L_shr( L_var1, var2);
- }
- else
- {
- return ASM_L_shl( L_var1, -var2);
- }
-#else
- Word32 L_var_out;
-
- if (var2 < 0)
- {
- L_var_out = L_shl (L_var1, (Word16)-var2);
- }
- else
- {
- if (var2 >= 31)
- {
- L_var_out = (L_var1 < 0L) ? -1 : 0;
- }
- else
- {
- if (L_var1 < 0)
- {
- L_var_out = ~((~L_var1) >> var2);
- }
- else
- {
- L_var_out = L_var1 >> var2;
- }
- }
- }
- return (L_var_out);
-#endif
-}
-#endif
-
-/* Short add, 1 */
-#if (ADD_IS_INLINE)
-__inline Word16 add (Word16 var1, Word16 var2)
-{
-#if ARMV5TE_ADD
- Word32 result;
- asm volatile(
- "ADD %[result], %[var1], %[var2] \n"
- "MOV r3, #0x1\n"
- "MOV r2, %[result], ASR #15\n"
- "RSB r3, r3, r3, LSL, #15\n"
- "TEQ r2, %[result], ASR #31\n"
- "EORNE %[result], r3, %[result], ASR #31"
- :[result]"+r"(result)
- :[var1]"r"(var1), [var2]"r"(var2)
- :"r2", "r3"
- );
- return result;
-#else
- Word16 var_out;
- Word32 L_sum;
-
- L_sum = (Word32) var1 + var2;
- var_out = saturate(L_sum);
-
- return (var_out);
-#endif
-}
-#endif
-
-/* Short sub, 1 */
-#if (SUB_IS_INLINE)
-__inline Word16 sub(Word16 var1, Word16 var2)
-{
-#if ARMV5TE_SUB
- Word32 result;
- asm volatile(
- "MOV r3, #1\n"
- "SUB %[result], %[var1], %[var2] \n"
- "RSB r3,r3,r3,LSL#15\n"
- "MOV r2, %[var1], ASR #15 \n"
- "TEQ r2, %[var1], ASR #31 \n"
- "EORNE %[result], r3, %[result], ASR #31 \n"
- :[result]"+r"(result)
- :[var1]"r"(var1), [var2]"r"(var2)
- :"r2", "r3"
- );
- return result;
-#else
- Word16 var_out;
- Word32 L_diff;
-
- L_diff = (Word32) var1 - var2;
- var_out = saturate(L_diff);
-
- return (var_out);
-#endif
-}
-#endif
-
-/* Short division, 18 */
-#if (DIV_S_IS_INLINE)
-__inline Word16 div_s (Word16 var1, Word16 var2)
-{
- Word16 var_out = 0;
- Word16 iteration;
- Word32 L_num;
- Word32 L_denom;
-
- var_out = MAX_16;
- if (var1!= var2)//var1!= var2
- {
- var_out = 0;
- L_num = (Word32) var1;
-
- L_denom = (Word32) var2;
-
- //return (L_num<<15)/var2;
-
- for (iteration = 0; iteration < 15; iteration++)
- {
- var_out <<= 1;
- L_num <<= 1;
-
- if (L_num >= L_denom)
- {
- L_num -= L_denom;
- var_out++;
- }
- }
- }
- return (var_out);
-}
-#endif
-
-/* Short mult, 1 */
-#if (MULT_IS_INLINE)
-__inline Word16 mult (Word16 var1, Word16 var2)
-{
-#if ARMV5TE_MULT
- Word32 result;
- asm volatile(
- "SMULBB r2, %[var1], %[var2] \n"
- "MOV r3, #1\n"
- "MOV %[result], r2, ASR #15\n"
- "RSB r3, r3, r3, LSL #15\n"
- "MOV r2, %[result], ASR #15\n"
- "TEQ r2, %[result], ASR #31\n"
- "EORNE %[result], r3, %[result], ASR #31 \n"
- :[result]"+r"(result)
- :[var1]"r"(var1), [var2]"r"(var2)
- :"r2", "r3"
- );
- return result;
-#else
- Word16 var_out;
- Word32 L_product;
-
- L_product = (Word32) var1 *(Word32) var2;
- L_product = (L_product & (Word32) 0xffff8000L) >> 15;
- if (L_product & (Word32) 0x00010000L)
- L_product = L_product | (Word32) 0xffff0000L;
- var_out = saturate(L_product);
-
- return (var_out);
-#endif
-}
-#endif
-
-
-/* Short norm, 15 */
-#if (NORM_S_IS_INLINE)
-__inline Word16 norm_s (Word16 var1)
-{
-#if ARMV5TE_NORM_S
- Word16 result;
- asm volatile(
- "MOV r2,%[var1] \n"
- "CMP r2, #0\n"
- "RSBLT %[var1], %[var1], #0 \n"
- "CLZNE %[result], %[var1]\n"
- "SUBNE %[result], %[result], #17\n"
- "MOVEQ %[result], #0\n"
- "CMP r2, #-1\n"
- "MOVEQ %[result], #15\n"
- :[result]"+r"(result)
- :[var1]"r"(var1)
- :"r2"
- );
- return result;
-#else
- Word16 var_out;
-
- if (var1 == 0)
- {
- var_out = 0;
- }
- else
- {
- if (var1 == -1)
- {
- var_out = 15;
- }
- else
- {
- if (var1 < 0)
- {
- var1 = (Word16)~var1;
- }
- for (var_out = 0; var1 < 0x4000; var_out++)
- {
- var1 <<= 1;
- }
- }
- }
- return (var_out);
-#endif
-}
-#endif
-
-/* Long norm, 30 */
-#if (NORM_L_IS_INLINE)
-__inline Word16 norm_l (Word32 L_var1)
-{
-#if ARMV5TE_NORM_L
- Word16 result;
- asm volatile(
- "CMP %[L_var1], #0\n"
- "CLZNE %[result], %[L_var1]\n"
- "SUBNE %[result], %[result], #1\n"
- "MOVEQ %[result], #0\n"
- :[result]"+r"(result)
- :[L_var1]"r"(L_var1)
- );
- return result;
-#else
- //Word16 var_out;
-
- //if (L_var1 == 0)
- //{
- // var_out = 0;
- //}
- //else
- //{
- // if (L_var1 == (Word32) 0xffffffffL)
- // {
- // var_out = 31;
- // }
- // else
- // {
- // if (L_var1 < 0)
- // {
- // L_var1 = ~L_var1;
- // }
- // for (var_out = 0; L_var1 < (Word32) 0x40000000L; var_out++)
- // {
- // L_var1 <<= 1;
- // }
- // }
- //}
- //return (var_out);
- Word16 a16;
- Word16 r = 0 ;
-
-
- if ( L_var1 < 0 ) {
- L_var1 = ~L_var1;
- }
-
- if (0 == (L_var1 & 0x7fff8000)) {
- a16 = extract_l(L_var1);
- r += 16;
-
- if (0 == (a16 & 0x7f80)) {
- r += 8;
-
- if (0 == (a16 & 0x0078)) {
- r += 4;
-
- if (0 == (a16 & 0x0006)) {
- r += 2;
-
- if (0 == (a16 & 0x0001)) {
- r += 1;
- }
- }
- else {
-
- if (0 == (a16 & 0x0004)) {
- r += 1;
- }
- }
- }
- else {
-
- if (0 == (a16 & 0x0060)) {
- r += 2;
-
- if (0 == (a16 & 0x0010)) {
- r += 1;
- }
- }
- else {
-
- if (0 == (a16 & 0x0040)) {
- r += 1;
- }
- }
- }
- }
- else {
-
- if (0 == (a16 & 0x7800)) {
- r += 4;
-
- if (0 == (a16 & 0x0600)) {
- r += 2;
-
- if (0 == (a16 & 0x0100)) {
- r += 1;
- }
- }
- else {
-
- if (0 == (a16 & 0x0400)) {
- r += 1;
- }
- }
- }
- else {
-
- if (0 == (a16 & 0x6000)) {
- r += 2;
-
- if (0 == (a16 & 0x1000)) {
- r += 1;
- }
- }
- else {
-
- if (0 == (a16 & 0x4000)) {
- r += 1;
- }
- }
- }
- }
- }
- else {
- a16 = extract_h(L_var1);
-
- if (0 == (a16 & 0x7f80)) {
- r += 8;
-
- if (0 == (a16 & 0x0078)) {
- r += 4 ;
-
- if (0 == (a16 & 0x0006)) {
- r += 2;
-
- if (0 == (a16 & 0x0001)) {
- r += 1;
- }
- }
- else {
-
- if (0 == (a16 & 0x0004)) {
- r += 1;
- }
- }
- }
- else {
-
- if (0 == (a16 & 0x0060)) {
- r += 2;
-
- if (0 == (a16 & 0x0010)) {
- r += 1;
- }
- }
- else {
-
- if (0 == (a16 & 0x0040)) {
- r += 1;
- }
- }
- }
- }
- else {
-
- if (0 == (a16 & 0x7800)) {
- r += 4;
-
- if (0 == (a16 & 0x0600)) {
- r += 2;
-
- if (0 == (a16 & 0x0100)) {
- r += 1;
- }
- }
- else {
-
- if (0 == (a16 & 0x0400)) {
- r += 1;
- }
- }
- }
- else {
-
- if (0 == (a16 & 0x6000)) {
- r += 2;
-
- if (0 == (a16 & 0x1000)) {
- r += 1;
- }
- }
- else {
-
- if (0 == (a16 & 0x4000)) {
- return 1;
- }
- }
- }
- }
- }
-
- return r ;
-#endif
-}
-#endif
-
-/* Round, 1 */
-#if (ROUND_IS_INLINE)
-__inline Word16 round16(Word32 L_var1)
-{
-#if ARMV5TE_ROUND
- Word16 result;
- asm volatile(
- "MOV r1,#0x00008000\n"
- "QADD %[result], %[L_var1], r1\n"
- "MOV %[result], %[result], ASR #16 \n"
- :[result]"+r"(result)
- :[L_var1]"r"(L_var1)
- :"r1"
- );
- return result;
-#else
- Word16 var_out;
- Word32 L_rounded;
-
- L_rounded = L_add (L_var1, (Word32) 0x00008000L);
- var_out = extract_h (L_rounded);
- return (var_out);
-#endif
-}
-#endif
-
-/* Mac, 1 */
-#if (L_MAC_IS_INLINE)
-__inline Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2)
-{
-#if ARMV5TE_L_MAC
- Word32 result;
- asm volatile(
- "SMULBB %[result], %[var1], %[var2]\n"
- "QADD %[result], %[result], %[result]\n"
- "QADD %[result], %[result], %[L_var3]\n"
- :[result]"+r"(result)
- : [L_var3]"r"(L_var3), [var1]"r"(var1), [var2]"r"(var2)
- );
- return result;
-#else
- Word32 L_var_out;
- Word32 L_product;
-
- L_product = L_mult(var1, var2);
- L_var_out = L_add (L_var3, L_product);
- return (L_var_out);
-#endif
-}
-#endif
-
-#if (L_ADD_IS_INLINE)
-__inline Word32 L_add (Word32 L_var1, Word32 L_var2)
-{
-#if ARMV5TE_L_ADD
- Word32 result;
- asm volatile(
- "QADD %[result], %[L_var1], %[L_var2]\n"
- :[result]"+r"(result)
- :[L_var1]"r"(L_var1), [L_var2]"r"(L_var2)
- );
- return result;
-#else
- Word32 L_var_out;
-
- L_var_out = L_var1 + L_var2;
- if (((L_var1 ^ L_var2) & MIN_32) == 0)
- {
- if ((L_var_out ^ L_var1) & MIN_32)
- {
- L_var_out = (L_var1 < 0) ? MIN_32 : MAX_32;
- }
- }
- return (L_var_out);
-#endif
-}
-#endif
-
-
-
-#if (MULT_R_IS_INLINE)
-__inline Word16 mult_r (Word16 var1, Word16 var2)
-{
- Word16 var_out;
- Word32 L_product_arr;
-
- L_product_arr = (Word32)var1 *(Word32)var2; /* product */
- L_product_arr += (Word32)0x00004000L; /* round */
- L_product_arr >>= 15; /* shift */
-
- var_out = saturate(L_product_arr);
-
- return (var_out);
-}
-#endif
-
-#if (SHR_R_IS_INLINE)
-__inline Word16 shr_r (Word16 var1, Word16 var2)
-{
- Word16 var_out;
-
- if (var2 > 15)
- {
- var_out = 0;
- }
- else
- {
- var_out = shr(var1, var2);
-
- if (var2 > 0)
- {
- if ((var1 & ((Word16) 1 << (var2 - 1))) != 0)
- {
- var_out++;
- }
- }
- }
-
- return (var_out);
-}
-#endif
-
-#if (MAC_R_IS_INLINE)
-__inline Word16 mac_r (Word32 L_var3, Word16 var1, Word16 var2)
-{
- Word16 var_out;
-
- L_var3 = L_mac (L_var3, var1, var2);
- var_out = (Word16)((L_var3 + 0x8000L) >> 16);
-
- return (var_out);
-}
-#endif
-
-#if (MSU_R_IS_INLINE)
-__inline Word16 msu_r (Word32 L_var3, Word16 var1, Word16 var2)
-{
- Word16 var_out;
-
- L_var3 = L_msu (L_var3, var1, var2);
- var_out = (Word16)((L_var3 + 0x8000L) >> 16);
-
- return (var_out);
-}
-#endif
-
-#if (L_SHR_R_IS_INLINE)
-__inline Word32 L_shr_r (Word32 L_var1, Word16 var2)
-{
- Word32 L_var_out;
-
- if (var2 > 31)
- {
- L_var_out = 0;
- }
- else
- {
- L_var_out = L_shr(L_var1, var2);
-
- if (var2 > 0)
- {
- if ((L_var1 & ((Word32) 1 << (var2 - 1))) != 0)
- {
- L_var_out++;
- }
- }
- }
-
- return (L_var_out);
-}
-#endif
-
-#if (EXTRACT_H_IS_INLINE)
-__inline Word16 extract_h (Word32 L_var1)
-{
- Word16 var_out;
-
- var_out = (Word16) (L_var1 >> 16);
-
- return (var_out);
-}
-#endif
-
-#if (EXTRACT_L_IS_INLINE)
-__inline Word16 extract_l(Word32 L_var1)
-{
- return (Word16) L_var1;
-}
-#endif
-
+#define ABS(a) ((a) >= 0) ? (a) : (-(a))
+
+/* Short abs, 1 */
+#define abs_s(x) ((Word16)(((x) != MIN_16) ? (((x) >= 0) ? (x) : (-(x))) : MAX_16))
+
+/* 16 bit var1 -> MSB, 2 */
+#define L_deposit_h(x) (((Word32)(x)) << 16)
+
+
+/* 16 bit var1 -> LSB, 2 */
+#define L_deposit_l(x) ((Word32)(x))
+
+
+/* Long abs, 3 */
+#define L_abs(x) (((x) != MIN_32) ? (((x) >= 0) ? (x) : (-(x))) : MAX_32)
+
+
+/* Short negate, 1 */
+#define negate(var1) ((Word16)(((var1) == MIN_16) ? MAX_16 : (-(var1))))
+
+
+/* Long negate, 2 */
+#define L_negate(L_var1) (((L_var1) == (MIN_32)) ? (MAX_32) : (-(L_var1)))
+
+
+#define MULHIGH(A,B) (int)(((Word64)(A)*(Word64)(B)) >> 32)
+#define fixmul(a, b) (int)((((Word64)(a)*(Word64)(b)) >> 32) << 1)
+
+
+#if (SATRUATE_IS_INLINE)
+__inline Word16 saturate(Word32 L_var1);
+#else
+Word16 saturate(Word32 L_var1);
+#endif
+
+/* Short shift left, 1 */
+#if (SHL_IS_INLINE)
+__inline Word16 shl (Word16 var1, Word16 var2);
+#else
+Word16 shl (Word16 var1, Word16 var2);
+#endif
+
+/* Short shift right, 1 */
+#if (SHR_IS_INLINE)
+__inline Word16 shr (Word16 var1, Word16 var2);
+#else
+Word16 shr (Word16 var1, Word16 var2);
+#endif
+
+#if (L_MULT_IS_INLINE)
+__inline Word32 L_mult(Word16 var1, Word16 var2);
+#else
+Word32 L_mult(Word16 var1, Word16 var2);
+#endif
+
+/* Msu, 1 */
+#if (L_MSU_IS_INLINE)
+__inline Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2);
+#else
+Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2);
+#endif
+
+/* Long sub, 2 */
+#if (L_SUB_IS_INLINE)
+__inline Word32 L_sub(Word32 L_var1, Word32 L_var2);
+#else
+Word32 L_sub(Word32 L_var1, Word32 L_var2);
+#endif
+
+/* Long shift left, 2 */
+#if (L_SHL_IS_INLINE)
+__inline Word32 L_shl (Word32 L_var1, Word16 var2);
+#else
+Word32 L_shl (Word32 L_var1, Word16 var2);
+#endif
+
+/* Long shift right, 2*/
+#if (L_SHR_IS_INLINE)
+__inline Word32 L_shr (Word32 L_var1, Word16 var2);
+#else
+Word32 L_shr (Word32 L_var1, Word16 var2);
+#endif
+
+/* Short add, 1 */
+#if (ADD_IS_INLINE)
+__inline Word16 add (Word16 var1, Word16 var2);
+#else
+Word16 add (Word16 var1, Word16 var2);
+#endif
+
+/* Short sub, 1 */
+#if (SUB_IS_INLINE)
+__inline Word16 sub(Word16 var1, Word16 var2);
+#else
+Word16 sub(Word16 var1, Word16 var2);
+#endif
+
+/* Short division, 18 */
+#if (DIV_S_IS_INLINE)
+__inline Word16 div_s (Word16 var1, Word16 var2);
+#else
+Word16 div_s (Word16 var1, Word16 var2);
+#endif
+
+/* Short mult, 1 */
+#if (MULT_IS_INLINE)
+__inline Word16 mult (Word16 var1, Word16 var2);
+#else
+Word16 mult (Word16 var1, Word16 var2);
+#endif
+
+/* Short norm, 15 */
+#if (NORM_S_IS_INLINE)
+__inline Word16 norm_s (Word16 var1);
+#else
+Word16 norm_s (Word16 var1);
+#endif
+
+/* Long norm, 30 */
+#if (NORM_L_IS_INLINE)
+__inline Word16 norm_l (Word32 L_var1);
+#else
+Word16 norm_l (Word32 L_var1);
+#endif
+
+/* Round, 1 */
+#if (ROUND_IS_INLINE)
+__inline Word16 round16(Word32 L_var1);
+#else
+Word16 round16(Word32 L_var1);
+#endif
+
+/* Mac, 1 */
+#if (L_MAC_IS_INLINE)
+__inline Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2);
+#else
+Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2);
+#endif
+
+#if (L_ADD_IS_INLINE)
+__inline Word32 L_add (Word32 L_var1, Word32 L_var2);
+#else
+Word32 L_add (Word32 L_var1, Word32 L_var2);
+#endif
+
+/* Extract high, 1 */
+#if (EXTRACT_H_IS_INLINE)
+__inline Word16 extract_h (Word32 L_var1);
+#else
+Word16 extract_h (Word32 L_var1);
+#endif
+
+/* Extract low, 1 */
+#if (EXTRACT_L_IS_INLINE)
+__inline Word16 extract_l(Word32 L_var1);
+#else
+Word16 extract_l(Word32 L_var1);
+#endif
+
+/* Mult with round, 2 */
+#if (MULT_R_IS_INLINE)
+__inline Word16 mult_r(Word16 var1, Word16 var2);
+#else
+Word16 mult_r(Word16 var1, Word16 var2);
+#endif
+
+/* Shift right with round, 2 */
+#if (SHR_R_IS_INLINE)
+__inline Word16 shr_r (Word16 var1, Word16 var2);
+#else
+Word16 shr_r (Word16 var1, Word16 var2);
+#endif
+
+/* Mac with rounding,2 */
+#if (MAC_R_IS_INLINE)
+__inline Word16 mac_r (Word32 L_var3, Word16 var1, Word16 var2);
+#else
+Word16 mac_r (Word32 L_var3, Word16 var1, Word16 var2);
+#endif
+
+/* Msu with rounding,2 */
+#if (MSU_R_IS_INLINE)
+__inline Word16 msu_r (Word32 L_var3, Word16 var1, Word16 var2);
+#else
+Word16 msu_r (Word32 L_var3, Word16 var1, Word16 var2);
+#endif
+
+/* Long shift right with round, 3 */
+#if (L_SHR_R_IS_INLINE)
+__inline Word32 L_shr_r (Word32 L_var1, Word16 var2);
+#else
+Word32 L_shr_r (Word32 L_var1, Word16 var2);
+#endif
+
+#if ARMV4_INASM
+__inline Word32 ASM_L_shr(Word32 L_var1, Word16 var2)
+{
+ Word32 result;
+ asm volatile(
+ "MOV %[result], %[L_var1], ASR %[var2] \n"
+ :[result]"=r"(result)
+ :[L_var1]"r"(L_var1), [var2]"r"(var2)
+ );
+ return result;
+}
+
+__inline Word32 ASM_L_shl(Word32 L_var1, Word16 var2)
+{
+ Word32 result;
+ asm volatile(
+ "MOV r2, %[L_var1] \n"
+ "MOV r3, #0x7fffffff\n"
+ "MOV %[result], %[L_var1], ASL %[var2] \n"
+ "TEQ r2, %[result], ASR %[var2]\n"
+ "EORNE %[result],r3,r2,ASR#31\n"
+ :[result]"+r"(result)
+ :[L_var1]"r"(L_var1), [var2]"r"(var2)
+ :"r2", "r3"
+ );
+ return result;
+}
+
+__inline Word32 ASM_shr(Word32 L_var1, Word16 var2)
+{
+ Word32 result;
+ asm volatile(
+ "CMP %[var2], #15\n"
+ "MOVGE %[var2], #15\n"
+ "MOV %[result], %[L_var1], ASR %[var2]\n"
+ :[result]"=r"(result)
+ :[L_var1]"r"(L_var1), [var2]"r"(var2)
+ );
+ return result;
+}
+
+__inline Word32 ASM_shl(Word32 L_var1, Word16 var2)
+{
+ Word32 result;
+ asm volatile(
+ "CMP %[var2], #16\n"
+ "MOVGE %[var2], #16\n"
+ "MOV %[result], %[L_var1], ASL %[var2]\n"
+ "MOV r3, #1\n"
+ "MOV r2, %[result], ASR #15\n"
+ "RSB r3,r3,r3,LSL #15 \n"
+ "TEQ r2, %[result], ASR #31 \n"
+ "EORNE %[result], r3, %[result],ASR #31"
+ :[result]"+r"(result)
+ :[L_var1]"r"(L_var1), [var2]"r"(var2)
+ :"r2", "r3"
+ );
+ return result;
+}
+#endif
+
+/*___________________________________________________________________________
+ | |
+ | definitions for inline basic arithmetic operators |
+ |___________________________________________________________________________|
+*/
+#if (SATRUATE_IS_INLINE)
+__inline Word16 saturate(Word32 L_var1)
+{
+#if ARMV5TE_SAT
+ Word16 result;
+ asm volatile (
+ "MOV %[result], %[L_var1]\n"
+ "MOV r3, #1\n"
+ "MOV r2,%[L_var1],ASR#15\n"
+ "RSB r3, r3, r3, LSL #15\n"
+ "TEQ r2,%[L_var1],ASR#31\n"
+ "EORNE %[result],r3,%[L_var1],ASR#31\n"
+ :[result]"+r"(result)
+ :[L_var1]"r"(L_var1)
+ :"r2", "r3"
+ );
+
+ return result;
+#else
+ Word16 var_out;
+
+ //var_out = (L_var1 > (Word32)0X00007fffL) ? (MAX_16) : ((L_var1 < (Word32)0xffff8000L) ? (MIN_16) : ((Word16)L_var1));
+
+ if (L_var1 > 0X00007fffL)
+ {
+ var_out = MAX_16;
+ }
+ else if (L_var1 < (Word32) 0xffff8000L)
+ {
+ var_out = MIN_16;
+ }
+ else
+ {
+ var_out = extract_l(L_var1);
+ }
+
+ return (var_out);
+#endif
+}
+#endif
+
+/* Short shift left, 1 */
+#if (SHL_IS_INLINE)
+__inline Word16 shl (Word16 var1, Word16 var2)
+{
+#if ARMV5TE_SHL
+ if(var2>=0)
+ {
+ return ASM_shl( var1, var2);
+ }
+ else
+ {
+ return ASM_shr( var1, -var2);
+ }
+#else
+ Word16 var_out;
+ Word32 result;
+
+ if (var2 < 0)
+ {
+ var_out = shr (var1, (Word16)-var2);
+ }
+ else
+ {
+ result = (Word32) var1 *((Word32) 1 << var2);
+
+ if ((var2 > 15 && var1 != 0) || (result != (Word32) ((Word16) result)))
+ {
+ var_out = (Word16)((var1 > 0) ? MAX_16 : MIN_16);
+ }
+ else
+ {
+ var_out = extract_l(result);
+ }
+ }
+ return (var_out);
+#endif
+}
+#endif
+
+/* Short shift right, 1 */
+#if (SHR_IS_INLINE)
+__inline Word16 shr (Word16 var1, Word16 var2)
+{
+#if ARMV5TE_SHR
+ if(var2>=0)
+ {
+ return ASM_shr( var1, var2);
+ }
+ else
+ {
+ return ASM_shl( var1, -var2);
+ }
+#else
+ Word16 var_out;
+
+ if (var2 < 0)
+ {
+ var_out = shl (var1, (Word16)-var2);
+ }
+ else
+ {
+ if (var2 >= 15)
+ {
+ var_out = (Word16)((var1 < 0) ? -1 : 0);
+ }
+ else
+ {
+ if (var1 < 0)
+ {
+ var_out = (Word16)(~((~var1) >> var2));
+ }
+ else
+ {
+ var_out = (Word16)(var1 >> var2);
+ }
+ }
+ }
+
+ return (var_out);
+#endif
+}
+#endif
+
+
+#if (L_MULT_IS_INLINE)
+__inline Word32 L_mult(Word16 var1, Word16 var2)
+{
+#if ARMV5TE_L_MULT
+ Word32 result;
+ asm volatile(
+ "SMULBB %[result], %[var1], %[var2] \n"
+ "QADD %[result], %[result], %[result] \n"
+ :[result]"+r"(result)
+ :[var1]"r"(var1), [var2]"r"(var2)
+ );
+ return result;
+#else
+ Word32 L_var_out;
+
+ L_var_out = (Word32) var1 *(Word32) var2;
+
+ if (L_var_out != (Word32) 0x40000000L)
+ {
+ L_var_out <<= 1;
+ }
+ else
+ {
+ L_var_out = MAX_32;
+ }
+ return (L_var_out);
+#endif
+}
+#endif
+
+#if (L_MSU_IS_INLINE)
+__inline Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2)
+{
+#if ARMV5TE_L_MSU
+ Word32 result;
+ asm volatile(
+ "SMULBB %[result], %[var1], %[var2] \n"
+ "QADD %[result], %[result], %[result] \n"
+ "QSUB %[result], %[L_var3], %[result]\n"
+ :[result]"+r"(result)
+ :[L_var3]"r"(L_var3), [var1]"r"(var1), [var2]"r"(var2)
+ );
+ return result;
+#else
+ Word32 L_var_out;
+ Word32 L_product;
+
+ L_product = L_mult(var1, var2);
+ L_var_out = L_sub(L_var3, L_product);
+ return (L_var_out);
+#endif
+}
+#endif
+
+#if (L_SUB_IS_INLINE)
+__inline Word32 L_sub(Word32 L_var1, Word32 L_var2)
+{
+#if ARMV5TE_L_SUB
+ Word32 result;
+ asm volatile(
+ "QSUB %[result], %[L_var1], %[L_var2]\n"
+ :[result]"+r"(result)
+ :[L_var1]"r"(L_var1), [L_var2]"r"(L_var2)
+ );
+ return result;
+#else
+ Word32 L_var_out;
+
+ L_var_out = L_var1 - L_var2;
+
+ if (((L_var1 ^ L_var2) & MIN_32) != 0)
+ {
+ if ((L_var_out ^ L_var1) & MIN_32)
+ {
+ L_var_out = (L_var1 < 0L) ? MIN_32 : MAX_32;
+ }
+ }
+
+ return (L_var_out);
+#endif
+}
+#endif
+
+#if (L_SHL_IS_INLINE)
+__inline Word32 L_shl(Word32 L_var1, Word16 var2)
+{
+#if ARMV5TE_L_SHL
+ if(var2>=0)
+ {
+ return ASM_L_shl( L_var1, var2);
+ }
+ else
+ {
+ return ASM_L_shr( L_var1, -var2);
+ }
+#else
+ Word32 L_var_out = 0L;
+
+ if (var2 <= 0)
+ {
+ L_var1 = L_shr(L_var1, (Word16)-var2);
+ }
+ else
+ {
+ for (; var2 > 0; var2--)
+ {
+ if (L_var1 > (Word32) 0X3fffffffL)
+ {
+ return MAX_32;
+ }
+ else
+ {
+ if (L_var1 < (Word32) 0xc0000000L)
+ {
+ return MIN_32;
+ }
+ }
+ L_var1 <<= 1;
+ L_var_out = L_var1;
+ }
+ }
+ return (L_var1);
+#endif
+}
+#endif
+
+#if (L_SHR_IS_INLINE)
+__inline Word32 L_shr (Word32 L_var1, Word16 var2)
+{
+#if ARMV5TE_L_SHR
+ if(var2>=0)
+ {
+ return ASM_L_shr( L_var1, var2);
+ }
+ else
+ {
+ return ASM_L_shl( L_var1, -var2);
+ }
+#else
+ Word32 L_var_out;
+
+ if (var2 < 0)
+ {
+ L_var_out = L_shl (L_var1, (Word16)-var2);
+ }
+ else
+ {
+ if (var2 >= 31)
+ {
+ L_var_out = (L_var1 < 0L) ? -1 : 0;
+ }
+ else
+ {
+ if (L_var1 < 0)
+ {
+ L_var_out = ~((~L_var1) >> var2);
+ }
+ else
+ {
+ L_var_out = L_var1 >> var2;
+ }
+ }
+ }
+ return (L_var_out);
+#endif
+}
+#endif
+
+/* Short add, 1 */
+#if (ADD_IS_INLINE)
+__inline Word16 add (Word16 var1, Word16 var2)
+{
+#if ARMV5TE_ADD
+ Word32 result;
+ asm volatile(
+ "ADD %[result], %[var1], %[var2] \n"
+ "MOV r3, #0x1\n"
+ "MOV r2, %[result], ASR #15\n"
+ "RSB r3, r3, r3, LSL, #15\n"
+ "TEQ r2, %[result], ASR #31\n"
+ "EORNE %[result], r3, %[result], ASR #31"
+ :[result]"+r"(result)
+ :[var1]"r"(var1), [var2]"r"(var2)
+ :"r2", "r3"
+ );
+ return result;
+#else
+ Word16 var_out;
+ Word32 L_sum;
+
+ L_sum = (Word32) var1 + var2;
+ var_out = saturate(L_sum);
+
+ return (var_out);
+#endif
+}
+#endif
+
+/* Short sub, 1 */
+#if (SUB_IS_INLINE)
+__inline Word16 sub(Word16 var1, Word16 var2)
+{
+#if ARMV5TE_SUB
+ Word32 result;
+ asm volatile(
+ "MOV r3, #1\n"
+ "SUB %[result], %[var1], %[var2] \n"
+ "RSB r3,r3,r3,LSL#15\n"
+ "MOV r2, %[var1], ASR #15 \n"
+ "TEQ r2, %[var1], ASR #31 \n"
+ "EORNE %[result], r3, %[result], ASR #31 \n"
+ :[result]"+r"(result)
+ :[var1]"r"(var1), [var2]"r"(var2)
+ :"r2", "r3"
+ );
+ return result;
+#else
+ Word16 var_out;
+ Word32 L_diff;
+
+ L_diff = (Word32) var1 - var2;
+ var_out = saturate(L_diff);
+
+ return (var_out);
+#endif
+}
+#endif
+
+/* Short division, 18 */
+#if (DIV_S_IS_INLINE)
+__inline Word16 div_s (Word16 var1, Word16 var2)
+{
+ Word16 var_out = 0;
+ Word16 iteration;
+ Word32 L_num;
+ Word32 L_denom;
+
+ var_out = MAX_16;
+ if (var1!= var2)//var1!= var2
+ {
+ var_out = 0;
+ L_num = (Word32) var1;
+
+ L_denom = (Word32) var2;
+
+ //return (L_num<<15)/var2;
+
+ for (iteration = 0; iteration < 15; iteration++)
+ {
+ var_out <<= 1;
+ L_num <<= 1;
+
+ if (L_num >= L_denom)
+ {
+ L_num -= L_denom;
+ var_out++;
+ }
+ }
+ }
+ return (var_out);
+}
+#endif
+
+/* Short mult, 1 */
+#if (MULT_IS_INLINE)
+__inline Word16 mult (Word16 var1, Word16 var2)
+{
+#if ARMV5TE_MULT
+ Word32 result;
+ asm volatile(
+ "SMULBB r2, %[var1], %[var2] \n"
+ "MOV r3, #1\n"
+ "MOV %[result], r2, ASR #15\n"
+ "RSB r3, r3, r3, LSL #15\n"
+ "MOV r2, %[result], ASR #15\n"
+ "TEQ r2, %[result], ASR #31\n"
+ "EORNE %[result], r3, %[result], ASR #31 \n"
+ :[result]"+r"(result)
+ :[var1]"r"(var1), [var2]"r"(var2)
+ :"r2", "r3"
+ );
+ return result;
+#else
+ Word16 var_out;
+ Word32 L_product;
+
+ L_product = (Word32) var1 *(Word32) var2;
+ L_product = (L_product & (Word32) 0xffff8000L) >> 15;
+ if (L_product & (Word32) 0x00010000L)
+ L_product = L_product | (Word32) 0xffff0000L;
+ var_out = saturate(L_product);
+
+ return (var_out);
+#endif
+}
+#endif
+
+
+/* Short norm, 15 */
+#if (NORM_S_IS_INLINE)
+__inline Word16 norm_s (Word16 var1)
+{
+#if ARMV5TE_NORM_S
+ Word16 result;
+ asm volatile(
+ "MOV r2,%[var1] \n"
+ "CMP r2, #0\n"
+ "RSBLT %[var1], %[var1], #0 \n"
+ "CLZNE %[result], %[var1]\n"
+ "SUBNE %[result], %[result], #17\n"
+ "MOVEQ %[result], #0\n"
+ "CMP r2, #-1\n"
+ "MOVEQ %[result], #15\n"
+ :[result]"+r"(result)
+ :[var1]"r"(var1)
+ :"r2"
+ );
+ return result;
+#else
+ Word16 var_out;
+
+ if (var1 == 0)
+ {
+ var_out = 0;
+ }
+ else
+ {
+ if (var1 == -1)
+ {
+ var_out = 15;
+ }
+ else
+ {
+ if (var1 < 0)
+ {
+ var1 = (Word16)~var1;
+ }
+ for (var_out = 0; var1 < 0x4000; var_out++)
+ {
+ var1 <<= 1;
+ }
+ }
+ }
+ return (var_out);
+#endif
+}
+#endif
+
+/* Long norm, 30 */
+#if (NORM_L_IS_INLINE)
+__inline Word16 norm_l (Word32 L_var1)
+{
+#if ARMV5TE_NORM_L
+ Word16 result;
+ asm volatile(
+ "CMP %[L_var1], #0\n"
+ "CLZNE %[result], %[L_var1]\n"
+ "SUBNE %[result], %[result], #1\n"
+ "MOVEQ %[result], #0\n"
+ :[result]"+r"(result)
+ :[L_var1]"r"(L_var1)
+ );
+ return result;
+#else
+ //Word16 var_out;
+
+ //if (L_var1 == 0)
+ //{
+ // var_out = 0;
+ //}
+ //else
+ //{
+ // if (L_var1 == (Word32) 0xffffffffL)
+ // {
+ // var_out = 31;
+ // }
+ // else
+ // {
+ // if (L_var1 < 0)
+ // {
+ // L_var1 = ~L_var1;
+ // }
+ // for (var_out = 0; L_var1 < (Word32) 0x40000000L; var_out++)
+ // {
+ // L_var1 <<= 1;
+ // }
+ // }
+ //}
+ //return (var_out);
+ Word16 a16;
+ Word16 r = 0 ;
+
+
+ if ( L_var1 < 0 ) {
+ L_var1 = ~L_var1;
+ }
+
+ if (0 == (L_var1 & 0x7fff8000)) {
+ a16 = extract_l(L_var1);
+ r += 16;
+
+ if (0 == (a16 & 0x7f80)) {
+ r += 8;
+
+ if (0 == (a16 & 0x0078)) {
+ r += 4;
+
+ if (0 == (a16 & 0x0006)) {
+ r += 2;
+
+ if (0 == (a16 & 0x0001)) {
+ r += 1;
+ }
+ }
+ else {
+
+ if (0 == (a16 & 0x0004)) {
+ r += 1;
+ }
+ }
+ }
+ else {
+
+ if (0 == (a16 & 0x0060)) {
+ r += 2;
+
+ if (0 == (a16 & 0x0010)) {
+ r += 1;
+ }
+ }
+ else {
+
+ if (0 == (a16 & 0x0040)) {
+ r += 1;
+ }
+ }
+ }
+ }
+ else {
+
+ if (0 == (a16 & 0x7800)) {
+ r += 4;
+
+ if (0 == (a16 & 0x0600)) {
+ r += 2;
+
+ if (0 == (a16 & 0x0100)) {
+ r += 1;
+ }
+ }
+ else {
+
+ if (0 == (a16 & 0x0400)) {
+ r += 1;
+ }
+ }
+ }
+ else {
+
+ if (0 == (a16 & 0x6000)) {
+ r += 2;
+
+ if (0 == (a16 & 0x1000)) {
+ r += 1;
+ }
+ }
+ else {
+
+ if (0 == (a16 & 0x4000)) {
+ r += 1;
+ }
+ }
+ }
+ }
+ }
+ else {
+ a16 = extract_h(L_var1);
+
+ if (0 == (a16 & 0x7f80)) {
+ r += 8;
+
+ if (0 == (a16 & 0x0078)) {
+ r += 4 ;
+
+ if (0 == (a16 & 0x0006)) {
+ r += 2;
+
+ if (0 == (a16 & 0x0001)) {
+ r += 1;
+ }
+ }
+ else {
+
+ if (0 == (a16 & 0x0004)) {
+ r += 1;
+ }
+ }
+ }
+ else {
+
+ if (0 == (a16 & 0x0060)) {
+ r += 2;
+
+ if (0 == (a16 & 0x0010)) {
+ r += 1;
+ }
+ }
+ else {
+
+ if (0 == (a16 & 0x0040)) {
+ r += 1;
+ }
+ }
+ }
+ }
+ else {
+
+ if (0 == (a16 & 0x7800)) {
+ r += 4;
+
+ if (0 == (a16 & 0x0600)) {
+ r += 2;
+
+ if (0 == (a16 & 0x0100)) {
+ r += 1;
+ }
+ }
+ else {
+
+ if (0 == (a16 & 0x0400)) {
+ r += 1;
+ }
+ }
+ }
+ else {
+
+ if (0 == (a16 & 0x6000)) {
+ r += 2;
+
+ if (0 == (a16 & 0x1000)) {
+ r += 1;
+ }
+ }
+ else {
+
+ if (0 == (a16 & 0x4000)) {
+ return 1;
+ }
+ }
+ }
+ }
+ }
+
+ return r ;
+#endif
+}
+#endif
+
+/* Round, 1 */
+#if (ROUND_IS_INLINE)
+__inline Word16 round16(Word32 L_var1)
+{
+#if ARMV5TE_ROUND
+ Word16 result;
+ asm volatile(
+ "MOV r1,#0x00008000\n"
+ "QADD %[result], %[L_var1], r1\n"
+ "MOV %[result], %[result], ASR #16 \n"
+ :[result]"+r"(result)
+ :[L_var1]"r"(L_var1)
+ :"r1"
+ );
+ return result;
+#else
+ Word16 var_out;
+ Word32 L_rounded;
+
+ L_rounded = L_add (L_var1, (Word32) 0x00008000L);
+ var_out = extract_h (L_rounded);
+ return (var_out);
+#endif
+}
+#endif
+
+/* Mac, 1 */
+#if (L_MAC_IS_INLINE)
+__inline Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2)
+{
+#if ARMV5TE_L_MAC
+ Word32 result;
+ asm volatile(
+ "SMULBB %[result], %[var1], %[var2]\n"
+ "QADD %[result], %[result], %[result]\n"
+ "QADD %[result], %[result], %[L_var3]\n"
+ :[result]"+r"(result)
+ : [L_var3]"r"(L_var3), [var1]"r"(var1), [var2]"r"(var2)
+ );
+ return result;
+#else
+ Word32 L_var_out;
+ Word32 L_product;
+
+ L_product = L_mult(var1, var2);
+ L_var_out = L_add (L_var3, L_product);
+ return (L_var_out);
+#endif
+}
+#endif
+
+#if (L_ADD_IS_INLINE)
+__inline Word32 L_add (Word32 L_var1, Word32 L_var2)
+{
+#if ARMV5TE_L_ADD
+ Word32 result;
+ asm volatile(
+ "QADD %[result], %[L_var1], %[L_var2]\n"
+ :[result]"+r"(result)
+ :[L_var1]"r"(L_var1), [L_var2]"r"(L_var2)
+ );
+ return result;
+#else
+ Word32 L_var_out;
+
+ L_var_out = L_var1 + L_var2;
+ if (((L_var1 ^ L_var2) & MIN_32) == 0)
+ {
+ if ((L_var_out ^ L_var1) & MIN_32)
+ {
+ L_var_out = (L_var1 < 0) ? MIN_32 : MAX_32;
+ }
+ }
+ return (L_var_out);
+#endif
+}
+#endif
+
+
+
+#if (MULT_R_IS_INLINE)
+__inline Word16 mult_r (Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+ Word32 L_product_arr;
+
+ L_product_arr = (Word32)var1 *(Word32)var2; /* product */
+ L_product_arr += (Word32)0x00004000L; /* round */
+ L_product_arr >>= 15; /* shift */
+
+ var_out = saturate(L_product_arr);
+
+ return (var_out);
+}
+#endif
+
+#if (SHR_R_IS_INLINE)
+__inline Word16 shr_r (Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+
+ if (var2 > 15)
+ {
+ var_out = 0;
+ }
+ else
+ {
+ var_out = shr(var1, var2);
+
+ if (var2 > 0)
+ {
+ if ((var1 & ((Word16) 1 << (var2 - 1))) != 0)
+ {
+ var_out++;
+ }
+ }
+ }
+
+ return (var_out);
+}
+#endif
+
+#if (MAC_R_IS_INLINE)
+__inline Word16 mac_r (Word32 L_var3, Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+
+ L_var3 = L_mac (L_var3, var1, var2);
+ var_out = (Word16)((L_var3 + 0x8000L) >> 16);
+
+ return (var_out);
+}
+#endif
+
+#if (MSU_R_IS_INLINE)
+__inline Word16 msu_r (Word32 L_var3, Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+
+ L_var3 = L_msu (L_var3, var1, var2);
+ var_out = (Word16)((L_var3 + 0x8000L) >> 16);
+
+ return (var_out);
+}
+#endif
+
+#if (L_SHR_R_IS_INLINE)
+__inline Word32 L_shr_r (Word32 L_var1, Word16 var2)
+{
+ Word32 L_var_out;
+
+ if (var2 > 31)
+ {
+ L_var_out = 0;
+ }
+ else
+ {
+ L_var_out = L_shr(L_var1, var2);
+
+ if (var2 > 0)
+ {
+ if ((L_var1 & ((Word32) 1 << (var2 - 1))) != 0)
+ {
+ L_var_out++;
+ }
+ }
+ }
+
+ return (L_var_out);
+}
+#endif
+
+#if (EXTRACT_H_IS_INLINE)
+__inline Word16 extract_h (Word32 L_var1)
+{
+ Word16 var_out;
+
+ var_out = (Word16) (L_var1 >> 16);
+
+ return (var_out);
+}
+#endif
+
+#if (EXTRACT_L_IS_INLINE)
+__inline Word16 extract_l(Word32 L_var1)
+{
+ return (Word16) L_var1;
+}
+#endif
+
#endif
diff --git a/media/libstagefright/codecs/aacenc/basic_op/basicop2.c b/media/libstagefright/codecs/aacenc/basic_op/basicop2.c
index a0d5dba..82d3f38 100644
--- a/media/libstagefright/codecs/aacenc/basic_op/basicop2.c
+++ b/media/libstagefright/codecs/aacenc/basic_op/basicop2.c
@@ -1,1624 +1,1624 @@
-/*
- ** Copyright 2003-2010, VisualOn, Inc.
- **
- ** 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.
- */
-/*******************************************************************************
- File: basicop2.c
-
- Content: Basic arithmetic operators.
-
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** 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.
+ */
+/*******************************************************************************
+ File: basicop2.c
+
+ Content: Basic arithmetic operators.
+
*******************************************************************************/
#include "typedef.h"
-#include "basic_op.h"
-
-
-/*___________________________________________________________________________
- | |
- | Functions |
- |___________________________________________________________________________|
-*/
-
-/*___________________________________________________________________________
- | |
- | Function Name : saturate |
- | |
- | Purpose : |
- | |
- | Limit the 32 bit input to the range of a 16 bit word. |
- | |
- | Inputs : |
- | |
- | L_var1 |
- | 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | var_out |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
- |___________________________________________________________________________|
-*/
-
-#if (!SATRUATE_IS_INLINE)
-Word16 saturate(Word32 L_var1)
-{
- Word16 var_out;
-
- if (L_var1 > 0X00007fffL)
- {
- var_out = MAX_16;
- }
- else if (L_var1 < (Word32) 0xffff8000L)
- {
- var_out = MIN_16;
- }
- else
- {
- var_out = extract_l(L_var1);
- }
-
- return (var_out);
-}
-#endif
-
-/*___________________________________________________________________________
- | |
- | Function Name : add |
- | |
- | Purpose : |
- | |
- | Performs the addition (var1+var2) with overflow control and saturation;|
- | the 16 bit result is set at +32767 when overflow occurs or at -32768 |
- | when underflow occurs. |
- | |
- | Complexity weight : 1 |
- | |
- | Inputs : |
- | |
- | var1 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | var2 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | var_out |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
- |___________________________________________________________________________|
-*/
-
-#if (!ADD_IS_INLINE)
-Word16 add (Word16 var1, Word16 var2)
-{
- Word16 var_out;
- Word32 L_sum;
-
- L_sum = (Word32)var1 + (Word32)var2;
- var_out = saturate(L_sum);
-
- return (var_out);
-}
-#endif
-
-/*___________________________________________________________________________
- | |
- | Function Name : sub |
- | |
- | Purpose : |
- | |
- | Performs the subtraction (var1+var2) with overflow control and satu- |
- | ration; the 16 bit result is set at +32767 when overflow occurs or at |
- | -32768 when underflow occurs. |
- | |
- | Complexity weight : 1 |
- | |
- | Inputs : |
- | |
- | var1 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | var2 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | var_out |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
- |___________________________________________________________________________|
-*/
-#if (!SUB_IS_INLINE)
-Word16 sub(Word16 var1, Word16 var2)
-{
- Word16 var_out;
- Word32 L_diff;
-
- L_diff = (Word32) var1 - var2;
- var_out = saturate(L_diff);
-
- return (var_out);
-}
-#endif
-
-/*___________________________________________________________________________
- | |
- | Function Name : abs_s |
- | |
- | Purpose : |
- | |
- | Absolute value of var1; abs_s(-32768) = 32767. |
- | |
- | Complexity weight : 1 |
- | |
- | Inputs : |
- | |
- | var1 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | var_out |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0x0000 0000 <= var_out <= 0x0000 7fff. |
- |___________________________________________________________________________|
-*/
-//Word16 abs_s (Word16 var1)
-//{
-// Word16 var_out;
-//
-// if (var1 == MIN_16)
-// {
-// var_out = MAX_16;
-// }
-// else
-// {
-// if (var1 < 0)
-// {
-// var_out = (Word16)-var1;
-// }
-// else
-// {
-// var_out = var1;
-// }
-// }
-//
-// return (var_out);
-//}
-
-
-/*___________________________________________________________________________
- | |
- | Function Name : shl |
- | |
- | Purpose : |
- | |
- | Arithmetically shift the 16 bit input var1 left var2 positions.Zero fill|
- | the var2 LSB of the result. If var2 is negative, arithmetically shift |
- | var1 right by -var2 with sign extension. Saturate the result in case of |
- | underflows or overflows. |
- | |
- | Complexity weight : 1 |
- | |
- | Inputs : |
- | |
- | var1 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | var2 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | var_out |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
- |___________________________________________________________________________|
-*/
-
-#if (!SHL_IS_INLINE)
-Word16 shl (Word16 var1, Word16 var2)
-{
- Word16 var_out;
- Word32 result;
-
- if (var2 < 0)
- {
- if (var2 < -16)
- var2 = -16;
- var_out = shr (var1, (Word16)-var2);
- }
- else
- {
- result = (Word32) var1 *((Word32) 1 << var2);
-
- if ((var2 > 15 && var1 != 0) || (result != (Word32) ((Word16) result)))
- {
- //Overflow = 1;
- var_out = (Word16)((var1 > 0) ? MAX_16 : MIN_16);
- }
- else
- {
- var_out = extract_l(result);
- }
- }
-
- return (var_out);
-}
-#endif
-// end
-
-/*___________________________________________________________________________
- | |
- | Function Name : shr |
- | |
- | Purpose : |
- | |
- | Arithmetically shift the 16 bit input var1 right var2 positions with |
- | sign extension. If var2 is negative, arithmetically shift var1 left by |
- | -var2 with sign extension. Saturate the result in case of underflows or |
- | overflows. |
- | |
- | Complexity weight : 1 |
- | |
- | Inputs : |
- | |
- | var1 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | var2 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | var_out |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
- |___________________________________________________________________________|
-*/
-
-#if (!SHR_IS_INLINE)
-Word16 shr (Word16 var1, Word16 var2)
-{
- Word16 var_out;
-
- if (var2 < 0)
- {
- if (var2 < -16)
- var2 = -16;
- var_out = shl (var1, (Word16)-var2);
- }
- else
- {
- if (var2 >= 15)
- {
- var_out = (Word16)((var1 < 0) ? -1 : 0);
- }
- else
- {
- if (var1 < 0)
- {
- var_out = (Word16)(~((~var1) >> var2));
- }
- else
- {
- var_out = (Word16)(var1 >> var2);
- }
- }
- }
-
- return (var_out);
-}
-#endif
-
-
-/*___________________________________________________________________________
- | |
- | Function Name : mult |
- | |
- | Purpose : |
- | |
- | Performs the multiplication of var1 by var2 and gives a 16 bit result |
- | which is scaled i.e.: |
- | mult(var1,var2) = extract_l(L_shr((var1 times var2),15)) and |
- | mult(-32768,-32768) = 32767. |
- | |
- | Complexity weight : 1 |
- | |
- | Inputs : |
- | |
- | var1 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | var2 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | var_out |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
- |___________________________________________________________________________|
-*/
-#if (!MULT_IS_INLINE)
-Word16 mult (Word16 var1, Word16 var2)
-{
- Word16 var_out;
- Word32 L_product;
-
- L_product = (Word32) var1 *(Word32) var2;
-
- L_product = (L_product & (Word32) 0xffff8000L) >> 15;
-
- if (L_product & (Word32) 0x00010000L)
- L_product = L_product | (Word32) 0xffff0000L;
-
- var_out = saturate(L_product);
-
- return (var_out);
-}
-#endif
-
-/*___________________________________________________________________________
- | |
- | Function Name : L_mult |
- | |
- | Purpose : |
- | |
- | L_mult is the 32 bit result of the multiplication of var1 times var2 |
- | with one shift left i.e.: |
- | L_mult(var1,var2) = L_shl((var1 times var2),1) and |
- | L_mult(-32768,-32768) = 2147483647. |
- | |
- | Complexity weight : 1 |
- | |
- | Inputs : |
- | |
- | var1 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | var2 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | L_var_out |
- | 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
- |___________________________________________________________________________|
-*/
-
-#if (!L_MULT_IS_INLINE)
-Word32 L_mult(Word16 var1, Word16 var2)
-{
- Word32 L_var_out;
-
- L_var_out = (Word32) var1 *(Word32) var2;
-
- if (L_var_out != (Word32) 0x40000000L)
- {
- L_var_out <<= 1;
- }
- else
- {
- L_var_out = MAX_32;
- }
-
- return (L_var_out);
-}
-#endif
-// end
-
-/*___________________________________________________________________________
- | |
- | Function Name : negate |
- | |
- | Purpose : |
- | |
- | Negate var1 with saturation, saturate in the case where input is -32768:|
- | negate(var1) = sub(0,var1). |
- | |
- | Complexity weight : 1 |
- | |
- | Inputs : |
- | |
- | var1 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | var_out |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
- |___________________________________________________________________________|
-*/
-//Word16 negate (Word16 var1)
-//{
-// Word16 var_out;
-//
-// var_out = (Word16)((var1 == MIN_16) ? MAX_16 : -var1);
-//
-// return (var_out);
-//}
-
-
-/*___________________________________________________________________________
- | |
- | Function Name : extract_h |
- | |
- | Purpose : |
- | |
- | Return the 16 MSB of L_var1. |
- | |
- | Complexity weight : 1 |
- | |
- | Inputs : |
- | |
- | L_var1 |
- | 32 bit long signed integer (Word32 ) whose value falls in the |
- | range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | var_out |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
- |___________________________________________________________________________|
-*/
-#if (!EXTRACT_H_IS_INLINE)
-Word16 extract_h (Word32 L_var1)
-{
- Word16 var_out;
-
- var_out = (Word16) (L_var1 >> 16);
-
- return (var_out);
-}
-#endif
-
-/*___________________________________________________________________________
- | |
- | Function Name : extract_l |
- | |
- | Purpose : |
- | |
- | Return the 16 LSB of L_var1. |
- | |
- | Complexity weight : 1 |
- | |
- | Inputs : |
- | |
- | L_var1 |
- | 32 bit long signed integer (Word32 ) whose value falls in the |
- | range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | var_out |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
- |___________________________________________________________________________|
-*/
-#if (!EXTRACT_L_IS_INLINE)
-Word16 extract_l(Word32 L_var1)
-{
- Word16 var_out;
-
- var_out = (Word16) L_var1;
-
- return (var_out);
-}
-#endif
-
-/*___________________________________________________________________________
- | |
- | Function Name : round |
- | |
- | Purpose : |
- | |
- | Round the lower 16 bits of the 32 bit input number into the MS 16 bits |
- | with saturation. Shift the resulting bits right by 16 and return the 16 |
- | bit number: |
- | round(L_var1) = extract_h(L_add(L_var1,32768)) |
- | |
- | Complexity weight : 1 |
- | |
- | Inputs : |
- | |
- | L_var1 |
- | 32 bit long signed integer (Word32 ) whose value falls in the |
- | range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | var_out |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
- |___________________________________________________________________________|
-*/
-
-#if (!ROUND_IS_INLINE)
-Word16 round16(Word32 L_var1)
-{
- Word16 var_out;
- Word32 L_rounded;
-
- L_rounded = L_add (L_var1, (Word32) 0x00008000L);
- var_out = extract_h (L_rounded);
-
- return (var_out);
-}
-#endif
-// end
-
-/*___________________________________________________________________________
- | |
- | Function Name : L_mac |
- | |
- | Purpose : |
- | |
- | Multiply var1 by var2 and shift the result left by 1. Add the 32 bit |
- | result to L_var3 with saturation, return a 32 bit result: |
- | L_mac(L_var3,var1,var2) = L_add(L_var3,L_mult(var1,var2)). |
- | |
- | Complexity weight : 1 |
- | |
- | Inputs : |
- | |
- | L_var3 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
- | |
- | var1 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | var2 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | L_var_out |
- | 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
- |___________________________________________________________________________|
-*/
-#if (!L_MSU_IS_INLINE)
-Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2)
-{
- Word32 L_var_out;
- Word32 L_product;
-
- L_product = L_mult(var1, var2);
- L_var_out = L_add (L_var3, L_product);
-
- return (L_var_out);
-}
-#endif
-
-/*___________________________________________________________________________
- | |
- | Function Name : L_msu |
- | |
- | Purpose : |
- | |
- | Multiply var1 by var2 and shift the result left by 1. Subtract the 32 |
- | bit result to L_var3 with saturation, return a 32 bit result: |
- | L_msu(L_var3,var1,var2) = L_sub(L_var3,L_mult(var1,var2)). |
- | |
- | Complexity weight : 1 |
- | |
- | Inputs : |
- | |
- | L_var3 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
- | |
- | var1 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | var2 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | L_var_out |
- | 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
- |___________________________________________________________________________|
-*/
-
-#if (!L_MSU_IS_INLINE)
-Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2)
-{
- Word32 L_var_out;
- Word32 L_product;
-
- L_product = L_mult(var1, var2);
- L_var_out = L_sub (L_var3, L_product);
-
- return (L_var_out);
-}
-#endif
-
-
-/*___________________________________________________________________________
- | |
- | Function Name : L_add |
- | |
- | Purpose : |
- | |
- | 32 bits addition of the two 32 bits variables (L_var1+L_var2) with |
- | overflow control and saturation; the result is set at +2147483647 when |
- | overflow occurs or at -2147483648 when underflow occurs. |
- | |
- | Complexity weight : 2 |
- | |
- | Inputs : |
- | |
- | L_var1 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
- | |
- | L_var2 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | L_var_out |
- | 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
- |___________________________________________________________________________|
-*/
-#if (!L_ADD_IS_INLINE)
-Word32 L_add (Word32 L_var1, Word32 L_var2)
-{
- Word32 L_var_out;
-
- L_var_out = L_var1 + L_var2;
-
- if (((L_var1 ^ L_var2) & MIN_32) == 0)
- {
- if ((L_var_out ^ L_var1) & MIN_32)
- {
- L_var_out = (L_var1 < 0) ? MIN_32 : MAX_32;
- //Overflow = 1;
- }
- }
-
- return (L_var_out);
-}
-#endif
-
-/*___________________________________________________________________________
- | |
- | Function Name : L_sub |
- | |
- | Purpose : |
- | |
- | 32 bits subtraction of the two 32 bits variables (L_var1-L_var2) with |
- | overflow control and saturation; the result is set at +2147483647 when |
- | overflow occurs or at -2147483648 when underflow occurs. |
- | |
- | Complexity weight : 2 |
- | |
- | Inputs : |
- | |
- | L_var1 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
- | |
- | L_var2 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | L_var_out |
- | 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
- |___________________________________________________________________________|
-*/
-#if (!L_SUB_IS_INLINE)
-Word32 L_sub(Word32 L_var1, Word32 L_var2)
-{
- Word32 L_var_out;
-
- L_var_out = L_var1 - L_var2;
-
- if (((L_var1 ^ L_var2) & MIN_32) != 0)
- {
- if ((L_var_out ^ L_var1) & MIN_32)
- {
- L_var_out = (L_var1 < 0L) ? MIN_32 : MAX_32;
- //Overflow = 1;
- }
- }
-
- return (L_var_out);
-}
-#endif
-
-
-/*___________________________________________________________________________
- | |
- | Function Name : L_negate |
- | |
- | Purpose : |
- | |
- | Negate the 32 bit variable L_var1 with saturation; saturate in the case |
- | where input is -2147483648 (0x8000 0000). |
- | |
- | Complexity weight : 2 |
- | |
- | Inputs : |
- | |
- | L_var1 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | L_var_out |
- | 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
- |___________________________________________________________________________|
-*/
-//Word32 L_negate (Word32 L_var1)
-//{
-// Word32 L_var_out;
-//
-// L_var_out = (L_var1 == MIN_32) ? MAX_32 : -L_var1;
-//
-// return (L_var_out);
-//}
-
-
-/*___________________________________________________________________________
- | |
- | Function Name : mult_r |
- | |
- | Purpose : |
- | |
- | Same as mult with rounding, i.e.: |
- | mult_r(var1,var2) = extract_l(L_shr(((var1 * var2) + 16384),15)) and |
- | mult_r(-32768,-32768) = 32767. |
- | |
- | Complexity weight : 2 |
- | |
- | Inputs : |
- | |
- | var1 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | var2 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | var_out |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
- |___________________________________________________________________________|
-*/
-#if (!MULT_R_IS_INLINE)
-Word16 mult_r (Word16 var1, Word16 var2)
-{
- Word16 var_out;
- Word32 L_product_arr;
-
- L_product_arr = (Word32) var1 *(Word32) var2; /* product */
- L_product_arr += (Word32) 0x00004000L; /* round */
- L_product_arr &= (Word32) 0xffff8000L;
- L_product_arr >>= 15; /* shift */
-
- if (L_product_arr & (Word32) 0x00010000L) /* sign extend when necessary */
- {
- L_product_arr |= (Word32) 0xffff0000L;
- }
- var_out = saturate(L_product_arr);
-
- return (var_out);
-}
-#endif
-
-/*___________________________________________________________________________
- | |
- | Function Name : L_shl |
- | |
- | Purpose : |
- | |
- | Arithmetically shift the 32 bit input L_var1 left var2 positions. Zero |
- | fill the var2 LSB of the result. If var2 is negative, arithmetically |
- | shift L_var1 right by -var2 with sign extension. Saturate the result in |
- | case of underflows or overflows. |
- | |
- | Complexity weight : 2 |
- | |
- | Inputs : |
- | |
- | L_var1 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
- | |
- | var2 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | L_var_out |
- | 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
- |___________________________________________________________________________|
-*/
-
-#if (!L_SHL_IS_INLINE)
-Word32 L_shl (Word32 L_var1, Word16 var2)
-{
- Word32 L_var_out = 0L;
-
- if (var2 <= 0)
- {
- L_var1 = L_shr(L_var1, (Word16)-var2);
- }
- else
- {
- for (; var2 > 0; var2--)
- {
- if (L_var1 > (Word32) 0X3fffffffL)
- {
- return MAX_32;
- }
- else
- {
- if (L_var1 < (Word32) 0xc0000000L)
- {
- return MIN_32;
- }
- }
- L_var1 <<= 1;
- }
- }
- return (L_var1);
-}
-#endif
-
-/*___________________________________________________________________________
- | |
- | Function Name : L_shr |
- | |
- | Purpose : |
- | |
- | Arithmetically shift the 32 bit input L_var1 right var2 positions with |
- | sign extension. If var2 is negative, arithmetically shift L_var1 left |
- | by -var2 and zero fill the -var2 LSB of the result. Saturate the result |
- | in case of underflows or overflows. |
- | |
- | Complexity weight : 2 |
- | |
- | Inputs : |
- | |
- | L_var1 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
- | |
- | var2 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | L_var_out |
- | 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
- |___________________________________________________________________________|
-*/
-
-#if (!L_SHR_IS_INLINE)
-Word32 L_shr (Word32 L_var1, Word16 var2)
-{
- Word32 L_var_out;
-
- if (var2 < 0)
- {
- L_var_out = L_shl (L_var1, (Word16)-var2);
- }
- else
- {
- if (var2 >= 31)
- {
- L_var_out = (L_var1 < 0L) ? -1 : 0;
- }
- else
- {
- if (L_var1 < 0)
- {
- L_var_out = ~((~L_var1) >> var2);
- }
- else
- {
- L_var_out = L_var1 >> var2;
- }
- }
- }
- return (L_var_out);
-}
-#endif
-
-/*___________________________________________________________________________
- | |
- | Function Name : shr_r |
- | |
- | Purpose : |
- | |
- | Same as shr(var1,var2) but with rounding. Saturate the result in case of|
- | underflows or overflows : |
- | - If var2 is greater than zero : |
- | if (sub(shl(shr(var1,var2),1),shr(var1,sub(var2,1)))) |
- | is equal to zero |
- | then |
- | shr_r(var1,var2) = shr(var1,var2) |
- | else |
- | shr_r(var1,var2) = add(shr(var1,var2),1) |
- | - If var2 is less than or equal to zero : |
- | shr_r(var1,var2) = shr(var1,var2). |
- | |
- | Complexity weight : 2 |
- | |
- | Inputs : |
- | |
- | var1 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | var2 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | var_out |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
- |___________________________________________________________________________|
-*/
-#if (!SHR_R_IS_INLINE)
-Word16 shr_r (Word16 var1, Word16 var2)
-{
- Word16 var_out;
-
- if (var2 > 15)
- {
- var_out = 0;
- }
- else
- {
- var_out = shr (var1, var2);
-
- if (var2 > 0)
- {
- if ((var1 & ((Word16) 1 << (var2 - 1))) != 0)
- {
- var_out++;
- }
- }
- }
-
- return (var_out);
-}
-#endif
-
-/*___________________________________________________________________________
- | |
- | Function Name : mac_r |
- | |
- | Purpose : |
- | |
- | Multiply var1 by var2 and shift the result left by 1. Add the 32 bit |
- | result to L_var3 with saturation. Round the LS 16 bits of the result |
- | into the MS 16 bits with saturation and shift the result right by 16. |
- | Return a 16 bit result. |
- | mac_r(L_var3,var1,var2) = round(L_mac(L_var3,var1,var2)) |
- | |
- | Complexity weight : 2 |
- | |
- | Inputs : |
- | |
- | L_var3 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
- | |
- | var1 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | var2 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | var_out |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0x0000 8000 <= L_var_out <= 0x0000 7fff. |
- |___________________________________________________________________________|
-*/
-#if (!MAC_R_IS_INLINE)
-Word16 mac_r (Word32 L_var3, Word16 var1, Word16 var2)
-{
- Word16 var_out;
-
- L_var3 = L_mac (L_var3, var1, var2);
- L_var3 = L_add (L_var3, (Word32) 0x00008000L);
- var_out = extract_h (L_var3);
-
- return (var_out);
-}
-#endif
-
-/*___________________________________________________________________________
- | |
- | Function Name : msu_r |
- | |
- | Purpose : |
- | |
- | Multiply var1 by var2 and shift the result left by 1. Subtract the 32 |
- | bit result to L_var3 with saturation. Round the LS 16 bits of the res- |
- | ult into the MS 16 bits with saturation and shift the result right by |
- | 16. Return a 16 bit result. |
- | msu_r(L_var3,var1,var2) = round(L_msu(L_var3,var1,var2)) |
- | |
- | Complexity weight : 2 |
- | |
- | Inputs : |
- | |
- | L_var3 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
- | |
- | var1 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | var2 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | var_out |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0x0000 8000 <= L_var_out <= 0x0000 7fff. |
- |___________________________________________________________________________|
-*/
-#if (!MSU_R_IS_INLINE)
-Word16 msu_r (Word32 L_var3, Word16 var1, Word16 var2)
-{
- Word16 var_out;
-
- L_var3 = L_msu (L_var3, var1, var2);
- L_var3 = L_add (L_var3, (Word32) 0x00008000L);
- var_out = extract_h (L_var3);
-
- return (var_out);
-}
-#endif
-
-/*___________________________________________________________________________
- | |
- | Function Name : L_deposit_h |
- | |
- | Purpose : |
- | |
- | Deposit the 16 bit var1 into the 16 MS bits of the 32 bit output. The |
- | 16 LS bits of the output are zeroed. |
- | |
- | Complexity weight : 2 |
- | |
- | Inputs : |
- | |
- | var1 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | L_var_out |
- | 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= var_out <= 0x7fff 0000. |
- |___________________________________________________________________________|
-*/
-//Word32 L_deposit_h (Word16 var1)
-//{
-// Word32 L_var_out;
-//
-// L_var_out = (Word32) var1 << 16;
-//
-// return (L_var_out);
-//}
-
-
-/*___________________________________________________________________________
- | |
- | Function Name : L_deposit_l |
- | |
- | Purpose : |
- | |
- | Deposit the 16 bit var1 into the 16 LS bits of the 32 bit output. The |
- | 16 MS bits of the output are sign extended. |
- | |
- | Complexity weight : 2 |
- | |
- | Inputs : |
- | |
- | var1 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | L_var_out |
- | 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0xFFFF 8000 <= var_out <= 0x0000 7fff. |
- |___________________________________________________________________________|
-*/
-//Word32 L_deposit_l (Word16 var1)
-//{
-// Word32 L_var_out;
-//
-// L_var_out = (Word32) var1;
-//
-// return (L_var_out);
-//}
-
-
-/*___________________________________________________________________________
- | |
- | Function Name : L_shr_r |
- | |
- | Purpose : |
- | |
- | Same as L_shr(L_var1,var2) but with rounding. Saturate the result in |
- | case of underflows or overflows : |
- | - If var2 is greater than zero : |
- | if (L_sub(L_shl(L_shr(L_var1,var2),1),L_shr(L_var1,sub(var2,1))))|
- | is equal to zero |
- | then |
- | L_shr_r(L_var1,var2) = L_shr(L_var1,var2) |
- | else |
- | L_shr_r(L_var1,var2) = L_add(L_shr(L_var1,var2),1) |
- | - If var2 is less than or equal to zero : |
- | L_shr_r(L_var1,var2) = L_shr(L_var1,var2). |
- | |
- | Complexity weight : 3 |
- | |
- | Inputs : |
- | |
- | L_var1 |
- | 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= var1 <= 0x7fff ffff. |
- | |
- | var2 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | L_var_out |
- | 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= var_out <= 0x7fff ffff. |
- |___________________________________________________________________________|
-*/
-#if (!L_SHR_R_IS_INLINE)
-Word32 L_shr_r (Word32 L_var1, Word16 var2)
-{
- Word32 L_var_out;
-
- if (var2 > 31)
- {
- L_var_out = 0;
- }
- else
- {
- L_var_out = L_shr (L_var1, var2);
-
- if (var2 > 0)
- {
- if ((L_var1 & ((Word32) 1 << (var2 - 1))) != 0)
- {
- L_var_out++;
- }
- }
- }
-
- return (L_var_out);
-}
-#endif
-
-/*___________________________________________________________________________
- | |
- | Function Name : L_abs |
- | |
- | Purpose : |
- | |
- | Absolute value of L_var1; Saturate in case where the input is |
- | -214783648 |
- | |
- | Complexity weight : 3 |
- | |
- | Inputs : |
- | |
- | L_var1 |
- | 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= var1 <= 0x7fff ffff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | L_var_out |
- | 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x0000 0000 <= var_out <= 0x7fff ffff. |
- |___________________________________________________________________________|
-*/
-//Word32 L_abs (Word32 L_var1)
-//{
-// Word32 L_var_out;
-//
-// if (L_var1 == MIN_32)
-// {
-// L_var_out = MAX_32;
-// }
-// else
-// {
-// if (L_var1 < 0)
-// {
-// L_var_out = -L_var1;
-// }
-// else
-// {
-// L_var_out = L_var1;
-// }
-// }
-//
-// return (L_var_out);
-//}
-
-/*___________________________________________________________________________
- | |
- | Function Name : norm_s |
- | |
- | Purpose : |
- | |
- | Produces the number of left shift needed to normalize the 16 bit varia- |
- | ble var1 for positive values on the interval with minimum of 16384 and |
- | maximum of 32767, and for negative values on the interval with minimum |
- | of -32768 and maximum of -16384; in order to normalize the result, the |
- | following operation must be done : |
- | norm_var1 = shl(var1,norm_s(var1)). |
- | |
- | Complexity weight : 15 |
- | |
- | Inputs : |
- | |
- | var1 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | var_out |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0x0000 0000 <= var_out <= 0x0000 000f. |
- |___________________________________________________________________________|
-*/
-
-#if (!NORM_S_IS_INLINE)
-Word16 norm_s (Word16 var1)
-{
- Word16 var_out;
-
- if (var1 == 0)
- {
- var_out = 0;
- }
- else
- {
- if (var1 == -1)
- {
- var_out = 15;
- }
- else
- {
- if (var1 < 0)
- {
- var1 = (Word16)~var1;
- }
- for (var_out = 0; var1 < 0x4000; var_out++)
- {
- var1 <<= 1;
- }
- }
- }
-
- return (var_out);
-}
-#endif
-
-/*___________________________________________________________________________
- | |
- | Function Name : div_s |
- | |
- | Purpose : |
- | |
- | Produces a result which is the fractional integer division of var1 by |
- | var2; var1 and var2 must be positive and var2 must be greater or equal |
- | to var1; the result is positive (leading bit equal to 0) and truncated |
- | to 16 bits. |
- | If var1 = var2 then div(var1,var2) = 32767. |
- | |
- | Complexity weight : 18 |
- | |
- | Inputs : |
- | |
- | var1 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0x0000 0000 <= var1 <= var2 and var2 != 0. |
- | |
- | var2 |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : var1 <= var2 <= 0x0000 7fff and var2 != 0. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | var_out |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0x0000 0000 <= var_out <= 0x0000 7fff. |
- | It's a Q15 value (point between b15 and b14). |
- |___________________________________________________________________________|
-*/
-
-#if (!DIV_S_IS_INLINE)
-Word16 div_s (Word16 var1, Word16 var2)
-{
- Word16 var_out = 0;
- Word16 iteration;
- Word32 L_num;
- Word32 L_denom;
-
- if (var1 == 0)
- {
- var_out = 0;
- }
- else
- {
- if (var1 == var2)
- {
- var_out = MAX_16;
- }
- else
- {
- L_num = L_deposit_l (var1);
- L_denom = L_deposit_l (var2);
-
- for (iteration = 0; iteration < 15; iteration++)
- {
- var_out <<= 1;
- L_num <<= 1;
-
- if (L_num >= L_denom)
- {
- L_num = L_sub(L_num, L_denom);
- var_out = add (var_out, 1);
- }
- }
- }
- }
-
- return (var_out);
-}
-#endif
-
-/*___________________________________________________________________________
- | |
- | Function Name : norm_l |
- | |
- | Purpose : |
- | |
- | Produces the number of left shifts needed to normalize the 32 bit varia-|
- | ble L_var1 for positive values on the interval with minimum of |
- | 1073741824 and maximum of 2147483647, and for negative values on the in-|
- | terval with minimum of -2147483648 and maximum of -1073741824; in order |
- | to normalize the result, the following operation must be done : |
- | norm_L_var1 = L_shl(L_var1,norm_l(L_var1)). |
- | |
- | Complexity weight : 30 |
- | |
- | Inputs : |
- | |
- | L_var1 |
- | 32 bit long signed integer (Word32) whose value falls in the |
- | range : 0x8000 0000 <= var1 <= 0x7fff ffff. |
- | |
- | Outputs : |
- | |
- | none |
- | |
- | Return Value : |
- | |
- | var_out |
- | 16 bit short signed integer (Word16) whose value falls in the |
- | range : 0x0000 0000 <= var_out <= 0x0000 001f. |
- |___________________________________________________________________________|
-*/
-
-#if (!NORM_L_IS_INLINE)
-Word16 norm_l (Word32 L_var1)
-{
- Word16 var_out;
-
- if (L_var1 == 0)
- {
- var_out = 0;
- }
- else
- {
- if (L_var1 == (Word32) 0xffffffffL)
- {
- var_out = 31;
- }
- else
- {
- if (L_var1 < 0)
- {
- L_var1 = ~L_var1;
- }
- for (var_out = 0; L_var1 < (Word32) 0x40000000L; var_out++)
- {
- L_var1 <<= 1;
- }
- }
- }
-
- return (var_out);
-}
-#endif
+#include "basic_op.h"
+
+
+/*___________________________________________________________________________
+ | |
+ | Functions |
+ |___________________________________________________________________________|
+*/
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : saturate |
+ | |
+ | Purpose : |
+ | |
+ | Limit the 32 bit input to the range of a 16 bit word. |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+
+#if (!SATRUATE_IS_INLINE)
+Word16 saturate(Word32 L_var1)
+{
+ Word16 var_out;
+
+ if (L_var1 > 0X00007fffL)
+ {
+ var_out = MAX_16;
+ }
+ else if (L_var1 < (Word32) 0xffff8000L)
+ {
+ var_out = MIN_16;
+ }
+ else
+ {
+ var_out = extract_l(L_var1);
+ }
+
+ return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : add |
+ | |
+ | Purpose : |
+ | |
+ | Performs the addition (var1+var2) with overflow control and saturation;|
+ | the 16 bit result is set at +32767 when overflow occurs or at -32768 |
+ | when underflow occurs. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+
+#if (!ADD_IS_INLINE)
+Word16 add (Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+ Word32 L_sum;
+
+ L_sum = (Word32)var1 + (Word32)var2;
+ var_out = saturate(L_sum);
+
+ return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : sub |
+ | |
+ | Purpose : |
+ | |
+ | Performs the subtraction (var1+var2) with overflow control and satu- |
+ | ration; the 16 bit result is set at +32767 when overflow occurs or at |
+ | -32768 when underflow occurs. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+#if (!SUB_IS_INLINE)
+Word16 sub(Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+ Word32 L_diff;
+
+ L_diff = (Word32) var1 - var2;
+ var_out = saturate(L_diff);
+
+ return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : abs_s |
+ | |
+ | Purpose : |
+ | |
+ | Absolute value of var1; abs_s(-32768) = 32767. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0x0000 0000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+//Word16 abs_s (Word16 var1)
+//{
+// Word16 var_out;
+//
+// if (var1 == MIN_16)
+// {
+// var_out = MAX_16;
+// }
+// else
+// {
+// if (var1 < 0)
+// {
+// var_out = (Word16)-var1;
+// }
+// else
+// {
+// var_out = var1;
+// }
+// }
+//
+// return (var_out);
+//}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : shl |
+ | |
+ | Purpose : |
+ | |
+ | Arithmetically shift the 16 bit input var1 left var2 positions.Zero fill|
+ | the var2 LSB of the result. If var2 is negative, arithmetically shift |
+ | var1 right by -var2 with sign extension. Saturate the result in case of |
+ | underflows or overflows. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+
+#if (!SHL_IS_INLINE)
+Word16 shl (Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+ Word32 result;
+
+ if (var2 < 0)
+ {
+ if (var2 < -16)
+ var2 = -16;
+ var_out = shr (var1, (Word16)-var2);
+ }
+ else
+ {
+ result = (Word32) var1 *((Word32) 1 << var2);
+
+ if ((var2 > 15 && var1 != 0) || (result != (Word32) ((Word16) result)))
+ {
+ //Overflow = 1;
+ var_out = (Word16)((var1 > 0) ? MAX_16 : MIN_16);
+ }
+ else
+ {
+ var_out = extract_l(result);
+ }
+ }
+
+ return (var_out);
+}
+#endif
+// end
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : shr |
+ | |
+ | Purpose : |
+ | |
+ | Arithmetically shift the 16 bit input var1 right var2 positions with |
+ | sign extension. If var2 is negative, arithmetically shift var1 left by |
+ | -var2 with sign extension. Saturate the result in case of underflows or |
+ | overflows. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+
+#if (!SHR_IS_INLINE)
+Word16 shr (Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+
+ if (var2 < 0)
+ {
+ if (var2 < -16)
+ var2 = -16;
+ var_out = shl (var1, (Word16)-var2);
+ }
+ else
+ {
+ if (var2 >= 15)
+ {
+ var_out = (Word16)((var1 < 0) ? -1 : 0);
+ }
+ else
+ {
+ if (var1 < 0)
+ {
+ var_out = (Word16)(~((~var1) >> var2));
+ }
+ else
+ {
+ var_out = (Word16)(var1 >> var2);
+ }
+ }
+ }
+
+ return (var_out);
+}
+#endif
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : mult |
+ | |
+ | Purpose : |
+ | |
+ | Performs the multiplication of var1 by var2 and gives a 16 bit result |
+ | which is scaled i.e.: |
+ | mult(var1,var2) = extract_l(L_shr((var1 times var2),15)) and |
+ | mult(-32768,-32768) = 32767. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+#if (!MULT_IS_INLINE)
+Word16 mult (Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+ Word32 L_product;
+
+ L_product = (Word32) var1 *(Word32) var2;
+
+ L_product = (L_product & (Word32) 0xffff8000L) >> 15;
+
+ if (L_product & (Word32) 0x00010000L)
+ L_product = L_product | (Word32) 0xffff0000L;
+
+ var_out = saturate(L_product);
+
+ return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_mult |
+ | |
+ | Purpose : |
+ | |
+ | L_mult is the 32 bit result of the multiplication of var1 times var2 |
+ | with one shift left i.e.: |
+ | L_mult(var1,var2) = L_shl((var1 times var2),1) and |
+ | L_mult(-32768,-32768) = 2147483647. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+
+#if (!L_MULT_IS_INLINE)
+Word32 L_mult(Word16 var1, Word16 var2)
+{
+ Word32 L_var_out;
+
+ L_var_out = (Word32) var1 *(Word32) var2;
+
+ if (L_var_out != (Word32) 0x40000000L)
+ {
+ L_var_out <<= 1;
+ }
+ else
+ {
+ L_var_out = MAX_32;
+ }
+
+ return (L_var_out);
+}
+#endif
+// end
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : negate |
+ | |
+ | Purpose : |
+ | |
+ | Negate var1 with saturation, saturate in the case where input is -32768:|
+ | negate(var1) = sub(0,var1). |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+//Word16 negate (Word16 var1)
+//{
+// Word16 var_out;
+//
+// var_out = (Word16)((var1 == MIN_16) ? MAX_16 : -var1);
+//
+// return (var_out);
+//}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : extract_h |
+ | |
+ | Purpose : |
+ | |
+ | Return the 16 MSB of L_var1. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 |
+ | 32 bit long signed integer (Word32 ) whose value falls in the |
+ | range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+#if (!EXTRACT_H_IS_INLINE)
+Word16 extract_h (Word32 L_var1)
+{
+ Word16 var_out;
+
+ var_out = (Word16) (L_var1 >> 16);
+
+ return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : extract_l |
+ | |
+ | Purpose : |
+ | |
+ | Return the 16 LSB of L_var1. |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 |
+ | 32 bit long signed integer (Word32 ) whose value falls in the |
+ | range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+#if (!EXTRACT_L_IS_INLINE)
+Word16 extract_l(Word32 L_var1)
+{
+ Word16 var_out;
+
+ var_out = (Word16) L_var1;
+
+ return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : round |
+ | |
+ | Purpose : |
+ | |
+ | Round the lower 16 bits of the 32 bit input number into the MS 16 bits |
+ | with saturation. Shift the resulting bits right by 16 and return the 16 |
+ | bit number: |
+ | round(L_var1) = extract_h(L_add(L_var1,32768)) |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 |
+ | 32 bit long signed integer (Word32 ) whose value falls in the |
+ | range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+
+#if (!ROUND_IS_INLINE)
+Word16 round16(Word32 L_var1)
+{
+ Word16 var_out;
+ Word32 L_rounded;
+
+ L_rounded = L_add (L_var1, (Word32) 0x00008000L);
+ var_out = extract_h (L_rounded);
+
+ return (var_out);
+}
+#endif
+// end
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_mac |
+ | |
+ | Purpose : |
+ | |
+ | Multiply var1 by var2 and shift the result left by 1. Add the 32 bit |
+ | result to L_var3 with saturation, return a 32 bit result: |
+ | L_mac(L_var3,var1,var2) = L_add(L_var3,L_mult(var1,var2)). |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var3 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+#if (!L_MSU_IS_INLINE)
+Word32 L_mac (Word32 L_var3, Word16 var1, Word16 var2)
+{
+ Word32 L_var_out;
+ Word32 L_product;
+
+ L_product = L_mult(var1, var2);
+ L_var_out = L_add (L_var3, L_product);
+
+ return (L_var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_msu |
+ | |
+ | Purpose : |
+ | |
+ | Multiply var1 by var2 and shift the result left by 1. Subtract the 32 |
+ | bit result to L_var3 with saturation, return a 32 bit result: |
+ | L_msu(L_var3,var1,var2) = L_sub(L_var3,L_mult(var1,var2)). |
+ | |
+ | Complexity weight : 1 |
+ | |
+ | Inputs : |
+ | |
+ | L_var3 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+
+#if (!L_MSU_IS_INLINE)
+Word32 L_msu (Word32 L_var3, Word16 var1, Word16 var2)
+{
+ Word32 L_var_out;
+ Word32 L_product;
+
+ L_product = L_mult(var1, var2);
+ L_var_out = L_sub (L_var3, L_product);
+
+ return (L_var_out);
+}
+#endif
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_add |
+ | |
+ | Purpose : |
+ | |
+ | 32 bits addition of the two 32 bits variables (L_var1+L_var2) with |
+ | overflow control and saturation; the result is set at +2147483647 when |
+ | overflow occurs or at -2147483648 when underflow occurs. |
+ | |
+ | Complexity weight : 2 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | L_var2 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+#if (!L_ADD_IS_INLINE)
+Word32 L_add (Word32 L_var1, Word32 L_var2)
+{
+ Word32 L_var_out;
+
+ L_var_out = L_var1 + L_var2;
+
+ if (((L_var1 ^ L_var2) & MIN_32) == 0)
+ {
+ if ((L_var_out ^ L_var1) & MIN_32)
+ {
+ L_var_out = (L_var1 < 0) ? MIN_32 : MAX_32;
+ //Overflow = 1;
+ }
+ }
+
+ return (L_var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_sub |
+ | |
+ | Purpose : |
+ | |
+ | 32 bits subtraction of the two 32 bits variables (L_var1-L_var2) with |
+ | overflow control and saturation; the result is set at +2147483647 when |
+ | overflow occurs or at -2147483648 when underflow occurs. |
+ | |
+ | Complexity weight : 2 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | L_var2 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+#if (!L_SUB_IS_INLINE)
+Word32 L_sub(Word32 L_var1, Word32 L_var2)
+{
+ Word32 L_var_out;
+
+ L_var_out = L_var1 - L_var2;
+
+ if (((L_var1 ^ L_var2) & MIN_32) != 0)
+ {
+ if ((L_var_out ^ L_var1) & MIN_32)
+ {
+ L_var_out = (L_var1 < 0L) ? MIN_32 : MAX_32;
+ //Overflow = 1;
+ }
+ }
+
+ return (L_var_out);
+}
+#endif
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_negate |
+ | |
+ | Purpose : |
+ | |
+ | Negate the 32 bit variable L_var1 with saturation; saturate in the case |
+ | where input is -2147483648 (0x8000 0000). |
+ | |
+ | Complexity weight : 2 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+//Word32 L_negate (Word32 L_var1)
+//{
+// Word32 L_var_out;
+//
+// L_var_out = (L_var1 == MIN_32) ? MAX_32 : -L_var1;
+//
+// return (L_var_out);
+//}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : mult_r |
+ | |
+ | Purpose : |
+ | |
+ | Same as mult with rounding, i.e.: |
+ | mult_r(var1,var2) = extract_l(L_shr(((var1 * var2) + 16384),15)) and |
+ | mult_r(-32768,-32768) = 32767. |
+ | |
+ | Complexity weight : 2 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+#if (!MULT_R_IS_INLINE)
+Word16 mult_r (Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+ Word32 L_product_arr;
+
+ L_product_arr = (Word32) var1 *(Word32) var2; /* product */
+ L_product_arr += (Word32) 0x00004000L; /* round */
+ L_product_arr &= (Word32) 0xffff8000L;
+ L_product_arr >>= 15; /* shift */
+
+ if (L_product_arr & (Word32) 0x00010000L) /* sign extend when necessary */
+ {
+ L_product_arr |= (Word32) 0xffff0000L;
+ }
+ var_out = saturate(L_product_arr);
+
+ return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_shl |
+ | |
+ | Purpose : |
+ | |
+ | Arithmetically shift the 32 bit input L_var1 left var2 positions. Zero |
+ | fill the var2 LSB of the result. If var2 is negative, arithmetically |
+ | shift L_var1 right by -var2 with sign extension. Saturate the result in |
+ | case of underflows or overflows. |
+ | |
+ | Complexity weight : 2 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+
+#if (!L_SHL_IS_INLINE)
+Word32 L_shl (Word32 L_var1, Word16 var2)
+{
+ Word32 L_var_out = 0L;
+
+ if (var2 <= 0)
+ {
+ L_var1 = L_shr(L_var1, (Word16)-var2);
+ }
+ else
+ {
+ for (; var2 > 0; var2--)
+ {
+ if (L_var1 > (Word32) 0X3fffffffL)
+ {
+ return MAX_32;
+ }
+ else
+ {
+ if (L_var1 < (Word32) 0xc0000000L)
+ {
+ return MIN_32;
+ }
+ }
+ L_var1 <<= 1;
+ }
+ }
+ return (L_var1);
+}
+#endif
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_shr |
+ | |
+ | Purpose : |
+ | |
+ | Arithmetically shift the 32 bit input L_var1 right var2 positions with |
+ | sign extension. If var2 is negative, arithmetically shift L_var1 left |
+ | by -var2 and zero fill the -var2 LSB of the result. Saturate the result |
+ | in case of underflows or overflows. |
+ | |
+ | Complexity weight : 2 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+
+#if (!L_SHR_IS_INLINE)
+Word32 L_shr (Word32 L_var1, Word16 var2)
+{
+ Word32 L_var_out;
+
+ if (var2 < 0)
+ {
+ L_var_out = L_shl (L_var1, (Word16)-var2);
+ }
+ else
+ {
+ if (var2 >= 31)
+ {
+ L_var_out = (L_var1 < 0L) ? -1 : 0;
+ }
+ else
+ {
+ if (L_var1 < 0)
+ {
+ L_var_out = ~((~L_var1) >> var2);
+ }
+ else
+ {
+ L_var_out = L_var1 >> var2;
+ }
+ }
+ }
+ return (L_var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : shr_r |
+ | |
+ | Purpose : |
+ | |
+ | Same as shr(var1,var2) but with rounding. Saturate the result in case of|
+ | underflows or overflows : |
+ | - If var2 is greater than zero : |
+ | if (sub(shl(shr(var1,var2),1),shr(var1,sub(var2,1)))) |
+ | is equal to zero |
+ | then |
+ | shr_r(var1,var2) = shr(var1,var2) |
+ | else |
+ | shr_r(var1,var2) = add(shr(var1,var2),1) |
+ | - If var2 is less than or equal to zero : |
+ | shr_r(var1,var2) = shr(var1,var2). |
+ | |
+ | Complexity weight : 2 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+#if (!SHR_R_IS_INLINE)
+Word16 shr_r (Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+
+ if (var2 > 15)
+ {
+ var_out = 0;
+ }
+ else
+ {
+ var_out = shr (var1, var2);
+
+ if (var2 > 0)
+ {
+ if ((var1 & ((Word16) 1 << (var2 - 1))) != 0)
+ {
+ var_out++;
+ }
+ }
+ }
+
+ return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : mac_r |
+ | |
+ | Purpose : |
+ | |
+ | Multiply var1 by var2 and shift the result left by 1. Add the 32 bit |
+ | result to L_var3 with saturation. Round the LS 16 bits of the result |
+ | into the MS 16 bits with saturation and shift the result right by 16. |
+ | Return a 16 bit result. |
+ | mac_r(L_var3,var1,var2) = round(L_mac(L_var3,var1,var2)) |
+ | |
+ | Complexity weight : 2 |
+ | |
+ | Inputs : |
+ | |
+ | L_var3 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0x0000 8000 <= L_var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+#if (!MAC_R_IS_INLINE)
+Word16 mac_r (Word32 L_var3, Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+
+ L_var3 = L_mac (L_var3, var1, var2);
+ L_var3 = L_add (L_var3, (Word32) 0x00008000L);
+ var_out = extract_h (L_var3);
+
+ return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : msu_r |
+ | |
+ | Purpose : |
+ | |
+ | Multiply var1 by var2 and shift the result left by 1. Subtract the 32 |
+ | bit result to L_var3 with saturation. Round the LS 16 bits of the res- |
+ | ult into the MS 16 bits with saturation and shift the result right by |
+ | 16. Return a 16 bit result. |
+ | msu_r(L_var3,var1,var2) = round(L_msu(L_var3,var1,var2)) |
+ | |
+ | Complexity weight : 2 |
+ | |
+ | Inputs : |
+ | |
+ | L_var3 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= L_var3 <= 0x7fff ffff. |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0x0000 8000 <= L_var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+#if (!MSU_R_IS_INLINE)
+Word16 msu_r (Word32 L_var3, Word16 var1, Word16 var2)
+{
+ Word16 var_out;
+
+ L_var3 = L_msu (L_var3, var1, var2);
+ L_var3 = L_add (L_var3, (Word32) 0x00008000L);
+ var_out = extract_h (L_var3);
+
+ return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_deposit_h |
+ | |
+ | Purpose : |
+ | |
+ | Deposit the 16 bit var1 into the 16 MS bits of the 32 bit output. The |
+ | 16 LS bits of the output are zeroed. |
+ | |
+ | Complexity weight : 2 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= var_out <= 0x7fff 0000. |
+ |___________________________________________________________________________|
+*/
+//Word32 L_deposit_h (Word16 var1)
+//{
+// Word32 L_var_out;
+//
+// L_var_out = (Word32) var1 << 16;
+//
+// return (L_var_out);
+//}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_deposit_l |
+ | |
+ | Purpose : |
+ | |
+ | Deposit the 16 bit var1 into the 16 LS bits of the 32 bit output. The |
+ | 16 MS bits of the output are sign extended. |
+ | |
+ | Complexity weight : 2 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0xFFFF 8000 <= var_out <= 0x0000 7fff. |
+ |___________________________________________________________________________|
+*/
+//Word32 L_deposit_l (Word16 var1)
+//{
+// Word32 L_var_out;
+//
+// L_var_out = (Word32) var1;
+//
+// return (L_var_out);
+//}
+
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_shr_r |
+ | |
+ | Purpose : |
+ | |
+ | Same as L_shr(L_var1,var2) but with rounding. Saturate the result in |
+ | case of underflows or overflows : |
+ | - If var2 is greater than zero : |
+ | if (L_sub(L_shl(L_shr(L_var1,var2),1),L_shr(L_var1,sub(var2,1))))|
+ | is equal to zero |
+ | then |
+ | L_shr_r(L_var1,var2) = L_shr(L_var1,var2) |
+ | else |
+ | L_shr_r(L_var1,var2) = L_add(L_shr(L_var1,var2),1) |
+ | - If var2 is less than or equal to zero : |
+ | L_shr_r(L_var1,var2) = L_shr(L_var1,var2). |
+ | |
+ | Complexity weight : 3 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= var1 <= 0x7fff ffff. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+#if (!L_SHR_R_IS_INLINE)
+Word32 L_shr_r (Word32 L_var1, Word16 var2)
+{
+ Word32 L_var_out;
+
+ if (var2 > 31)
+ {
+ L_var_out = 0;
+ }
+ else
+ {
+ L_var_out = L_shr (L_var1, var2);
+
+ if (var2 > 0)
+ {
+ if ((L_var1 & ((Word32) 1 << (var2 - 1))) != 0)
+ {
+ L_var_out++;
+ }
+ }
+ }
+
+ return (L_var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : L_abs |
+ | |
+ | Purpose : |
+ | |
+ | Absolute value of L_var1; Saturate in case where the input is |
+ | -214783648 |
+ | |
+ | Complexity weight : 3 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= var1 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | L_var_out |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x0000 0000 <= var_out <= 0x7fff ffff. |
+ |___________________________________________________________________________|
+*/
+//Word32 L_abs (Word32 L_var1)
+//{
+// Word32 L_var_out;
+//
+// if (L_var1 == MIN_32)
+// {
+// L_var_out = MAX_32;
+// }
+// else
+// {
+// if (L_var1 < 0)
+// {
+// L_var_out = -L_var1;
+// }
+// else
+// {
+// L_var_out = L_var1;
+// }
+// }
+//
+// return (L_var_out);
+//}
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : norm_s |
+ | |
+ | Purpose : |
+ | |
+ | Produces the number of left shift needed to normalize the 16 bit varia- |
+ | ble var1 for positive values on the interval with minimum of 16384 and |
+ | maximum of 32767, and for negative values on the interval with minimum |
+ | of -32768 and maximum of -16384; in order to normalize the result, the |
+ | following operation must be done : |
+ | norm_var1 = shl(var1,norm_s(var1)). |
+ | |
+ | Complexity weight : 15 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0xffff 8000 <= var1 <= 0x0000 7fff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0x0000 0000 <= var_out <= 0x0000 000f. |
+ |___________________________________________________________________________|
+*/
+
+#if (!NORM_S_IS_INLINE)
+Word16 norm_s (Word16 var1)
+{
+ Word16 var_out;
+
+ if (var1 == 0)
+ {
+ var_out = 0;
+ }
+ else
+ {
+ if (var1 == -1)
+ {
+ var_out = 15;
+ }
+ else
+ {
+ if (var1 < 0)
+ {
+ var1 = (Word16)~var1;
+ }
+ for (var_out = 0; var1 < 0x4000; var_out++)
+ {
+ var1 <<= 1;
+ }
+ }
+ }
+
+ return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : div_s |
+ | |
+ | Purpose : |
+ | |
+ | Produces a result which is the fractional integer division of var1 by |
+ | var2; var1 and var2 must be positive and var2 must be greater or equal |
+ | to var1; the result is positive (leading bit equal to 0) and truncated |
+ | to 16 bits. |
+ | If var1 = var2 then div(var1,var2) = 32767. |
+ | |
+ | Complexity weight : 18 |
+ | |
+ | Inputs : |
+ | |
+ | var1 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0x0000 0000 <= var1 <= var2 and var2 != 0. |
+ | |
+ | var2 |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : var1 <= var2 <= 0x0000 7fff and var2 != 0. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0x0000 0000 <= var_out <= 0x0000 7fff. |
+ | It's a Q15 value (point between b15 and b14). |
+ |___________________________________________________________________________|
+*/
+
+#if (!DIV_S_IS_INLINE)
+Word16 div_s (Word16 var1, Word16 var2)
+{
+ Word16 var_out = 0;
+ Word16 iteration;
+ Word32 L_num;
+ Word32 L_denom;
+
+ if (var1 == 0)
+ {
+ var_out = 0;
+ }
+ else
+ {
+ if (var1 == var2)
+ {
+ var_out = MAX_16;
+ }
+ else
+ {
+ L_num = L_deposit_l (var1);
+ L_denom = L_deposit_l (var2);
+
+ for (iteration = 0; iteration < 15; iteration++)
+ {
+ var_out <<= 1;
+ L_num <<= 1;
+
+ if (L_num >= L_denom)
+ {
+ L_num = L_sub(L_num, L_denom);
+ var_out = add (var_out, 1);
+ }
+ }
+ }
+ }
+
+ return (var_out);
+}
+#endif
+
+/*___________________________________________________________________________
+ | |
+ | Function Name : norm_l |
+ | |
+ | Purpose : |
+ | |
+ | Produces the number of left shifts needed to normalize the 32 bit varia-|
+ | ble L_var1 for positive values on the interval with minimum of |
+ | 1073741824 and maximum of 2147483647, and for negative values on the in-|
+ | terval with minimum of -2147483648 and maximum of -1073741824; in order |
+ | to normalize the result, the following operation must be done : |
+ | norm_L_var1 = L_shl(L_var1,norm_l(L_var1)). |
+ | |
+ | Complexity weight : 30 |
+ | |
+ | Inputs : |
+ | |
+ | L_var1 |
+ | 32 bit long signed integer (Word32) whose value falls in the |
+ | range : 0x8000 0000 <= var1 <= 0x7fff ffff. |
+ | |
+ | Outputs : |
+ | |
+ | none |
+ | |
+ | Return Value : |
+ | |
+ | var_out |
+ | 16 bit short signed integer (Word16) whose value falls in the |
+ | range : 0x0000 0000 <= var_out <= 0x0000 001f. |
+ |___________________________________________________________________________|
+*/
+
+#if (!NORM_L_IS_INLINE)
+Word16 norm_l (Word32 L_var1)
+{
+ Word16 var_out;
+
+ if (L_var1 == 0)
+ {
+ var_out = 0;
+ }
+ else
+ {
+ if (L_var1 == (Word32) 0xffffffffL)
+ {
+ var_out = 31;
+ }
+ else
+ {
+ if (L_var1 < 0)
+ {
+ L_var1 = ~L_var1;
+ }
+ for (var_out = 0; L_var1 < (Word32) 0x40000000L; var_out++)
+ {
+ L_var1 <<= 1;
+ }
+ }
+ }
+
+ return (var_out);
+}
+#endif
diff --git a/media/libstagefright/codecs/aacenc/basic_op/oper_32b.c b/media/libstagefright/codecs/aacenc/basic_op/oper_32b.c
index 906a9df..0ad82f0 100644
--- a/media/libstagefright/codecs/aacenc/basic_op/oper_32b.c
+++ b/media/libstagefright/codecs/aacenc/basic_op/oper_32b.c
@@ -1,23 +1,23 @@
-/*
- ** Copyright 2003-2010, VisualOn, Inc.
- **
- ** 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.
- */
-/*******************************************************************************
- File: oper_32b.c
-
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** 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.
+ */
+/*******************************************************************************
+ File: oper_32b.c
+
Content: This file contains operations in double precision.
-
+
*******************************************************************************/
#include "typedef.h"
@@ -198,164 +198,164 @@ Word32 Div_32 (Word32 L_num, Word32 denom)
return (L_32);
}
-
-/*!
-
- \brief calculates the log dualis times 4 of argument
- iLog4(x) = (Word32)(4 * log(value)/log(2.0))
-
- \return ilog4 value
-
-*/
-Word16 iLog4(Word32 value)
-{
- Word16 iLog4;
-
- if(value != 0){
- Word32 tmp;
- Word16 tmp16;
- iLog4 = norm_l(value);
- tmp = (value << iLog4);
- tmp16 = round16(tmp);
- tmp = L_mult(tmp16, tmp16);
- tmp16 = round16(tmp);
- tmp = L_mult(tmp16, tmp16);
- tmp16 = round16(tmp);
-
- iLog4 = (-(iLog4 << 2) - norm_s(tmp16)) - 1;
- }
- else {
- iLog4 = -128; /* -(INT_BITS*4); */
- }
-
- return iLog4;
-}
-
-#define step(shift) \
- if ((0x40000000l >> shift) + root <= value) \
- { \
- value -= (0x40000000l >> shift) + root; \
- root = (root >> 1) | (0x40000000l >> shift); \
- } else { \
- root = root >> 1; \
- }
-
-Word32 rsqrt(Word32 value, /*!< Operand to square root (0.0 ... 1) */
- Word32 accuracy) /*!< Number of valid bits that will be calculated */
-{
- Word32 root = 0;
- Word32 scale;
-
- if(value < 0)
- return 0;
-
- scale = norm_l(value);
- if(scale & 1) scale--;
-
- value <<= scale;
-
- step( 0); step( 2); step( 4); step( 6);
- step( 8); step(10); step(12); step(14);
- step(16); step(18); step(20); step(22);
- step(24); step(26); step(28); step(30);
-
- scale >>= 1;
- if (root < value)
- ++root;
-
- root >>= scale;
- return root* 46334;
-}
-
-static const Word32 pow2Table[POW2_TABLE_SIZE] = {
-0x7fffffff, 0x7fa765ad, 0x7f4f08ae, 0x7ef6e8da,
-0x7e9f0606, 0x7e476009, 0x7deff6b6, 0x7d98c9e6,
-0x7d41d96e, 0x7ceb2523, 0x7c94acde, 0x7c3e7073,
-0x7be86fb9, 0x7b92aa88, 0x7b3d20b6, 0x7ae7d21a,
-0x7a92be8b, 0x7a3de5df, 0x79e947ef, 0x7994e492,
-0x7940bb9e, 0x78ecccec, 0x78991854, 0x78459dac,
-0x77f25cce, 0x779f5591, 0x774c87cc, 0x76f9f359,
-0x76a7980f, 0x765575c8, 0x76038c5b, 0x75b1dba2,
-0x75606374, 0x750f23ab, 0x74be1c20, 0x746d4cac,
-0x741cb528, 0x73cc556d, 0x737c2d55, 0x732c3cba,
-0x72dc8374, 0x728d015d, 0x723db650, 0x71eea226,
-0x719fc4b9, 0x71511de4, 0x7102ad80, 0x70b47368,
-0x70666f76, 0x7018a185, 0x6fcb096f, 0x6f7da710,
-0x6f307a41, 0x6ee382de, 0x6e96c0c3, 0x6e4a33c9,
-0x6dfddbcc, 0x6db1b8a8, 0x6d65ca38, 0x6d1a1057,
-0x6cce8ae1, 0x6c8339b2, 0x6c381ca6, 0x6bed3398,
-0x6ba27e66, 0x6b57fce9, 0x6b0daeff, 0x6ac39485,
-0x6a79ad56, 0x6a2ff94f, 0x69e6784d, 0x699d2a2c,
-0x69540ec9, 0x690b2601, 0x68c26fb1, 0x6879ebb6,
-0x683199ed, 0x67e97a34, 0x67a18c68, 0x6759d065,
-0x6712460b, 0x66caed35, 0x6683c5c3, 0x663ccf92,
-0x65f60a80, 0x65af766a, 0x6569132f, 0x6522e0ad,
-0x64dcdec3, 0x64970d4f, 0x64516c2e, 0x640bfb41,
-0x63c6ba64, 0x6381a978, 0x633cc85b, 0x62f816eb,
-0x62b39509, 0x626f4292, 0x622b1f66, 0x61e72b65,
-0x61a3666d, 0x615fd05f, 0x611c6919, 0x60d9307b,
-0x60962665, 0x60534ab7, 0x60109d51, 0x5fce1e12,
-0x5f8bccdb, 0x5f49a98c, 0x5f07b405, 0x5ec5ec26,
-0x5e8451d0, 0x5e42e4e3, 0x5e01a540, 0x5dc092c7,
-0x5d7fad59, 0x5d3ef4d7, 0x5cfe6923, 0x5cbe0a1c,
-0x5c7dd7a4, 0x5c3dd19c, 0x5bfdf7e5, 0x5bbe4a61,
-0x5b7ec8f2, 0x5b3f7377, 0x5b0049d4, 0x5ac14bea,
-0x5a82799a, 0x5a43d2c6, 0x5a055751, 0x59c7071c,
-0x5988e209, 0x594ae7fb, 0x590d18d3, 0x58cf7474,
-0x5891fac1, 0x5854ab9b, 0x581786e6, 0x57da8c83,
-0x579dbc57, 0x57611642, 0x57249a29, 0x56e847ef,
-0x56ac1f75, 0x567020a0, 0x56344b52, 0x55f89f70,
-0x55bd1cdb, 0x5581c378, 0x55469329, 0x550b8bd4,
-0x54d0ad5b, 0x5495f7a1, 0x545b6a8b, 0x542105fd,
-0x53e6c9db, 0x53acb607, 0x5372ca68, 0x533906e0,
-0x52ff6b55, 0x52c5f7aa, 0x528cabc3, 0x52538786,
-0x521a8ad7, 0x51e1b59a, 0x51a907b4, 0x5170810b,
-0x51382182, 0x50ffe8fe, 0x50c7d765, 0x508fec9c,
-0x50582888, 0x50208b0e, 0x4fe91413, 0x4fb1c37c,
-0x4f7a9930, 0x4f439514, 0x4f0cb70c, 0x4ed5ff00,
-0x4e9f6cd4, 0x4e69006e, 0x4e32b9b4, 0x4dfc988c,
-0x4dc69cdd, 0x4d90c68b, 0x4d5b157e, 0x4d25899c,
-0x4cf022ca, 0x4cbae0ef, 0x4c85c3f1, 0x4c50cbb8,
-0x4c1bf829, 0x4be7492b, 0x4bb2bea5, 0x4b7e587d,
-0x4b4a169c, 0x4b15f8e6, 0x4ae1ff43, 0x4aae299b,
-0x4a7a77d5, 0x4a46e9d6, 0x4a137f88, 0x49e038d0,
-0x49ad1598, 0x497a15c4, 0x4947393f, 0x49147fee,
-0x48e1e9ba, 0x48af768a, 0x487d2646, 0x484af8d6,
-0x4818ee22, 0x47e70611, 0x47b5408c, 0x47839d7b,
-0x47521cc6, 0x4720be55, 0x46ef8210, 0x46be67e0,
-0x468d6fae, 0x465c9961, 0x462be4e2, 0x45fb521a,
-0x45cae0f2, 0x459a9152, 0x456a6323, 0x453a564d,
-0x450a6abb, 0x44daa054, 0x44aaf702, 0x447b6ead,
-0x444c0740, 0x441cc0a3, 0x43ed9ac0, 0x43be9580,
-0x438fb0cb, 0x4360ec8d, 0x433248ae, 0x4303c517,
-0x42d561b4, 0x42a71e6c, 0x4278fb2b, 0x424af7da,
-0x421d1462, 0x41ef50ae, 0x41c1aca8, 0x41942839,
-0x4166c34c, 0x41397dcc, 0x410c57a2, 0x40df50b8,
-0x40b268fa, 0x4085a051, 0x4058f6a8, 0x402c6be9
-};
-
-/*!
-
- \brief calculates 2 ^ (x/y) for x<=0, y > 0, x <= 32768 * y
-
- avoids integer division
-
- \return
-*/
-Word32 pow2_xy(Word32 x, Word32 y)
-{
- Word32 iPart;
- Word32 fPart;
- Word32 res;
- Word32 tmp, tmp2;
- Word32 shift, shift2;
-
- tmp2 = -x;
- iPart = tmp2 / y;
- fPart = tmp2 - iPart*y;
- iPart = min(iPart,INT_BITS-1);
-
- res = pow2Table[(POW2_TABLE_SIZE*fPart)/y] >> iPart;
-
- return(res);
+
+/*!
+
+ \brief calculates the log dualis times 4 of argument
+ iLog4(x) = (Word32)(4 * log(value)/log(2.0))
+
+ \return ilog4 value
+
+*/
+Word16 iLog4(Word32 value)
+{
+ Word16 iLog4;
+
+ if(value != 0){
+ Word32 tmp;
+ Word16 tmp16;
+ iLog4 = norm_l(value);
+ tmp = (value << iLog4);
+ tmp16 = round16(tmp);
+ tmp = L_mult(tmp16, tmp16);
+ tmp16 = round16(tmp);
+ tmp = L_mult(tmp16, tmp16);
+ tmp16 = round16(tmp);
+
+ iLog4 = (-(iLog4 << 2) - norm_s(tmp16)) - 1;
+ }
+ else {
+ iLog4 = -128; /* -(INT_BITS*4); */
+ }
+
+ return iLog4;
+}
+
+#define step(shift) \
+ if ((0x40000000l >> shift) + root <= value) \
+ { \
+ value -= (0x40000000l >> shift) + root; \
+ root = (root >> 1) | (0x40000000l >> shift); \
+ } else { \
+ root = root >> 1; \
+ }
+
+Word32 rsqrt(Word32 value, /*!< Operand to square root (0.0 ... 1) */
+ Word32 accuracy) /*!< Number of valid bits that will be calculated */
+{
+ Word32 root = 0;
+ Word32 scale;
+
+ if(value < 0)
+ return 0;
+
+ scale = norm_l(value);
+ if(scale & 1) scale--;
+
+ value <<= scale;
+
+ step( 0); step( 2); step( 4); step( 6);
+ step( 8); step(10); step(12); step(14);
+ step(16); step(18); step(20); step(22);
+ step(24); step(26); step(28); step(30);
+
+ scale >>= 1;
+ if (root < value)
+ ++root;
+
+ root >>= scale;
+ return root* 46334;
+}
+
+static const Word32 pow2Table[POW2_TABLE_SIZE] = {
+0x7fffffff, 0x7fa765ad, 0x7f4f08ae, 0x7ef6e8da,
+0x7e9f0606, 0x7e476009, 0x7deff6b6, 0x7d98c9e6,
+0x7d41d96e, 0x7ceb2523, 0x7c94acde, 0x7c3e7073,
+0x7be86fb9, 0x7b92aa88, 0x7b3d20b6, 0x7ae7d21a,
+0x7a92be8b, 0x7a3de5df, 0x79e947ef, 0x7994e492,
+0x7940bb9e, 0x78ecccec, 0x78991854, 0x78459dac,
+0x77f25cce, 0x779f5591, 0x774c87cc, 0x76f9f359,
+0x76a7980f, 0x765575c8, 0x76038c5b, 0x75b1dba2,
+0x75606374, 0x750f23ab, 0x74be1c20, 0x746d4cac,
+0x741cb528, 0x73cc556d, 0x737c2d55, 0x732c3cba,
+0x72dc8374, 0x728d015d, 0x723db650, 0x71eea226,
+0x719fc4b9, 0x71511de4, 0x7102ad80, 0x70b47368,
+0x70666f76, 0x7018a185, 0x6fcb096f, 0x6f7da710,
+0x6f307a41, 0x6ee382de, 0x6e96c0c3, 0x6e4a33c9,
+0x6dfddbcc, 0x6db1b8a8, 0x6d65ca38, 0x6d1a1057,
+0x6cce8ae1, 0x6c8339b2, 0x6c381ca6, 0x6bed3398,
+0x6ba27e66, 0x6b57fce9, 0x6b0daeff, 0x6ac39485,
+0x6a79ad56, 0x6a2ff94f, 0x69e6784d, 0x699d2a2c,
+0x69540ec9, 0x690b2601, 0x68c26fb1, 0x6879ebb6,
+0x683199ed, 0x67e97a34, 0x67a18c68, 0x6759d065,
+0x6712460b, 0x66caed35, 0x6683c5c3, 0x663ccf92,
+0x65f60a80, 0x65af766a, 0x6569132f, 0x6522e0ad,
+0x64dcdec3, 0x64970d4f, 0x64516c2e, 0x640bfb41,
+0x63c6ba64, 0x6381a978, 0x633cc85b, 0x62f816eb,
+0x62b39509, 0x626f4292, 0x622b1f66, 0x61e72b65,
+0x61a3666d, 0x615fd05f, 0x611c6919, 0x60d9307b,
+0x60962665, 0x60534ab7, 0x60109d51, 0x5fce1e12,
+0x5f8bccdb, 0x5f49a98c, 0x5f07b405, 0x5ec5ec26,
+0x5e8451d0, 0x5e42e4e3, 0x5e01a540, 0x5dc092c7,
+0x5d7fad59, 0x5d3ef4d7, 0x5cfe6923, 0x5cbe0a1c,
+0x5c7dd7a4, 0x5c3dd19c, 0x5bfdf7e5, 0x5bbe4a61,
+0x5b7ec8f2, 0x5b3f7377, 0x5b0049d4, 0x5ac14bea,
+0x5a82799a, 0x5a43d2c6, 0x5a055751, 0x59c7071c,
+0x5988e209, 0x594ae7fb, 0x590d18d3, 0x58cf7474,
+0x5891fac1, 0x5854ab9b, 0x581786e6, 0x57da8c83,
+0x579dbc57, 0x57611642, 0x57249a29, 0x56e847ef,
+0x56ac1f75, 0x567020a0, 0x56344b52, 0x55f89f70,
+0x55bd1cdb, 0x5581c378, 0x55469329, 0x550b8bd4,
+0x54d0ad5b, 0x5495f7a1, 0x545b6a8b, 0x542105fd,
+0x53e6c9db, 0x53acb607, 0x5372ca68, 0x533906e0,
+0x52ff6b55, 0x52c5f7aa, 0x528cabc3, 0x52538786,
+0x521a8ad7, 0x51e1b59a, 0x51a907b4, 0x5170810b,
+0x51382182, 0x50ffe8fe, 0x50c7d765, 0x508fec9c,
+0x50582888, 0x50208b0e, 0x4fe91413, 0x4fb1c37c,
+0x4f7a9930, 0x4f439514, 0x4f0cb70c, 0x4ed5ff00,
+0x4e9f6cd4, 0x4e69006e, 0x4e32b9b4, 0x4dfc988c,
+0x4dc69cdd, 0x4d90c68b, 0x4d5b157e, 0x4d25899c,
+0x4cf022ca, 0x4cbae0ef, 0x4c85c3f1, 0x4c50cbb8,
+0x4c1bf829, 0x4be7492b, 0x4bb2bea5, 0x4b7e587d,
+0x4b4a169c, 0x4b15f8e6, 0x4ae1ff43, 0x4aae299b,
+0x4a7a77d5, 0x4a46e9d6, 0x4a137f88, 0x49e038d0,
+0x49ad1598, 0x497a15c4, 0x4947393f, 0x49147fee,
+0x48e1e9ba, 0x48af768a, 0x487d2646, 0x484af8d6,
+0x4818ee22, 0x47e70611, 0x47b5408c, 0x47839d7b,
+0x47521cc6, 0x4720be55, 0x46ef8210, 0x46be67e0,
+0x468d6fae, 0x465c9961, 0x462be4e2, 0x45fb521a,
+0x45cae0f2, 0x459a9152, 0x456a6323, 0x453a564d,
+0x450a6abb, 0x44daa054, 0x44aaf702, 0x447b6ead,
+0x444c0740, 0x441cc0a3, 0x43ed9ac0, 0x43be9580,
+0x438fb0cb, 0x4360ec8d, 0x433248ae, 0x4303c517,
+0x42d561b4, 0x42a71e6c, 0x4278fb2b, 0x424af7da,
+0x421d1462, 0x41ef50ae, 0x41c1aca8, 0x41942839,
+0x4166c34c, 0x41397dcc, 0x410c57a2, 0x40df50b8,
+0x40b268fa, 0x4085a051, 0x4058f6a8, 0x402c6be9
+};
+
+/*!
+
+ \brief calculates 2 ^ (x/y) for x<=0, y > 0, x <= 32768 * y
+
+ avoids integer division
+
+ \return
+*/
+Word32 pow2_xy(Word32 x, Word32 y)
+{
+ Word32 iPart;
+ Word32 fPart;
+ Word32 res;
+ Word32 tmp, tmp2;
+ Word32 shift, shift2;
+
+ tmp2 = -x;
+ iPart = tmp2 / y;
+ fPart = tmp2 - iPart*y;
+ iPart = min(iPart,INT_BITS-1);
+
+ res = pow2Table[(POW2_TABLE_SIZE*fPart)/y] >> iPart;
+
+ return(res);
} \ No newline at end of file
diff --git a/media/libstagefright/codecs/aacenc/basic_op/oper_32b.h b/media/libstagefright/codecs/aacenc/basic_op/oper_32b.h
index 4119bc3..1d35e5e 100644
--- a/media/libstagefright/codecs/aacenc/basic_op/oper_32b.h
+++ b/media/libstagefright/codecs/aacenc/basic_op/oper_32b.h
@@ -1,86 +1,86 @@
-/*
- ** Copyright 2003-2010, VisualOn, Inc.
- **
- ** 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.
- */
-/*******************************************************************************
- File: oper_32b.h
-
- Content: Double precision operations
-
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** 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.
+ */
+/*******************************************************************************
+ File: oper_32b.h
+
+ Content: Double precision operations
+
*******************************************************************************/
#ifndef __OPER_32b_H
#define __OPER_32b_H
-
-#include "typedef.h"
+
+#include "typedef.h"
#ifdef __cplusplus
extern "C" {
#endif
-
-#define POW2_TABLE_BITS 8
-#define POW2_TABLE_SIZE (1<<POW2_TABLE_BITS)
+
+#define POW2_TABLE_BITS 8
+#define POW2_TABLE_SIZE (1<<POW2_TABLE_BITS)
void L_Extract (Word32 L_32, Word16 *hi, Word16 *lo);
Word32 L_Comp (Word16 hi, Word16 lo);
Word32 Mpy_32 (Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2);
Word32 Mpy_32_16 (Word16 hi, Word16 lo, Word16 n);
Word32 Div_32 (Word32 L_num, Word32 denom);
-Word16 iLog4(Word32 value);
-Word32 rsqrt(Word32 value, Word32 accuracy);
-Word32 pow2_xy(Word32 x, Word32 y);
-
-__inline Word32 L_mpy_ls(Word32 L_var2, Word16 var1)
-{
- unsigned short swLow1;
- Word16 swHigh1;
- Word32 l_var_out;
-
- swLow1 = (unsigned short)(L_var2);
- swHigh1 = (Word16)(L_var2 >> 16);
-
- l_var_out = (long)swLow1 * (long)var1 >> 15;
-
- l_var_out += swHigh1 * var1 << 1;
-
- return(l_var_out);
-}
-
-__inline Word32 L_mpy_wx(Word32 L_var2, Word16 var1)
-{
-#if ARMV5TE_L_MPY_LS
- Word32 result;
- asm volatile(
- "SMULWB %[result], %[L_var2], %[var1] \n"
- :[result]"+r"(result)
- :[L_var2]"r"(L_var2), [var1]"r"(var1)
- );
- return result;
-#else
- unsigned short swLow1;
- Word16 swHigh1;
- Word32 l_var_out;
-
- swLow1 = (unsigned short)(L_var2);
- swHigh1 = (Word16)(L_var2 >> 16);
-
- l_var_out = (long)swLow1 * (long)var1 >> 16;
- l_var_out += swHigh1 * var1;
-
- return(l_var_out);
-#endif
-}
+Word16 iLog4(Word32 value);
+Word32 rsqrt(Word32 value, Word32 accuracy);
+Word32 pow2_xy(Word32 x, Word32 y);
+
+__inline Word32 L_mpy_ls(Word32 L_var2, Word16 var1)
+{
+ unsigned short swLow1;
+ Word16 swHigh1;
+ Word32 l_var_out;
+
+ swLow1 = (unsigned short)(L_var2);
+ swHigh1 = (Word16)(L_var2 >> 16);
+
+ l_var_out = (long)swLow1 * (long)var1 >> 15;
+
+ l_var_out += swHigh1 * var1 << 1;
+
+ return(l_var_out);
+}
+
+__inline Word32 L_mpy_wx(Word32 L_var2, Word16 var1)
+{
+#if ARMV5TE_L_MPY_LS
+ Word32 result;
+ asm volatile(
+ "SMULWB %[result], %[L_var2], %[var1] \n"
+ :[result]"+r"(result)
+ :[L_var2]"r"(L_var2), [var1]"r"(var1)
+ );
+ return result;
+#else
+ unsigned short swLow1;
+ Word16 swHigh1;
+ Word32 l_var_out;
+
+ swLow1 = (unsigned short)(L_var2);
+ swHigh1 = (Word16)(L_var2 >> 16);
+
+ l_var_out = (long)swLow1 * (long)var1 >> 16;
+ l_var_out += swHigh1 * var1;
+
+ return(l_var_out);
+#endif
+}
#ifdef __cplusplus
}
diff --git a/media/libstagefright/codecs/aacenc/basic_op/typedef.h b/media/libstagefright/codecs/aacenc/basic_op/typedef.h
index d3a626a..1030803 100644
--- a/media/libstagefright/codecs/aacenc/basic_op/typedef.h
+++ b/media/libstagefright/codecs/aacenc/basic_op/typedef.h
@@ -1,23 +1,23 @@
-/*
- ** Copyright 2003-2010, VisualOn, Inc.
- **
- ** 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.
- */
-/*******************************************************************************
- File: typedef.h
-
- Content: type defined for defferent paltform
-
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** 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.
+ */
+/*******************************************************************************
+ File: typedef.h
+
+ Content: type defined for defferent paltform
+
*******************************************************************************/
#ifndef typedef_h
@@ -54,7 +54,7 @@ typedef int Flag;
/*
* use (improved) type definition file typdefs.h and add a "Flag" type
- */
+ */
#include "typedefs.h"
typedef int Flag;
diff --git a/media/libstagefright/codecs/aacenc/basic_op/typedefs.h b/media/libstagefright/codecs/aacenc/basic_op/typedefs.h
index 7d16fca..c7e774b 100644
--- a/media/libstagefright/codecs/aacenc/basic_op/typedefs.h
+++ b/media/libstagefright/codecs/aacenc/basic_op/typedefs.h
@@ -1,56 +1,56 @@
-/*
- ** Copyright 2003-2010, VisualOn, Inc.
- **
- ** 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.
- */
-/*******************************************************************************
- File: typedefs.h
-
- Content: type defined or const defined
-
+/*
+ ** Copyright 2003-2010, VisualOn, Inc.
+ **
+ ** 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.
+ */
+/*******************************************************************************
+ File: typedefs.h
+
+ Content: type defined or const defined
+
*******************************************************************************/
#ifndef typedefs_h
#define typedefs_h "$Id $"
-#ifndef CHAR_BIT
-#define CHAR_BIT 8 /* number of bits in a char */
-#endif
-
-#ifndef VOAAC_SHRT_MAX
-#define VOAAC_SHRT_MAX (32767) /* maximum (signed) short value */
-#endif
-
-#ifndef VOAAC_SHRT_MIN
-#define VOAAC_SHRT_MIN (-32768) /* minimum (signed) short value */
-#endif
-
-/* Define NULL pointer value */
-#ifndef NULL
-#ifdef __cplusplus
-#define NULL 0
-#else
-#define NULL ((void *)0)
-#endif
+#ifndef CHAR_BIT
+#define CHAR_BIT 8 /* number of bits in a char */
+#endif
+
+#ifndef VOAAC_SHRT_MAX
+#define VOAAC_SHRT_MAX (32767) /* maximum (signed) short value */
+#endif
+
+#ifndef VOAAC_SHRT_MIN
+#define VOAAC_SHRT_MIN (-32768) /* minimum (signed) short value */
+#endif
+
+/* Define NULL pointer value */
+#ifndef NULL
+#ifdef __cplusplus
+#define NULL 0
+#else
+#define NULL ((void *)0)
+#endif
#endif
#ifndef assert
#define assert(_Expression) ((void)0)
#endif
-
-#ifdef LINUX
-#define __inline static __inline__
-#endif
+
+#ifdef LINUX
+#define __inline static __inline__
+#endif
#define INT_BITS 32
/*
@@ -80,100 +80,100 @@ typedef unsigned short UWord16;
typedef long Word32;
typedef unsigned long UWord32;
-
-
+
+
#ifdef LINUX
typedef long long Word64;
typedef unsigned long long UWord64;
#else
-typedef __int64 Word64;
+typedef __int64 Word64;
typedef unsigned __int64 UWord64;
#endif
-#ifndef min
-#define min(a,b) ( a < b ? a : b)
-#endif
-
-#ifndef max
-#define max(a,b) ( a > b ? a : b)
-#endif
-
-#ifdef ARM_INASM
-#ifdef ARMV5_INASM
-#define ARMV5E_INASM 1
-#endif
-#define ARMV4_INASM 1
-#endif
-
-#if ARMV4_INASM
- #define ARMV5TE_SAT 1
- #define ARMV5TE_ADD 1
- #define ARMV5TE_SUB 1
- #define ARMV5TE_SHL 1
- #define ARMV5TE_SHR 1
- #define ARMV5TE_L_SHL 1
- #define ARMV5TE_L_SHR 1
-#endif//ARMV4
-#if ARMV5E_INASM
- #define ARMV5TE_L_ADD 1
- #define ARMV5TE_L_SUB 1
- #define ARMV5TE_L_MULT 1
- #define ARMV5TE_L_MAC 1
- #define ARMV5TE_L_MSU 1
-
-
- #define ARMV5TE_DIV_S 1
- #define ARMV5TE_ROUND 1
- #define ARMV5TE_MULT 1
-
- #define ARMV5TE_NORM_S 1
- #define ARMV5TE_NORM_L 1
- #define ARMV5TE_L_MPY_LS 1
+#ifndef min
+#define min(a,b) ( a < b ? a : b)
+#endif
+
+#ifndef max
+#define max(a,b) ( a > b ? a : b)
+#endif
+
+#ifdef ARM_INASM
+#ifdef ARMV5_INASM
+#define ARMV5E_INASM 1
+#endif
+#define ARMV4_INASM 1
+#endif
+
+#if ARMV4_INASM
+ #define ARMV5TE_SAT 1
+ #define ARMV5TE_ADD 1
+ #define ARMV5TE_SUB 1
+ #define ARMV5TE_SHL 1
+ #define ARMV5TE_SHR 1
+ #define ARMV5TE_L_SHL 1
+ #define ARMV5TE_L_SHR 1
+#endif//ARMV4
+#if ARMV5E_INASM
+ #define ARMV5TE_L_ADD 1
+ #define ARMV5TE_L_SUB 1
+ #define ARMV5TE_L_MULT 1
+ #define ARMV5TE_L_MAC 1
+ #define ARMV5TE_L_MSU 1
+
+
+ #define ARMV5TE_DIV_S 1
+ #define ARMV5TE_ROUND 1
+ #define ARMV5TE_MULT 1
+
+ #define ARMV5TE_NORM_S 1
+ #define ARMV5TE_NORM_L 1
+ #define ARMV5TE_L_MPY_LS 1
#endif
-
-//basic operation functions optimization flags
-#define SATRUATE_IS_INLINE 1 //define saturate as inline function
-#define SHL_IS_INLINE 1 //define shl as inline function
-#define SHR_IS_INLINE 1 //define shr as inline function
-#define L_MULT_IS_INLINE 1 //define L_mult as inline function
-#define L_MSU_IS_INLINE 1 //define L_msu as inline function
-#define L_SUB_IS_INLINE 1 //define L_sub as inline function
-#define L_SHL_IS_INLINE 1 //define L_shl as inline function
-#define L_SHR_IS_INLINE 1 //define L_shr as inline function
-#define ADD_IS_INLINE 1 //define add as inline function //add, inline is the best
-#define SUB_IS_INLINE 1 //define sub as inline function //sub, inline is the best
-#define DIV_S_IS_INLINE 1 //define div_s as inline function
-#define MULT_IS_INLINE 1 //define mult as inline function
-#define NORM_S_IS_INLINE 1 //define norm_s as inline function
-#define NORM_L_IS_INLINE 1 //define norm_l as inline function
-#define ROUND_IS_INLINE 1 //define round as inline function
-#define L_MAC_IS_INLINE 1 //define L_mac as inline function
-#define L_ADD_IS_INLINE 1 //define L_add as inline function
-#define EXTRACT_H_IS_INLINE 1 //define extract_h as inline function
-#define EXTRACT_L_IS_INLINE 1 //define extract_l as inline function //???
-#define MULT_R_IS_INLINE 1 //define mult_r as inline function
-#define SHR_R_IS_INLINE 1 //define shr_r as inline function
-#define MAC_R_IS_INLINE 1 //define mac_r as inline function
-#define MSU_R_IS_INLINE 1 //define msu_r as inline function
-#define L_SHR_R_IS_INLINE 1 //define L_shr_r as inline function
-
-#define PREFIX voAACEnc
-#define LINK0(x, y, z) LINK1(x,y,z)
-#define LINK1(x,y,z) x##y##z
-#define ADD_PREFIX(func) LINK0(PREFIX, _, func)
-
-#define L_Extract ADD_PREFIX(L_Extract)
-#define L_Comp ADD_PREFIX(L_Comp)
-#define Mpy_32 ADD_PREFIX(Mpy_32)
-#define Mpy_32_16 ADD_PREFIX(Mpy_32_16)
-#define Div_32 ADD_PREFIX(Div_32)
-#define iLog4 ADD_PREFIX(iLog4)
-#define rsqrt ADD_PREFIX(rsqrt)
-#define pow2_xy ADD_PREFIX(pow2_xy)
-#define L_mpy_ls ADD_PREFIX(L_mpy_ls)
-#define L_mpy_wx ADD_PREFIX(L_mpy_wx)
-
-#define mem_malloc ADD_PREFIX(mem_malloc)
-#define mem_free ADD_PREFIX(mem_free)
-
+
+//basic operation functions optimization flags
+#define SATRUATE_IS_INLINE 1 //define saturate as inline function
+#define SHL_IS_INLINE 1 //define shl as inline function
+#define SHR_IS_INLINE 1 //define shr as inline function
+#define L_MULT_IS_INLINE 1 //define L_mult as inline function
+#define L_MSU_IS_INLINE 1 //define L_msu as inline function
+#define L_SUB_IS_INLINE 1 //define L_sub as inline function
+#define L_SHL_IS_INLINE 1 //define L_shl as inline function
+#define L_SHR_IS_INLINE 1 //define L_shr as inline function
+#define ADD_IS_INLINE 1 //define add as inline function //add, inline is the best
+#define SUB_IS_INLINE 1 //define sub as inline function //sub, inline is the best
+#define DIV_S_IS_INLINE 1 //define div_s as inline function
+#define MULT_IS_INLINE 1 //define mult as inline function
+#define NORM_S_IS_INLINE 1 //define norm_s as inline function
+#define NORM_L_IS_INLINE 1 //define norm_l as inline function
+#define ROUND_IS_INLINE 1 //define round as inline function
+#define L_MAC_IS_INLINE 1 //define L_mac as inline function
+#define L_ADD_IS_INLINE 1 //define L_add as inline function
+#define EXTRACT_H_IS_INLINE 1 //define extract_h as inline function
+#define EXTRACT_L_IS_INLINE 1 //define extract_l as inline function //???
+#define MULT_R_IS_INLINE 1 //define mult_r as inline function
+#define SHR_R_IS_INLINE 1 //define shr_r as inline function
+#define MAC_R_IS_INLINE 1 //define mac_r as inline function
+#define MSU_R_IS_INLINE 1 //define msu_r as inline function
+#define L_SHR_R_IS_INLINE 1 //define L_shr_r as inline function
+
+#define PREFIX voAACEnc
+#define LINK0(x, y, z) LINK1(x,y,z)
+#define LINK1(x,y,z) x##y##z
+#define ADD_PREFIX(func) LINK0(PREFIX, _, func)
+
+#define L_Extract ADD_PREFIX(L_Extract)
+#define L_Comp ADD_PREFIX(L_Comp)
+#define Mpy_32 ADD_PREFIX(Mpy_32)
+#define Mpy_32_16 ADD_PREFIX(Mpy_32_16)
+#define Div_32 ADD_PREFIX(Div_32)
+#define iLog4 ADD_PREFIX(iLog4)
+#define rsqrt ADD_PREFIX(rsqrt)
+#define pow2_xy ADD_PREFIX(pow2_xy)
+#define L_mpy_ls ADD_PREFIX(L_mpy_ls)
+#define L_mpy_wx ADD_PREFIX(L_mpy_wx)
+
+#define mem_malloc ADD_PREFIX(mem_malloc)
+#define mem_free ADD_PREFIX(mem_free)
+
#endif