Debian Codegraph @

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

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 #include "InstCompactor.hpp"
10 #include "../../bits.hpp"
11
12 using namespace iga;
13
14 bool InstCompactor::compactIndex(const CompactionMapping &cm, int immLo,
15 int immHi) {
16 // fragments are ordered from high bit down to 0
17 // hence, we have to walk them in reverse order to build the
18 // word in reverse order
19 //
20 // we build up the don't-care mask as we assemble the
21 // desired mapping
22 uint64_t relevantBits = 0xFFFFFFFFFFFFFFFFull;
23 int indexOffset = 0; // offset into the compaction index value
24 uint64_t mappedValue = 0;
25 for (int i = (int)cm.numMappings - 1; i >= 0; i--) {
26 // assume atomic field
27 const Fragment &mappedFragment = *cm.mappings[i];
28 if (rangeContains(immLo, immHi, mappedFragment.offset) ||
29 rangeContains(immLo, immHi,
30 mappedFragment.offset + mappedFragment.length - 1)) {
31 // this is a don't-care field since the imm value expands
32 // into this field; strip those bits out
33 relevantBits &=
34 ~getFieldMask<uint64_t>(indexOffset, mappedFragment.length);
35 } else {
36 // we omit the random bits in don't care fields to give us
37 // a normalized lookup value (for debugging)
38 // technically we can match any table entry for don't-care
39 // bits
40 uint64_t uncompactedValue = uncompactedBits.getFragment(mappedFragment);
41 iga::setBits(mappedValue, indexOffset, mappedFragment.length,
42 uncompactedValue);
43 }
44 indexOffset += mappedFragment.length;
45 }
46
47 // TODO: make lookup constant (could use a prefix tree or just a simple hash)
48 for (size_t i = 0; i < cm.numValues; i++) {
49 if ((cm.values[i] & relevantBits) == mappedValue) {
50 if (!compactedBits.setField(cm.index, (uint64_t)i)) {
51 IGA_ASSERT_FALSE("compaction index overruns field");
52 }
53 return true; // hit
54 }
55 }
56
57 // compaction miss
58 fail(cm, mappedValue);
59 return compactionDebugInfo != nullptr;
60 }
61
62 CompactionResult InstCompactor::tryToCompactImpl() {
63 switch (model.platform) {
64 case Platform::XE:
65 case Platform::XE_HP:
66 case Platform::XE_HPG:
67 case Platform::XE_HPC:
68 case Platform::XE2:
69 case Platform::XE3:
70 return tryToCompactImplFamilyXE();
71 case Platform::FUTURE:
72 default:
73 compactionMissed = true;
74 IGA_ASSERT_FALSE("compaction not supported on this platform");
75 return CompactionResult::CR_NO_COMPACT;
76 }
77 }
78
79 CompactionResult InstCompactor::tryToCompactImplFamilyXE() {
80 compactionResult = CompactionResult::CR_NO_FORMAT;
81 return compactionResult;
82 }