On Sat, Apr 04, 2015 at 11:25:36AM +0200, Borislav Petkov wrote:
> On Sat, Apr 04, 2015 at 10:36:11AM +0200, Quentin Casasnovas wrote:
> > Since all of these are compile time constants, could we not use the safe
> > variant on that same page?  Not that I'm too worried about the signed right
> > shift but heh that would be portable and should not impact performance
> > anyway, so no added value in using the optimized version is there?
> 
> Seems to work with the experimental diff below. I need to do
> 
>       -(-(x < y))
> 
> with the last term though as we're working with s32s.
> 
> ---
> diff --git a/arch/x86/include/asm/alternative-asm.h 
> b/arch/x86/include/asm/alternative-asm.h
> index 44a1fc5439d3..2cb6da2716bf 100644
> --- a/arch/x86/include/asm/alternative-asm.h
> +++ b/arch/x86/include/asm/alternative-asm.h
> @@ -53,14 +53,14 @@
>   * Shamelessly stolen and adapted from:
>   * http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax
>   */
> -#define alt_max_short(a,b)   (((a) - (((a) - (b)) & (((a) - (b)) >> 15))) & 
> 0xffff)
> +#define alt_max_short(a, b)  ((a) ^ (((a) ^ (b)) & -(-((a) < (b)))))
>

So I'm not claiming I've spent the time to fully understand this macro but
it looks like it's doing the right thing on my dummy tests:

  http://pastebin.com/DDhtZQgX

Did you also change it in the alternative.h file BTW?

>  .macro ALTERNATIVE_2 oldinstr, newinstr1, feature1, newinstr2, feature2
>  140:
>       \oldinstr
>  141:
> -     .skip -((alt_max_short(new_len1, new_len2) - old_len) > 0) * \
> -             (alt_max_short(new_len1, new_len2) - old_len),0x90
> +     .skip -((alt_max_short(new_len1, new_len2) - (old_len)) > 0) * \
> +             (alt_max_short(new_len1, new_len2) - (old_len)),0x90
>  142:

Good catch for the missing parenthesis!

> > 
> > Looks good to me and I find it much easier to understand here :)
> > 
> 
> Cool. Please give it more critical staring as we're under time pressure
> here.
> 

So I _think_ it's OK but it would be re-assuring if somebody else could
have a look as well just in case.. :)

Do you have a cleaned up version of the patch you're planning to apply on
top of tip/master instead of just snippets?  This way we can hammer it with
different calls to ALTERNATIVE_2 and alternative_2 to check it's good?
I'll have to leave soonish though..

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

Reply via email to