1 /****************************************************************************** 2 * * 3 * Copyright (C) 2018 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ***************************************************************************** 18 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore 19 */ 20 #ifndef IXHEAACD_BASIC_OPS_ARR_H 21 #define IXHEAACD_BASIC_OPS_ARR_H 22 23 static PLATFORM_INLINE WORD16 norm32_arr(WORD32 *word32_arr, WORD32 n) { 24 WORD32 i; 25 WORD32 max_bits = 0; 26 27 for (i = 0; i < n; i++) { 28 max_bits = max_bits | ixheaacd_abs32_sat(word32_arr[i]); 29 } 30 31 return (ixheaacd_norm32(max_bits)); 32 } 33 34 static PLATFORM_INLINE WORD16 norm16_arr(WORD16 *word16_arr, WORD32 n) { 35 WORD32 i; 36 WORD16 max_bits = 0; 37 38 for (i = 0; i < n; i++) { 39 max_bits = max_bits | ixheaacd_abs16_sat(word16_arr[i]); 40 } 41 42 return (norm16(max_bits)); 43 } 44 45 static PLATFORM_INLINE VOID shl32_arr(WORD32 *word32_arr, WORD16 shift, 46 WORD32 n) { 47 WORD32 i; 48 49 for (i = 0; i < n; i++) { 50 word32_arr[i] = ixheaacd_shl32(word32_arr[i], shift); 51 } 52 53 return; 54 } 55 56 static PLATFORM_INLINE VOID ixheaacd_shr32_arr(WORD32 *word32_arr, WORD16 shift, 57 WORD32 n) { 58 WORD32 i; 59 60 for (i = 0; i < n; i++) { 61 *word32_arr = ixheaacd_shr32(*word32_arr, shift); 62 word32_arr++; 63 } 64 65 return; 66 } 67 68 static PLATFORM_INLINE VOID shl32_arr_dir(WORD32 *word32_arr, WORD16 shift, 69 WORD32 n) { 70 WORD32 i; 71 72 for (i = 0; i < n; i++) { 73 word32_arr[i] = ixheaacd_shl32_dir(word32_arr[i], shift); 74 } 75 76 return; 77 } 78 79 static PLATFORM_INLINE VOID shr32_arr_dir(WORD32 *word32_arr, WORD16 shift, 80 WORD32 n) { 81 WORD32 i; 82 83 for (i = 0; i < n; i++) { 84 word32_arr[i] = ixheaacd_shr32_dir(word32_arr[i], shift); 85 } 86 87 return; 88 } 89 90 static PLATFORM_INLINE VOID shl32_arr_dir_sat(WORD32 *word32_arr, WORD16 shift, 91 WORD32 n) { 92 WORD32 i; 93 94 for (i = 0; i < n; i++) { 95 word32_arr[i] = ixheaacd_shl32_dir_sat(word32_arr[i], shift); 96 } 97 98 return; 99 } 100 101 static PLATFORM_INLINE VOID shr32_arr_dir_sat(WORD32 *word32_arr, WORD16 shift, 102 WORD32 n) { 103 WORD32 i; 104 105 for (i = 0; i < n; i++) { 106 word32_arr[i] = shr32_dir_sat(word32_arr[i], shift); 107 } 108 109 return; 110 } 111 112 static PLATFORM_INLINE VOID ixheaacd_shl32_arr_sat(WORD32 *word32_arr, 113 WORD16 shift, WORD32 n) { 114 WORD32 i; 115 116 for (i = 0; i < n; i++) { 117 *word32_arr = ixheaacd_shl32_sat(*word32_arr, shift); 118 word32_arr++; 119 } 120 121 return; 122 } 123 124 static PLATFORM_INLINE VOID shl16_arr(WORD16 *word16_arr, WORD16 shift, 125 WORD32 n) { 126 WORD32 i; 127 128 for (i = 0; i < n; i++) { 129 word16_arr[i] = ixheaacd_shl16(word16_arr[i], shift); 130 } 131 132 return; 133 } 134 135 static PLATFORM_INLINE VOID ixheaacd_shr16_arr(WORD16 *word16_arr, WORD16 shift, 136 WORD32 n) { 137 WORD32 i; 138 139 for (i = 0; i < n; i++) { 140 *word16_arr = ixheaacd_shr16(*word16_arr, shift); 141 word16_arr++; 142 } 143 144 return; 145 } 146 147 static PLATFORM_INLINE VOID shl16_arr_dir(WORD16 *word16_arr, WORD16 shift, 148 WORD32 n) { 149 WORD32 i; 150 151 for (i = 0; i < n; i++) { 152 word16_arr[i] = shl16_dir(word16_arr[i], shift); 153 } 154 155 return; 156 } 157 158 static PLATFORM_INLINE VOID shr16_arr_dir(WORD16 *word16_arr, WORD16 shift, 159 WORD32 n) { 160 WORD32 i; 161 162 for (i = 0; i < n; i++) { 163 word16_arr[i] = shr16_dir(word16_arr[i], shift); 164 } 165 166 return; 167 } 168 169 static PLATFORM_INLINE VOID shl16_arr_dir_sat(WORD16 *word16_arr, WORD16 shift, 170 WORD32 n) { 171 WORD32 i; 172 173 for (i = 0; i < n; i++) { 174 word16_arr[i] = shl16_dir_sat(word16_arr[i], shift); 175 } 176 177 return; 178 } 179 180 static PLATFORM_INLINE VOID shr16_arr_dir_sat(WORD16 *word16_arr, WORD16 shift, 181 WORD32 n) { 182 WORD32 i; 183 184 for (i = 0; i < n; i++) { 185 word16_arr[i] = ixheaacd_shr16_dir_sat(word16_arr[i], shift); 186 } 187 188 return; 189 } 190 191 static PLATFORM_INLINE VOID shl16_arr_sat(WORD16 *word16_arr, WORD16 shift, 192 WORD32 n) { 193 WORD32 i; 194 195 for (i = 0; i < n; i++) { 196 word16_arr[i] = ixheaacd_shl16_sat(word16_arr[i], shift); 197 } 198 199 return; 200 } 201 202 static PLATFORM_INLINE VOID shl3216_arr(WORD32 *word32_arr, WORD16 *word16_arr, 203 WORD16 shift, WORD32 n) { 204 WORD32 i; 205 206 for (i = 0; i < n; i++) { 207 word16_arr[i] = (WORD16)ixheaacd_shl32_dir(word32_arr[i], shift); 208 } 209 210 return; 211 } 212 213 static PLATFORM_INLINE WORD32 max32_arr(WORD32 *word32_arr, WORD32 n) { 214 WORD32 i; 215 216 WORD32 max_value; 217 218 max_value = word32_arr[0]; 219 220 for (i = 1; i < n; i++) { 221 max_value = ixheaacd_max32(max_value, word32_arr[i]); 222 } 223 224 return max_value; 225 } 226 227 static PLATFORM_INLINE WORD32 min32_arr(WORD32 *word32_arr, WORD32 n) { 228 WORD32 i; 229 230 WORD32 min_value; 231 232 min_value = word32_arr[0]; 233 234 for (i = 1; i < n; i++) { 235 min_value = ixheaacd_min32(min_value, word32_arr[i]); 236 } 237 238 return min_value; 239 } 240 241 static PLATFORM_INLINE WORD16 max16_arr(WORD16 *word16_arr, WORD32 n) { 242 WORD32 i; 243 244 WORD16 max_value; 245 246 max_value = word16_arr[0]; 247 248 for (i = 1; i < n; i++) { 249 max_value = ixheaacd_max16(max_value, word16_arr[i]); 250 } 251 252 return max_value; 253 } 254 255 static PLATFORM_INLINE WORD16 min16_arr(WORD16 *word16_arr, WORD32 n) { 256 WORD32 i; 257 258 WORD16 min_value; 259 260 min_value = word16_arr[0]; 261 262 for (i = 1; i < n; i++) { 263 min_value = ixheaacd_min16(min_value, word16_arr[i]); 264 } 265 266 return min_value; 267 } 268 269 static PLATFORM_INLINE VOID copy8(WORD8 *src, WORD8 *dst, WORD32 n) { 270 WORD32 i; 271 272 for (i = 0; i < n; i++) { 273 dst[i] = src[i]; 274 } 275 276 return; 277 } 278 279 static PLATFORM_INLINE VOID copy16(WORD16 *src, WORD16 *dst, WORD32 n) { 280 WORD32 i; 281 282 for (i = 0; i < n; i++) { 283 dst[i] = src[i]; 284 } 285 286 return; 287 } 288 289 static PLATFORM_INLINE VOID copy32(WORD32 *src, WORD32 *dst, WORD32 n) { 290 WORD32 i; 291 292 for (i = 0; i < n; i++) { 293 dst[i] = src[i]; 294 } 295 296 return; 297 } 298 299 static PLATFORM_INLINE VOID delay8(WORD8 *word8_arr, WORD32 delay, WORD32 n) { 300 WORD32 source_index; 301 WORD32 destination_index; 302 303 source_index = (n - 1) - delay; 304 destination_index = n - 1; 305 306 for (; source_index >= 0; source_index--, destination_index--) { 307 word8_arr[destination_index] = word8_arr[source_index]; 308 } 309 310 return; 311 } 312 313 static PLATFORM_INLINE VOID delay16(WORD16 *word16_arr, WORD32 delay, 314 WORD32 n) { 315 WORD32 source_index; 316 WORD32 destination_index; 317 318 source_index = (n - 1) - delay; 319 destination_index = n - 1; 320 321 for (; source_index >= 0; source_index--, destination_index--) { 322 word16_arr[destination_index] = word16_arr[source_index]; 323 } 324 325 return; 326 } 327 328 static PLATFORM_INLINE VOID delay32(WORD32 *word32_arr, WORD32 delay, 329 WORD32 n) { 330 WORD32 source_index; 331 WORD32 destination_index; 332 333 source_index = (n - 1) - delay; 334 destination_index = n - 1; 335 336 for (; source_index >= 0; source_index--, destination_index--) { 337 word32_arr[destination_index] = word32_arr[source_index]; 338 } 339 340 return; 341 } 342 343 static PLATFORM_INLINE VOID copy_reverse16(WORD16 *src, WORD16 *dst, WORD32 n) { 344 WORD32 i; 345 346 for (i = 0; i < n; i++) { 347 *dst++ = *src--; 348 } 349 350 return; 351 } 352 353 static PLATFORM_INLINE VOID copy_reverse32(WORD32 *src, WORD32 *dst, WORD32 n) { 354 WORD32 i; 355 356 for (i = 0; i < n; i++) { 357 *dst++ = *src--; 358 } 359 360 return; 361 } 362 363 static PLATFORM_INLINE VOID set_val8(WORD8 *word8_arr, WORD8 set_val, 364 WORD32 n) { 365 WORD32 i; 366 367 for (i = 0; i < n; i++) { 368 word8_arr[i] = set_val; 369 } 370 371 return; 372 } 373 374 static PLATFORM_INLINE VOID set_val16(WORD16 *word16_arr, WORD16 set_val, 375 WORD32 n) { 376 WORD32 i; 377 378 for (i = 0; i < n; i++) { 379 word16_arr[i] = set_val; 380 } 381 382 return; 383 } 384 385 static PLATFORM_INLINE VOID set_val32(WORD32 *word32_arr, WORD32 set_val, 386 WORD32 n) { 387 WORD32 i; 388 389 for (i = 0; i < n; i++) { 390 word32_arr[i] = set_val; 391 } 392 393 return; 394 } 395 396 static PLATFORM_INLINE VOID set_zero8(WORD8 *word8_arr, WORD32 n) { 397 WORD32 i; 398 399 for (i = 0; i < n; i++) { 400 word8_arr[i] = 0; 401 } 402 403 return; 404 } 405 406 static PLATFORM_INLINE VOID set_zero16(WORD16 *word16_arr, WORD32 n) { 407 WORD32 i; 408 409 for (i = 0; i < n; i++) { 410 word16_arr[i] = 0; 411 } 412 413 return; 414 } 415 416 static PLATFORM_INLINE VOID set_zero32(WORD32 *word32_arr, WORD32 n) { 417 WORD32 i; 418 419 for (i = 0; i < n; i++) { 420 word32_arr[i] = 0; 421 } 422 423 return; 424 } 425 #endif 426