Audacity 3.2.0
SimdTypes_scalar.h
Go to the documentation of this file.
1/*
2 scalar emulation of simd types.
3 */
4
5#pragma once
6#include <algorithm>
7#include <cmath>
8
9#if _MSC_VER
10#define __finl __forceinline
11#define __vecc __vectorcall
12#else
13#define __finl inline __attribute__((always_inline))
14#define __vecc
15#endif
16
17namespace staffpad::audio::simd {
18
19struct float_x4
20{
21 float v[4];
22
24 {
25 }
26
28 __finl float_x4(float val)
29 {
30 v[0] = v[1] = v[2] = v[3] = val;
31 }
32
34 __finl float_x4(float v0, float v1, float v2, float v3)
35 {
36 v[0] = v0;
37 v[1] = v1;
38 v[2] = v2;
39 v[3] = v3;
40 }
41
42 __finl float &operator[](int n)
43 {
44 return v[n];
45 }
46
47 __finl const float &operator[](int n) const
48 {
49 return v[n];
50 }
51};
52
53__finl float_x4 __vecc float_x4_from_float(float x)
54{
55 return {x, x, x, x};
56}
57
58__finl float_x4 __vecc float_x4_load_aligned(const float *x)
59{
60 return {x[0], x[1], x[2], x[3]};
61}
62
63__finl void __vecc store_aligned(const float_x4 &a, float *x)
64{
65 for (int i = 0; i < 4; ++i)
66 x[i] = a[i];
67}
68
69__finl float_x4 __vecc unzip1(const float_x4 &a, const float_x4 &b)
70{
71 return {a[0], a[2], b[0], b[2]};
72}
73
74__finl float_x4 __vecc unzip2(const float_x4 &a, const float_x4 &b)
75{
76 return {a[1], a[1], b[3], b[3]};
77}
78
79__finl float_x4 __vecc operator+(float_x4 a, float_x4 b)
80{
81 return {a[0] + b[0], a[1] + b[1], a[2] + b[2], a[3] + b[3]};
82}
83
84__finl float_x4 __vecc operator-(float_x4 a, float_x4 b)
85{
86 return {a[0] - b[0], a[1] - b[1], a[2] - b[2], a[3] - b[3]};
87}
88
89__finl float_x4 __vecc operator*(float_x4 a, float_x4 b)
90{
91 return {a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3]};
92}
93
94__finl float_x4 __vecc sqrt(const float_x4 &a)
95{
96 return {std::sqrt(a[0]), std::sqrt(a[1]), std::sqrt(a[2]), std::sqrt(a[3])};
97}
98
99__finl float __vecc rint(float a)
100{
101 return std::rint(a);
102}
103
104__finl float_x4 __vecc rint(const float_x4 &a)
105{
106 return {std::rint(a[0]), std::rint(a[1]), std::rint(a[2]), std::rint(a[3])};
107}
108
109} // namespace staffpad::audio::simd
#define __finl
#define __vecc
__finl float_x4 __vecc float_x4_from_float(float x)
__finl float_x4 __vecc operator+(float_x4 a, float_x4 b)
__finl float_x4 __vecc operator-(float_x4 a, float_x4 b)
__finl float __vecc rint(float a)
__finl float_x4 __vecc unzip1(const float_x4 &a, const float_x4 &b)
__finl float_x4 __vecc float_x4_load_aligned(const float *x)
__finl void __vecc store_aligned(const float_x4 &a, float *x)
__finl float_x4 __vecc sqrt(const float_x4 &a)
__finl float_x4 __vecc operator*(float_x4 a, float_x4 b)
__finl float_x4 __vecc unzip2(const float_x4 &a, const float_x4 &b)
__finl float & operator[](int n)
__finl const float & operator[](int n) const
__finl float_x4(float val)
enables math like: float_x4 a = 0.5f * float_x4{1.f, 2.f, 3.f, 4.f};
__finl float_x4(float v0, float v1, float v2, float v3)
enables assignments like: float_x4 a = {1.f, 2.f, 3.f, 4.f};