A later patch will make use of this in other places. Also, remove dependency on undefined behavior of left-shifting a signed value. --- src/intel/vulkan/anv_batch_chain.c | 12 +----------- src/intel/vulkan/anv_private.h | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/src/intel/vulkan/anv_batch_chain.c b/src/intel/vulkan/anv_batch_chain.c index e083d79d35b..09514c7b84a 100644 --- a/src/intel/vulkan/anv_batch_chain.c +++ b/src/intel/vulkan/anv_batch_chain.c @@ -1110,18 +1110,8 @@ write_reloc(const struct anv_device *device, void *p, uint64_t v, bool flush) { unsigned reloc_size = 0; if (device->info.gen >= 8) { - /* From the Broadwell PRM Vol. 2a, MI_LOAD_REGISTER_MEM::MemoryAddress: - * - * "This field specifies the address of the memory location where the - * register value specified in the DWord above will read from. The - * address specifies the DWord location of the data. Range = - * GraphicsVirtualAddress[63:2] for a DWord register GraphicsAddress - * [63:48] are ignored by the HW and assumed to be in correct - * canonical form [63:48] == [47]." - */ - const int shift = 63 - 47; reloc_size = sizeof(uint64_t); - *(uint64_t *)p = (((int64_t)v) << shift) >> shift; + *(uint64_t *)p = canonical_address(v); } else { reloc_size = sizeof(uint32_t); *(uint32_t *)p = v; diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index d043c77826e..761601d1e37 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -155,6 +155,21 @@ align_i32(int32_t v, int32_t a) return (v + a - 1) & ~(a - 1); } +static inline uint64_t +canonical_address(uint64_t v) { + /* From the Broadwell PRM Vol. 2a, MI_LOAD_REGISTER_MEM::MemoryAddress: + * + * "This field specifies the address of the memory location where the + * register value specified in the DWord above will read from. The + * address specifies the DWord location of the data. Range = + * GraphicsVirtualAddress[63:2] for a DWord register GraphicsAddress + * [63:48] are ignored by the HW and assumed to be in correct + * canonical form [63:48] == [47]." + */ + const int shift = 63 - 47; + return (int64_t)(v << shift) >> shift; +} + /** Alignment must be a power of 2. */ static inline bool anv_is_aligned(uintmax_t n, uintmax_t a) -- 2.14.3 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev