[mathic] 42/62: Turned off link time optimization for Relaase-Assert Visual Studio configuration. Also added macroes that tell the compiler extra things about the code, such as whether two pointers alias.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Wed Apr 1 11:36:22 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch master
in repository mathic.

commit 75ca27001190ab292e51965cb6c2f6d22e2abf7e
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date:   Thu Oct 25 21:03:47 2012 +0200

    Turned off link time optimization for Relaase-Assert Visual Studio configuration. Also added macroes that tell the compiler extra things about the code, such as whether two pointers alias.
---
 build/vs12/mathic-lib/mathic-lib.vcxproj   |  5 +-
 build/vs12/mathic-test/mathic-test.vcxproj |  4 +-
 src/mathic/BinaryKDTree.h                  |  9 ++--
 src/mathic/BitTriangle.h                   |  4 +-
 src/mathic/ComTree.h                       | 15 +++---
 src/mathic/DivList.h                       |  2 +-
 src/mathic/Geobucket.h                     | 11 +++--
 src/mathic/Heap.h                          | 11 +++--
 src/mathic/PackedKDTree.h                  | 17 +++----
 src/mathic/TourTree.h                      | 11 +++--
 src/mathic/stdinc.h                        | 76 +++++++++++++++++++++++++++++-
 11 files changed, 122 insertions(+), 43 deletions(-)

diff --git a/build/vs12/mathic-lib/mathic-lib.vcxproj b/build/vs12/mathic-lib/mathic-lib.vcxproj
index b85a66a..2b9ac59 100755
--- a/build/vs12/mathic-lib/mathic-lib.vcxproj
+++ b/build/vs12/mathic-lib/mathic-lib.vcxproj
@@ -150,14 +150,14 @@
     <ConfigurationType>StaticLibrary</ConfigurationType>
     <UseDebugLibraries>false</UseDebugLibraries>
     <PlatformToolset>v110</PlatformToolset>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <WholeProgramOptimization>false</WholeProgramOptimization>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Assert|x64'" Label="Configuration">
     <ConfigurationType>StaticLibrary</ConfigurationType>
     <UseDebugLibraries>false</UseDebugLibraries>
     <PlatformToolset>v110</PlatformToolset>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <WholeProgramOptimization>false</WholeProgramOptimization>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
@@ -384,6 +384,7 @@
       <PreprocessorDefinitions>WIN64;NDEBUG;_WINDOWS;_USRDLL;MATHICLIB_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <AdditionalIncludeDirectories>C:\projs\mathic\memtailor\src;C:\projs\mathic\mathic\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <MultiProcessorCompilation>true</MultiProcessorCompilation>
+      <OpenMPSupport>true</OpenMPSupport>
     </ClCompile>
     <Link>
       <SubSystem>Windows</SubSystem>
diff --git a/build/vs12/mathic-test/mathic-test.vcxproj b/build/vs12/mathic-test/mathic-test.vcxproj
index c950cad..8f2cf2b 100755
--- a/build/vs12/mathic-test/mathic-test.vcxproj
+++ b/build/vs12/mathic-test/mathic-test.vcxproj
@@ -102,14 +102,14 @@
     <ConfigurationType>Application</ConfigurationType>
     <UseDebugLibraries>false</UseDebugLibraries>
     <PlatformToolset>v110</PlatformToolset>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <WholeProgramOptimization>false</WholeProgramOptimization>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Assert|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <UseDebugLibraries>false</UseDebugLibraries>
     <PlatformToolset>v110</PlatformToolset>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <WholeProgramOptimization>false</WholeProgramOptimization>
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
diff --git a/src/mathic/BinaryKDTree.h b/src/mathic/BinaryKDTree.h
index 05e67ff..3366ec4 100755
--- a/src/mathic/BinaryKDTree.h
+++ b/src/mathic/BinaryKDTree.h
@@ -224,9 +224,8 @@ namespace mathic {
 
     void print(std::ostream& out) const;
 
-#ifdef MATHIC_DEBUG
+    /// Asserts internal invariants if asserts are turned on.
     bool debugIsValid() const;
-#endif
 
   private:
     BinaryKDTree(const BinaryKDTree<C>&); // unavailable
@@ -619,9 +618,11 @@ next:
     }
   }
 
