PandA-2024.02
diff_sq_acc_tb.cpp
Go to the documentation of this file.
1 /************************************************
2 Copyright (c) 2016, Xilinx, Inc.
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7 
8 1. Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 
11 2. Redistributions in binary form must reproduce the above copyright notice,
12 this list of conditions and the following disclaimer in the documentation
13 and/or other materials provided with the distribution.
14 
15 3. Neither the name of the copyright holder nor the names of its contributors
16 may be used to endorse or promote products derived from this software
17 without specific prior written permission.
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.// Copyright (c) 2016 Xilinx, Inc.
28 ************************************************/
29 
30 #include <stdio.h>
31 #include "../src/diff_sq_acc.h"
32 
33 
34 
35 void ref_diff_sq_acc(int a[N], int b[N], long long int *dout)
36 {
37  int i;
38  long long int acc = 0;
39  int diff;
40  long long int diff2;
41 
42  for(i=0; i<N; i++)
43  {
44  diff = a[i]-b[i];
45  diff2 = (long long int) diff * (long long int) diff;
46  acc += diff2;
47  }
48 
49  *dout = acc;
50 
51 }
52 
53 int main(void)
54 {
55  int i, k, cnt;
56  int ret_val = 0;
57 
58  int a[N], b[N];
59  din_t aa[N], bb[N];
60 
61  long long int ref_res;
62  dout_t res;
63 
64  cnt = 0;
65  for (k=0; k<10; k++)
66  {
67  //create random data
68  for(i=0; i<N; i++)
69  {
70  a[i] = rand() % (1024*16);
71  b[i] = rand() % (1024*16);
72  aa[i] = (din_t) a[i];
73  bb[i] = (din_t) b[i];
74  }
75 
76  //call reference function
77  ref_diff_sq_acc(a, b, &ref_res);
78 
79  //call design Under Test
80  diff_sq_acc( aa, bb, &res);
81 
82  //check results
83  printf("got %lld expected %lld\n", (long long int) res.to_double(), (long long int) ref_res);
84  if ( (ref_res - (long long int) res) !=0 ) cnt++;
85  }
86 
87  if (cnt>0)
88  {
89  printf("TEST FAILED: %d errors\n", cnt);
90  ret_val = 1;
91  }
92  else
93  {
94  printf("TEST SUCCESS!\n");
95  ret_val = 0;
96  }
97 
98 
99  return ret_val;
100 
101 }
102 
ap_int< 16 > din_t
Definition: diff_sq_acc.h:36
void diff_sq_acc(din_t a[N], din_t b[N], dout_t *dout)
Definition: diff_sq_acc.cpp:32
void ref_diff_sq_acc(int a[N], int b[N], long long int *dout)
ap_int< 48 > dout_t
Definition: diff_sq_acc.h:37
static const uint32_t k[]
Definition: sha-256.c:22
#define N
Definition: dfdiv.c:60
int main(void)
unsigned char aa[]
Definition: spec.c:10

Generated on Mon Feb 12 2024 13:02:49 for PandA-2024.02 by doxygen 1.8.13