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

Last change on this file since 4939 was 4939, checked in by lindanl, 4 years ago

new version using the kernels.

File size: 2.3 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
9
10void s2p_step(IDISA::IDISA_Builder * iBuilder, Value * s0, Value * s1, Value * hi_mask, unsigned shift, Value * &p0, Value * &p1) {
11    Value * t0 = iBuilder->hsimd_packh(16, s0, s1);
12    Value * t1 = iBuilder->hsimd_packl(16, s0, s1);
13    p0 = iBuilder->simd_if(1, hi_mask, t0, iBuilder->simd_srli(16, t1, shift));
14    p1 = iBuilder->simd_if(1, hi_mask, iBuilder->simd_slli(16, t0, shift), t1);
15}
16
17void s2p(IDISA::IDISA_Builder * iBuilder, std::vector<Value*> s, Value* p[]) {
18    Value * bit00224466[4];
19    Value * bit11335577[4];
20    for (unsigned i = 0; i<4; i++) {
21        s2p_step(iBuilder, s[2*i], s[2*i+1], iBuilder->simd_himask(2), 1, bit00224466[i], bit11335577[i]);
22    }
23    Value * bit00004444[2];
24    Value * bit22226666[2];
25    Value * bit11115555[2];
26    Value * bit33337777[2];
27    for (unsigned j = 0; j<2; j++) {
28        s2p_step(iBuilder, bit00224466[2*j], bit00224466[2*j+1],
29                 iBuilder->simd_himask(4), 2, bit00004444[j], bit22226666[j]);
30        s2p_step(iBuilder, bit11335577[2*j], bit11335577[2*j+1],
31                 iBuilder->simd_himask(4), 2, bit11115555[j], bit33337777[j]);
32    }
33    s2p_step(iBuilder, bit00004444[0], bit00004444[1], iBuilder->simd_himask(8), 4, p[0], p[4]);
34    s2p_step(iBuilder, bit11115555[0], bit11115555[1], iBuilder->simd_himask(8), 4, p[1], p[5]);
35    s2p_step(iBuilder, bit22226666[0], bit22226666[1], iBuilder->simd_himask(8), 4, p[2], p[6]);
36    s2p_step(iBuilder, bit33337777[0], bit33337777[1], iBuilder->simd_himask(8), 4, p[3], p[7]);
37}
38
39
40void generateS2PKernel(Module * m, IDISA::IDISA_Builder * iBuilder, KernelBuilder * kBuilder){
41
42    kBuilder->addKernelInputStream(8, "byte_pack");
43    for(int i=0; i<8; i++)
44        kBuilder->addKernelOutputStream(1);
45
46    int segBlocks = kBuilder->getSegmentBlocks();
47
48    kBuilder->PrepareDoBlockFunction();   
49    struct Inputs inputs = kBuilder->openDoBlock();
50    struct Outputs outputs;
51
52    valptr basis_bit[segBlocks][8];
53    for(int i=0; i<segBlocks; i++){
54        s2p(iBuilder, inputs.streams[i], basis_bit[i]);
55        outputs.streams.push_back(basis_bit[i]);
56    }
57
58    kBuilder->closeDoBlock(outputs);
59
60    kBuilder->finalizeMethods();
61
62}
63
64
65
66
67
68
69
70
71
72
73
Note: See TracBrowser for help on using the repository browser.