[Mesa-dev] [PATCH 1/4] i965: Remove spurious casts in copy_image_with_memcpy()

Chad Versace chad.versace at intel.com
Wed Nov 19 13:31:15 PST 2014


On Wed 19 Nov 2014, Matt Turner wrote:
>On Wed, Nov 19, 2014 at 3:35 AM, Kristian Høgsberg <krh at bitplanet.net> wrote:
>> On Tue, Nov 18, 2014 at 9:02 PM, Chad Versace
>> <chad.versace at linux.intel.com> wrote:
>>> If a pointer points to raw, untyped memory and is never dereferenced,
>>> then declare it as 'void*' instead of casting it to 'void*'.
>>>
>>> Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
>>> ---
>>>  src/mesa/drivers/dri/i965/intel_copy_image.c | 8 ++++----
>>>  1 file changed, 4 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/src/mesa/drivers/dri/i965/intel_copy_image.c b/src/mesa/drivers/dri/i965/intel_copy_image.c
>>> index 341220c..cb44474 100644
>>> --- a/src/mesa/drivers/dri/i965/intel_copy_image.c
>>> +++ b/src/mesa/drivers/dri/i965/intel_copy_image.c
>>> @@ -144,7 +144,7 @@ copy_image_with_memcpy(struct brw_context *brw,
>>>                         int src_width, int src_height)
>>>  {
>>>     bool same_slice;
>>> -   uint8_t *mapped, *src_mapped, *dst_mapped;
>>> +   void *mapped, *src_mapped, *dst_mapped;
>>
>> Making these void * means that this code below:
>>
>>       src_mapped = mapped + ((src_y - map_y1) / src_bh) * src_stride +
>>                             ((src_x - map_x1) / src_bw) * cpp;
>>
>> (same for dst_mapped) becomes arithmetic on void pointers. gcc
>> supports that and treats it as uint8_t pointer arithmetic [1], but I'm
>> not aware of any official C standard that allows it.  I don't think we
>> rely on that elsewhere

i965 relies on it elsewhere. Look at the intel_miptree_map family of 
functions.

Arithmetic on void* works on gcc and clang, and i965 has relied on that 
gcc support for a long time.

>We have in the past, and using gcc extensions are fine. But as you
>say, it's probably  not what he wanted anyway.

This patch makes the code a little bit cleaner by removing a weird cast 
in a function call. And it relies on no new compiler features that i965 
doesn't already required. Is anything wrong with that?


More information about the mesa-dev mailing list