source: icGREP/icgrep-devel/icgrep/IR_Gen/idisa_avx_builder.h

Last change on this file was 6295, checked in by cameron, 4 months ago

Merge branch 'feat-simd-ternary' into 'master'

Implementing both simd_binary and simd_ternary operations

See merge request cameron/parabix-devel!1

File size: 5.4 KB
Line 
1#ifndef IDISA_AVX_BUILDER_H
2#define IDISA_AVX_BUILDER_H
3
4/*
5 *  Copyright (c) 2015 International Characters.
6 *  This software is licensed to the public under the Open Software License 3.0.
7*/
8
9#include <IR_Gen/idisa_sse_builder.h>
10#include <toolchain/toolchain.h>
11
12namespace IDISA {
13   
14    const unsigned AVX_width = 256;
15    const unsigned AVX512_width = 512;
16
17class IDISA_AVX_Builder : public IDISA_SSE2_Builder {
18public:
19    static const unsigned NativeBitBlockWidth = AVX_width;
20    IDISA_AVX_Builder(llvm::LLVMContext & C, unsigned vectorWidth, unsigned laneWidth)
21    : IDISA_Builder(C, AVX_width, vectorWidth, laneWidth)
22    , IDISA_SSE2_Builder(C, vectorWidth, laneWidth)
23    {
24    }
25
26    virtual std::string getBuilderUniqueName() override;
27
28    llvm::Value * hsimd_signmask(unsigned fw, llvm::Value * a) override;
29
30    ~IDISA_AVX_Builder() {}
31};
32
33class IDISA_AVX2_Builder : public IDISA_AVX_Builder {
34public:
35    static const unsigned NativeBitBlockWidth = AVX_width;
36    IDISA_AVX2_Builder(llvm::LLVMContext & C, unsigned vectorWidth, unsigned laneWidth)
37    : IDISA_Builder(C, AVX_width, vectorWidth, laneWidth)
38    , IDISA_AVX_Builder(C, vectorWidth, laneWidth) {
39        llvm::StringMap<bool> features;
40        hasBMI2 = llvm::sys::getHostCPUFeatures(features) && features.lookup("bmi2");
41    }
42
43    virtual std::string getBuilderUniqueName() override;
44    llvm::Value * hsimd_packh(unsigned fw, llvm::Value * a, llvm::Value * b) override;
45    llvm::Value * hsimd_packl(unsigned fw, llvm::Value * a, llvm::Value * b) override;
46    llvm::Value * esimd_mergeh(unsigned fw, llvm::Value * a, llvm::Value * b) override;
47    llvm::Value * esimd_mergel(unsigned fw, llvm::Value * a, llvm::Value * b) override;
48    llvm::Value * hsimd_packh_in_lanes(unsigned lanes, unsigned fw, llvm::Value * a, llvm::Value * b) override;
49    llvm::Value * hsimd_packl_in_lanes(unsigned lanes, unsigned fw, llvm::Value * a, llvm::Value * b) override;
50    std::pair<llvm::Value *, llvm::Value *> bitblock_add_with_carry(llvm::Value * a, llvm::Value * b, llvm::Value * carryin) override;
51    std::pair<llvm::Value *, llvm::Value *> bitblock_indexed_advance(llvm::Value * a, llvm::Value * index_strm, llvm::Value * shiftin, unsigned shift) override;
52    llvm::Value * hsimd_signmask(unsigned fw, llvm::Value * a) override;
53    llvm::Value * mvmd_srl(unsigned fw, llvm::Value * a, llvm::Value * shift, const bool safe = false) override;
54    llvm::Value * mvmd_sll(unsigned fw, llvm::Value * a, llvm::Value * shift, const bool safe = false) override;
55    llvm::Value * mvmd_shuffle(unsigned fw, llvm::Value * data_table, llvm::Value * index_vector) override;
56    llvm::Value * mvmd_compress(unsigned fw, llvm::Value * a, llvm::Value * select_mask) override;
57    llvm::Value * simd_pext(unsigned fw, llvm::Value * v, llvm::Value * extract_mask) override;
58    llvm::Value * simd_pdep(unsigned fw, llvm::Value * v, llvm::Value * deposit_mask) override;
59   
60
61    ~IDISA_AVX2_Builder() {}
62protected:
63    bool hasBMI2;
64};
65
66#if LLVM_VERSION_INTEGER >= LLVM_VERSION_CODE(3, 8, 0)
67class IDISA_AVX512F_Builder : public IDISA_AVX2_Builder {
68public:
69    static const unsigned NativeBitBlockWidth = AVX512_width;
70    IDISA_AVX512F_Builder(llvm::LLVMContext & C, unsigned vectorWidth, unsigned laneWidth)
71    : IDISA_Builder(C, AVX512_width, vectorWidth, laneWidth)
72    , IDISA_AVX2_Builder(C, vectorWidth, laneWidth) {
73        getAVX512Features();
74    }
75
76    virtual std::string getBuilderUniqueName() override;
77    void getAVX512Features();
78    llvm::Value * hsimd_packh(unsigned fw, llvm::Value * a, llvm::Value * b) override;
79    llvm::Value * hsimd_packl(unsigned fw, llvm::Value * a, llvm::Value * b) override;
80    llvm::Value * esimd_mergeh(unsigned fw, llvm::Value * a, llvm::Value * b) override;
81    llvm::Value * esimd_mergel(unsigned fw, llvm::Value * a, llvm::Value * b) override;
82    llvm::Value * esimd_bitspread(unsigned fw, llvm::Value * bitmask) override;
83    llvm::Value * simd_popcount(unsigned fw, llvm::Value * a) override;
84    llvm::Value * mvmd_slli(unsigned fw, llvm::Value * a, unsigned shift) override;
85    llvm::Value * mvmd_dslli(unsigned fw, llvm::Value * a, llvm::Value * b, unsigned shift) override;
86    llvm::Value * hsimd_signmask(unsigned fw, llvm::Value * a) override;
87    llvm::Value * mvmd_shuffle(unsigned fw, llvm::Value * data_table, llvm::Value * index_vector) override;
88    llvm::Value * mvmd_shuffle2(unsigned fw, llvm::Value * table0, llvm::Value * table1, llvm::Value * index_vector) override;
89    llvm::Value * mvmd_compress(unsigned fw, llvm::Value * a, llvm::Value * select_mask) override;
90    llvm::Value * mvmd_srl(unsigned fw, llvm::Value * a, llvm::Value * shift, const bool safe) override;
91    llvm::Value * mvmd_sll(unsigned fw, llvm::Value * a, llvm::Value * shift, const bool safe) override;
92    llvm::Value * simd_if(unsigned fw, llvm::Value * cond, llvm::Value * a, llvm::Value * b) override;
93    llvm::Value * simd_ternary(unsigned char mask, llvm::Value * a, llvm::Value * b, llvm::Value * c) override;
94
95    ~IDISA_AVX512F_Builder() {
96    }
97private:
98    struct Features {
99        //not an exhaustive list, can be extended if needed
100        bool hasAVX512CD = false;
101        bool hasAVX512BW = false;
102        bool hasAVX512DQ = false;
103        bool hasAVX512VL = false;
104        bool hasAVX512VBMI = false;
105        bool hasAVX512VBMI2 = false;
106        bool hasAVX512VPOPCNTDQ = false;
107    };
108    Features hostCPUFeatures;
109};
110#endif
111
112}
113#endif // IDISA_AVX_BUILDER_H
Note: See TracBrowser for help on using the repository browser.