1 /*
2 * Copyright(c) 2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <stdio.h>
19 #include <stdint.h>
20 #include <string.h>
21 #include "hvx_histogram_row.h"
22
23 const int vector_len = 128;
24 const int width = 275;
25 const int height = 20;
26 const int stride = (width + vector_len - 1) & -vector_len;
27
28 int err;
29
30 static uint8_t input[height][stride] __attribute__((aligned(128))) = {
31 #include "hvx_histogram_input.h"
32 };
33
34 static int result[256] __attribute__((aligned(128)));
35 static int expect[256] __attribute__((aligned(128)));
36
check(void)37 static void check(void)
38 {
39 for (int i = 0; i < 256; i++) {
40 int res = result[i];
41 int exp = expect[i];
42 if (res != exp) {
43 printf("ERROR at %3d: 0x%04x != 0x%04x\n",
44 i, res, exp);
45 err++;
46 }
47 }
48 }
49
ref_histogram(uint8_t * src,int stride,int width,int height,int * hist)50 static void ref_histogram(uint8_t *src, int stride, int width, int height,
51 int *hist)
52 {
53 for (int i = 0; i < 256; i++) {
54 hist[i] = 0;
55 }
56
57 for (int i = 0; i < height; i++) {
58 for (int j = 0; j < width; j++) {
59 hist[src[i * stride + j]]++;
60 }
61 }
62 }
63
hvx_histogram(uint8_t * src,int stride,int width,int height,int * hist)64 static void hvx_histogram(uint8_t *src, int stride, int width, int height,
65 int *hist)
66 {
67 int n = 8192 / width;
68
69 for (int i = 0; i < 256; i++) {
70 hist[i] = 0;
71 }
72
73 for (int i = 0; i < height; i += n) {
74 int k = height - i > n ? n : height - i;
75 hvx_histogram_row(src, stride, width, k, hist);
76 src += n * stride;
77 }
78 }
79
main()80 int main()
81 {
82 ref_histogram(&input[0][0], stride, width, height, expect);
83 hvx_histogram(&input[0][0], stride, width, height, result);
84 check();
85
86 puts(err ? "FAIL" : "PASS");
87 return err ? 1 : 0;
88 }
89