1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 /**************************************************************************************** 19 Portions of this file are derived from the following 3GPP standard: 20 21 3GPP TS 26.073 22 ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec 23 Available from http://www.3gpp.org 24 25 (C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) 26 Permission to distribute, modify and use this file under the standard license 27 terms listed above has been obtained from the copyright holder. 28 ****************************************************************************************/ 29 /* 30 31 Filename: /audio/gsm_amr/c/include/mult.h 32 33 ------------------------------------------------------------------------------ 34 REVISION HISTORY 35 36 Description: Created separate header file for mult function. 37 38 Description: Changed prototype of the mult() function. Instead of using global 39 a pointer to overflow flag is now passed into the function. 40 41 Description: Updated copyright information. 42 Updated variable name from "overflow" to "pOverflow" to match 43 with original function declaration. 44 45 Description: Moved _cplusplus #ifdef after Include section. 46 47 Description: Providing support for ARM and Linux-ARM assembly instructions. 48 49 Who: Date: 50 Description: 51 52 ------------------------------------------------------------------------------ 53 INCLUDE DESCRIPTION 54 55 This file contains all the constant definitions and prototype definitions 56 needed by the mult function. 57 58 ------------------------------------------------------------------------------ 59 */ 60 61 #ifndef MULT_H 62 #define MULT_H 63 64 /*---------------------------------------------------------------------------- 65 ; INCLUDES 66 ----------------------------------------------------------------------------*/ 67 68 #include "basicop_malloc.h" 69 70 /*--------------------------------------------------------------------------*/ 71 #ifdef __cplusplus 72 extern "C" 73 { 74 #endif 75 76 /*---------------------------------------------------------------------------- 77 ; MACROS 78 ; Define module specific macros here 79 ----------------------------------------------------------------------------*/ 80 81 /*---------------------------------------------------------------------------- 82 ; DEFINES 83 ; Include all pre-processor statements here. 84 ----------------------------------------------------------------------------*/ 85 86 /*---------------------------------------------------------------------------- 87 ; EXTERNAL VARIABLES REFERENCES 88 ; Declare variables used in this module but defined elsewhere 89 ----------------------------------------------------------------------------*/ 90 91 /*---------------------------------------------------------------------------- 92 ; SIMPLE TYPEDEF'S 93 ----------------------------------------------------------------------------*/ 94 95 /*---------------------------------------------------------------------------- 96 ; ENUMERATED TYPEDEF'S 97 ----------------------------------------------------------------------------*/ 98 99 /*---------------------------------------------------------------------------- 100 ; STRUCTURES TYPEDEF'S 101 ----------------------------------------------------------------------------*/ 102 103 /*---------------------------------------------------------------------------- 104 ; GLOBAL FUNCTION DEFINITIONS 105 ; Function Prototype declaration 106 ----------------------------------------------------------------------------*/ 107 #if defined(PV_ARM_V5) 108 mult(Word16 var1,Word16 var2,Flag * pOverflow)109 __inline Word16 mult(Word16 var1, Word16 var2, Flag *pOverflow) 110 { 111 Word32 product; 112 113 OSCL_UNUSED_ARG(pOverflow); 114 115 __asm 116 { 117 SMULBB product, var1, var2 118 MOV product, product, ASR #15 119 CMP product, 0x7FFF 120 MOVGE product, 0x7FFF 121 } 122 123 return ((Word16) product); 124 } 125 126 #elif defined(PV_ARM_GCC_V5) 127 128 __inline Word16 mult(Word16 var1, Word16 var2, Flag *pOverflow) 129 { 130 register Word32 ra = var1; 131 register Word32 rb = var2; 132 Word32 product; 133 Word32 temp = 0x7FFF; 134 135 OSCL_UNUSED_ARG(pOverflow); 136 137 asm volatile("smulbb %0, %1, %2" 138 : "=r"(product) 139 : "r"(ra), "r"(rb) 140 ); 141 asm volatile("mov %0, %1, ASR #15" 142 : "=r"(product) 143 : "r"(product) 144 ); 145 asm volatile("cmp %0, %1" 146 : "=r"(product) 147 : "r"(temp) 148 ); 149 asm volatile("movge %0, %1" 150 : "=r"(product) 151 : "r"(temp) 152 ); 153 154 return ((Word16) product); 155 } 156 157 #else /* C EQUIVALENT */ 158 159 static inline Word16 mult(Word16 var1, Word16 var2, Flag *pOverflow) 160 { 161 register Word32 product; 162 163 product = ((Word32) var1 * var2) >> 15; 164 165 /* Saturate result (if necessary). */ 166 /* var1 * var2 >0x00007fff is the only case */ 167 /* that saturation occurs. */ 168 169 if (product > 0x00007fffL) 170 { 171 *pOverflow = 1; 172 product = (Word32) MAX_16; 173 } 174 175 176 /* Return the product as a 16 bit value by type casting Word32 to Word16 */ 177 178 return ((Word16) product); 179 } 180 181 #endif 182 /*---------------------------------------------------------------------------- 183 ; END 184 ----------------------------------------------------------------------------*/ 185 #ifdef __cplusplus 186 } 187 #endif 188 189 #endif /* _MULT_H_ */ 190 191