2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
12 /* This header file includes the inline functions for ARM processors in
13 * the fix point signal processing library.
16 #ifndef WEBRTC_SPL_SPL_INL_ARMV7_H_
17 #define WEBRTC_SPL_SPL_INL_ARMV7_H_
19 /* TODO(kma): Replace some assembly code with GCC intrinsics
20 * (e.g. __builtin_clz).
23 /* This function produces result that is not bit exact with that by the generic
24 * C version in some cases, although the former is at least as accurate as the
27 static __inline int32_t WEBRTC_SPL_MUL_16_32_RSFT16(int16_t a, int32_t b) {
29 __asm __volatile ("smulwb %0, %1, %2":"=r"(tmp):"r"(b), "r"(a));
33 static __inline int32_t WEBRTC_SPL_MUL_32_32_RSFT32BI(int32_t a, int32_t b) {
35 __asm volatile ("smmulr %0, %1, %2":"=r"(tmp):"r"(a), "r"(b));
39 static __inline int32_t WEBRTC_SPL_MUL_16_16(int16_t a, int16_t b) {
41 __asm __volatile ("smulbb %0, %1, %2":"=r"(tmp):"r"(a), "r"(b));
45 // TODO(kma): add unit test.
46 static __inline int32_t WebRtc_MulAccumW16(int16_t a, int16_t b, int32_t c) {
48 __asm __volatile ("smlabb %0, %1, %2, %3":"=r"(tmp):"r"(a), "r"(b), "r"(c));
52 static __inline int16_t WebRtcSpl_AddSatW16(int16_t a, int16_t b) {
55 __asm __volatile ("qadd16 %0, %1, %2":"=r"(s_sum):"r"(a), "r"(b));
57 return (int16_t) s_sum;
60 /* TODO(kma): find the cause of unittest errors by the next two functions:
61 * http://code.google.com/p/webrtc/issues/detail?id=740.
64 static __inline int32_t WebRtcSpl_AddSatW32(int32_t l_var1, int32_t l_var2) {
67 __asm __volatile ("qadd %0, %1, %2":"=r"(l_sum):"r"(l_var1), "r"(l_var2));
72 static __inline int32_t WebRtcSpl_SubSatW32(int32_t l_var1, int32_t l_var2) {
75 __asm __volatile ("qsub %0, %1, %2":"=r"(l_sub):"r"(l_var1), "r"(l_var2));
81 static __inline int16_t WebRtcSpl_SubSatW16(int16_t var1, int16_t var2) {
84 __asm __volatile ("qsub16 %0, %1, %2":"=r"(s_sub):"r"(var1), "r"(var2));
86 return (int16_t)s_sub;
89 static __inline int16_t WebRtcSpl_GetSizeInBits(uint32_t n) {
92 __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(n));
94 return (int16_t)(32 - tmp);
97 static __inline int WebRtcSpl_NormW32(int32_t a) {
107 __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(a));
112 static __inline int WebRtcSpl_NormU32(uint32_t a) {
115 if (a == 0) return 0;
117 __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(a));
122 static __inline int WebRtcSpl_NormW16(int16_t a) {
132 __asm __volatile ("clz %0, %1":"=r"(tmp):"r"(a));
137 // TODO(kma): add unit test.
138 static __inline int16_t WebRtcSpl_SatW32ToW16(int32_t value32) {
141 __asm __volatile ("ssat %0, #16, %1" : "=r"(out) : "r"(value32));
146 #endif // WEBRTC_SPL_SPL_INL_ARMV7_H_