source: icGREP/icgrep-devel/icgrep/kernels/lz4_index_decoder.h @ 5425

Last change on this file since 5425 was 5422, checked in by cameron, 2 years ago

lz4d - LZ4 decompressor - initial check-in

File size: 3.4 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 *  icgrep is a trademark of International Characters.
5 */
6
7#ifndef LZ4_INDEX_DECODER_H
8#define LZ4_INDEX_DECODER_H
9
10#include <map>
11
12#include "kernel.h"
13
14namespace llvm {
15    class Module;
16    class Function;
17    class BasicBlock;
18    class Value;
19}
20namespace IDISA { class IDISA_Builder; }
21
22namespace kernel {
23
24class LZ4IndexDecoderKernel : public BlockOrientedKernel {
25public:
26    LZ4IndexDecoderKernel(IDISA::IDISA_Builder * iBuilder);
27protected:
28    void generateDoBlockMethod() override;
29private:
30    bool useIndirectBr() const override;
31
32    enum State : unsigned char {
33        AT_BLOCK_SIZE = 0,
34        AT_TOKEN = 1,
35        EXTENDING_LITERAL_LENGTH = 2,
36        AT_LITERALS = 3,
37        AT_FIRST_OFFSET = 4,
38        AT_SECOND_OFFSET = 5,
39        EXTENDING_MATCH_LENGTH = 6,
40        AT_BLOCK_CHECKSUM = 7,
41        SKIPPING_BYTES = 255,   // not included in the indirectbr table
42    };
43
44    const std::map<enum State, std::string> StateLabels = {
45        {State::AT_BLOCK_SIZE, "at_block_size"},
46        {State::AT_TOKEN, "at_token"},
47        {State::EXTENDING_LITERAL_LENGTH, "extending_literal_length"},
48        {State::AT_LITERALS, "at_literals"},
49        {State::AT_FIRST_OFFSET, "at_first_offset"},
50        {State::AT_SECOND_OFFSET, "at_second_offset"},
51        {State::EXTENDING_MATCH_LENGTH, "extending_match_length"},
52        {State::AT_BLOCK_CHECKSUM, "at_block_checksum"},
53        {State::SKIPPING_BYTES, "skipping_bytes"},
54    };
55
56    const size_t wordWidth;
57
58    // Some variables that are constant (at least in each bit block).
59    llvm::Value * blockStartPos;        // The global position of the start of the block.
60    llvm::Value * extenders;    // Bitcasted extender stream.
61 
62    // Stack variables (will be promoted by mem2reg).
63    llvm::Value * sOffset;      // offset within the current bit block
64    llvm::Value * sTempLength;  // tempLength have different purposes in different states.
65    llvm::Value * sTempCount;   // tempCount is used as a loop counter.
66    llvm::Value * sExtender;    // Current extender word.
67    llvm::Value * sState;
68
69    // Helper methods.
70    llvm::Value * getWordOffset();
71    llvm::Value * getWordStartOffset();
72    llvm::Value * loadRawByte(llvm::Value * offset);
73    void setExtenderUntilOffset();
74    void loadCurrentExtender();
75
76    void generateProduceOutput();
77    void generateBoundaryDetection(State state, llvm::BasicBlock * exit_block, bool updateExtenderWord);
78    // Generate basic blocks for each state.
79    void generateSkippingBytes(llvm::BasicBlock * bb, llvm::BasicBlock * exit_block);
80    void generateAtBlockSize(llvm::BasicBlock * bb, llvm::BasicBlock * skippingBytes, llvm::BasicBlock * exit_block);
81    void generateAtToken(llvm::BasicBlock * bb, llvm::BasicBlock * exit_block);
82    void generateExtendingLiteralLen(llvm::BasicBlock * bb, llvm::BasicBlock * exit_block);
83    void generateAtLiterals(llvm::BasicBlock * bb);
84    void generateAtFirstOffset(llvm::BasicBlock * bb, llvm::BasicBlock * exit_block);
85    void generateAtSecondOffset(llvm::BasicBlock * bb, llvm::BasicBlock * exit_block);
86    void generateExtendingMatchLen(llvm::BasicBlock * bb, llvm::BasicBlock * exit_block);
87    void generateAtBlockChecksum(llvm::BasicBlock * bb, llvm::BasicBlock * skippingBytes);
88};
89
90}
91
92#endif // LZ4_INDEX_DECODER_H
Note: See TracBrowser for help on using the repository browser.