1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_AUDIO_CPU_X86_VECTOR_MATH_SSE_H_
6 #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_AUDIO_CPU_X86_VECTOR_MATH_SSE_H_
7 
8 #include <cstddef>
9 
10 #include "third_party/blink/renderer/platform/audio/audio_array.h"
11 
12 namespace blink {
13 namespace vector_math {
14 namespace sse {
15 
16 constexpr size_t kBitsPerRegister = 128u;
17 constexpr size_t kPackedFloatsPerRegister = kBitsPerRegister / 32u;
18 constexpr size_t kFramesToProcessMask = ~(kPackedFloatsPerRegister - 1u);
19 
20 bool IsAligned(const float*);
21 
22 // Direct vector convolution:
23 // dest[k] = sum(source[k+m]*filter[m*filter_stride]) for all m
24 // provided that |prepared_filter_p| is |prepared_filter->Data()| and that
25 // |prepared_filter| is prepared with |PrepareFilterForConv|.
26 void Conv(const float* source_p,
27           const float* prepared_filter_p,
28           float* dest_p,
29           uint32_t frames_to_process,
30           size_t filter_size);
31 
32 void PrepareFilterForConv(const float* filter_p,
33                           int filter_stride,
34                           size_t filter_size,
35                           AudioFloatArray* prepared_filter);
36 
37 // dest[k] = source1[k] + source2[k]
38 void Vadd(const float* source1p,
39           const float* source2p,
40           float* dest_p,
41           uint32_t frames_to_process);
42 
43 // dest[k] = clip(source[k], low_threshold, high_threshold)
44 //         = max(low_threshold, min(high_threshold, source[k]))
45 void Vclip(const float* source_p,
46            const float* low_threshold_p,
47            const float* high_threshold_p,
48            float* dest_p,
49            uint32_t frames_to_process);
50 
51 // *max_p = max(*max_p, source_max) where
52 // source_max = max(abs(source[k])) for all k
53 void Vmaxmgv(const float* source_p, float* max_p, uint32_t frames_to_process);
54 
55 // dest[k] = source1[k] * source2[k]
56 void Vmul(const float* source1p,
57           const float* source2p,
58           float* dest_p,
59           uint32_t frames_to_process);
60 
61 // dest[k] += scale * source[k]
62 void Vsma(const float* source_p,
63           const float* scale,
64           float* dest_p,
65           uint32_t frames_to_process);
66 
67 // dest[k] = scale * source[k]
68 void Vsmul(const float* source_p,
69            const float* scale,
70            float* dest_p,
71            uint32_t frames_to_process);
72 
73 // sum += sum(source[k]^2) for all k
74 void Vsvesq(const float* source_p, float* sum_p, uint32_t frames_to_process);
75 
76 // real_dest[k] = real1[k] * real2[k] - imag1[k] * imag2[k]
77 // imag_dest[k] = real1[k] * imag2[k] + imag1[k] * real2[k]
78 void Zvmul(const float* real1p,
79            const float* imag1p,
80            const float* real2p,
81            const float* imag2p,
82            float* real_dest_p,
83            float* imag_dest_p,
84            uint32_t frames_to_process);
85 
86 }  // namespace sse
87 }  // namespace vector_math
88 }  // namespace blink
89 
90 #endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_AUDIO_CPU_X86_VECTOR_MATH_SSE_H_
91