Changeset 5488


Ignore:
Timestamp:
Jun 1, 2017, 8:00:42 AM (21 months ago)
Author:
cameron
Message:

IDISA bitreverse

Location:
icGREP/icgrep-devel/icgrep/IR_Gen
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_builder.cpp

    r5454 r5488  
    158158}
    159159
     160Value * IDISA_Builder::simd_bitreverse(unsigned fw, Value * a) {
     161    /*  Pure sequential solution too slow!
     162     Value * func = Intrinsic::getDeclaration(getModule(), Intrinsic::bitreverse, fwVectorType(fw));
     163     return CreateCall(func, fwCast(fw, a));
     164     */
     165    if (fw > 8) {
     166        // Reverse the bits of each byte and then use a byte shuffle to complete the job.
     167        Value * bitrev8 = fwCast(8, simd_bitreverse(8, a));
     168        const auto bytes_per_field = fw/8;
     169        const auto byte_count = mBitBlockWidth / 8;
     170        Constant * Idxs[byte_count];
     171        for (unsigned i = 0; i < byte_count; i += bytes_per_field) {
     172            for (unsigned j = 0; j < bytes_per_field; j++) {
     173                Idxs[i + j] = getInt32(i + bytes_per_field - j - 1);
     174            }
     175        }
     176        Constant * revVec = ConstantVector::get({Idxs, byte_count});
     177        return CreateShuffleVector(bitrev8, UndefValue::get(fwVectorType(8)), ConstantVector::get({Idxs, byte_count}));
     178    }
     179    else {
     180        if (fw > 2) {
     181            a = simd_bitreverse(fw/2, a);
     182        }
     183        return simd_or(simd_srli(16, simd_and(a, simd_himask(fw)), fw/2), simd_slli(16, simd_and(a, simd_lomask(fw)), fw/2));
     184    }
     185}
     186
    160187Value * IDISA_Builder::simd_if(unsigned fw, Value * cond, Value * a, Value * b) {
    161188    if (fw == 1) {
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_builder.h

    r5464 r5488  
    8181    virtual llvm::Value * simd_cttz(unsigned fw, llvm::Value * a);
    8282    virtual llvm::Value * simd_popcount(unsigned fw, llvm::Value * a);
     83    virtual llvm::Value * simd_bitreverse(unsigned fw, llvm::Value * a);
    8384   
    8485    virtual llvm::Value * esimd_mergeh(unsigned fw, llvm::Value * a, llvm::Value * b);
Note: See TracChangeset for help on using the changeset viewer.