Enable branch prediction in TensorFlow
authorJustine Tunney <jart@google.com>
Thu, 5 Apr 2018 20:23:08 +0000 (13:23 -0700)
committerTensorFlower Gardener <gardener@tensorflow.org>
Thu, 5 Apr 2018 20:25:31 +0000 (13:25 -0700)
PiperOrigin-RevId: 191788253

tensorflow/core/platform/macros.h

index 6119edf..1b1faed 100644 (file)
@@ -67,11 +67,18 @@ limitations under the License.
 #define TF_EXPORT __attribute__((visibility("default")))
 #endif  // COMPILER_MSVC
 
-// GCC can be told that a certain branch is not likely to be taken (for
-// instance, a CHECK failure), and use that information in static analysis.
-// Giving it this information can help it optimize for the common case in
-// the absence of better information (ie. -fprofile-arcs).
-#if defined(COMPILER_GCC3)
+#ifdef __has_builtin
+#define TF_HAS_BUILTIN(x) __has_builtin(x)
+#else
+#define TF_HAS_BUILTIN(x) 0
+#endif
+
+// Compilers can be told that a certain branch is not likely to be taken
+// (for instance, a CHECK failure), and use that information in static
+// analysis. Giving it this information can help it optimize for the
+// common case in the absence of better information (ie.
+// -fprofile-arcs).
+#if TF_HAS_BUILTIN(__builtin_expect) || (defined(__GNUC__) && __GNUC__ >= 3)
 #define TF_PREDICT_FALSE(x) (__builtin_expect(x, 0))
 #define TF_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
 #else