-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathHexagonAlignment.h
More file actions
50 lines (40 loc) · 1.64 KB
/
HexagonAlignment.h
File metadata and controls
50 lines (40 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef HALIDE_HEXAGON_ALIGNMENT_H
#define HALIDE_HEXAGON_ALIGNMENT_H
/** \file
* Class for analyzing Alignment of loads and stores for Hexagon.
*/
#include "IR.h"
namespace Halide {
namespace Internal {
template<typename T>
bool is_hexagon_aligned(const T *op, int required_alignment, int *aligned_offset) {
int native_lanes;
if constexpr (std::is_same_v<T, Load>) {
native_lanes = required_alignment / op->type.bytes();
} else {
native_lanes = required_alignment / op->value.type().bytes();
}
debug(3) << "HexagonAlignmentAnalyzer: Check if " << op->index << " is aligned to a "
<< required_alignment << " byte boundary\n"
<< "native_lanes: " << native_lanes << "\n";
if (Expr index = op->index; !index.as<Ramp>() && index.type().is_vector()) {
debug(3) << "Is Unaligned\n";
return false;
}
internal_assert(native_lanes != 0) << "Type is larger than required alignment of " << required_alignment << " bytes\n";
// If this is a parameter, the base_alignment should be
// host_alignment. Otherwise, this is an internal buffer,
// which we assume has been aligned to the required alignment.
if (op->param.defined() && ((op->param.host_alignment() % required_alignment) != 0)) {
return false;
}
bool known_alignment = (op->alignment.modulus % native_lanes) == 0;
int64_t remainder = op->alignment.remainder % native_lanes;
if (known_alignment && aligned_offset != nullptr) {
*aligned_offset = static_cast<int>(remainder);
}
return known_alignment && remainder == 0;
}
} // namespace Internal
} // namespace Halide
#endif