introduce sqrt_approx() in -lsys

. use this to avoid -lm dependency in mfs
This commit is contained in:
Ben Gras 2011-07-04 02:51:12 +02:00
parent cf3b75c687
commit 9c01ceb576
5 changed files with 19 additions and 2 deletions

View file

@ -65,6 +65,7 @@ _PROTOTYPE( u32_t tsc_get_khz, (void));
_PROTOTYPE( u32_t micros_to_ticks, (u32_t micros));
_PROTOTYPE( void ser_putc, (char c));
_PROTOTYPE( void get_randomness, (struct k_randomness *, int));
_PROTOTYPE( u32_t sqrt_approx, (u32_t));
#define asynsend(ep, msg) asynsend3(ep, msg, 0)
_PROTOTYPE( int asynsend3, (endpoint_t ep, message *msg, int flags));

View file

@ -57,6 +57,7 @@ SRCS= \
sef_signal.c \
ser_putc.c \
spin.c \
sqrt_approx.c \
stacktrace.c \
sys_abort.c \
sys_clear.c \
@ -127,6 +128,7 @@ SRCS= \
vm_yield_get_block.c \
vprintf.c \
CPPFLAGS.sched_start.c+= -I${MINIXSRCDIR}
.if (${NBSD_LIBC} != "no")

14
lib/libsys/sqrt_approx.c Normal file
View file

@ -0,0 +1,14 @@
#include <minix/sysutil.h>
u32_t sqrt_approx(u32_t in)
{
int b, v = 0;
for(b = (sizeof(in)*8)/2-1; b >= 0; b--) {
u32_t n = v | (1UL << b);
if(n*n <= in)
v = n;
}
return v;
}

View file

@ -6,7 +6,7 @@ SRCS= cache.c device.c link.c \
write.c inode.c main.c path.c super.c
DPADD+= ${LIBM} ${LIBSYS}
LDADD+= -lm -lsys
LDADD+= -lsys
MAN=

View file

@ -601,7 +601,7 @@ PRIVATE int bufs_heuristic(struct super_block *sp)
/* heuristic for a desired cache size based on FS usage;
* but never bigger than half of the total filesystem
*/
kb_fsmax = sqrt(kbytes_used_fs)*40;
kb_fsmax = sqrt_approx(kbytes_used_fs)*40;
kb_fsmax = MIN(kb_fsmax, kbytes_total_fs/2);
/* heuristic for a maximum usage - 10% of remaining memory */