Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 26 Nov 2017 02:12:58 +0100
From: David Guillen Fandos <david@...idgf.es>
To: musl@...ts.openwall.com
Subject: Re: Do not use 64 bit division if possible


On 26/11/17 01:59, Rich Felker wrote:
> On Sun, Nov 26, 2017 at 01:49:09AM +0100, David Guillen Fandos wrote:
>> Hey,
>>
>> Wow that's an awesome optimization (the a&-a), didn't know gcc was
>> smart enough to figure that out by itself :D
> 
> It doesn't seem to be doing any optimizing for me. What it *should* do
> is optimize the div to ctz+shift.
> 
> BTW please don't top-reply; it makes threads hard to follow and hard
> to meaningfully reply to inline.
> 
> Rich
> 
> 
>> I just realized that PAGE_SIZE seems indeed to be defined to a
>> constant for some architectures, did not notice since I was running
>> on MIPS which has a page size different for each uarch.
>>
>> I'd say the (a&-a) is a very simple optimization and we should use
>> it, since it adds almost no complexity and sames some cycles and
>> some .text bytes, which is sometimes a bit tight.
>>
>> Something like this? Doesn't hurt constants, improves some arches :)
>>
>> diff --git a/src/conf/sysconf.c b/src/conf/sysconf.c
>> index b8b761d0..aa9fc9d1 100644
>> --- a/src/conf/sysconf.c
>> +++ b/src/conf/sysconf.c
>> @@ -206,7 +206,7 @@ long sysconf(int name)
>> 		if (name==_SC_PHYS_PAGES) mem = si.totalram;
>> 		else mem = si.freeram + si.bufferram;
>> 		mem *= si.mem_unit;
>> -		mem /= PAGE_SIZE;
>> +		mem /= (unsigned)(PAGE_SIZE & -PAGE_SIZE);
>> 		return (mem > LONG_MAX) ? LONG_MAX : mem;
>> 		case JT_ZERO & 255:
>> 		return 0;

Sorry for that, default settings you know :)

Well the main reason is cause in MIPS it requires adding __divdi3 which 
is around 1KB of code, which hey, it's not much, but why would we need 
it right? It makes a difference in embedded tools with statically linked 
musl.

Thanks for your interest!

David


Powered by blists - more mailing lists

Your e-mail address:

Powered by Openwall GNU/*/Linux - Powered by OpenVZ