lkml.org 
[lkml]   [1997]   [Dec]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: copy-bit macro
Date
On 	09 Dec 1997 18:06:49 +0000, James A said:
> Colin Plumb <colin@nyx.net> writes:
> > I notice that a lot of code contains long lines of
> > if (input & INPUT_FLAG_FOO)
> > output |= OUTPUT_FLAG_FOO;

> > The GCC output from this on the x86 is full of (slow) jumps.
> > Also, jumps inhibit optimization.
> > More efficient code, which can also be optimized around more,
> > is produced by

> > output |= ((input / INPUT_FLAG_FOO) & 1) * OUTPUT_FLAG_FOO;

> The only problem is that...

> #define INPUT_FLAG_FOO 1
> #define OUTPUT_FLAG_FOO 1
> input = 2;
> output |= ((input / INPUT_FLAG_FOO) & 1) * OUTPUT_FLAG_FOO;

> Doesn't work.

Yes it does. Why wouldn't it?

The only caveat (in general) is that the flags have to be unsigned -
otherwise gcc treats the division differently depending on whether
input<0 (which means there is still a jump in the code).

> output |= (input & INPUT_FLAG_FOO) ? OUTPUT_FLAG_FOO : 0;

> Might be better,

but contains a jump, so it is the same as the original.

imc

\
 
 \ /
  Last update: 2005-03-22 13:40    [from the cache]
©2003-2011 Jasper Spaans