diff options
author | marcel <marcel@FreeBSD.org> | 2010-07-01 00:48:00 +0000 |
---|---|---|
committer | marcel <marcel@FreeBSD.org> | 2010-07-01 00:48:00 +0000 |
commit | 9fe1156f87458b7f1141c7ad4c9bcdaeba3c3109 (patch) | |
tree | fbffdf6c0ccd19c4a26e7b3cdcbae9eabed775bb /lib/libc/gmon | |
parent | 1c976f915f2998502c243186509bbe70cd3a0a23 (diff) | |
download | FreeBSD-src-9fe1156f87458b7f1141c7ad4c9bcdaeba3c3109.zip FreeBSD-src-9fe1156f87458b7f1141c7ad4c9bcdaeba3c3109.tar.gz |
Simplify the calculation of s_scale by rewriting the FP expression to
use uintmax_t instead of float and thereby eliminating the need for
a non-FP version.
Tested on: amd64, ia64 & powerpc (book-E)
Suggested by: bde
MFC after: 1 month
Diffstat (limited to 'lib/libc/gmon')
-rw-r--r-- | lib/libc/gmon/gmon.c | 25 |
1 files changed, 5 insertions, 20 deletions
diff --git a/lib/libc/gmon/gmon.c b/lib/libc/gmon/gmon.c index 9b1406a..d699a80 100644 --- a/lib/libc/gmon/gmon.c +++ b/lib/libc/gmon/gmon.c @@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$"); #include <err.h> #include <fcntl.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -58,8 +59,8 @@ extern char *minbrk __asm ("minbrk"); struct gmonparam _gmonparam = { GMON_PROF_OFF }; static int s_scale; -/* see profil(2) where this is describe (incorrectly) */ -#define SCALE_1_TO_1 0x10000L +/* See profil(2) where this is described (incorrectly). */ +#define SCALE_SHIFT 16 #define ERR(s) _write(2, s, sizeof(s)) @@ -110,24 +111,8 @@ monstartup(lowpc, highpc) p->tos[0].link = 0; o = p->highpc - p->lowpc; - if (p->kcountsize < o) { -#if !defined(__powerpc__) - s_scale = ((float)p->kcountsize / o ) * SCALE_1_TO_1; -#else /* avoid floating point */ - int quot = o / p->kcountsize; - - if (quot >= 0x10000) - s_scale = 1; - else if (quot >= 0x100) - s_scale = 0x10000 / quot; - else if (o >= 0x800000) - s_scale = 0x1000000 / (o / (p->kcountsize >> 8)); - else - s_scale = 0x1000000 / ((o << 8) / p->kcountsize); -#endif - } else - s_scale = SCALE_1_TO_1; - + s_scale = (p->kcountsize < o) ? + ((uintmax_t)p->kcountsize << SCALE_SHIFT) / o : (1 << SCALE_SHIFT); moncontrol(1); } |