aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2004-07-15 17:42:08 +0000
committerH. Peter Anvin <hpa@zytor.com>2004-07-15 17:42:08 +0000
commit5b2a230d00474fdbfbcccc8aff6df5690cb8b10f (patch)
tree2a37d643dd5e5e1f100cb44eef8ad516f7b258b9
parentb2fe4a9a9e69ad91544c424c3bb4c64d82e96490 (diff)
downloadklibc-5b2a230d00474fdbfbcccc8aff6df5690cb8b10f.tar.gz
Use the BSR instruction on i386 to get the page shiftklibc-0.151
-rw-r--r--klibc/getpageshift.c27
-rw-r--r--klibc/getpagesize.c24
-rw-r--r--klibc/libc_init.c5
3 files changed, 5 insertions, 51 deletions
diff --git a/klibc/getpageshift.c b/klibc/getpageshift.c
deleted file mode 100644
index 40e857486ef29..0000000000000
--- a/klibc/getpageshift.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * getpageshift.c
- *
- * Return the current page size as a shift count
- */
-
-#include <klibc/compiler.h>
-#include <sys/syscall.h>
-#include <unistd.h>
-
-int __getpageshift(void)
-{
- static int page_shift;
- int page_size;
-
- if ( __likely(page_shift) )
- return page_shift;
-
- page_size = getpagesize();
-
- while ( page_size > 1 ) {
- page_shift++;
- page_size >>= 1;
- }
-
- return page_shift;
-}
diff --git a/klibc/getpagesize.c b/klibc/getpagesize.c
deleted file mode 100644
index 98e814fa182b0..0000000000000
--- a/klibc/getpagesize.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * getpagesize.c
- */
-
-#include <klibc/compiler.h>
-#include <sys/syscall.h>
-#include <unistd.h>
-#include <sys/sysinfo.h>
-
-int getpagesize(void)
-{
- static int page_size;
- struct sysinfo si;
- int rv;
-
- if ( __likely(page_size) )
- return page_size;
-
- rv = sysinfo(&si);
- if ( rv == -1 )
- return -1;
-
- return (page_size = si.mem_unit);
-}
diff --git a/klibc/libc_init.c b/klibc/libc_init.c
index 494d8cc48b930..444097db36a01 100644
--- a/klibc/libc_init.c
+++ b/klibc/libc_init.c
@@ -65,10 +65,15 @@ __noreturn __libc_init(uintptr_t *elfdata, void (*onexit)(void))
}
__page_size = page_size;
+
+#if defined(__i386__) || defined(__x86_64__)
+ asm("bsrl %1,%0" : "=r" (page_shift) : "rm" (page_size));
+#else
while ( page_size > 1 ) {
page_shift++;
page_size >>= 1;
}
+#endif
__page_shift = page_shift;
environ = envp;