Re: [PATCH] __get_order() cleanup

From: Jamie Lokier (lkd@tantalophile.demon.co.uk)
Date: Fri Jan 28 2000 - 20:27:33 EST


Jakub Jelinek wrote:
> At the moment, there are 11 identical implementations of __get_order
> function. This patch moves __get_order implementation to asm/page.h (so that
> architectures can optimize it - i386 __get_order is done using bsrl
> instruction) and kills all the private copies of that function.
> Patch against 2.3.41-4.

You might get better performance with an algorithm like this one. Maybe
even better than bsrl on i386 -- I think bsrl is very slow on modern
chips.

  const static table [32] =
    { 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
      5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 };

  size = (size - 1) >> PAGE_SHIFT; /* Let's assume it's 12. */
  if (size >= (1 << 10)) { size >>= 10; order += 10; }
  if (size >= (1 << 5)) { size >>= 5 ; order += 5; }
  order += table [size];

The table has to go outside the function because of the way GCC
implements inline functions. With a bit more typing, you can generalise
it for any PAGE_SHIFT and still have it optimise to the appropriate code
for a particular page size.

have a nice day,
-- Jamie

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



This archive was generated by hypermail 2b29 : Mon Jan 31 2000 - 21:00:22 EST