RavEngine
Loading...
Searching...
No Matches
simd_macros.h
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(__aarch64__) || defined(_M_ARM64)) || (defined(__arm__) && defined(__ARM_NEON__)))
36// ARM NEON is enabled.
37#include <arm_neon.h>
38typedef float32x4_t SimdVector;
39#define SIMD_NEON
40#define SIMD_LENGTH 4
41#define SIMD_MULTIPLY(a, b) vmulq_f32(a, b)
42#define SIMD_ADD(a, b) vaddq_f32(a, b)
43#define SIMD_SUB(a, b) vsubq_f32(a, b)
44#define SIMD_MULTIPLY_ADD(a, b, c) vmlaq_f32(c, a, b)
45#define SIMD_SQRT(a) vrecpeq_f32(vrsqrteq_f32(a))
46#define SIMD_RECIPROCAL_SQRT(a) vrsqrteq_f32(a)
47#define SIMD_LOAD_ONE_FLOAT(p) vld1q_dup_f32(&(p))
48#else
49// No SIMD optimizations enabled.
50#include "base/misc_math.h"
51typedef float SimdVector;
52#define SIMD_DISABLED
53#define SIMD_LENGTH 1
54#define SIMD_MULTIPLY(a, b) ((a) * (b))
55#define SIMD_ADD(a, b) ((a) + (b))
56#define SIMD_SUB(a, b) ((a) - (b))
57#define SIMD_MULTIPLY_ADD(a, b, c) ((a) * (b) + (c))
58#define SIMD_SQRT(a) (1.0f / FastReciprocalSqrt(a))
59#define SIMD_RECIPROCAL_SQRT(a) FastReciprocalSqrt(a)
60#define SIMD_LOAD_ONE_FLOAT(p) (p)
61#warning "Not using SIMD optimizations!"
62#endif
63
64#endif // RESONANCE_AUDIO_BASE_SIMD_MACROS_H_