[Mesa-dev] [PATCH v3 2/6] anv: Add a helper for doing mass allocations

Chris Wilson chris at chris-wilson.co.uk
Fri Apr 7 22:19:51 UTC 2017


On Fri, Apr 07, 2017 at 02:41:13PM -0700, Jason Ekstrand wrote:
>    On Fri, Apr 7, 2017 at 1:26 PM, Chris Wilson <[1]chris at chris-wilson.co.uk>
>    wrote:
> 
>      On Fri, Apr 07, 2017 at 12:55:53PM -0700, Jason Ekstrand wrote:
>      > +#define _ANV_MULTIALLOC_UPDATE_POINTER(_i) \
>      > +   if ((_i) < ma->ptr_count) \
>      > +      *ma->ptrs[_i] = ptr + (uintptr_t)*ma->ptrs[_i]
>      > +   _ANV_MULTIALLOC_UPDATE_POINTER(0);
>      > +   _ANV_MULTIALLOC_UPDATE_POINTER(1);
>      > +   _ANV_MULTIALLOC_UPDATE_POINTER(2);
>      > +   _ANV_MULTIALLOC_UPDATE_POINTER(3);
>      > +   _ANV_MULTIALLOC_UPDATE_POINTER(4);
>      > +   _ANV_MULTIALLOC_UPDATE_POINTER(5);
>      > +   _ANV_MULTIALLOC_UPDATE_POINTER(6);
>      > +   _ANV_MULTIALLOC_UPDATE_POINTER(7);
>      > +#undef _ANV_MULTIALLOC_UPDATE_POINTER
> 
>      #define _ANV_MULTIALLOC_UPDATE_POINTER(_i) case _i + 1: *ma->ptrs[_i] =
>      ptr +(uintptr)*ma->ptrs[_i]
> 
>      switch (ma->ptr_count) {
>      _ANV_MULTIALLOC_UPDATE_POINTER(7);
>      _ANV_MULTIALLOC_UPDATE_POINTER(6);
>      _ANV_MULTIALLOC_UPDATE_POINTER(5);
>      _ANV_MULTIALLOC_UPDATE_POINTER(4);
>      _ANV_MULTIALLOC_UPDATE_POINTER(3);
>      _ANV_MULTIALLOC_UPDATE_POINTER(2);
>      _ANV_MULTIALLOC_UPDATE_POINTER(1);
>      _ANV_MULTIALLOC_UPDATE_POINTER(0);
>      }
> 
>      #undef _ANV_MULITALLOC_UPDATE_POINTER
> 
>    If ma->ptr_count is constant, they generate exactly the same code.  If it
>    isn't (i.e. if one of the multialloc_adds is predicated), then they still
>    generate basically the same code with the code for the if version being
>    slightly more straightforward.

Took a look at this with https://godbolt.org/g/UwrMk1

clang does much better at seeing the constants, but gcc doesn't and
generates a large if-ladder for one and a jump table for the switch. icc
doesn't fare any better than gcc. The if-ladder is going to be worse
than the computed jump, but best is to file a gcc bug :|
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre


More information about the mesa-dev mailing list