Home | History | Annotate | Download | only in fec
      1 /* 16-bit signed integer dot product
      2  * Portable C version
      3  * Copyright 2004 Phil Karn
      4  * May be used under the terms of the GNU Lesser General Public License (LGPL)
      5  */
      6 #include <stdlib.h>
      7 #include "fec.h"
      8 
      9 struct dotprod {
     10   int len; /* Number of coefficients */
     11 
     12   signed short *coeffs;
     13 };
     14 
     15 /* Create and return a descriptor for use with the dot product function */
     16 void *initdp_port(signed short coeffs[],int len){
     17   struct dotprod *dp;
     18   int j;
     19 
     20   if(len == 0)
     21     return NULL;
     22 
     23   dp = (struct dotprod *)calloc(1,sizeof(struct dotprod));
     24   dp->len = len;
     25 
     26   /* Just one copy of the coefficients for the C version */
     27   dp->coeffs = (signed short *)calloc(len,sizeof(signed short));
     28   for(j=0;j<len;j++)
     29     dp->coeffs[j] = coeffs[j];
     30   return (void *)dp;
     31 }
     32 
     33 
     34 /* Free a dot product descriptor created earlier */
     35 void freedp_port(void *p){
     36   struct dotprod *dp = (struct dotprod *)p;
     37 
     38   if(dp->coeffs != NULL)
     39       free(dp->coeffs);
     40   free(dp);
     41 }
     42 
     43 /* Compute a dot product given a descriptor and an input array
     44  * The length is taken from the descriptor
     45  */
     46 long dotprod_port(void *p,signed short a[]){
     47   struct dotprod *dp = (struct dotprod *)p;
     48   long corr;
     49   int i;
     50 
     51   corr = 0;
     52   for(i=0;i<dp->len;i++){
     53     corr += (long)a[i] * dp->coeffs[i];
     54   }
     55   return corr;
     56 }
     57 
     58 
     59