|
20 | 20 | // LMUL values map to array indices as follows: |
21 | 21 | // MF8 -> Values[0], MF4 -> Values[1], MF2 -> Values[2], M1 -> Values[3], |
22 | 22 | // M2 -> Values[4], M4 -> Values[5], M8 -> Values[6] |
23 | | -// The !ge size checks ensure we don't access beyond the array bounds, for cases |
24 | | -// where M8 is not set (e.g., widening operations) |
25 | | -// TableGen will error if an invalid LMUL is passed or if the array is too short |
| 23 | +// Shorter lists are allowed, e.g., widening instructions don't work on M8 |
26 | 24 | class GetLMULValue<list<int> Values, string LMUL> { |
27 | | - int c = !cond( |
28 | | - !and(!eq(LMUL, "MF8"), !ge(!size(Values), 1)) : Values[0], |
29 | | - !and(!eq(LMUL, "MF4"), !ge(!size(Values), 2)) : Values[1], |
30 | | - !and(!eq(LMUL, "MF2"), !ge(!size(Values), 3)) : Values[2], |
31 | | - !and(!eq(LMUL, "M1"), !ge(!size(Values), 4)) : Values[3], |
32 | | - !and(!eq(LMUL, "M2"), !ge(!size(Values), 5)) : Values[4], |
33 | | - !and(!eq(LMUL, "M4"), !ge(!size(Values), 6)) : Values[5], |
34 | | - !and(!eq(LMUL, "M8"), !ge(!size(Values), 7)) : Values[6] |
| 25 | + int Index = !cond( |
| 26 | + !eq(LMUL, "MF8"): 0, |
| 27 | + !eq(LMUL, "MF4"): 1, |
| 28 | + !eq(LMUL, "MF2"): 2, |
| 29 | + !eq(LMUL, "M1"): 3, |
| 30 | + !eq(LMUL, "M2"): 4, |
| 31 | + !eq(LMUL, "M4"): 5, |
| 32 | + !eq(LMUL, "M8"): 6, |
35 | 33 | ); |
| 34 | + |
| 35 | + assert !lt(Index, !size(Values)), |
| 36 | + "Missing LMUL value for '" # LMUL # "'. " # |
| 37 | + "Expected at least " # !add(Index, 1) # " elements, but got " # |
| 38 | + !size(Values) # "."; |
| 39 | + |
| 40 | + int c = Values[Index]; |
36 | 41 | } |
37 | 42 |
|
38 | 43 | // Returns BaseValue for LMUL values before startLMUL, Value for startLMUL, |
|
0 commit comments