1*4930cef6SMatthias Ringwald /******************************************************************************
2*4930cef6SMatthias Ringwald *
3*4930cef6SMatthias Ringwald * Copyright 2022 Google LLC
4*4930cef6SMatthias Ringwald *
5*4930cef6SMatthias Ringwald * Licensed under the Apache License, Version 2.0 (the "License");
6*4930cef6SMatthias Ringwald * you may not use this file except in compliance with the License.
7*4930cef6SMatthias Ringwald * You may obtain a copy of the License at:
8*4930cef6SMatthias Ringwald *
9*4930cef6SMatthias Ringwald * http://www.apache.org/licenses/LICENSE-2.0
10*4930cef6SMatthias Ringwald *
11*4930cef6SMatthias Ringwald * Unless required by applicable law or agreed to in writing, software
12*4930cef6SMatthias Ringwald * distributed under the License is distributed on an "AS IS" BASIS,
13*4930cef6SMatthias Ringwald * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*4930cef6SMatthias Ringwald * See the License for the specific language governing permissions and
15*4930cef6SMatthias Ringwald * limitations under the License.
16*4930cef6SMatthias Ringwald *
17*4930cef6SMatthias Ringwald ******************************************************************************/
18*4930cef6SMatthias Ringwald
19*4930cef6SMatthias Ringwald #include "neon.h"
20*4930cef6SMatthias Ringwald
21*4930cef6SMatthias Ringwald #include <stdio.h>
22*4930cef6SMatthias Ringwald #include <stdint.h>
23*4930cef6SMatthias Ringwald #include <stdlib.h>
24*4930cef6SMatthias Ringwald
25*4930cef6SMatthias Ringwald /* -------------------------------------------------------------------------- */
26*4930cef6SMatthias Ringwald
27*4930cef6SMatthias Ringwald #define TEST_NEON
28*4930cef6SMatthias Ringwald #include <ltpf.c>
29*4930cef6SMatthias Ringwald
lc3_put_bits_generic(lc3_bits_t * a,unsigned b,int c)30*4930cef6SMatthias Ringwald void lc3_put_bits_generic(lc3_bits_t *a, unsigned b, int c)
31*4930cef6SMatthias Ringwald { (void)a, (void)b, (void)c; }
32*4930cef6SMatthias Ringwald
lc3_get_bits_generic(struct lc3_bits * a,int b)33*4930cef6SMatthias Ringwald unsigned lc3_get_bits_generic(struct lc3_bits *a, int b)
34*4930cef6SMatthias Ringwald { return (void)a, (void)b, 0; }
35*4930cef6SMatthias Ringwald
36*4930cef6SMatthias Ringwald /* -------------------------------------------------------------------------- */
37*4930cef6SMatthias Ringwald
check_resampler()38*4930cef6SMatthias Ringwald static int check_resampler()
39*4930cef6SMatthias Ringwald {
40*4930cef6SMatthias Ringwald int16_t __x[60+480], *x = __x + 60;
41*4930cef6SMatthias Ringwald for (int i = -60; i < 480; i++)
42*4930cef6SMatthias Ringwald x[i] = rand() & 0xffff;
43*4930cef6SMatthias Ringwald
44*4930cef6SMatthias Ringwald struct lc3_ltpf_hp50_state hp50 = { 0 }, hp50_neon = { 0 };
45*4930cef6SMatthias Ringwald int16_t y[128], y_neon[128];
46*4930cef6SMatthias Ringwald
47*4930cef6SMatthias Ringwald resample_16k_12k8(&hp50, x, y, 128);
48*4930cef6SMatthias Ringwald neon_resample_16k_12k8(&hp50_neon, x, y_neon, 128);
49*4930cef6SMatthias Ringwald if (memcmp(y, y_neon, 128 * sizeof(*y)) != 0)
50*4930cef6SMatthias Ringwald return printf("Error\n"), -1;
51*4930cef6SMatthias Ringwald
52*4930cef6SMatthias Ringwald resample_32k_12k8(&hp50, x, y, 128);
53*4930cef6SMatthias Ringwald neon_resample_32k_12k8(&hp50_neon, x, y_neon, 128);
54*4930cef6SMatthias Ringwald if (memcmp(y, y_neon, 128 * sizeof(*y)) != 0)
55*4930cef6SMatthias Ringwald return printf("Error\n"), -1;
56*4930cef6SMatthias Ringwald
57*4930cef6SMatthias Ringwald resample_48k_12k8(&hp50, x, y, 128);
58*4930cef6SMatthias Ringwald neon_resample_48k_12k8(&hp50_neon, x, y_neon, 128);
59*4930cef6SMatthias Ringwald if (memcmp(y, y_neon, 128 * sizeof(*y)) != 0)
60*4930cef6SMatthias Ringwald return -1;
61*4930cef6SMatthias Ringwald
62*4930cef6SMatthias Ringwald return 0;
63*4930cef6SMatthias Ringwald }
64*4930cef6SMatthias Ringwald
check_dot()65*4930cef6SMatthias Ringwald static int check_dot()
66*4930cef6SMatthias Ringwald {
67*4930cef6SMatthias Ringwald int16_t x[200];
68*4930cef6SMatthias Ringwald for (int i = 0; i < 200; i++)
69*4930cef6SMatthias Ringwald x[i] = rand() & 0xffff;
70*4930cef6SMatthias Ringwald
71*4930cef6SMatthias Ringwald float y = dot(x, x+3, 128);
72*4930cef6SMatthias Ringwald float y_neon = neon_dot(x, x+3, 128);
73*4930cef6SMatthias Ringwald if (y != y_neon)
74*4930cef6SMatthias Ringwald return -1;
75*4930cef6SMatthias Ringwald
76*4930cef6SMatthias Ringwald return 0;
77*4930cef6SMatthias Ringwald }
78*4930cef6SMatthias Ringwald
check_correlate()79*4930cef6SMatthias Ringwald static int check_correlate()
80*4930cef6SMatthias Ringwald {
81*4930cef6SMatthias Ringwald int16_t alignas(4) a[500], b[500];
82*4930cef6SMatthias Ringwald float y[100], y_neon[100];
83*4930cef6SMatthias Ringwald
84*4930cef6SMatthias Ringwald for (int i = 0; i < 500; i++) {
85*4930cef6SMatthias Ringwald a[i] = rand() & 0xffff;
86*4930cef6SMatthias Ringwald b[i] = rand() & 0xffff;
87*4930cef6SMatthias Ringwald }
88*4930cef6SMatthias Ringwald
89*4930cef6SMatthias Ringwald correlate(a, b+200, 128, y, 100);
90*4930cef6SMatthias Ringwald neon_correlate(a, b+200, 128, y_neon, 100);
91*4930cef6SMatthias Ringwald if (memcmp(y, y_neon, 100 * sizeof(*y)) != 0)
92*4930cef6SMatthias Ringwald return -1;
93*4930cef6SMatthias Ringwald
94*4930cef6SMatthias Ringwald correlate(a, b+199, 128, y, 99);
95*4930cef6SMatthias Ringwald neon_correlate(a, b+199, 128, y_neon, 99);
96*4930cef6SMatthias Ringwald if (memcmp(y, y_neon, 99 * sizeof(*y)) != 0)
97*4930cef6SMatthias Ringwald return -1;
98*4930cef6SMatthias Ringwald
99*4930cef6SMatthias Ringwald return 0;
100*4930cef6SMatthias Ringwald }
101*4930cef6SMatthias Ringwald
check_ltpf(void)102*4930cef6SMatthias Ringwald int check_ltpf(void)
103*4930cef6SMatthias Ringwald {
104*4930cef6SMatthias Ringwald int ret;
105*4930cef6SMatthias Ringwald
106*4930cef6SMatthias Ringwald if ((ret = check_resampler()) < 0)
107*4930cef6SMatthias Ringwald return ret;
108*4930cef6SMatthias Ringwald
109*4930cef6SMatthias Ringwald if ((ret = check_dot()) < 0)
110*4930cef6SMatthias Ringwald return ret;
111*4930cef6SMatthias Ringwald
112*4930cef6SMatthias Ringwald if ((ret = check_correlate()) < 0)
113*4930cef6SMatthias Ringwald return ret;
114*4930cef6SMatthias Ringwald
115*4930cef6SMatthias Ringwald return 0;
116*4930cef6SMatthias Ringwald }
117