1 /*
2 * Copyright 2023 Alyssa Rosenzweig
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include "agx_compile.h"
7 #include "agx_compiler.h"
8
9 /* Table describing the relationship between registers pressure and thread
10 * count. Each entry describes a maximum number of registers and the associated
11 * best-case thread count.
12 *
13 * Sorted in ascending order of maximum registers for easy lookup.
14 */
15 static const struct agx_occupancy occupancies[] = {
16 {104, 1024}, {112, 896}, {128, 832}, {136, 768}, {144, 704},
17 {160, 640}, {184, 576}, {208, 512}, {232, 448}, {256, 384},
18 };
19
20 struct agx_occupancy
agx_occupancy_for_register_count(unsigned halfregs)21 agx_occupancy_for_register_count(unsigned halfregs)
22 {
23 for (unsigned i = 0; i < ARRAY_SIZE(occupancies); ++i) {
24 unsigned max = occupancies[i].max_registers;
25 assert((i == 0 || max > occupancies[i - 1].max_registers) && "ascending");
26
27 if (halfregs <= max)
28 return occupancies[i];
29 }
30
31 unreachable("Register count must be less than the maximum");
32 }
33
34 unsigned
agx_max_registers_for_occupancy(unsigned occupancy)35 agx_max_registers_for_occupancy(unsigned occupancy)
36 {
37 unsigned max_regs = 0;
38
39 for (unsigned i = 0; i < ARRAY_SIZE(occupancies); ++i) {
40 if (occupancy <= occupancies[i].max_threads)
41 max_regs = occupancies[i].max_registers;
42 else
43 break;
44 }
45
46 assert(max_regs > 0 && "Thread count must be less than the maximum");
47 return max_regs;
48 }
49