[Mesa-dev] [PATCH 06/40] glsl: add helper to convert pointers to uint64_t
Davin McCall
davmac at davmac.org
Sat Feb 11 12:59:58 UTC 2017
On 11/02/17 12:03, Timothy Arceri wrote:
>
>
> On 10/02/17 21:43, Nicolai Hähnle wrote:
>> On 07.02.2017 04:42, Timothy Arceri wrote:
>>> From: Timothy Arceri <timothy.arceri at collabora.com>
>>>
>>> This will be used to store all pointers in the cache as 64bit ints
>>> allowing us to avoid issues when a 32bit program reads a cached
>>> shader that was created by a 64bit application.
>>> ---
>>> src/compiler/glsl/shader_cache.h | 10 ++++++++++
>>> 1 file changed, 10 insertions(+)
>>>
>>> diff --git a/src/compiler/glsl/shader_cache.h
>>> b/src/compiler/glsl/shader_cache.h
>>> index 8bd0a3c..1596c33 100644
>>> --- a/src/compiler/glsl/shader_cache.h
>>> +++ b/src/compiler/glsl/shader_cache.h
>>> @@ -27,6 +27,16 @@
>>>
>>> #include "util/disk_cache.h"
>>>
>>> +static uint64_t inline
>>> +ptr_to_uint64_t(void *ptr)
>>> +{
>>> + uint64_t ptr_int = (uint64_t) ptr;
>>> +#if __i386__
>>> + ptr_int &= 0xFFFFFFFF;
>>> +#endif
>>
>> Is the bit-wise and here really necessary?
> Yes. See [1] for an example and the standard and gcc quotes.
>
> [1]
> http://stackoverflow.com/questions/25039796/cast-from-32-bit-address-to-64-bit-integer-yields-unexpected-results
>
I'm just an occasional reader so sorry if this is out-of-place, but
wouldn't it be better to check the size directly rather than tie to a
specific architecture; i.e. rather than:
#if __i386__
ptr_int &= 0xFFFFFFFF;
#endif
It seems like what you really want is:
if (sizeof(uint64_t) > sizeof(ptr)) {
ptr_int &= 0xFFFFFFFF;
}
On any arch where the conversion is not sign-extended, the compiler
should in theory be able to optimise away the unecessary bitwise-and.
Davin
>>
>> Nicolai
>>
>>> + return ptr_int;
>>> +}
>>> +
>>> void
>>> shader_cache_write_program_metadata(struct gl_context *ctx,
>>> struct gl_shader_program *prog);
>>>
>>
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list