/* * Copyright (C) 2013 The Android Open Source Project * * 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. */ #ifndef ANDROID_AUDIO_RESAMPLER_FIR_OPS_H #define ANDROID_AUDIO_RESAMPLER_FIR_OPS_H namespace android { #if defined(__arm__) && !defined(__thumb__) #define USE_INLINE_ASSEMBLY (true) #else #define USE_INLINE_ASSEMBLY (false) #endif #if USE_INLINE_ASSEMBLY && defined(__ARM_NEON__) #define USE_NEON (true) #include #else #define USE_NEON (false) #endif template struct is_same { static const bool value = false; }; template struct is_same // partial specialization { static const bool value = true; }; static inline int32_t mulRL(int left, int32_t in, uint32_t vRL) { #if USE_INLINE_ASSEMBLY int32_t out; if (left) { asm( "smultb %[out], %[in], %[vRL] \n" : [out]"=r"(out) : [in]"%r"(in), [vRL]"r"(vRL) : ); } else { asm( "smultt %[out], %[in], %[vRL] \n" : [out]"=r"(out) : [in]"%r"(in), [vRL]"r"(vRL) : ); } return out; #else int16_t v = left ? static_cast(vRL) : static_cast(vRL>>16); return static_cast((static_cast(in) * v) >> 16); #endif } static inline int32_t mulAdd(int16_t in, int16_t v, int32_t a) { #if USE_INLINE_ASSEMBLY int32_t out; asm( "smlabb %[out], %[v], %[in], %[a] \n" : [out]"=r"(out) : [in]"%r"(in), [v]"r"(v), [a]"r"(a) : ); return out; #else return a + v * in; #endif } static inline int32_t mulAdd(int16_t in, int32_t v, int32_t a) { #if USE_INLINE_ASSEMBLY int32_t out; asm( "smlawb %[out], %[v], %[in], %[a] \n" : [out]"=r"(out) : [in]"%r"(in), [v]"r"(v), [a]"r"(a) : ); return out; #else return a + static_cast((static_cast(v) * in) >> 16); #endif } static inline int32_t mulAdd(int32_t in, int32_t v, int32_t a) { #if USE_INLINE_ASSEMBLY int32_t out; asm( "smmla %[out], %[v], %[in], %[a] \n" : [out]"=r"(out) : [in]"%r"(in), [v]"r"(v), [a]"r"(a) : ); return out; #else return a + static_cast((static_cast(v) * in) >> 32); #endif } static inline int32_t mulAddRL(int left, uint32_t inRL, int16_t v, int32_t a) { #if USE_INLINE_ASSEMBLY int32_t out; if (left) { asm( "smlabb %[out], %[v], %[inRL], %[a] \n" : [out]"=r"(out) : [inRL]"%r"(inRL), [v]"r"(v), [a]"r"(a) : ); } else { asm( "smlabt %[out], %[v], %[inRL], %[a] \n" : [out]"=r"(out) : [inRL]"%r"(inRL), [v]"r"(v), [a]"r"(a) : ); } return out; #else int16_t s = left ? static_cast(inRL) : static_cast(inRL>>16); return a + v * s; #endif } static inline int32_t mulAddRL(int left, uint32_t inRL, int32_t v, int32_t a) { #if USE_INLINE_ASSEMBLY int32_t out; if (left) { asm( "smlawb %[out], %[v], %[inRL], %[a] \n" : [out]"=r"(out) : [inRL]"%r"(inRL), [v]"r"(v), [a]"r"(a) : ); } else { asm( "smlawt %[out], %[v], %[inRL], %[a] \n" : [out]"=r"(out) : [inRL]"%r"(inRL), [v]"r"(v), [a]"r"(a) : ); } return out; #else int16_t s = left ? static_cast(inRL) : static_cast(inRL>>16); return a + static_cast((static_cast(v) * s) >> 16); #endif } }; // namespace android #endif /*ANDROID_AUDIO_RESAMPLER_FIR_OPS_H*/