From 4a22e24e98286a4b3cb19cc64d7a32ce0dd289db Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 30 Jan 2023 20:11:52 -0600 Subject: [PATCH] nouveau/push: Make P_IMMD more versatile It's now able to use either the immediate form or method form depending on whether or not the value fits into 13 bits. We wrap the check with __builtin_constant_p() so that this choice is compile-time determined instead of runtime. I've verified with SET_CT_SELECT() that GCC is able to determine which bits are used even if not all of them are constants. Part-of: --- src/nouveau/winsys/nouveau_push.h | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/nouveau/winsys/nouveau_push.h b/src/nouveau/winsys/nouveau_push.h index 2d641cb56be..780389ab74e 100644 --- a/src/nouveau/winsys/nouveau_push.h +++ b/src/nouveau/winsys/nouveau_push.h @@ -66,20 +66,27 @@ __push_verify(struct nouveau_ws_push *push) } static inline void -__push_mthd(struct nouveau_ws_push *push, int subc, uint32_t mthd) +__push_mthd_size(struct nouveau_ws_push *push, + int subc, uint32_t mthd, unsigned size) { __push_verify(push); push->last_size = push->map; - *push->map = NVC0_FIFO_PKHDR_SQ(subc, mthd, 0); + *push->map = NVC0_FIFO_PKHDR_SQ(subc, mthd, size); push->map++; } +static inline void +__push_mthd(struct nouveau_ws_push *push, int subc, uint32_t mthd) +{ + __push_mthd_size(push, subc, mthd, 0); +} + #define P_MTHD(push, class, mthd) __push_mthd(push, SUBC_##class, class##_##mthd) static inline uint32_t NVC0_FIFO_PKHDR_IL(int subc, int mthd, uint16_t data) { - assert(data < 0x2000); + assert(!(data & ~0x1fff)); return 0x80000000 | (data << 16) | (subc << 13) | (mthd >> 2); } @@ -92,11 +99,17 @@ __push_immd(struct nouveau_ws_push *push, int subc, uint32_t mthd, uint32_t val) push->map++; } -#define P_IMMD(push, class, mthd, args...) do {\ - uint32_t __val; \ - VA_##class##_##mthd(__val, args); \ - __push_immd(push, SUBC_##class, class##_##mthd, __val); \ - } while(0) +#define P_IMMD(push, class, mthd, args...) do { \ + uint32_t __val; \ + VA_##class##_##mthd(__val, args); \ + if (__builtin_constant_p(__val & ~0x1fff) && !(__val & ~0x1fff)) { \ + __push_immd(push, SUBC_##class, class##_##mthd, __val); \ + } else { \ + __push_mthd_size(push, SUBC_##class, class##_##mthd, 1); \ + *push->map = __val; \ + push->map++; \ + } \ +} while(0) static inline uint32_t NVC0_FIFO_PKHDR_1I(int subc, int mthd, unsigned size)