2 Copyright (C) 2007 Paul sDavis
3 Written by Sampo Savolainen
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <xmmintrin.h>
22 #include <ardour/types.h>
25 x86_sse_find_peaks(float *buf, nframes_t nframes, float *min, float *max)
27 __m128 current_max, current_min, work;
29 // Load max and min values into all four slots of the XMM registers
30 current_min = _mm_set1_ps(*min);
31 current_max = _mm_set1_ps(*max);
33 // Work input until "buf" reaches 16 byte alignment
34 while ( ((unsigned long)buf) % 16 != 0 && nframes > 0) {
36 // Load the next float into the work buffer
37 work = _mm_set1_ps(*buf);
39 current_min = _mm_min_ps(current_min, work);
40 current_max = _mm_max_ps(current_max, work);
46 // work through aligned buffers
47 while (nframes >= 4) {
49 work = _mm_load_ps(buf);
51 current_min = _mm_min_ps(current_min, work);
52 current_max = _mm_max_ps(current_max, work);
58 // work through the rest < 4 samples
59 while ( nframes > 0) {
61 // Load the next float into the work buffer
62 work = _mm_set1_ps(*buf);
64 current_min = _mm_min_ps(current_min, work);
65 current_max = _mm_max_ps(current_max, work);
71 // Find min & max value in current_max through shuffle tricks
74 work = _mm_shuffle_ps(work, work, _MM_SHUFFLE(2, 3, 0, 1));
75 work = _mm_min_ps (work, current_min);
77 work = _mm_shuffle_ps(work, work, _MM_SHUFFLE(1, 0, 3, 2));
78 work = _mm_min_ps (work, current_min);
80 _mm_store_ss(min, work);
83 work = _mm_shuffle_ps(work, work, _MM_SHUFFLE(2, 3, 0, 1));
84 work = _mm_max_ps (work, current_max);
86 work = _mm_shuffle_ps(work, work, _MM_SHUFFLE(1, 0, 3, 2));
87 work = _mm_max_ps (work, current_max);
89 _mm_store_ss(max, work);