* question about malloc's bin_index @ 2014-11-20 2:43 Weiming Zhao 2014-11-20 4:06 ` Rich Felker 2014-11-20 4:47 ` weimingz 0 siblings, 2 replies; 4+ messages in thread From: Weiming Zhao @ 2014-11-20 2:43 UTC (permalink / raw) To: musl; +Cc: weimingz [-- Attachment #1: Type: text/plain, Size: 760 bytes --] Hi, I'm trying to use MUSL on a hardware without floating point unit, however, the "union" in the bin_index brings some issues. I'm using -mgeneral-regs-only and gcc refuses to compile it due to the floating point conversion. I'm wondering what's the purpose of the union? How should I rewrite it to use integer only? static int bin_index(size_t x) { x = x / SIZE_ALIGN - 1; if (x <= 32) return x; if (x > 0x1c00) return 63; return ((union { float v; uint32_t r; }){(int)x}.r>>21) - 496; } Thanks a lot, Weiming Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project [-- Attachment #2: Type: text/html, Size: 3856 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: question about malloc's bin_index 2014-11-20 2:43 question about malloc's bin_index Weiming Zhao @ 2014-11-20 4:06 ` Rich Felker 2014-11-20 6:32 ` Szabolcs Nagy 2014-11-20 4:47 ` weimingz 1 sibling, 1 reply; 4+ messages in thread From: Rich Felker @ 2014-11-20 4:06 UTC (permalink / raw) To: musl On Wed, Nov 19, 2014 at 06:43:23PM -0800, Weiming Zhao wrote: > Hi, > > > > I'm trying to use MUSL on a hardware without floating point unit, however, > the "union" in the bin_index brings some issues. > > I'm using -mgeneral-regs-only and gcc refuses to compile it due to the > floating point conversion. This is odd. It should use soft-float if there's no fpu. > 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. Rich ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: question about malloc's bin_index 2014-11-20 4:06 ` Rich Felker @ 2014-11-20 6:32 ` Szabolcs Nagy 0 siblings, 0 replies; 4+ messages in thread From: Szabolcs Nagy @ 2014-11-20 6:32 UTC (permalink / raw) To: musl * Rich Felker <dalias@libc.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; } ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: question about malloc's bin_index 2014-11-20 2:43 question about malloc's bin_index Weiming Zhao 2014-11-20 4:06 ` Rich Felker @ 2014-11-20 4:47 ` weimingz 1 sibling, 0 replies; 4+ messages in thread From: weimingz @ 2014-11-20 4:47 UTC (permalink / raw) To: Weiming Zhao; +Cc: musl, weimingz I think I need a float-to-int-bits routine. But still I'm not clear why we need such conversion. Thanks, Weiming > Hi, > > > > I'm trying to use MUSL on a hardware without floating point unit, however, > the "union" in the bin_index brings some issues. > > I'm using -mgeneral-regs-only and gcc refuses to compile it due to the > floating point conversion. > > > > I'm wondering what's the purpose of the union? How should I rewrite it to > use integer only? > > > > static int bin_index(size_t x) > > { > > x = x / SIZE_ALIGN - 1; > > if (x <= 32) return x; > > if (x > 0x1c00) return 63; > > return ((union { float v; uint32_t r; }){(int)x}.r>>21) - > 496; > > } > > > > Thanks a lot, > > Weiming > > > > Qualcomm Innovation Center, Inc. > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, > a Linux Foundation Collaborative Project > > > > ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-11-20 6:32 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-11-20 2:43 question about malloc's bin_index Weiming Zhao 2014-11-20 4:06 ` Rich Felker 2014-11-20 6:32 ` Szabolcs Nagy 2014-11-20 4:47 ` weimingz
Code repositories for project(s) associated with this public inbox https://git.vuxu.org/mirror/musl/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).