On 9/21/06, Brian Paul <[EMAIL PROTECTED]> wrote:
> Jerome Glisse wrote:
> > On 9/21/06, Brian Paul <[EMAIL PROTECTED]> wrote:
> >
> >> Jerome Glisse wrote:
> >> > Hi,
> >> >
> >> > Roland  pointed me to this yesterday (src/mesa/main/glheader.h):
> >> > /*
> >> >  * Either define MESA_BIG_ENDIAN or MESA_LITTLE_ENDIAN.
> >> >  * Do not use them unless absolutely necessary!
> >> >  * Try to use a runtime test instead.
> >> >  * For now, only used by some DRI hardware drivers for color/texel
> >> packing.
> >> >  */
> >> >
> >> > So i am wondering what is best from a driver point of view,
> >> > use this macro or use a runtime test ? Maybe this comment
> >> > isn't revealent anymore. Any insight on this are welcome.
> >>
> >> I'd prefer to use a run-time test since it's a little more robust (one
> >> less preprocessor symbol to worry about).  Though in some places we
> >> really do need a compile-time symbol.
> >>
> >> Here's the code used in core Mesa:
> >>
> >>     const GLuint ui = 1;
> >>     const GLubyte littleEndian = *((const GLubyte *) &ui);
> >>
> >> I should probably put that into a reusable inline function in
> >> imports.h ...
> >>
> >> -Brian
> >>
> >
> > Would be nice to have a reusable function (i am a bit lazy :))
>
> Done.
>
> Interestingly, these two variations produce different code (gcc -O2):
>
> static INLINE GLboolean
> _mesa_little_endian(void)
> {
>     static const GLuint ui = 1;        // NOTE: static
>     return *((const GLubyte *) &ui);
> }
>
> static INLINE GLboolean
> _mesa_little_endian(void)
> {
>     const GLuint ui = 1;
>     return *((const GLubyte *) &ui);
> }
>
>
> If you have code such as:
>
>     if (_mesa_little_endian())
>        foo();
>     else
>        bar();
>
>
> The version without 'static' is evaluated at compile time and the
> branch code is optimized away.  With 'static' the compiler still
> generates the conditional code.
>
> -Brian
>

Compiler parser voodoo :) Thanx, i will use that for now, and will
correct code.

best,
Jerome Glisse

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Mesa3d-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to