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

📄 corr_kc.cpp

📁 H.264完整的C语言代码和DCT的代码
💻 CPP
字号:
#include "idb_kernelc.hpp"   
#include "mpeg.hpp"
#include "idb_kernelc2.hpp"   

KERNELDEF(correlate, KERNELS_DIR "/corr_kc.uc");

// corr.i    -- correlate idct'ed differences with reference block
// Scott Rixner 3/8/00

kernel correlate(istream<half2> diffyblks,
                 istream<half2> diffcblks,
                 istream<ubyte4> refyblks,
                 istream<half2> refcblks,
                 ostream<ubyte4> newrefyblks,
                 ostream<half2> newrefcblks,
                 uc<uint>& uc_pframe)
{
  // Comm permutations used to transpose the block
  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;

  // calculate cluster dependent send and store indices
  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;

  // Shuffle control words
  byte4 b32_to_lo = 0x88888823; // lo: zero | zero | zero |  3rd
                                // hi: zero | zero | zero |  2nd
  byte4 b10_to_lo = 0x88888801; // lo: zero | zero | zero |  1st
                                // hi: zero | zero | zero |  0th
  byte4 b32_to_hi = 0x88238888; // lo: zero |  3rd | zero | zero
                                // hi: zero |  2nd | zero | zero
  byte4 b10_to_hi = 0x88018888; // lo: zero |  1st | zero | zero
                                // hi: zero |  0th | zero | zero
  byte4 h2_to_b3  = 0x02888888; // lo:  2nd | zero | zero | zero
                                // hi:  0th | zero | zero | zero
  byte4 h2_to_b2  = 0x88028888; // lo: zero |  2nd | zero | zero
                                // hi: zero |  0th | zero | zero
  byte4 h2_to_b1  = 0x88880288; // lo: zero | zero |  2nd | zero
                                // hi: zero | zero |  0th | zero
  byte4 h2_to_b0  = 0x88888802; // lo: zero | zero | zero |  2nd
                                // hi: zero | zero | zero |  0th

  cc merge  = itocc(0x0000FFFF);
  cc pframe = itocc(commclperm(0x8, uint(0), uc_pframe));
                                   
  loop_stream(diffyblks) pipeline(1) {
    expand<half2> currc(8);
    expand<half2> refc(8);
    expand<half2> diffc(8);

    diffcblks >> diffc[0];
    diffcblks >> diffc[1];
    diffcblks >> diffc[2];
    diffcblks >> diffc[3];
    diffcblks >> diffc[4];
    diffcblks >> diffc[5];
    diffcblks >> diffc[6];
    diffcblks >> diffc[7];
    refcblks  >> refc[0];
    refcblks  >> refc[1];
    refcblks  >> refc[2];
    refcblks  >> refc[3];
    refcblks  >> refc[4];
    refcblks  >> refc[5];
    refcblks  >> refc[6];
    refcblks  >> refc[7];

    expand<half2> curry(8);
    expand<ubyte4> refy(8);
    expand<ubyte4> packedy(8);

    array<half2> diffy(8), diffy21(8), diffy43(8);

    diffyblks >> diffy21[0];
    diffyblks >> diffy21[1];
    diffyblks >> diffy21[2];
    diffyblks >> diffy21[3];
    diffyblks >> diffy21[4];
    diffyblks >> diffy21[5];
    diffyblks >> diffy21[6];
    diffyblks >> diffy21[7];
    diffyblks >> diffy43[0];
    diffyblks >> diffy43[1];
    diffyblks >> diffy43[2];
    diffyblks >> diffy43[3];
    diffyblks >> diffy43[4];
    diffyblks >> diffy43[5];
    diffyblks >> diffy43[6];
    diffyblks >> diffy43[7];
    refyblks  >> refy[0];
    refyblks  >> refy[1];
    refyblks  >> refy[2];
    refyblks  >> refy[3];
    refyblks  >> refy[4];
    refyblks  >> refy[5];
    refyblks  >> refy[6];
    refyblks  >> refy[7];

    currc[0] = diffc[0] + select(pframe, refc[0], 0);
    currc[1] = diffc[1] + select(pframe, refc[1], 0);
    currc[2] = diffc[2] + select(pframe, refc[2], 0);
    currc[3] = diffc[3] + select(pframe, refc[3], 0);
    currc[4] = diffc[4] + select(pframe, refc[4], 0);
    currc[5] = diffc[5] + select(pframe, refc[5], 0);
    currc[6] = diffc[6] + select(pframe, refc[6], 0);
    currc[7] = diffc[7] + select(pframe, refc[7], 0);

    newrefcblks << currc[0];
    newrefcblks << currc[1];
    newrefcblks << currc[2];
    newrefcblks << currc[3];
    newrefcblks << currc[4];
    newrefcblks << currc[5];
    newrefcblks << currc[6];
    newrefcblks << currc[7];

    // diffy has 9 bits of precision.  diffy + refy is guaranteed
    //  to have 8 bits of precision.
    
    // Transpose diffy21
    diffy[idx0] = diffy21[idx0];
    diffy[idx7] = commucperm(perm_a, diffy21[idx1]);
    diffy[idx6] = commucperm(perm_b, diffy21[idx2]);
    diffy[idx5] = commucperm(perm_c, diffy21[idx3]);
    diffy[idx4] = commucperm(perm_d, diffy21[idx4]);
    diffy[idx3] = commucperm(perm_e, diffy21[idx5]);
    diffy[idx2] = commucperm(perm_f, diffy21[idx6]);
    diffy[idx1] = commucperm(perm_g, diffy21[idx7]);

    // Unpack refy from byte4's to half2's
    double<ubyte4> h0, h1, h2, h3, h4, h5, h6, h7;
    expand<half2> ref(8);

    h0 = shuffled(refy[0], b32_to_lo);
    h1 = shuffled(refy[0], b10_to_lo);
    h2 = shuffled(refy[2], b32_to_lo);
    h3 = shuffled(refy[2], b10_to_lo);
    h4 = shuffled(refy[4], b32_to_hi);
    h5 = shuffled(refy[4], b10_to_hi);
    h6 = shuffled(refy[6], b32_to_hi);
    h7 = shuffled(refy[6], b10_to_hi);

    ref[0] = half2(lo(h0) | lo(h4));
    ref[1] = half2(hi(h0) | hi(h4));
    ref[2] = half2(lo(h1) | lo(h5));
    ref[3] = half2(hi(h1) | hi(h5));
    ref[4] = half2(lo(h2) | lo(h6));
    ref[5] = half2(hi(h2) | hi(h6));
    ref[6] = half2(lo(h3) | lo(h7));
    ref[7] = half2(hi(h3) | hi(h7));
      
    curry[0] = diffy[0] + select(pframe, ref[0], 0);
    curry[1] = diffy[1] + select(pframe, ref[1], 0);
    curry[2] = diffy[2] + select(pframe, ref[2], 0);
    curry[3] = diffy[3] + select(pframe, ref[3], 0);
    curry[4] = diffy[4] + select(pframe, ref[4], 0);
    curry[5] = diffy[5] + select(pframe, ref[5], 0);
    curry[6] = diffy[6] + select(pframe, ref[6], 0);
    curry[7] = diffy[7] + select(pframe, ref[7], 0);

    // Pack curry from half2's to byte4's
    double<half2> b3, b2, b1, b0;
    b3 = shuffled(curry[0], h2_to_b3);
    b2 = shuffled(curry[1], h2_to_b2);
    b1 = shuffled(curry[2], h2_to_b1);
    b0 = shuffled(curry[3], h2_to_b0);
      
    packedy[0] = ubyte4((hi(b3) | hi(b2)) | (hi(b1) | hi(b0)));
    packedy[4] = ubyte4((lo(b3) | lo(b2)) | (lo(b1) | lo(b0)));

    b3 = shuffled(curry[4], h2_to_b3);
    b2 = shuffled(curry[5], h2_to_b2);
    b1 = shuffled(curry[6], h2_to_b1);
    b0 = shuffled(curry[7], h2_to_b0);
    
    packedy[2] = ubyte4((hi(b3) | hi(b2)) | (hi(b1) | hi(b0)));
    packedy[6] = ubyte4((lo(b3) | lo(b2)) | (lo(b1) | lo(b0)));

    // Transpose diffy43
    diffy[idx0] = diffy43[idx0];
    diffy[idx7] = commucperm(perm_a, diffy43[idx1]);
    diffy[idx6] = commucperm(perm_b, diffy43[idx2]);
    diffy[idx5] = commucperm(perm_c, diffy43[idx3]);
    diffy[idx4] = commucperm(perm_d, diffy43[idx4]);
    diffy[idx3] = commucperm(perm_e, diffy43[idx5]);
    diffy[idx2] = commucperm(perm_f, diffy43[idx6]);
    diffy[idx1] = commucperm(perm_g, diffy43[idx7]);

    // Unpack refy from byte4's to half2's
    h0 = shuffled(refy[1], b32_to_lo);
    h1 = shuffled(refy[1], b10_to_lo);
    h2 = shuffled(refy[3], b32_to_lo);
    h3 = shuffled(refy[3], b10_to_lo);
    h4 = shuffled(refy[5], b32_to_hi);
    h5 = shuffled(refy[5], b10_to_hi);
    h6 = shuffled(refy[7], b32_to_hi);
    h7 = shuffled(refy[7], b10_to_hi);

    ref[0] = half2(lo(h0) | lo(h4));
    ref[1] = half2(hi(h0) | hi(h4));
    ref[2] = half2(lo(h1) | lo(h5));
    ref[3] = half2(hi(h1) | hi(h5));
    ref[4] = half2(lo(h2) | lo(h6));
    ref[5] = half2(hi(h2) | hi(h6));
    ref[6] = half2(lo(h3) | lo(h7));
    ref[7] = half2(hi(h3) | hi(h7));
      
    curry[0] = diffy[0] + select(pframe, ref[0], 0); 
    curry[1] = diffy[1] + select(pframe, ref[1], 0); 
    curry[2] = diffy[2] + select(pframe, ref[2], 0);
    curry[3] = diffy[3] + select(pframe, ref[3], 0);
    curry[4] = diffy[4] + select(pframe, ref[4], 0);
    curry[5] = diffy[5] + select(pframe, ref[5], 0);
    curry[6] = diffy[6] + select(pframe, ref[6], 0);
    curry[7] = diffy[7] + select(pframe, ref[7], 0);

    // Pack curry from half2's to byte4's
    b3 = shuffled(curry[0], h2_to_b3);
    b2 = shuffled(curry[1], h2_to_b2);
    b1 = shuffled(curry[2], h2_to_b1);
    b0 = shuffled(curry[3], h2_to_b0);
      
    packedy[1] = ubyte4((hi(b3) | hi(b2)) | (hi(b1) | hi(b0)));
    packedy[5] = ubyte4((lo(b3) | lo(b2)) | (lo(b1) | lo(b0)));

    b3 = shuffled(curry[4], h2_to_b3);
    b2 = shuffled(curry[5], h2_to_b2);
    b1 = shuffled(curry[6], h2_to_b1);
    b0 = shuffled(curry[7], h2_to_b0);
    
    packedy[3] = ubyte4((hi(b3) | hi(b2)) | (hi(b1) | hi(b0)));
    packedy[7] = ubyte4((lo(b3) | lo(b2)) | (lo(b1) | lo(b0)));

    newrefyblks << packedy[0];
    newrefyblks << packedy[1];
    newrefyblks << packedy[2];
    newrefyblks << packedy[3];
    newrefyblks << packedy[4];
    newrefyblks << packedy[5];
    newrefyblks << packedy[6];
    newrefyblks << packedy[7];
  }
}

⌨️ 快捷键说明

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