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