Re: [kbd] [PATCH] setleds: add option to reset state to the BIOS default

Petr Tesarik <[email protected]>
Newsgroups dev.linux.lists.kbd
Organization SUSE LINUX, s.r.o.
Message-ID <[email protected]>
Dne Čt 26. července 2012 21:49:05 Petr Tesarik napsal(a):
> Hello Alexey and everybody,
> 
> please consider the following patch for kbd.
>[...]
> +    bios_state = map[BIOS_KBD_ADDR - mapoff];
> +    *cur_leds = 0;
> +    if (bios_state & BIOS_LED_SCR)
> +	*cur_leds |= LED_SCR;
> +    if (bios_state & BIOS_LED_NUM)
> +	*cur_leds |= LED_NUM;
> +    if (bios_state & BIOS_LED_CAP)
> +	*cur_leds |= LED_CAP;

I've just noticed that this produces crappy code, especially given that the 
BIOS bits are numerically equal to the kernel bits, so a simple bitwise AND 
would be sufficient. Rewriting the series of conditionals into one expression 
allows GCC to optimize it:

    *cur_leds =
        (bios_state & BIOS_LED_SCR ? LED_SCR : 0) |
        (bios_state & BIOS_LED_NUM ? LED_NUM : 0) |
        (bios_state & BIOS_LED_CAP ? LED_CAP : 0);

Let me resend v2 of the patch,
Petr Tesarik
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.