annotate svolume_neon.c @ 5:07763f536182 default tip

ALIGNment support
author Peter Meerwald <p.meerwald@bct-electronic.com>
date Sun, 08 Jul 2012 21:48:08 +0200
parents 1f6289166006
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
1 /*
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
2 * Copyright 2012 Peter Meerwald <p.meerwald@bct-electronic.com>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
3 */
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
4
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
5 #include <stdlib.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
6 #include <stdio.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
7 #include <stdarg.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
8 #include <string.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
9 #include <math.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
10 #include <sys/time.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
11 #include <assert.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
12
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
13
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
14 typedef short int16_t;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
15 typedef unsigned int uint32_t;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
16 typedef enum pa_sample_format {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
17 PA_SAMPLE_S16LE,
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
18 PA_SAMPLE_FLOAT32LE,
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
19 } pa_sample_format_t;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
20 #define PA_SAMPLE_S16NE PA_SAMPLE_S16LE
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
21 #define PA_SAMPLE_FLOAT32NE PA_SAMPLE_FLOAT32LE
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
22 typedef long long unsigned int pa_usec_t;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
23
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
24 #define pa_assert(x) assert(x)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
25 #define pa_assert_not_reached() assert(0)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
26
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
27 #define PA_MAX(a, b) ((a) > (b) ? (a) : (b))
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
28
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
29 typedef uint32_t pa_volume_t;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
30 #define PA_VOLUME_MUTED ((pa_volume_t) 0U)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
31 #define PA_VOLUME_MAX ((pa_volume_t) UINT32_MAX/2)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
32
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
33 #define PA_UNLIKELY(x) (x)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
34 #define PA_CLAMP_UNLIKELY(x, low, high) (PA_UNLIKELY((x) > (high)) ? (high) : (PA_UNLIKELY((x) < (low)) ? (low) : (x)))
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
35 #define PA_CLAMP_VOLUME(v) (PA_CLAMP_UNLIKELY((v), PA_VOLUME_MUTED, PA_VOLUME_MAX))
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
36
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
37 static void pa_log_info(const char *format, ...) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
38 va_list ap;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
39 char buf[1024];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
40 va_start(ap, format);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
41 vsprintf(buf, format, ap);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
42 printf("%s\n", buf);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
43 va_end(ap);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
44 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
45
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
46 #define pa_log_debug pa_log_info
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
47
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
48 static pa_usec_t pa_rtclock_now() {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
49 struct timeval tv;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
50 gettimeofday(&tv, NULL);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
51
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
52 return tv.tv_sec * 1000000ULL + tv.tv_usec;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
53 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
54
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
55 static void pa_volume_s16ne_c(int16_t *samples, const uint32_t *volumes, unsigned channels, unsigned length) {
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
56 unsigned channel;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
57
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
58 length /= sizeof(int16_t);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
59
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
60 for (channel = 0; length; length--) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
61 int32_t t, hi, lo;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
62
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
63 /* Multiplying the 32bit volume factor with the 16bit
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
64 * sample might result in an 48bit value. We want to
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
65 * do without 64 bit integers and hence do the
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
66 * multiplication independently for the HI and LO part
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
67 * of the volume. */
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
68
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
69 hi = volumes[channel] >> 16;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
70 lo = volumes[channel] & 0xFFFF;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
71
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
72 t = (int32_t)(*samples);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
73 t = ((t * lo) >> 16) + (t * hi);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
74 t = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
75 *samples++ = (int16_t) t;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
76
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
77 if (PA_UNLIKELY(++channel >= channels))
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
78 channel = 0;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
79 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
80 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
81
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
82 static void pa_volume_float32ne_c(float *samples, const float *volumes, unsigned channels, unsigned length) {
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
83 unsigned channel;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
84
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
85 length /= sizeof(float);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
86
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
87 for (channel = 0; length; length--) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
88 *samples++ *= volumes[channel];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
89
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
90 if (PA_UNLIKELY(++channel >= channels))
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
91 channel = 0;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
92 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
93 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
94
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
95 #if defined(__arm__)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
96
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
97 #include "arm_neon.h"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
98
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
99 #define MOD_INC() \
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
100 " subs r0, r6, %2 \n\t" \
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
101 " itt cs \n\t" \
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
102 " addcs r0, %1 \n\t" \
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
103 " movcs r6, r0 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
104
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
105 static void pa_volume_s16ne_arm(int16_t *samples, const uint32_t *volumes, unsigned channels, unsigned length) {
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
106 /* Channels must be at least 4, and always a multiple of the original number.
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
107 * This is also the max amount we overread the volume array, which should
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
108 * have enough padding. */
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
109 channels = channels == 3 ? 6 : PA_MAX(4U, channels);
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
110 const uint32_t *ve = volumes + channels;
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
111
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
112 __asm__ __volatile__ (
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
113 " mov r6, %1 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
114 " mov %3, %3, LSR #1 \n\t" /* length /= sizeof (int16_t) */
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
115 " tst %3, #1 \n\t" /* check for odd samples */
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
116 " beq 2f \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
117
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
118 "1: \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
119 " ldr r0, [r6], #4 \n\t" /* odd samples volumes */
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
120 " ldrh r2, [%0] \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
121
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
122 " smulwb r0, r0, r2 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
123 " ssat r0, #16, r0 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
124
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
125 " strh r0, [%0], #2 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
126
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
127 MOD_INC()
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
128
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
129 "2: \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
130 " mov %3, %3, LSR #1 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
131 " tst %3, #1 \n\t" /* check for odd samples */
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
132 " beq 4f \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
133
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
134 "3: \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
135 " ldrd r2, [r6], #8 \n\t" /* 2 samples at a time */
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
136 " ldr r0, [%0] \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
137
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
138 " smulwt r2, r2, r0 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
139 " smulwb r3, r3, r0 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
140
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
141 " ssat r2, #16, r2 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
142 " ssat r3, #16, r3 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
143
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
144 " pkhbt r0, r3, r2, LSL #16 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
145 " str r0, [%0], #4 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
146
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
147 MOD_INC()
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
148
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
149 "4: \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
150 " movs %3, %3, LSR #1 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
151 " beq 6f \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
152
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
153 "5: \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
154 " ldrd r2, [r6], #8 \n\t" /* 4 samples at a time */
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
155 " ldrd r4, [r6], #8 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
156 " ldrd r0, [%0] \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
157
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
158 " smulwt r2, r2, r0 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
159 " smulwb r3, r3, r0 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
160 " smulwt r4, r4, r1 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
161 " smulwb r5, r5, r1 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
162
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
163 " ssat r2, #16, r2 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
164 " ssat r3, #16, r3 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
165 " ssat r4, #16, r4 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
166 " ssat r5, #16, r5 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
167
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
168 " pkhbt r0, r3, r2, LSL #16 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
169 " pkhbt r1, r5, r4, LSL #16 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
170 " strd r0, [%0], #8 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
171
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
172 MOD_INC()
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
173
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
174 " subs %3, %3, #1 \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
175 " bne 5b \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
176 "6: \n\t"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
177
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
178 : "+r" (samples), "+r" (volumes), "+r" (ve), "+r" (length)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
179 :
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
180 : "r6", "r5", "r4", "r3", "r2", "r1", "r0", "cc"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
181 );
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
182 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
183
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
184 static inline void vol_s16_neon(const uint32x4_t *vol4, int16_t *samples, unsigned length) {
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
185 asm volatile (
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
186 "mov %[length], %[length], lsr #2\n\t"
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
187 "vld1.s32 {q0}, [%[vol]]\n\t"
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
188 "vshl.u32 q3, q0, #16\n\t" /* lo */
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
189 "vshrn.s32 d1, q0, #16\n\t" /* hi */
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
190 "vshr.u32 q3, q3, #16\n\t"
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
191 "1:\n\t"
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
192 "vld1.16 {d0}, [%[samples]]\n\t"
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
193
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
194 "vmull.s16 q1, d0, d1\n\t"
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
195
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
196 "vmovl.s16 q2, d0\n\t"
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
197 "vmul.s32 q2, q2, q3\n\t"
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
198
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
199 "vsra.s32 q1, q2, #16\n\t"
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
200 "vmovn.s32 d0, q1\n\t"
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
201
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
202 "subs %[length], %[length], #1\n\t"
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
203 "vst1.16 {d0}, [%[samples]]!\n\t"
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
204 "bgt 1b\n\t"
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
205 /* output operands (or input operands that get modified) */
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
206 : [samples] "+r" (samples), [length] "+r" (length)
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
207 : [vol] "r" (vol4) /* input operands */
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
208 : "memory", "cc", "q0", "q1", "q2", "q3" /* clobber list */
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
209 );
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
210 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
211
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
212 static inline void vol_float_neon(const float32x4_t *vol4, float *samples, unsigned length) {
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
213 asm volatile (
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
214 "mov %[length], %[length], lsr #2\n\t"
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
215 "vld1.32 {q1}, [%[vol]]\n\t"
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
216 "1:\n\t"
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
217 "vld1.32 {q0}, [%[samples]]\n\t"
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
218 "vmul.f32 q0, q0, q1\n\t"
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
219 "subs %[length], %[length], #1\n\t"
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
220 "vst1.32 {q0}, [%[samples]]!\n\t"
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
221 "bgt 1b\n\t"
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
222 /* output operands (or input operands that get modified) */
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
223 : [samples] "+r" (samples), [length] "+r" (length)
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
224 : [vol] "r" (vol4) /* input operands */
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
225 : "memory", "cc", "q0", "q1" /* clobber list */
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
226 );
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
227 }
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
228
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
229 static void pa_volume_s16ne_neon(int16_t *samples, const uint32_t *volumes, unsigned channels, unsigned length) {
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
230 unsigned channel = 0, i;
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
231 uint32x4_t vol4;
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
232
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
233 length /= sizeof(int16_t);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
234
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
235 switch (channels) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
236 case 1:
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
237 vol4 = vdupq_n_u32(*volumes);
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
238 vol_s16_neon(&vol4, samples, length);
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
239
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
240 for (i = length & ~3; i < length; i++) {
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
241 int32_t t = samples[i];
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
242 t = ((int32_t) (t * (*volumes & 0xFFFF)) >> 16) + (t * (*volumes >> 16));
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
243 samples[i] = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
244 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
245 break;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
246 case 2:
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
247 vol4 = vcombine_u32(*(uint32x2_t *)volumes, *(uint32x2_t *)volumes);
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
248 vol_s16_neon(&vol4, samples, length);
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
249
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
250 for (i = length & ~3; i < length; i++) {
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
251 int32_t t = samples[i];
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
252 uint32_t vol = volumes[(channel++) & 1];
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
253 t = ((int32_t) (t * (vol & 0xFFFF)) >> 16) + (t * (vol >> 16));
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
254 samples[i] = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
255 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
256 break;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
257 case 4:
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
258 vol4 = *(uint32x4_t *)volumes;
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
259 vol_s16_neon(&vol4, samples, length);
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
260
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
261 for (i = length & ~3; i < length; i++) {
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
262 int32_t t = samples[i];
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
263 uint32_t vol = volumes[(channel++) & 3];
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
264 t = ((int32_t) (t * (vol & 0xFFFF)) >> 16) + (t * (vol >> 16));
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
265 samples[i] = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
266 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
267 break;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
268 default:
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
269 for (; length; length--) {
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
270 int32_t t;
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
271 uint32_t hi, lo;
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
272
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
273 /* Multiplying the 32bit volume factor with the 16bit
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
274 * sample might result in an 48bit value. We want to
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
275 * do without 64 bit integers and hence do the
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
276 * multiplication independently for the HI and LO part
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
277 * of the volume. */
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
278
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
279 hi = volumes[channel] >> 16;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
280 lo = volumes[channel] & 0xFFFF;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
281
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
282 t = (int32_t)(*samples);
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
283 t = ((int32_t) (t * lo) >> 16) + (t * hi);
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
284 t = PA_CLAMP_UNLIKELY(t, -0x8000, 0x7FFF);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
285 *samples++ = (int16_t) t;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
286
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
287 if (PA_UNLIKELY(++channel >= channels))
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
288 channel = 0;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
289 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
290 break;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
291 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
292 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
293
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
294 static void pa_volume_float32ne_neon(float *samples, const float *volumes, unsigned channels, unsigned length) {
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
295 unsigned channel = 0, i;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
296 float32x4_t vol4;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
297
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
298 length /= sizeof(float);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
299
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
300 switch (channels) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
301 case 1:
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
302 vol4 = vdupq_n_f32(*volumes);
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
303 vol_float_neon(&vol4, samples, length);
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
304
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
305 for (i = length & ~3; i < length; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
306 samples[i] *= volumes[0];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
307 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
308 break;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
309 case 2:
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
310 vol4 = vcombine_f32(*(float32x2_t *)volumes, *(float32x2_t *)volumes);
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
311 vol_float_neon(&vol4, samples, length);
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
312
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
313 for (i = length & ~3; i < length; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
314 samples[i] *= volumes[channel];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
315
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
316 if (PA_UNLIKELY(++channel >= channels))
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
317 channel = 0;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
318 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
319 break;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
320 case 4:
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
321 vol4 = *(float32x4_t *)volumes;
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
322 vol_float_neon(&vol4, samples, length);
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
323
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
324 for (i = length & ~3; i < length; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
325 samples[i] *= volumes[channel++];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
326 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
327 break;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
328 default:
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
329 for (; length; length--) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
330 *samples++ *= volumes[channel];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
331
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
332 if (PA_UNLIKELY(++channel >= channels))
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
333 channel = 0;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
334 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
335 break;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
336 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
337 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
338
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
339 #define SAMPLES 1019
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
340 #define TIMES 50000
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
341 #define CHANNELS 4
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
342 #define PADDING 16
5
07763f536182 ALIGNment support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
343 #define ALIGN 1
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
344
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
345 static void run_test_float(void) {
5
07763f536182 ALIGNment support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
346 float floats[SAMPLES+ALIGN];
07763f536182 ALIGNment support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
347 float floats_ref[SAMPLES+ALIGN];
07763f536182 ALIGNment support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
348 float floats_orig[SAMPLES+ALIGN];
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
349 float volumes[CHANNELS];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
350 unsigned i;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
351 pa_usec_t start, stop;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
352
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
353 pa_log_debug("checking NEON volume_float32ne(%d)", SAMPLES);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
354
5
07763f536182 ALIGNment support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
355 for (i = 0; i < SAMPLES+ALIGN; i++) {
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
356 floats_orig[i] = rand()/(float) RAND_MAX - 0.5f;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
357 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
358 memcpy(floats_ref, floats_orig, sizeof(floats_orig));
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
359 memcpy(floats, floats_orig, sizeof(floats_orig));
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
360
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
361 for (i = 0; i < CHANNELS; i++)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
362 volumes[i] = 0.5f * rand() / (float) RAND_MAX;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
363
5
07763f536182 ALIGNment support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
364 pa_volume_float32ne_neon(floats+ALIGN, volumes, CHANNELS, sizeof(floats));
07763f536182 ALIGNment support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
365 pa_volume_float32ne_c(floats_ref+ALIGN, volumes, CHANNELS, sizeof(floats_ref));
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
366
5
07763f536182 ALIGNment support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
367 for (i = ALIGN; i < SAMPLES+ALIGN; i++) {
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
368 if (fabsf(floats[i] - floats_ref[i]) > 0.00001) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
369 pa_log_debug("%d: %.3f != %.3f (%.3f)", i, floats[i], floats_ref[i],
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
370 floats_orig[i]);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
371 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
372 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
373
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
374 start = pa_rtclock_now();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
375 for (i = 0; i < TIMES; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
376 memcpy(floats, floats_orig, sizeof(floats_orig));
5
07763f536182 ALIGNment support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
377 pa_volume_float32ne_neon(floats+ALIGN, volumes, CHANNELS, sizeof(floats));
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
378 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
379 stop = pa_rtclock_now();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
380 pa_log_info("NEON: %llu usec.", (long long unsigned int)(stop - start));
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
381
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
382 start = pa_rtclock_now();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
383 for (i = 0; i < TIMES; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
384 memcpy(floats_ref, floats_orig, sizeof(floats_orig));
5
07763f536182 ALIGNment support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
385 pa_volume_float32ne_c(floats_ref+ALIGN, volumes, CHANNELS, sizeof(floats_ref));
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
386 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
387 stop = pa_rtclock_now();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
388 pa_log_info("ref: %llu usec.", (long long unsigned int)(stop - start));
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
389 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
390
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
391 static void run_test_s16(void) {
5
07763f536182 ALIGNment support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
392 int16_t samples[SAMPLES+ALIGN];
07763f536182 ALIGNment support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
393 int16_t samples_ref[SAMPLES+ALIGN];
07763f536182 ALIGNment support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
394 int16_t samples_orig[SAMPLES+ALIGN];
4
1f6289166006 complete
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 1
diff changeset
395 uint32_t volumes[CHANNELS + PADDING];
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
396 unsigned i, padding;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
397 pa_usec_t start, stop;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
398
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
399 pa_log_debug("checking NEON volume_s16ne(%d)", SAMPLES);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
400
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
401 for (i = 0; i < SAMPLES; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
402 samples_orig[i] = rand() - RAND_MAX/2;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
403 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
404 memcpy(samples_ref, samples_orig, sizeof(samples_orig));
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
405 memcpy(samples, samples_orig, sizeof(samples_orig));
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
406
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
407 for (i = 0; i < CHANNELS; i++)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
408 volumes[i] = PA_CLAMP_VOLUME(rand() >> 15);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
409 for (padding = 0; padding < PADDING; padding++, i++)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
410 volumes[i] = volumes[padding];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
411
5
07763f536182 ALIGNment support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
412 pa_volume_s16ne_neon(samples+ALIGN, volumes, CHANNELS, sizeof(samples));
07763f536182 ALIGNment support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
413 pa_volume_s16ne_c(samples_ref+ALIGN, volumes, CHANNELS, sizeof(samples_ref));
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
414
5
07763f536182 ALIGNment support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
415 for (i = ALIGN; i < SAMPLES+ALIGN; i++) {
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
416 if (abs(samples[i] - samples_ref[i]) > 0) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
417 pa_log_debug("%d: %d != %d (%d)", i, samples[i], samples_ref[i],
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
418 samples_orig[i]);
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
419 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
420 }
5
07763f536182 ALIGNment support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
421
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
422 start = pa_rtclock_now();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
423 for (i = 0; i < TIMES; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
424 memcpy(samples, samples_orig, sizeof(samples_orig));
5
07763f536182 ALIGNment support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
425 pa_volume_s16ne_neon(samples+ALIGN, volumes, CHANNELS, sizeof(samples));
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
426 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
427 stop = pa_rtclock_now();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
428 pa_log_info("NEON: %llu usec.", (long long unsigned int)(stop - start));
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
429
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
430 start = pa_rtclock_now();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
431 for (i = 0; i < TIMES; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
432 memcpy(samples, samples_orig, sizeof(samples_orig));
5
07763f536182 ALIGNment support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
433 pa_volume_s16ne_arm(samples+ALIGN, volumes, CHANNELS, sizeof(samples));
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
434 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
435 stop = pa_rtclock_now();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
436 pa_log_info("ARM: %llu usec.", (long long unsigned int)(stop - start));
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
437
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
438 start = pa_rtclock_now();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
439 for (i = 0; i < TIMES; i++) {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
440 memcpy(samples_ref, samples_orig, sizeof(samples_orig));
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
441 pa_volume_s16ne_c(samples_ref, volumes, CHANNELS, sizeof(samples_ref));
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
442 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
443 stop = pa_rtclock_now();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
444 pa_log_info("ref: %llu usec.", (long long unsigned int)(stop - start));
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
445 }
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
446
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
447 #endif /* defined(__arm__) */
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
448
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
449 int main() {
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
450
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
451 run_test_float();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
452 run_test_s16();
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
453
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
454 return EXIT_SUCCESS;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
455 }

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.