1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include <stdio.h>
19#include <stdint.h>
20#include <string.h>
21#include "hvx_histogram_row.h"
22
23const int vector_len = 128;
24const int width = 275;
25const int height = 20;
26const int stride = (width + vector_len - 1) & -vector_len;
27
28int err;
29
30static uint8_t input[height][stride] __attribute__((aligned(128))) = {
31#include "hvx_histogram_input.h"
32};
33
34static int result[256] __attribute__((aligned(128)));
35static int expect[256] __attribute__((aligned(128)));
36
37static 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
50static 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
64static 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
80int 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