Ignore:
Timestamp:
Jun 14, 2018, 10:41:45 AM (13 months ago)
Author:
cameron
Message:

Little-endian/big-endian bit number options, default to little-endian

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.cpp

    r6004 r6089  
    1818    s0 = iBuilder->esimd_mergel(8, t1, t0);
    1919}
    20 
    21 inline void p2s(const std::unique_ptr<KernelBuilder> & iBuilder, Value * p[], Value * s[]) {
     20#define LITTLE_ENDIAN_BIT_NUMBERING
     21
     22inline void p2s(const std::unique_ptr<KernelBuilder> & iBuilder, Value * p[], Value * s[], cc::BitNumbering basisNumbering = cc::BitNumbering::LittleEndian) {
    2223    Value * bit00004444[2];
    2324    Value * bit22226666[2];
    2425    Value * bit11115555[2];
    2526    Value * bit33337777[2];
    26     p2s_step(iBuilder, p[0], p[4], iBuilder->simd_himask(8), 4, bit00004444[1], bit00004444[0]);
    27     p2s_step(iBuilder, p[1], p[5], iBuilder->simd_himask(8), 4, bit11115555[1], bit11115555[0]);
    28     p2s_step(iBuilder, p[2], p[6], iBuilder->simd_himask(8), 4, bit22226666[1], bit22226666[0]);
    29     p2s_step(iBuilder, p[3], p[7], iBuilder->simd_himask(8), 4, bit33337777[1], bit33337777[0]);
     27    if (basisNumbering == cc::BitNumbering::BigEndian) {
     28        p2s_step(iBuilder, p[0], p[4], iBuilder->simd_himask(8), 4, bit00004444[1], bit00004444[0]);
     29        p2s_step(iBuilder, p[1], p[5], iBuilder->simd_himask(8), 4, bit11115555[1], bit11115555[0]);
     30        p2s_step(iBuilder, p[2], p[6], iBuilder->simd_himask(8), 4, bit22226666[1], bit22226666[0]);
     31        p2s_step(iBuilder, p[3], p[7], iBuilder->simd_himask(8), 4, bit33337777[1], bit33337777[0]);
     32    }  else {
     33        p2s_step(iBuilder, p[7], p[3], iBuilder->simd_himask(8), 4, bit00004444[1], bit00004444[0]);
     34        p2s_step(iBuilder, p[6], p[2], iBuilder->simd_himask(8), 4, bit11115555[1], bit11115555[0]);
     35        p2s_step(iBuilder, p[5], p[1], iBuilder->simd_himask(8), 4, bit22226666[1], bit22226666[0]);
     36        p2s_step(iBuilder, p[4], p[0], iBuilder->simd_himask(8), 4, bit33337777[1], bit33337777[0]);
     37    }
    3038    Value * bit00224466[4];
    3139    Value * bit11335577[4];
     
    4553    }
    4654    Value * s_bytepack[8];
    47     p2s(b, p_bitblock, s_bytepack);
     55    p2s(b, p_bitblock, s_bytepack, mBasisSetNumbering);
    4856    for (unsigned j = 0; j < 8; ++j) {
    4957        b->storeOutputStreamPack("byteStream", b->getInt32(0), b->getInt32(j), s_bytepack[j]);
     
    7078    }
    7179    Value * bytePack[8];
    72     p2s(b, basisBits, bytePack);
     80    p2s(b, basisBits, bytePack, mBasisSetNumbering);
    7381
    7482    Value * const fieldCounts = b->loadInputStreamBlock("fieldCounts", b->getInt32(0));
     
    9199    Value * hi_input[8];
    92100    for (unsigned j = 0; j < 8; ++j) {
    93         hi_input[j] = b->loadInputStreamBlock("basisBits", b->getInt32(j));
     101        const unsigned idx = mBasisSetNumbering == cc::BitNumbering::LittleEndian ? j + 8 : j;
     102        hi_input[j] = b->loadInputStreamBlock("basisBits", b->getInt32(idx));
    94103    }
    95104    Value * hi_bytes[8];
    96     p2s(b, hi_input, hi_bytes);
     105    p2s(b, hi_input, hi_bytes, mBasisSetNumbering);
    97106    Value * lo_input[8];
    98107    for (unsigned j = 0; j < 8; ++j) {
    99         lo_input[j] = b->loadInputStreamBlock("basisBits", b->getInt32(j + 8));
     108        const unsigned idx = mBasisSetNumbering == cc::BitNumbering::LittleEndian ? j : j + 8;
     109        lo_input[j] = b->loadInputStreamBlock("basisBits", b->getInt32(idx));
    100110    }
    101111    Value * lo_bytes[8];
    102     p2s(b, lo_input, lo_bytes);
     112    p2s(b, lo_input, lo_bytes, mBasisSetNumbering);
    103113    for (unsigned j = 0; j < 8; ++j) {
    104114        Value * merge0 = b->bitCast(b->esimd_mergel(8, hi_bytes[j], lo_bytes[j]));
     
    118128    Value * hi_input[8];
    119129    for (unsigned j = 0; j < 8; ++j) {
    120         hi_input[j] = b->loadInputStreamBlock("basisBits", b->getInt32(j));
     130        const unsigned idx = mBasisSetNumbering == cc::BitNumbering::LittleEndian ? j + 8 : j;
     131        hi_input[j] = b->loadInputStreamBlock("basisBits", b->getInt32(idx));
    121132    }
    122133    Value * hi_bytes[8];
    123     p2s(b, hi_input, hi_bytes);
     134    p2s(b, hi_input, hi_bytes, mBasisSetNumbering);
    124135
    125136    Value * lo_input[8];
    126137    for (unsigned j = 0; j < 8; ++j) {
    127         lo_input[j] = b->loadInputStreamBlock("basisBits", b->getInt32(j + 8));
     138        const unsigned idx = mBasisSetNumbering == cc::BitNumbering::LittleEndian ? j : j + 8;
     139        lo_input[j] = b->loadInputStreamBlock("basisBits", b->getInt32(idx));
    128140    }
    129141    Value * lo_bytes[8];
    130     p2s(b, lo_input, lo_bytes);
     142    p2s(b, lo_input, lo_bytes, mBasisSetNumbering);
    131143
    132144    Value * const fieldCounts = b->loadInputStreamBlock("fieldCounts", b->getInt32(0));
     
    160172}
    161173
    162 P2SKernel::P2SKernel(const std::unique_ptr<kernel::KernelBuilder> & b)
    163 : BlockOrientedKernel("p2s",
     174P2SKernel::P2SKernel(const std::unique_ptr<kernel::KernelBuilder> & b, cc::BitNumbering numbering)
     175    : BlockOrientedKernel("p2s" + cc::numberingSuffix(numbering),
    164176              {Binding{b->getStreamSetTy(8, 1), "basisBits"}},
    165177              {Binding{b->getStreamSetTy(1, 8), "byteStream"}},
    166               {}, {}, {}) {
    167 }
    168 
    169 P2SKernelWithCompressedOutput::P2SKernelWithCompressedOutput(const std::unique_ptr<kernel::KernelBuilder> & b)
    170 : BlockOrientedKernel("p2s_compress",
     178              {}, {}, {}),
     179    mBasisSetNumbering(numbering) {
     180}
     181
     182P2SKernelWithCompressedOutput::P2SKernelWithCompressedOutput(const std::unique_ptr<kernel::KernelBuilder> & b, cc::BitNumbering numbering)
     183: BlockOrientedKernel("p2s_compress" + cc::numberingSuffix(numbering),
    171184              {Binding{b->getStreamSetTy(8, 1), "basisBits"}, Binding{b->getStreamSetTy(1, 1), "fieldCounts"}},
    172185              {Binding{b->getStreamSetTy(1, 8), "byteStream", BoundedRate(0, 1)}},
    173               {}, {}, {}) {
    174 }
    175 
    176 P2S16Kernel::P2S16Kernel(const std::unique_ptr<kernel::KernelBuilder> & b)
    177 : BlockOrientedKernel("p2s_16",
     186                      {}, {}, {}),
     187    mBasisSetNumbering(numbering) {
     188}
     189
     190P2S16Kernel::P2S16Kernel(const std::unique_ptr<kernel::KernelBuilder> & b, cc::BitNumbering numbering)
     191: BlockOrientedKernel("p2s_16" + cc::numberingSuffix(numbering),
    178192              {Binding{b->getStreamSetTy(16, 1), "basisBits"}},
    179193              {Binding{b->getStreamSetTy(1, 16), "i16Stream"}},
    180               {}, {}, {}) {
    181 }
    182 
    183 
    184 P2S16KernelWithCompressedOutput::P2S16KernelWithCompressedOutput(const std::unique_ptr<kernel::KernelBuilder> & b)
    185 : BlockOrientedKernel("p2s_16_compress",
     194                      {}, {}, {}),
     195    mBasisSetNumbering(numbering) {
     196}
     197
     198
     199P2S16KernelWithCompressedOutput::P2S16KernelWithCompressedOutput(const std::unique_ptr<kernel::KernelBuilder> & b, cc::BitNumbering numbering)
     200: BlockOrientedKernel("p2s_16_compress" + cc::numberingSuffix(numbering),
    186201              {Binding{b->getStreamSetTy(16, 1), "basisBits"}, Binding{b->getStreamSetTy(1, 1), "fieldCounts"}},
    187202              {Binding{b->getStreamSetTy(1, 16), "i16Stream", BoundedRate(0, 1)}},
    188203              {},
    189204              {},
    190               {}) {
    191 
    192 }
    193    
    194    
    195 }
     205              {}),
     206    mBasisSetNumbering(numbering) {
     207}
     208   
     209   
     210}
Note: See TracChangeset for help on using the changeset viewer.