source: icGREP/icgrep-devel/icgrep/kernels/alignedprint.cpp @ 5298

Last change on this file since 5298 was 5297, checked in by nmedfort, 3 years ago

Partial removal of BlockNo?

File size: 3.8 KB
Line 
1/*
2 *  Copyright (c) 2017 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5
6#include "alignedprint.h"
7#include <IR_Gen/idisa_builder.h>  // for IDISA_Builder
8
9using namespace llvm;
10
11namespace kernel {
12
13    void p2s_step(IDISA::IDISA_Builder * iBuilder, Value * p0, Value * p1, Value * hi_mask, unsigned shift, Value * &s1, Value * &s0) {
14    Value * t0 = iBuilder->simd_if(1, hi_mask, p0, iBuilder->simd_srli(16, p1, shift));
15    Value * t1 = iBuilder->simd_if(1, hi_mask, iBuilder->simd_slli(16, p0, shift), p1);
16    s1 = iBuilder->esimd_mergeh(8, t1, t0);
17    s0 = iBuilder->esimd_mergel(8, t1, t0);
18}
19
20inline void p2s(IDISA::IDISA_Builder * iBuilder, Value * p[], Value * s[]) {
21    Value * bit00004444[2];
22    Value * bit22226666[2];
23    Value * bit11115555[2];
24    Value * bit33337777[2];
25    p2s_step(iBuilder, p[0], p[4], iBuilder->simd_himask(8), 4, bit00004444[1], bit00004444[0]);
26    p2s_step(iBuilder, p[1], p[5], iBuilder->simd_himask(8), 4, bit11115555[1], bit11115555[0]);
27    p2s_step(iBuilder, p[2], p[6], iBuilder->simd_himask(8), 4, bit22226666[1], bit22226666[0]);
28    p2s_step(iBuilder, p[3], p[7], iBuilder->simd_himask(8), 4, bit33337777[1], bit33337777[0]);
29    Value * bit00224466[4];
30    Value * bit11335577[4];
31    for (unsigned j = 0; j<2; j++) {
32        p2s_step(iBuilder, bit00004444[j], bit22226666[j],iBuilder->simd_himask(4), 2, bit00224466[2*j+1], bit00224466[2*j]);
33        p2s_step(iBuilder, bit11115555[j], bit33337777[j],iBuilder->simd_himask(4), 2, bit11335577[2*j+1], bit11335577[2*j]);
34    }
35    for (unsigned j = 0; j<4; j++) {
36        p2s_step(iBuilder, bit00224466[j], bit11335577[j], iBuilder->simd_himask(2), 1, s[2*j+1], s[2*j]);
37    }
38}
39
40void PrintableBits::generateDoBlockMethod() {
41    Value * strmPtr = getStream("bitStream", iBuilder->getInt32(0));
42   
43    Value * bitStrmVal = iBuilder->CreateBlockAlignedLoad(strmPtr);
44    Value * bits[8];
45    bits[0] = ConstantInt::getNullValue(iBuilder->getBitBlockType());
46    bits[1] = ConstantInt::getNullValue(iBuilder->getBitBlockType());
47    bits[2] = ConstantInt::getAllOnesValue(iBuilder->getBitBlockType());
48    bits[3] = bitStrmVal;
49    Value * negBitStrmVal = iBuilder->simd_not(bitStrmVal);
50    bits[4] = negBitStrmVal;
51    bits[5] = negBitStrmVal;
52    bits[6] = negBitStrmVal;
53    bits[7] = bitStrmVal;
54   
55    Value * printableBytes[8];
56    p2s(iBuilder, bits, printableBytes);
57   
58    for (unsigned j = 0; j < 8; ++j) {
59        Value * ptr = getStream("byteStream", iBuilder->getInt32(0), iBuilder->getInt32(j));
60        iBuilder->CreateBlockAlignedStore(iBuilder->bitCast(printableBytes[j]), ptr);
61    }
62}
63
64PrintableBits::PrintableBits(IDISA::IDISA_Builder * builder)
65: BlockOrientedKernel(builder, "PrintableBits", {Binding{builder->getStreamSetTy(1, 1), "bitStream"}}, {Binding{builder->getStreamSetTy(1, 8), "byteStream"}}, {}, {}, {})
66{
67    setNoTerminateAttribute(true);
68    setDoBlockUpdatesProducedItemCountsAttribute(false);
69
70}
71
72SelectStream::SelectStream(IDISA::IDISA_Builder * builder, unsigned sizeInputStreamSet, unsigned streamIndex)
73: BlockOrientedKernel(builder, "SelectStream", {Binding{builder->getStreamSetTy(sizeInputStreamSet, 1), "bitStreams"}}, {Binding{builder->getStreamSetTy(1, 1), "bitStream"}}, {}, {}, {}), mSizeInputStreamSet(sizeInputStreamSet), mStreamIndex(streamIndex)
74{
75    setNoTerminateAttribute(true);
76    setDoBlockUpdatesProducedItemCountsAttribute(false);
77
78}
79
80void SelectStream::generateDoBlockMethod() {
81    if (mStreamIndex >= mSizeInputStreamSet)
82        llvm::report_fatal_error("Stream index out of bounds.\n");
83   
84    Value * strmPtr = getStream("bitStreams", iBuilder->getInt32(mStreamIndex));
85    Value * bitStrmVal = iBuilder->CreateBlockAlignedLoad(strmPtr);
86
87    Value * ptr = getStream("bitStream", iBuilder->getInt32(0));
88    iBuilder->CreateBlockAlignedStore(bitStrmVal, ptr);
89}
90}
Note: See TracBrowser for help on using the repository browser.