From 4714784daeb4df97fa82cfcf8f566661cc4ff4a4 Mon Sep 17 00:00:00 2001 From: Scott D Phillips Date: Thu, 15 Mar 2018 12:53:05 -0700 Subject: [PATCH] anv: move canonical_address calculation into a separate function A later patch will make use of this in other places. Also, remove dependency on undefined behavior of left-shifting a signed value. v2: - move function into a separate header (Chris) v3: (by Ken) Add new header to the various build systems. Reviewed-by: Jordan Justen Reviewed-by: Kenneth Graunke --- src/intel/Makefile.sources | 1 + src/intel/common/gen_gem.h | 43 ++++++++++++++++++++++++++++++++++++++ src/intel/common/meson.build | 1 + src/intel/vulkan/anv_batch_chain.c | 12 +---------- src/intel/vulkan/anv_private.h | 1 + 5 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 src/intel/common/gen_gem.h diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources index 1adf6f9..f22e727 100644 --- a/src/intel/Makefile.sources +++ b/src/intel/Makefile.sources @@ -17,6 +17,7 @@ COMMON_FILES = \ common/gen_disasm.c \ common/gen_disasm.h \ common/gen_defines.h \ + common/gen_gem.h \ common/gen_l3_config.c \ common/gen_l3_config.h \ common/gen_urb_config.c \ diff --git a/src/intel/common/gen_gem.h b/src/intel/common/gen_gem.h new file mode 100644 index 0000000..842a455 --- /dev/null +++ b/src/intel/common/gen_gem.h @@ -0,0 +1,43 @@ +/* + * Copyright © 2018 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef GEN_GEM_H +#define GEN_GEM_H + +static inline uint64_t +gen_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; +} + +#endif /* GEN_GEM_H */ diff --git a/src/intel/common/meson.build b/src/intel/common/meson.build index ebf69c0..332e978 100644 --- a/src/intel/common/meson.build +++ b/src/intel/common/meson.build @@ -29,6 +29,7 @@ files_libintel_common = files( 'gen_decoder.h', 'gen_disasm.c', 'gen_disasm.h', + 'gen_gem.h', 'gen_l3_config.c', 'gen_l3_config.h', 'gen_urb_config.c', diff --git a/src/intel/vulkan/anv_batch_chain.c b/src/intel/vulkan/anv_batch_chain.c index e083d79..a1fb8bf7 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 = gen_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 d043c77..c10af14 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -42,6 +42,7 @@ #endif #include "common/gen_clflush.h" +#include "common/gen_gem.h" #include "dev/gen_device_info.h" #include "blorp/blorp.h" #include "compiler/brw_compiler.h" -- 2.7.4