⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dct_kc.i

📁 H.264完整的C语言代码和DCT的代码
💻 I
字号:
#line 1 "D:\\working\\im_apps\\h264\\dct_kc.cpp"
#line 1 "D:/working/tools/isim/isimexe/blank_headers\\idb_kernelc.hpp"








#line 2 "D:\\working\\im_apps\\h264\\dct_kc.cpp"
#line 1 "D:\\working\\im_apps\\h264\\mpeg.hpp"




#line 1 "D:/working/tools/isim/isimexe/blank_headers\\idb_types.hpp"













#line 6 "D:\\working\\im_apps\\h264\\mpeg.hpp"
#line 1 "D:/working/tools/isim/isimexe/blank_headers\\idb_deftypes.hpp"




#line 7 "D:\\working\\im_apps\\h264\\mpeg.hpp"

#decl idxGen(ostream<uint>   indices,
              uc<int>&        uc_size,
              uc<int>&        uc_params);
;


#decl icolor(istream<ubyte4> datain,
              ostream<half2> Yout,
              ostream<half2> CrCbout);
;


#decl pcolor(istream<ubyte4> datain,
              ostream<ubyte4> Yout,
              ostream<half2> CrCbout);
;


#decl dct(istream<half2> datain,
           istream<uhalf2> consts,
           ostream<half2> out,
           uc<uhalf2>& uc_quantizer_scale);
;


#decl idct(istream<half2> datain,
            istream<uhalf2> consts,
            ostream<half2> out,
            uc<half2>& uc_quantizer_scale);
;


#decl rle(istream<half2> Yin,
           istream<half2> CrCbin,
           istream<int> indices,
           cistream<half2> motion,
           costream<half2> out,
           uc<uint>& pframe,
           uc<uint>& quant_scale);
;


#decl difference(istream<ubyte4> curryblks,
                  istream<half2> currcblks,
                  istream<ubyte4> refyblks,
                  istream<half2> refcblks,
                  ostream<half2> diffyblks,
                  ostream<half2> diffcblks);
;


#decl correlate(istream<half2> diffyblks,
                 istream<half2> diffcblks,
                 istream<ubyte4> refyblks,
                 istream<half2> refcblks,
                 ostream<ubyte4> newrefyblks,
                 ostream<half2> newrefcblks,
                 uc<uint>& uc_pframe);
;


#decl MV2idx(cistream<half2> motion,      
              ostream<uint>   yindices,    
              ostream<uint>   crcbindices, 
              uc<int>&        uc_offsets,  
              uc<int>&        uc_mblks,    
              uc<int>&        uc_mb_width);
;


#decl blocksearch(istream<ubyte4> row0,
                   istream<ubyte4> row1,
                   istream<ubyte4> row2,
                   istream<ubyte4> mblocks,
                   costream<half2> motions,
                   uc<int>& location);
;


#decl mb_encode(istream<byte4> datain,
                 istream<half2> consts,
                 ostream<half2> color_out,
                 ostream<half2> dct_out,
                 costream<int> out);
;



#line 1 "D:/working/tools/isim/isimexe/blank_headers\\idb_undeftypes.hpp"




#line 97 "D:\\working\\im_apps\\h264\\mpeg.hpp"

#line 99 "D:\\working\\im_apps\\h264\\mpeg.hpp"
#line 3 "D:\\working\\im_apps\\h264\\dct_kc.cpp"
#line 1 "D:/working/tools/isim/isimexe/blank_headers\\idb_kernelc2.hpp"






#line 4 "D:\\working\\im_apps\\h264\\dct_kc.cpp"

;















