Skip to contentSkip to conversation

Avoid imaxdiv when only one of the results is wanted

PATCH In review Harald van Dijk 2 participants 3 messages Jul 25, 2011 – Aug 17, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Avoid imaxdiv when only one of the results is wanted

dash rather pointlessly calls imaxdiv, only to discard one of its results. The call was already made conditional a while back because some systems don't have imaxdiv, but the generated code for the version with imaxdiv and the one with / and % is identical (with GCC 4.6.1 or ICC 12.0.2, with -O0, -O2 or -Os), so it could just as well go entirely to clean up the code a little bit.

ChangeLog +4 -0
index b96e5b2..02bfda0 100644
@@ -1,3 +1,7 @@
+2011-07-26  Harald van Dijk <[email protected]>
+
+	* Avoid imaxdiv when only one of the results is wanted.
+
 2010-07-09  maximilian attems <[email protected]>
 
 	* Fix klibc DEBUG compilation.
configure.ac +0 -1
index 7eae954..5cd6e95 100644
@@ -85,7 +85,7 @@ AC_CHECK_DECL([PRIdMAX],,
 ])
 
 dnl Checks for library functions.
-AC_CHECK_FUNCS(bsearch faccessat getpwnam getrlimit imaxdiv isalpha

killpg \
+AC_CHECK_FUNCS(bsearch faccessat getpwnam getrlimit isalpha killpg \
mempcpy \
sigsetmask stpcpy strchrnul strsignal strtod strtoimax \
strtoumax sysconf)

src/arith_yacc.c +0 -3
index bf21830..1a087c3 100644
@@ -94,22 +94,13 @@ static inline int higher_prec(int op1, int op2)
 
 static intmax_t do_binop(int op, intmax_t a, intmax_t b)
 {
-#ifdef HAVE_IMAXDIV
-	imaxdiv_t div;
-#endif
#1 lore raw
Quoted 6 lines · Harald van Dijk

dash rather pointlessly calls imaxdiv, only to discard one of its results. The call was already made conditional a while back because some systems don't have imaxdiv, but the generated code for the version with imaxdiv and the one with / and % is identical (with GCC 4.6.1 or ICC 12.0.2, with -O0, -O2 or -Os), so it could just as well go entirely to clean up the code a little bit.

As I should have expected from those results, I messed up on the comparisons. I still had an alternate definition of imaxdiv I was testing with. The size actually decreases with the patch.

#2 lore raw
In reply to Harald van Dijk
Quoted 8 lines · Harald van Dijk

dash rather pointlessly calls imaxdiv, only to discard one of its results. The call was already made conditional a while back because some systems don't have imaxdiv, but the generated code for the version with imaxdiv and the one with / and % is identical (with GCC 4.6.1 or ICC 12.0.2, with -O0, -O2 or -Os), so it could just as well go entirely to clean up the code a little bit.

Nice work, patch applied.

Thanks!

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt