Dear Anand,
thanks for your reply....sorry for the confusion and messing things up....I have posted three codes below under headings SOURCE file, HEADER and TEST BENCH. This will definitely give you the whole idea.
Regarding your question ".What for the below lines are used and where is the function? " please check the third code under TEST BENCH.
Regarding your question "How check results session of code works?" also please check the third code under TEST BENCH.
SOURCE file
# include "../src/diff_sq_acc.h"
void diff_sq_acc(din_t a[N], din_t b[N], dout_t *dout)
{
unsigned char i;
float acc= 0;
float a_reg, b_reg, sub, sub2;
diff_sq_acc_label0:for(i=0; i<N; i++)
{
a_reg = a
;
b_reg = b;
sub = a_reg - b_reg;
sub2 = sub*sub;
acc += sub2;
}
*dout = acc;
}
HEADER
# ifndef H_SQRT_ACC_H# define H_SQRT_ACC_H
# include <stdlib.h># include "ap_int.h"
typedef float din_t;
typedef float dout_t;
# define N 100
void diff_sq_acc(din_t a[N], din_t b[N], dout_t *dout);
# endif //#ifndef H_SQRT_ACC_H
TEST BENCH
# include <stdio.h># include "../src/diff_sq_acc.h"
void ref_diff_sq_acc(int a[N], int b[N], long long int *dout)
{
int i;
long long int acc = 0;
int diff;
long long int diff2;
for(i=0; i<N; i++)
{
diff = a
-b;
diff2 = (long long int) diff * (long long int) diff;
acc += diff2;
}
*dout = acc;
}
int main(void)
{
int i, k, cnt;
int ret_val = 0;
int a[N], b[N];
din_t aa[N], bb[N];
long long int ref_res;
dout_t res;
cnt = 0;
for (k=0; k<10; k++)
{
//create random data
for(i=0; i<N; i++)
{
a
= rand() % (1024*16);
b = rand() % (1024*16);
aa
= (din_t) a;
bb
= (din_t) b;
}
//call reference function
ref_diff_sq_acc(a, b, &ref_res);
//call design Under Test
diff_sq_acc( aa, bb, &res);
//check results
printf("got %lld expected %lld\n", (long long int) res.to_double(), (long long int) ref_res);
if ( (ref_res - (long long int) res) !=0 ) cnt++;
}
if (cnt>0)
{
printf("TEST FAILED: %d errors\n", cnt);
ret_val = 1;
}
else
{
printf("TEST SUCCESS!\n");
ret_val = 0;
}
return ret_val;
}