annotate svolume_neon.c @ 0:e0040ee59c3c

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

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