|
Message-ID: <20141120063209.GJ10829@port70.net> Date: Thu, 20 Nov 2014 07:32:09 +0100 From: Szabolcs Nagy <nsz@...t70.net> To: musl@...ts.openwall.com Subject: Re: question about malloc's bin_index * Rich Felker <dalias@...c.org> [2014-11-19 23:06:33 -0500]: > On Wed, Nov 19, 2014 at 06:43:23PM -0800, Weiming Zhao wrote: > > I'm wondering what's the purpose of the union? How should I rewrite it to > > use integer only? > > The value we want, for categorizing sizes into bins, is exactly the > floating point exponent and first 2 bits of the mantissa. It's > basically a sort of base-2 log with 4 linear steps between successive > logarithmic-scale points. I think nsz has an integer-only version of > this code that might be useful; it performs mildly better on archs > without fpu and mildly worse on ones with fpu and it's somewhat larger > (but of course not as large as soft-float code). I'll see if I can > find a copy or if he can post it. i have this in src/malloc/malloc.c with #ifdef NOFPU: /* non-float bin index */ static const unsigned char bintab[32]={ 0, 0, 0, 0,32,33,34,35,36,36,37,37,38,38,39,39, 40,40,40,40,41,41,41,41,42,42,42,42,43,43,43,43 }; static int bin_index(size_t x) { x = x / SIZE_ALIGN - 1; if (x <= 32) return x; x /= 8; if (x < 32) return bintab[x]; x /= 8; if (x < 32) return bintab[x]+12; x /= 8; if (x < 16) return bintab[x]+24; return 63; } static int bin_index_up(size_t x) { x = x / SIZE_ALIGN - 1; if (x <= 32) return x; x--; x /= 8; if (x < 32) return bintab[x]+1; x /= 8; if (x < 32) return bintab[x]+13; x /= 8; return bintab[x]+25; }
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.