1 /* Verify correctness of the sum-of-square routines */
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <time.h>
5 
6 /* These values should trigger leading/trailing array fragment handling */
7 #define NSAMP 200002
8 #define OFFSET 1
9 
10 long long sumsq_wq(signed short *in,int cnt);
11 long long sumsq_wq_ref(signed short *in,int cnt);
12 
main()13 int main(){
14   int i;
15   long long result,rresult;
16   signed short samples[NSAMP];
17 
18   srandom(time(NULL));
19 
20   for(i=0;i<NSAMP;i++)
21     samples[i] = random() & 0xffff;
22 
23   rresult = sumsq_wq(&samples[OFFSET],NSAMP-OFFSET);
24   result = sumsq_wq(&samples[OFFSET],NSAMP-OFFSET);
25   if(result == rresult){
26     printf("OK\n");
27   } else {
28     printf("sum mismatch: %lld != %lld\n",result,rresult);
29   }
30   exit(0);
31 }
32 
sumsq_wq_ref(signed short * in,int cnt)33 long long sumsq_wq_ref(signed short *in,int cnt){
34   long long sum = 0;
35   int i;
36 
37   for(i=0;i<cnt;i++){
38     sum += (long)in[i] * in[i];
39   }
40   return sum;
41 }
42 
43