mailing list of musl libc
 help / color / mirror / code / Atom feed
* Do not use 64 bit division if possible
@ 2017-11-25 20:52 David Guillen Fandos
  2017-11-25 23:15 ` Michael Clark
  0 siblings, 1 reply; 11+ messages in thread
From: David Guillen Fandos @ 2017-11-25 20:52 UTC (permalink / raw)
  To: musl

Hey there,

Just noticed that my binary was getting some gcc functions for integer 
division in some places coming from musl. I checked and it seems that, 
even though musl assumes PAGE_SIZE is always power of two, that we 
divide by it instead of using shifts for that. This results in extra 
overhead and slow division on platforms that do not have a 64 bit 
divider (even the ones that do have 32 bit divider).

So I propose a patch here, let me know what you people think about.

David


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
@@ -4,6 +4,7 @@ long sysconf(int name)
  #include <sys/sysinfo.h>
  #include "syscall.h"
  #include "libc.h"
+#include "atomic.h"

  #define JT(x) (-256|(x))
  #define VER JT(1)
@@ -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)(a_ctz_l(PAGE_SIZE));
  		return (mem > LONG_MAX) ? LONG_MAX : mem;
  		case JT_ZERO & 255:
  		return 0;


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-11-26  1:40 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-25 20:52 Do not use 64 bit division if possible David Guillen Fandos
2017-11-25 23:15 ` Michael Clark
2017-11-25 23:46   ` David Guillen Fandos
2017-11-25 23:53     ` Rich Felker
2017-11-26  0:10       ` Michael Clark
2017-11-26  0:49         ` David Guillen Fandos
2017-11-26  0:59           ` Rich Felker
2017-11-26  1:12             ` David Guillen Fandos
2017-11-26  1:23               ` Rich Felker
2017-11-26  1:40                 ` David Guillen Fandos
2017-11-26  0:49         ` Rich Felker

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).