AutoPilot高层次综合C算法设计技巧-移位寄存器

// Register-based shift register implementation using C

// for High-Level Synthesis with AutoESL : AutoPilot

 

#define SIZE 10

typedef int dType;

 

void shiftReg(dType din, dType *dout)

{

#pragma AUTOPILOT pipeline II=1

    static dType regs[SIZE];

    int i;

 

    for (i = SIZE-1; i > 0; i--)

        regs[i] = regs[i-1];

    regs[0] = din;

 

    *dout = regs[SIZE-1];

}

熟悉RTL设计的话,对这种C描述应该比较习惯,如果是纯软件开发人员刚开始接触这样的C代码估计够呛。
会觉得很别扭。
上面的C代码就是一个比较高效的移位寄存器的C语言实现,用高层次综合工具AutoPilot综合可以得到和手写
RTL(verilog和vhdl)效果一样的移位寄存器。
在这里:
1.
#pragma AUTOPILOT pipeline II=1
告诉综合工具让这个模块流水起来,并且达到每一个时钟周期进一个数据的吞吐率。
2.
Regs数组会被partition掉,综合成寄存器。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以处理无限数据,求其线性复杂度 //by史瑞 //LFSR线性移位寄存器以及求异或运算OK unsigned char LFSRB_M(unsigned char *fun,unsigned char *seq,unsigned long Cont){ unsigned long x; unsigned char ch=0x00,t=0x00,*array; array=(unsigned char *)malloc(Cont*sizeof(unsigned char)); for(x=0;x<Cont;x++) *(array+x)=(*(seq+x))&(*(fun+x)); for(x=0;x<Cont*8;x++){ ch=(*array)&0x80; LeftShift(array,Cont); t^=ch; } free(array); return t; } #define word(ln) ((ln-1)/8+1) #define place(ln) ((ln-1)%8) //Berlek_Massey求生成任意序列的联接多项式OK unsigned char *Berlek_Massey(unsigned char *seq,unsigned long *Rank,unsigned long Cont,FILE *fmm){ unsigned long n=0,m,lm,ln=0; int d; unsigned long lfm; unsigned char *fun,*fm,*array,ch,t=0x00; unsigned char *func,*fmc; unsigned long x,y,k; fun=(unsigned char *)malloc(sizeof(unsigned char)); *(fun)=0x00; for(x=0;x<Cont*8;x++){ if(ln!=0){ array=(unsigned char *)malloc(word(ln)); InitialDSR(array,word(ln)); for(y=0;y<ln;y++){ ch=((*(seq+(n-(y+1))/8))<<((n-(y+1))%8))&0x80; if(ch) *(array+y/8)^=(ch>>(y%8)); } t=LFSRB_M(fun,array,word(ln)); d=((((*(seq+n/8))<<(n%8))&0x80;)^t)?1:0; free(array); } else d=(((*(seq+n/8))<<(n%8))&0x80;)?1:0; if(d){ if(ln!=0){ lm=ln; func=(unsigned char *)malloc(word(ln)*sizeof(unsigned char)); memcpy(func,fun,word(ln)); if(ln<(n+1-ln)){ ln=n+1-ln; } fmc=(unsigned char *)malloc(word(ln)*sizeof(unsigned char)); InitialDSR(fmc,word(ln)); memcpy(fmc,fm,word(lfm)); for(k=0;k<n-m;k++){ RightShift(fmc,word(ln)); } ch=0x80; *(fmc+(n-m-1)/8)^=(ch>>((n-m-1)%8)); fun=(unsigned char *)realloc(fun,word(ln)*sizeof(unsigned char)); for(k=word(lm);k<word(ln);k++) *(fun+k)=0x00; XorDSR(fun,fmc,word(ln)); free(fmc); if(lm<(n+1-lm)){ m=n; lfm=lm; fm=(unsigned char *)realloc(fm,word(lm)); memcpy(fm,func,word(lfm)); } free(func); } else{ ln=n+1; m=n; if(m!=0){ fm=(unsigned char *)malloc(word(m)*sizeof(unsigned char)); InitialDSR(fm,word(m)); lfm=m; } else{ fm=(unsigned char *)malloc(sizeof(unsigned char)); *fm=0x00; lfm=1; } fun=(unsigned char *)realloc(fun,word(ln)); InitialDSR(fun,word(ln)); ch=0x80; ch>>=(place(ln)); *(fun+(word(ln)-1))^=ch; } } n++; printf(&quot;\t<%d,%d>&quot;,n,ln); fprintf(fmm,&quot;\t<n,d,ln>=<%d,%d,%d>&quot;,n,d,ln); if(n%3==0){ printf(&quot;\n&quot;); fprintf(fmm,&quot;\n&quot;); } } printf(&quot;\nFn=&quot;); // for(k=0;k<word(ln);k++) // FromBytetoBit(*(fun+k)); *Rank=ln; return fun; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值