Re: [patch/rfc 2/4] pcf875x I2C GPIO expander driver



Hi Bill,

On Fri, 30 Nov 2007 07:04:10 -0600, Bill Gatliff wrote:
Jean Delvare wrote:
!!(value & (1 << offset))
is more efficiently written
(value >> offset) & 1

... but not more efficiently implemented.

Your version requires code to do the shift on live data at runtime.
David's version lets the compiler create the mask once, at compile-time.

I don't understand. How could the compiler create the mask at
compile-time when "offset" is only known at runtime?

Anyway, I just checked and gcc (4.1.2 on x86_86) generates the same
code for both expressions, so there's not much to argue about. David,
feel free to ignore my comment if you prefer your implementation :)

--
Jean Delvare
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • Re: Variadic functions calling variadic functions with the argument list, HLL bit shifts on LE proce
    ... There's no such thing as a "LE register" on most popular CPU ... shift is done on the value. ... >but one would hope that the shr for shift right instruction would ... The compiler needs to use assembler instructions. ...
    (comp.lang.c)
  • Re: Byte-wise boolean optimisation
    ... Create a mask of the bits of interest say bits 0,1,3,7 ... You are potentially wasting time with the shift operators (depending ... on how smart your compiler is). ... unsigned char get_byte ...
    (comp.arch.embedded)
  • Re: Cohens paper on byte order
    ... If an 8-bit chunk is input, say, from a file into ... possible dependence even on compiler. ... file and this is naturally the lower order bit of the ... extract that bit with a corresponding mask. ...
    (sci.crypt)
  • Re: Problem using Ada.Text_IO.Modular_IO
    ... to the generated assembly code. ... Using for shift left ... As for the "Interfaces" package the compiler uses if possible a machine ... Create a test program and compile it using either ...
    (comp.lang.ada)
  • Re: signed RSHIFT
    ... > It makes more work for the compiler (because it has to recognize the ... > idiom rather than just look up a name), ... there is no sane way to do this with repeated shift instructions. ... >>The alternative of defining primitives that correspond to many of the ...
    (comp.lang.forth)