[Mesa-dev] [PATCH 3/5] nir: Avoid structure initalization expressions.

Jose Fonseca jfonseca at vmware.com
Wed Apr 13 18:53:08 UTC 2016


On 13/04/16 19:35, Jason Ekstrand wrote:
>
>
> On Wed, Apr 13, 2016 at 10:19 AM, Emil Velikov <emil.l.velikov at gmail.com
> <mailto:emil.l.velikov at gmail.com>> wrote:
>
>     From: Jose Fonseca <jfonseca at vmware.com <mailto:jfonseca at vmware.com>>
>
>     Not supported by MSVC, and completely unnecessary -- inline functions
>     work just as well.
>
>     NIR_SRC_INIT/NIR_DEST_INIT could and probably should be replaced by the
>     inline functions.
>
>     Cc: Jason Ekstrand <jason at jlekstrand.net <mailto:jason at jlekstrand.net>>
>
>     ---
>
>     Jason, I believe you (used to) have an alternative in the vulkan branch.
>     This approach looks more reasonable imho, although I don't feel strongly
>     either way.
>
>     -Emil
>     ---
>       src/compiler/nir/nir.h | 18 ++++++++++++++++--
>       1 file changed, 16 insertions(+), 2 deletions(-)
>
>     diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
>     index ebac750..0adadc2 100644
>     --- a/src/compiler/nir/nir.h
>     +++ b/src/compiler/nir/nir.h
>     @@ -503,7 +503,14 @@ typedef struct nir_src {
>          bool is_ssa;
>       } nir_src;
>
>     -#define NIR_SRC_INIT (nir_src) { { NULL } }
>     +static inline nir_src
>     +nir_src_init(void)
>     +{
>     +   nir_src src = { { NULL } };
>     +   return src;
>     +}
>     +
>     +#define NIR_SRC_INIT nir_src_init()
>
>
> Is this a problem in C or only in C++?

IIRC, the problem was with C.

> If it's only a problem in C++,
> another option (and I've written this patch before) is to do
>
> #ifdef _cplusplus
> #define NIR_SRC_INIT nir_src()
> #else
> #define NIR_SRC_INIT { { NULL } }
> #endif
>
> and the same for NIR_ALU_SRC_INIT, NIR_DST_INIT, etc.

But is there any thing to be gained by using { { NULL } } as opposed to 
the inline?  Is the generated code better, or error messages cleaner or 
something like that?

Generally speaking inlines tend to have much better characteristics that 
macros (e.g, in this case, type safety).

Jose


More information about the mesa-dev mailing list