Debian Codegraph @

visa/iga/IGALibrary/Backend/Native/InstCompactor.hpp

raw
1 /*========================== begin_copyright_notice ============================
2
3 Copyright (C) 2020-2021 Intel Corporation
4
5 SPDX-License-Identifier: MIT
6
7 ============================= end_copyright_notice ===========================*/
8
9 #ifndef IGA_BACKEND_NATIVE_INSTCOMPACTOR_HPP
10 #define IGA_BACKEND_NATIVE_INSTCOMPACTOR_HPP
11
12 #include "Field.hpp"
13 #include "InstEncoder.hpp"
14 #include "MInst.hpp"
15
16 namespace iga {
17 class InstCompactor : public BitProcessor {
18 const Model &model;
19
20 const OpSpec *os = nullptr;
21 Subfunction sfs;
22
23 MInst compactedBits;
24 MInst uncompactedBits;
25 CompactionDebugInfo *compactionDebugInfo = nullptr;
26 bool compactionMissed = false;
27
28 // the compaction result (if compaction enabled)
29 CompactionResult compactionResult = CompactionResult::CR_NO_COMPACT;
30
31 CompactionResult tryToCompactImpl();
32 CompactionResult tryToCompactImplFamilyXE();
33
34 public:
35 InstCompactor(BitProcessor &_parent, const Model &_model)
36 : BitProcessor(_parent), model(_model) {}
37
38 CompactionResult tryToCompact(const OpSpec *_os, Subfunction _sfs,
39 MInst _uncompactedBits, // copy-in
40 MInst *compactedBitsOutput, // output
41 CompactionDebugInfo *cdbi) {
42 os = _os;
43 sfs = _sfs;
44 uncompactedBits = _uncompactedBits;
45 compactedBits.qw0 = compactedBits.qw1 = 0;
46 compactionDebugInfo = cdbi;
47
48 auto cr = tryToCompactImpl();
49 if (cr == CompactionResult::CR_SUCCESS) {
50 // only clobber their memory if we succeed
51 *compactedBitsOutput = compactedBits;
52 }
53 return cr;
54 }
55 CompactionResult tryToCompact(const OpSpec *_os,
56 MInst _uncompactedBits, // copy-in
57 MInst *compactedBitsOutput, // output
58 CompactionDebugInfo *cdbi) {
59 return tryToCompact(_os, MathFC::INVALID, _uncompactedBits,
60 compactedBitsOutput, cdbi);
61 }
62
63 ///////////////////////////////////////////////////////////////////////
64 // used by child implementations
65 const OpSpec &getOpSpec() const { return *os; }
66
67 unsigned getSourceCount() const { return os->getSourceCount(sfs); }
68
69 uint64_t getUncompactedField(const Field &f) const {
70 return uncompactedBits.getField(f);
71 }
72
73 void setCompactedField(const Field &f, uint64_t val) {
74 compactedBits.setField(f, val);
75 }
76
77 bool getCompactionMissed() const { return compactionMissed; }
78
79 void setCompactionResult(CompactionResult cr) { compactionResult = cr; }
80
81 void transferField(const Field &compactedField, const Field &nativeField) {
82 IGA_ASSERT(compactedField.length() == nativeField.length(),
83 "native and compaction field length mismatch");
84 compactedBits.setField(compactedField,
85 uncompactedBits.getField(nativeField));
86 }
87
88 // returns false upon failure (so we can exit compaction early)
89 //
90 // the immLo and immHi values tells us the range of bits that hold
91 // immediate value bits; the bounds are [lo,hi): inclusive/exclusive
92 bool compactIndex(const CompactionMapping &cm, int immLo, int immHi);
93
94 bool compactIndex(const CompactionMapping &cm) {
95 return compactIndex(cm, 0, 0);
96 }
97
98 void fail(const CompactionMapping &cm, uint64_t mappedValue) {
99 if (compactionDebugInfo) {
100 compactionDebugInfo->fieldOps.push_back(os->op);
101 compactionDebugInfo->fieldMisses.push_back(&cm);
102 compactionDebugInfo->fieldMapping.push_back(mappedValue);
103 }
104 compactionMissed = true;
105 }
106 }; // InstCompactor
107
108 //
109 void CompactGenXE(Platform p, InstCompactor &ic);
110 }; // namespace iga
111
112 #endif // IGA_BACKEND_NATIVE_INSTCOMPACTOR_HPP