source: icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.cpp @ 4957

Last change on this file since 4957 was 4957, checked in by cameron, 3 years ago

Alternative transposition strategies with AVX2

File size: 2.7 KB
Line 
1/*
2 *  Copyright (c) 2015 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5#include "kernel.h"
6#include "s2p_kernel.h"
7#include <iostream>
8
9const int PACK_LANES = 1;
10
11void s2p_step(IDISA::IDISA_Builder * iBuilder, Value * s0, Value * s1, Value * hi_mask, unsigned shift, Value * &p0, Value * &p1) {
12    Value * t0 = nullptr;
13    Value * t1 = nullptr;
14    if ((iBuilder->getBitBlockWidth() == 256) && (PACK_LANES == 2)) {
15        Value * x0 = iBuilder->esimd_mergel(128, s0, s1);
16        Value * x1 = iBuilder->esimd_mergeh(128, s0, s1);
17        t0 = iBuilder->hsimd_packh_in_lanes(PACK_LANES, 16, x0, x1);
18        t1 = iBuilder->hsimd_packl_in_lanes(PACK_LANES, 16, x0, x1);
19    }
20    else {
21        t0 = iBuilder->hsimd_packh(16, s0, s1);
22        t1 = iBuilder->hsimd_packl(16, s0, s1);
23    }
24    p0 = iBuilder->simd_if(1, hi_mask, t0, iBuilder->simd_srli(16, t1, shift));
25    p1 = iBuilder->simd_if(1, hi_mask, iBuilder->simd_slli(16, t0, shift), t1);
26}
27
28void s2p(IDISA::IDISA_Builder * iBuilder, std::vector<Value*> s, Value* p[]) {
29    Value * bit00224466[4];
30    Value * bit11335577[4];
31    for (unsigned i = 0; i<4; i++) {
32        s2p_step(iBuilder, s[2*i], s[2*i+1], iBuilder->simd_himask(2), 1, bit00224466[i], bit11335577[i]);
33    }
34    Value * bit00004444[2];
35    Value * bit22226666[2];
36    Value * bit11115555[2];
37    Value * bit33337777[2];
38    for (unsigned j = 0; j<2; j++) {
39        s2p_step(iBuilder, bit00224466[2*j], bit00224466[2*j+1],
40                 iBuilder->simd_himask(4), 2, bit00004444[j], bit22226666[j]);
41        s2p_step(iBuilder, bit11335577[2*j], bit11335577[2*j+1],
42                 iBuilder->simd_himask(4), 2, bit11115555[j], bit33337777[j]);
43    }
44    s2p_step(iBuilder, bit00004444[0], bit00004444[1], iBuilder->simd_himask(8), 4, p[0], p[4]);
45    s2p_step(iBuilder, bit11115555[0], bit11115555[1], iBuilder->simd_himask(8), 4, p[1], p[5]);
46    s2p_step(iBuilder, bit22226666[0], bit22226666[1], iBuilder->simd_himask(8), 4, p[2], p[6]);
47    s2p_step(iBuilder, bit33337777[0], bit33337777[1], iBuilder->simd_himask(8), 4, p[3], p[7]);
48}
49
50
51void generateS2PKernel(Module * m, IDISA::IDISA_Builder * iBuilder, KernelBuilder * kBuilder){
52
53    kBuilder->addKernelInputStream(8, "byte_pack");
54    for(int i=0; i<8; i++)
55        kBuilder->addKernelOutputStream(1);
56
57    int segBlocks = kBuilder->getSegmentBlocks();
58
59    kBuilder->PrepareDoBlockFunction();   
60    struct Inputs inputs = kBuilder->openDoBlock();
61    struct Outputs outputs;
62
63    valptr basis_bit[segBlocks][8];
64    for(int i=0; i<segBlocks; i++){
65        s2p(iBuilder, inputs.streams[i], basis_bit[i]);
66        outputs.streams.push_back(basis_bit[i]);
67    }
68
69    kBuilder->closeDoBlock(outputs);
70
71    kBuilder->finalizeMethods();
72
73}
74
75
76
77
78
79
80
81
82
83
84
Note: See TracBrowser for help on using the repository browser.