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
This commit is contained in:
Marcel Moolenaar 2010-07-01 00:48:00 +00:00
parent b9c9542267
commit af448c52e4

View file

@ -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);
}