-#ifdef MATHIC_DEBUG
   template<class C>
   bool BinaryKDTree<C>::debugIsValid() const {
+#ifndef MATHIC_DEBUG
+    return true;
+#else
     MATHIC_ASSERT(_tmp.empty());
     MATHIC_ASSERT(!_conf.getDoAutomaticRebuilds() || _conf.getRebuildRatio() > 0);
 
@@ -694,8 +695,8 @@ next:
       }
     }
     return true;
-  }
 #endif
+  }
 
   template<class C>
   BinaryKDTree<C>::KDTreeLeaf::KDTreeLeaf(memt::Arena& arena, const C& conf):
diff --git a/src/mathic/BitTriangle.h b/src/mathic/BitTriangle.h
index 9c1ce63..c29a4dc 100755
--- a/src/mathic/BitTriangle.h
+++ b/src/mathic/BitTriangle.h
@@ -38,7 +38,7 @@ namespace mathic {
 
 	// Returns the bit in the given column and row. As this is a triangle it
 	// must be true that row < column.
-	bool bit(size_t column, size_t row) const {
+	MATHIC_INLINE bool bit(size_t column, size_t row) const {
 	  MATHIC_ASSERT(column < columnCount());
 	  MATHIC_ASSERT(row < column);
 	  return mColumns[column][row];
@@ -57,7 +57,7 @@ namespace mathic {
 
 	// Sets the bit in the given column and row. As this is a triangle
 	// it must be true that column >= row.
-	void setBit(size_t column, size_t row, bool value) {
+	MATHIC_INLINE void setBit(size_t column, size_t row, bool value) {
 	  MATHIC_ASSERT(column < columnCount());
 	  MATHIC_ASSERT(row < column);
 	  mColumns[column][row] = value;
diff --git a/src/mathic/ComTree.h b/src/mathic/ComTree.h
index ff2f4e1..eeaf22d 100755
--- a/src/mathic/ComTree.h
+++ b/src/mathic/ComTree.h
@@ -95,9 +95,8 @@ namespace mathic {
 
     size_t getMemoryUse() const;
 
-#ifdef MATHIC_DEBUG
+    /// Asserts internal invariants if asserts are turned on.
 	bool isValid() const;
-#endif
 
   private:
 	ComTree& operator=(const ComTree& tree) const; // not available
@@ -226,12 +225,12 @@ namespace mathic {
   }
 
   template<class E, bool FI>
-	typename ComTree<E, FI>::Node ComTree<E, FI>::Node::prev() const {
+  typename ComTree<E, FI>::Node ComTree<E, FI>::Node::prev() const {
 	return fi ? Node(_index - S) : Node(_index - 1);
   }
 
   template<class E, bool FI>
-	void ComTree<E, FI>::print(std::ostream& out) const {
+  void ComTree<E, FI>::print(std::ostream& out) const {
 	Node last = lastLeaf();
 	for (Node i; i <= last; i = i.next()) {
 	  if ((i._index & (i._index - 1)) == 0) // if i._index is a power of 2
@@ -241,9 +240,11 @@ namespace mathic {
 	out << "}\n";
   }
 
-#ifdef MATHIC_DEBUG
   template<class E, bool FI>
-	bool ComTree<E, FI>::isValid() const {
+  bool ComTree<E, FI>::isValid() const {
+#ifndef MATHIC_DEBUG
+    return true;
+#else
 	// sizeof(Entry) must be a power of two if FastIndex is true.
 	MATHIC_ASSERT(!FI || (sizeof(E) & (sizeof(E) - 1)) == 0);
 	if (capacity() == 0) {
@@ -256,8 +257,8 @@ namespace mathic {
 	  MATHIC_ASSERT(_lastLeaf <= _capacityEnd);
 	}
 	return true;
-  }
 #endif
+  }
 
   template<class E, bool FI>
 	bool ComTree<E, FI>::hasFreeCapacity(size_t extraCapacity) const {
diff --git a/src/mathic/DivList.h b/src/mathic/DivList.h
index 1f5928a..03cf87d 100755
--- a/src/mathic/DivList.h
+++ b/src/mathic/DivList.h
@@ -435,7 +435,7 @@ namespace mathic {
 #endif
     const size_t removedCount =
       DivListHelper::removeMultiples(_conf, _list, extMonomial, out);
-    MATHIC_ASSERT(size() + removedCount == origSize);
+    MATHIC_ASSERT_NO_ASSUME(size() + removedCount == origSize);
     reportChanges(removedCount);
     return removedCount > 0;
   }
diff --git a/src/mathic/Geobucket.h b/src/mathic/Geobucket.h
index 6bb40fc..0784608 100755
--- a/src/mathic/Geobucket.h
+++ b/src/mathic/Geobucket.h
@@ -304,9 +304,8 @@ namespace mathic {
 	Configuration _conf;
 	GeoFront<Configuration> _front;
 
-#ifdef MATHIC_DEBUG
+    /// Asserts internal invariants if asserts are turned on.
 	bool isValid() const;
-#endif
   };
 
   template<class C>
@@ -320,7 +319,7 @@ namespace mathic {
 	_front(_conf, _entryCount) {
 	MATHIC_ASSERT(_conf.geoBase > 1);
 	addBucket(); // this avoids the special case of no buckets.
-    MATHIC_ASSERT(_front.debugIsValid(_bucketBegin, _bucketEnd));
+    MATHIC_ASSERT_NO_ASSUME(_front.debugIsValid(_bucketBegin, _bucketEnd));
   }
 
   template<class C>
@@ -790,9 +789,11 @@ namespace mathic {
       _front.getMemoryUse();
   }
 
-#ifdef MATHIC_DEBUG
   template<class C>
   bool Geobucket<C>::isValid() const {
+#ifndef MATHIC_DEBUG
+    return true;
+#else
 	MATHIC_ASSERT(_conf.geoBase >= 2);
 	MATHIC_ASSERT(!_buckets.empty());
 	MATHIC_ASSERT(_bucketBegin == &_buckets.front());
@@ -811,8 +812,8 @@ namespace mathic {
 	}
 	MATHIC_ASSERT(entryCount == _entryCount);
 	return _front.debugIsValid(_bucketBegin, _bucketEnd);
-  }
 #endif
+  }
 };
 
 #endif
diff --git a/src/mathic/Heap.h b/src/mathic/Heap.h
index 860da51..655e9c4 100755
--- a/src/mathic/Heap.h
+++ b/src/mathic/Heap.h
@@ -68,9 +68,8 @@ namespace mathic {
 	Node moveHoleDown(Node hole);
 	void moveValueUp(Node pos, Entry value);
 
-#ifdef MATHIC_DEBUG
+    /// Asserts internal invariants if asserts are turned on.
 	bool isValid() const;
-#endif
 
 	Tree _tree;
 	Configuration _conf;
@@ -186,16 +185,18 @@ namespace mathic {
 	MATHIC_SLOW_ASSERT(isValid());
   }
 
-#ifdef MATHIC_DEBUG
   template<class C>
-	bool Heap<C>::isValid() const {
+  bool Heap<C>::isValid() const {
+#ifndef MATHIC_DEBUG
+    return true;
+#else
 	MATHIC_ASSERT(_tree.isValid());
 	for (Node i = Node().next(); i <= _tree.lastLeaf(); ++i) {
 	  MATHIC_ASSERT(!_conf.cmpLessThan(_conf.compare(_tree[i.parent()], _tree[i])));
 	}
 	return true;
-  }
 #endif
+  }
 }
 
 #endif
diff --git a/src/mathic/PackedKDTree.h b/src/mathic/PackedKDTree.h
index 1300147..19dd091 100755
--- a/src/mathic/PackedKDTree.h
+++ b/src/mathic/PackedKDTree.h
@@ -86,9 +86,8 @@ namespace mathic {
         memt::Arena& arena,
         const C& conf);
 
-#ifdef MATHIC_DEBUG
+      /// Asserts internal invariants if asserts are turned on.
       bool debugIsValid() const;
-#endif
 
     private:
       Node(const Node&); // unavailable
@@ -149,9 +148,7 @@ namespace mathic {
 
     C& getConfiguration() {return _conf;}
 
-#ifdef MATHIC_DEBUG
     bool debugIsValid() const;
-#endif
 
   private:
     PackedKDTree(const PackedKDTree<C>&); // unavailable
@@ -576,9 +573,11 @@ next:
     MATHIC_ASSERT(_tmp.empty());
   }
 
-#ifdef MATHIC_DEBUG
   template<class C>
   bool PackedKDTree<C>::debugIsValid() const {
+#ifndef MATHIC_DEBUG
+    return true;
+#else
     //print(std::cerr); std::cerr << std::flush;
     MATHIC_ASSERT(_tmp.empty());
     MATHIC_ASSERT(!_conf.getDoAutomaticRebuilds() || _conf.getRebuildRatio() > 0);
@@ -650,8 +649,8 @@ next:
       }
     }
     return true;
-  }
 #endif
+  }
 
   template<class C>
   class PackedKDTree<C>::Node::SplitEqualOrLess {
@@ -735,9 +734,11 @@ next:
     return copied;
   }
 
-#ifdef MATHIC_DEBUG
   template<class C>
   bool PackedKDTree<C>::Node::debugIsValid() const {
+#ifndef MATHIC_DEBUG
+    return true;
+#else
     MATHIC_ASSERT(entries().debugIsValid());
     MATHIC_ASSERT(childBegin() <= childEnd());
     if (C::UseTreeDivMask) {
@@ -753,8 +754,8 @@ next:
       }
     }
     return true;
-  }
 #endif
+  }
 }
 
 #endif
diff --git a/src/mathic/TourTree.h b/src/mathic/TourTree.h
index 71bcef0..2eeedaa 100755
--- a/src/mathic/TourTree.h
+++ b/src/mathic/TourTree.h
@@ -70,9 +70,8 @@ namespace mathic {
 
 	void reallocate();
 
-#ifdef MATHIC_DEBUG
+    /// Asserts internal invariants if asserts are turned on.
 	bool isValid() const;
-#endif
 
 	Tree _tree;
 	std::vector<Player> _players;
@@ -236,9 +235,11 @@ namespace mathic {
 	MATHIC_ASSERT(isValid());
   }
 
-#ifdef MATHIC_DEBUG
   template<class C>
-	bool TourTree<C>::isValid() const {
+  bool TourTree<C>::isValid() const {
+#ifndef MATHIC_DEBUG
+    return true;
+#else
 	MATHIC_ASSERT
 	  ((_tree.empty() && _players.empty()) || // just constructed
 	   (_tree.capacity() + 1 <= 2 * _players.capacity()));
@@ -267,8 +268,8 @@ namespace mathic {
 	  }
 	}
 	return true;
-  }
 #endif
+  }
 }
 
 #endif
diff --git a/src/mathic/stdinc.h b/src/mathic/stdinc.h
index 6eff6dd..6500526 100755
--- a/src/mathic/stdinc.h
+++ b/src/mathic/stdinc.h
@@ -1,6 +1,76 @@
 #ifndef MATHIC_STDINC_GUARD
 #define MATHIC_STDINC_GUARD
 
+#ifdef _MSC_VER // For Microsoft Compiler in Visual Studio C++.
+// Sometimes you know that a function will be called very rarely so you want to
+// tell the compiler not to inline it even if it could be inlined at only a
+// modest increase in code size. That is what MATHIC_NO_INLINE does.
+#define MATHIC_NO_INLINE __declspec(noinline)
+
+// Sometimes the compiler just will not inline functions that should
+// be inlined. Use sparingly --- preferably only if a profiler says
+// that a tiny often-called function consumes a significant amount of time.
+#define MATHIC_INLINE __forceinline
+
+// Tells the compiler to always assume that the expression X is true.
+#define MATHIC_ASSUME(X) __assume(X)
+
+// As MATHIC_ASSUME, but might actually evaluate X at run-time if it has
+// side-effects. The point is that this can be used on compilers with no other
+// support for assuming things. So there is no difference on MS VC++.
+#define MATHIC_ASSUME_AND_MAY_EVALUATE(X) __assume(X)
+
+// Tells the compiler that this function returns a pointer that is not an alias
+// for any other point that is currently valid in the program - like malloc.
+#define MATHIC_RETURN_NO_ALIAS __declspec(restrict)
+
+// Tells the compiler that this function will never throw an exception.
+#define MATHIC_NOTHROW __declspec(nothrow)
+
+// Tells the compiler that this function has no effects except the return value
+// and the return value depends only on the arguments and first-level
+// indirections of the arguments. (this is the common denominator of GCC
+// and MS VC++ capabilities)
+#define MATHIC_PURE __declspec(noalias)
+
+// Tells the compiler that the return value of this function must be looked
+// at by the caller. For example this is appropriate for realloc.
+#define MATHIC_MUST_CHECK_RETURN_VALUE
+
+// Tells the compiler that the current line of code cannot be reached.
+#define MATHIC_UNREACHABLE __assume(false)
+
+// Tells the compiler that a variable that is a pointer (not a reference)
+// does not alias any other pointer that is used in the current scope.
+#define MATHIC_RESTRICT __restrict
+
+#elif defined (__GNUC__) // GCC compiler
+
+#define MATHIC_NO_INLINE __attribute__((noinline))
+#define MATHIC_INLINE __attribute__((always_inline)) inline
+#define MATHIC_ASSUME(X)
+#define MATHIC_ASSUME_AND_MAY_EVALUATE(X) do {if(!(X)){MATHIC_UNREACHABLE;}while(0)}
+#define MATHIC_RETURN_NO_ALIAS __attribute__(malloc)
+#define MATHIC_NOTHROW __attribute__(nothrow)
+#define MATHIC_PURE __attribute__(pure)
+#define MATHIC_MUST_CHECK_RETURN_VALUE __attribute__(warn_unused_result)
+#define MATHIC_UNREACHABLE __builtin_unreachable()
+
+#else
+
+#define MATHIC_NO_INLINE
+#define MATHIC_INLINE inline
+#define MATHIC_ASSUME(X)
+#define MATHIC_ASSUME_AND_MAY_EVALUATE(X)
+#define MATHIC_RETURN_NO_ALIAS
+#define MATHIC_NOTHROW
+#define MATHIC_PURE
+#define MATHIC_MUST_CHECK_RETURN_VALUE
+#define MATHIC_UNREACHABLE
+
+#endif
+
+
 #ifdef MATHIC_SLOW_DEBUG
 // for asserts that take a long time.
 #define MATHIC_SLOW_ASSERT(X) MATHIC_ASSERT(X)
@@ -13,9 +83,11 @@
 
 #ifdef MATHIC_DEBUG
 #include <cassert>
-#define MATHIC_ASSERT(X) assert(X)
+#define MATHIC_ASSERT(X) do{assert(X);}while(0)
+#define MATHIC_ASSERT_NO_ASSUME(X) MATHIC_ASSERT(X)
 #else
-#define MATHIC_ASSERT(X)
+#define MATHIC_ASSERT(X) MATHIC_ASSUME(X)
+#define MATHIC_ASSERT_NO_ASSUME(X)
 #endif
 
 namespace mathic {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mathic.git



More information about the debian-science-commits mailing list