kernel dct(istream<half2> datain,
           istream<uhalf2> consts,           
           ostream<half2> out,
           uc<uhalf2>& uc_quantizer_scale)   
{
  
  half2 COS_2             = 0x2d412d41;    
  half2 COS_3             = 0x187e187e;    
  half2 COS_1_plus_COS_3  = 0x539f539f;    
  half2 COS_1_minus_COS_3 = 0x22a322a3;    

  expand<half2> K(8);
  
  K[0] = 0x16a116a1;        
  K[1] = 0x10501050;        
  K[2] = 0x11511151;        
  K[3] = 0x133e133e;        
  K[4] = 0x16a116a1;        
  K[5] = 0x1ccd1ccd;        
  K[6] = 0x29cf29cf;        
  K[7] = 0x52035203;        

  
  
  
  
  
  
  
  
  
  

  
  
  
  
  

  uhalf2 quant_scale = commclperm(0x8, 0, uc_quantizer_scale);
  expand<half2> quant(8);
  int quant_idx = 0;
  uhalf2 utmp;

  
  
  consts >> utmp;
  quant[0] = half2(shift(hi(mulrnd(quant_scale, utmp)), -1));
  consts >> utmp;
  quant[1] = half2(shift(hi(mulrnd(quant_scale, utmp)), -1));
  consts >> utmp;
  quant[2] = half2(shift(hi(mulrnd(quant_scale, utmp)), -1));
  consts >> utmp;
  quant[3] = half2(shift(hi(mulrnd(quant_scale, utmp)), -1));
  consts >> utmp;
  quant[4] = half2(shift(hi(mulrnd(quant_scale, utmp)), -1));
  consts >> utmp;
  quant[5] = half2(shift(hi(mulrnd(quant_scale, utmp)), -1));
  consts >> utmp;
  quant[6] = half2(shift(hi(mulrnd(quant_scale, utmp)), -1));
  consts >> utmp;
  quant[7] = half2(shift(hi(mulrnd(quant_scale, utmp)), -1));


  
  
  
  
  

  
  uc<int> perm_a = 0x07654321;
  uc<int> perm_b = 0x10765432;
  uc<int> perm_c = 0x21076543;
  uc<int> perm_d = 0x32107654;
  uc<int> perm_e = 0x43210765;
  uc<int> perm_f = 0x54321076;
  uc<int> perm_g = 0x65432107;


  
  half2 h2_one = 1 | half2(shift(1, 16));
  uhalf2 uh2_half = shift(uhalf2(h2_one), 16 - 1);
  uhalf2 uh2_almost_half = uh2_half - uhalf2(h2_one);

  
  int idx0 = cid();
  int idx1 = (idx0 - 1) & 7;
  int idx2 = (idx1 - 1) & 7;
  int idx3 = (idx2 - 1) & 7;
  int idx4 = (idx3 - 1) & 7;
  int idx5 = (idx4 - 1) & 7;
  int idx6 = (idx5 - 1) & 7;
  int idx7 = (idx6 - 1) & 7;

  loop_stream(datain) pipeline(1) {
    
    half2 a0, a1, a2, a3, a4, a5, a6, a7;
    datain >> a0 >> a1 >> a2 >> a3 >> a4 >> a5 >> a6 >> a7;

    
    half2 s16, s07, s25, s34, s1625, s0734;
  
    s07 = a0 + a7;
    s16 = a1 + a6;
    s25 = a2 + a5;
    s34 = a3 + a4;
    s1625 = s16 + s25;
    s0734 = s07 + s34;
  
    half2 d16, d07, d25, d34, d1625, d0734;
  
    d07 = a0 - a7;
    d16 = a1 - a6;
    d25 = a2 - a5;
    d34 = a3 - a4;
    d1625 = s16 - s25;
    d0734 = s07 - s34;

    half2 sd16d07, sd25d34;
  
    sd16d07 = d07 + d16;
    sd25d34 = d25 + d34;
  
    half2 m1_over_2, m2, m5, m6, m7, m8, m9;
  
    
    m1_over_2 = s0734 + s1625;
    m2 = s0734 - s1625;
    m5 = hi(mulrnd(COS_2, shift(d1625 + d0734, 2)));
    m6 = hi(mulrnd(COS_2, shift(d25 + d16, 2)));
    m7 = hi(mulrnd(COS_3, shift(sd16d07 - sd25d34, 2)));
    m8 = hi(mulrnd(COS_1_plus_COS_3, shift(sd16d07, 2)));
    m9 = hi(mulrnd(COS_1_minus_COS_3, shift(sd25d34, 2)));
  
    half2 s5, s6, s7, s8;
  
    s5 = d07 + m6;
    s6 = d07 - m6;
    s7 = m8 - m7;
    s8 = m9 - m7;
  
    array<half2> buf1(8);  
    array<half2> buf2(8);  

    
    buf1[0] = hi(mulrnd(K[0], shift(m1_over_2, 2)));
    buf1[1] = hi(mulrnd(K[1], shift(s5 + s7, 2)));
    buf1[2] = hi(mulrnd(K[2], shift(d0734 + m5, 2)));
    buf1[3] = hi(mulrnd(K[3], shift(s6 - s8, 2)));
    buf1[4] = hi(mulrnd(K[4], shift(m2, 2)));
    buf1[5] = hi(mulrnd(K[5], shift(s6 + s8, 2)));
    buf1[6] = hi(mulrnd(K[6], shift(d0734 - m5, 2)));
    buf1[7] = hi(mulrnd(K[7], shift(s5 - s7, 2)));
  
    
  
    buf2[idx0] = buf1[idx0];
    buf2[idx7] = commucperm(perm_a, buf1[idx1]);
    buf2[idx6] = commucperm(perm_b, buf1[idx2]);
    buf2[idx5] = commucperm(perm_c, buf1[idx3]);
    buf2[idx4] = commucperm(perm_d, buf1[idx4]);
    buf2[idx3] = commucperm(perm_e, buf1[idx5]);
    buf2[idx2] = commucperm(perm_f, buf1[idx6]);
    buf2[idx1] = commucperm(perm_g, buf1[idx7]);
    
    
    a0 = buf2[0];
    a1 = buf2[1];
    a2 = buf2[2];
    a3 = buf2[3];
    a4 = buf2[4];
    a5 = buf2[5];
    a6 = buf2[6];
    a7 = buf2[7];

    s07 = a0 + a7;
    s16 = a1 + a6;
    s25 = a2 + a5;
    s34 = a3 + a4;
    s1625 = s16 + s25;
    s0734 = s07 + s34;
  
    d07 = a0 - a7;
    d16 = a1 - a6;
    d25 = a2 - a5;
    d34 = a3 - a4;
    d1625 = s16 - s25;
    d0734 = s07 - s34;
  
    sd16d07 = d07 + d16;
    sd25d34 = d25 + d34;
  
    
    m1_over_2 = s0734 + s1625;
    m2 = s0734 - s1625;
    m5 = hi(mulrnd(COS_2, shift(d1625 + d0734, 2)));
    m6 = hi(mulrnd(COS_2, shift(d25 + d16, 2)));
    m7 = hi(mulrnd(COS_3, shift(sd16d07 - sd25d34, 2)));
    m8 = hi(mulrnd(COS_1_plus_COS_3, shift(sd16d07, 2)));
    m9 = hi(mulrnd(COS_1_minus_COS_3, shift(sd25d34, 2)));
  
    s5 = d07 + m6;
    s6 = d07 - m6;
    s7 = m8 - m7;
    s8 = m9 - m7;
  
    half2 d0, d1, d2, d3, d4, d5, d6, d7;
    d0 = m1_over_2;
    d1 = s5 + s7;
    d2 = d0734 + m5;
    d3 = s6 - s8;
    d4 = m2;
    d5 = s6 + s8;
    d6 = d0734 - m5;
    d7 = s5 - s7;
  
    
    uhalf2 round_cmp;          
    double<half2> dct_quant;   
    cc sign, add;
  
    sign = itocc(int(d0 <= 0));
    round_cmp = select(sign, uh2_half, uh2_almost_half);
    dct_quant = quant[0] * shift(d0, 2);
    add = itocc(int(round_cmp < uhalf2(lo(dct_quant))));
    out << select(add, (hi(dct_quant)+h2_one), hi(dct_quant));
  
    sign = itocc(int(d1 <= 0));
    round_cmp = select(sign, uh2_half, uh2_almost_half);
    dct_quant = quant[1] * shift(d1, 2);
    add = itocc(int(round_cmp < uhalf2(lo(dct_quant))));
    out << select(add, (hi(dct_quant)+h2_one), hi(dct_quant));
  
    sign = itocc(int(d2 <= 0));
    round_cmp = select(sign, uh2_half, uh2_almost_half);
    dct_quant = quant[2] * shift(d2, 2);
    add = itocc(int(round_cmp < uhalf2(lo(dct_quant))));
    out << select(add, (hi(dct_quant)+h2_one), hi(dct_quant));
  
    sign = itocc(int(d3 <= 0));
    round_cmp = select(sign, uh2_half, uh2_almost_half);
    dct_quant = quant[3] * shift(d3, 2);
    add = itocc(int(round_cmp < uhalf2(lo(dct_quant))));
    out << select(add, (hi(dct_quant)+h2_one), hi(dct_quant));
  
    sign = itocc(int(d4 <= 0));
    round_cmp = select(sign, uh2_half, uh2_almost_half);
    dct_quant = quant[4] * shift(d4, 2);
    add = itocc(int(round_cmp < uhalf2(lo(dct_quant))));
    out << select(add, (hi(dct_quant)+h2_one), hi(dct_quant));
  
    sign = itocc(int(d5 <= 0));
    round_cmp = select(sign, uh2_half, uh2_almost_half);
    dct_quant = quant[5] * shift(d5, 2);
    add = itocc(int(round_cmp < uhalf2(lo(dct_quant))));
    out << select(add, (hi(dct_quant)+h2_one), hi(dct_quant));
  
    sign = itocc(int(d6 <= 0));
    round_cmp = select(sign, uh2_half, uh2_almost_half);
    dct_quant = quant[6] * shift(d6, 2);
    add = itocc(int(round_cmp < uhalf2(lo(dct_quant))));
    out << select(add, (hi(dct_quant)+h2_one), hi(dct_quant));
  
    sign = itocc(int(d7 <= 0));
    round_cmp = select(sign, uh2_half, uh2_almost_half);
    dct_quant = quant[7] * shift(d7, 2);
    add = itocc(int(round_cmp < uhalf2(lo(dct_quant))));
    out << select(add, (hi(dct_quant)+h2_one), hi(dct_quant));
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -