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

Petr Tesarik ptesarik at suse.cz
Fri Jul 27 11:05:46 MSK 2012


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


More information about the kbd mailing list