1/*
2Copyright 2018 Google Inc. All Rights Reserved.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS-IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef RESONANCE_AUDIO_BASE_SIMD_MACROS_H_
18#define RESONANCE_AUDIO_BASE_SIMD_MACROS_H_
19
20#if !defined(DISABLE_SIMD) && (defined(__x86_64__) || defined(_M_X64) || \
21 defined(i386) || defined(_M_IX86))
22// SSE1 is enabled.
23#include <xmmintrin.h>
24typedef __m128 SimdVector;
25#define SIMD_SSE
26#define SIMD_LENGTH 4
27#define SIMD_MULTIPLY(a, b) _mm_mul_ps(a, b)
28#define SIMD_ADD(a, b) _mm_add_ps(a, b)
29#define SIMD_SUB(a, b) _mm_sub_ps(a, b)
30#define SIMD_MULTIPLY_ADD(a, b, c) _mm_add_ps(_mm_mul_ps(a, b), c)
31#define SIMD_SQRT(a) _mm_rcp_ps(_mm_rsqrt_ps(a))
32#define SIMD_RECIPROCAL_SQRT(a) _mm_rsqrt_ps(a)
33#define SIMD_LOAD_ONE_FLOAT(p) _mm_set1_ps(p)
34#elif !defined(DISABLE_SIMD) && \
35 (((defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_M_ARM)) && defined(__ARM_NEON__)) || \
36 defined(_M_ARM64) || defined(__aarch64__) || defined(__ARM64__))
37// ARM NEON is enabled.
38#include <arm_neon.h>
39typedef float32x4_t SimdVector;
40#define SIMD_NEON
41#define SIMD_LENGTH 4
42#define SIMD_MULTIPLY(a, b) vmulq_f32(a, b)
43#define SIMD_ADD(a, b) vaddq_f32(a, b)
44#define SIMD_SUB(a, b) vsubq_f32(a, b)
45#define SIMD_MULTIPLY_ADD(a, b, c) vmlaq_f32(c, a, b)
46#define SIMD_SQRT(a) vrecpeq_f32(vrsqrteq_f32(a))
47#define SIMD_RECIPROCAL_SQRT(a) vrsqrteq_f32(a)
48#define SIMD_LOAD_ONE_FLOAT(p) vld1q_dup_f32(&(p))
49#else
50// No SIMD optimizations enabled.
51#include "base/misc_math.h"
52typedef float SimdVector;
53#define SIMD_DISABLED
54#define SIMD_LENGTH 1
55#define SIMD_MULTIPLY(a, b) ((a) * (b))
56#define SIMD_ADD(a, b) ((a) + (b))
57#define SIMD_SUB(a, b) ((a) - (b))
58#define SIMD_MULTIPLY_ADD(a, b, c) ((a) * (b) + (c))
59#define SIMD_SQRT(a) (1.0f / FastReciprocalSqrt(a))
60#define SIMD_RECIPROCAL_SQRT(a) FastReciprocalSqrt(a)
61#define SIMD_LOAD_ONE_FLOAT(p) (p)
62#warning "Not using SIMD optimizations!"
63#endif
64
65#endif // RESONANCE_AUDIO_BASE_SIMD_MACROS_H_
66

source code of qtmultimedia/src/3rdparty/resonance-audio/resonance_audio/base/simd_macros.h