lkml.org 
[lkml]   [2011]   [Mar]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2] x86: page: get_order() optimization

* H. Peter Anvin <hpa@zytor.com> wrote:

> On 03/27/2011 01:45 AM, Maksym Planeta wrote:
> > For x86 architecture get_order function can be optimized due to
> > assembler instruction bsr.
> >
> > This is second version of patch where for constants gcc precompute the
> > result.
> >
> > Signed-off-by: Maksym Planeta <mcsim.planeta@gmail.com>
>
> gcc 4.x has an intrinsic, __builtin_clz(), which does the opposite of
> the bsr instruction; specifically:
>
> __builtin_clz(x) ^ 31
>
> ... generates a bsrl instruction if x is variable. This tends to
> generate much better code than any assembly hacks.

Indeed, that should work better and should be tried - and it can probably
propagate the flags result sensibly (which GCC's asm() cannot, unfortunately).

Thanks,

Ingo


\
 
 \ /
  Last update: 2011-03-29 09:29    [W:0.076 / U:0.304 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site