This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch] Simple __gslice_to_index tweak


Hi all, hi Gaby,

a couple of days ago I noticed this nit. The loop over the indexes works by tentatively increasing the last one and then propagating the info back to the lower ones: if I understand the logic correctly, as soon as the condition is false we don't do ++__t[__k2 - 1] and that means that the lower positions of __t will remain unchanged, we can as well end the loop.

The below passes the testsuite and I checked that indeed is worth a measurable improvement in stupid tests like (P4-2400, -O2):

valarray<double> va(1000000);

 for (int i = 0; i < 1000000; ++i)
   va[i] = i;

 size_t lengthvalues[] = { 10, 10, 10, 10, 10, 10 };
 size_t stridevalues[] = { 1, 1, 1, 1, 1, 1 };

 valarray<size_t> lengths(lengthvalues, 6);
 valarray<size_t> stride(stridevalues, 6);

 for (int j = 0; j < 1000; ++j)
   va[gslice(0, lengths, stride)];

---

base:
30.973u 8.068s 0:39.14 99.7%    0+0k 0+0io 0pf+0w

peak:
23.053u 7.856s 0:30.91 99.9%    0+0k 0+0io 0pf+0w

Ok?

Thanks,
Paolo.

//////////////////
2006-07-28  Paolo Carlini  <pcarlini@suse.de>

	* src/valarray-inst.cc (__gslice_to_index): Bail out from the
	multi-index processing loop as soon as the condition is false
	(i.e., nothing more to back propagate).
Index: src/valarray-inst.cc
===================================================================
--- src/valarray-inst.cc	(revision 115791)
+++ src/valarray-inst.cc	(working copy)
@@ -1,6 +1,7 @@
 // Explicit instantiation file.
 
-// Copyright (C) 2001, 2004, 2005 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
+// Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -94,7 +95,7 @@
         __i[__j] = __a;
 
         // Process the next multi-index.  The loop ought to be
-        // backward since we're making a lexicagraphical visit.
+        // backward since we're making a lexicographical visit.
         ++__t[__n - 1];
         for (size_t __k2 = __n - 1; __k2; --__k2)
           {
@@ -103,6 +104,8 @@
                 __t[__k2] = 0;
                 ++__t[__k2 - 1];
               }
+	    else
+	      break;
           }
       }
   }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]