Commit 92812a61 authored by Mark Florisson's avatar Mark Florisson

Workaround for __builtin_expect OpenMP compiler bugs on OS X Lion

parent 28c23739
......@@ -7430,6 +7430,8 @@ class ParallelStatNode(StatNode, ParallelNode):
self.begin_of_parallel_control_block_point = code.insertion_point()
self.begin_of_parallel_control_block_point_after_decls = code.insertion_point()
self.undef_builtin_expect_apple_gcc_bug(code)
def begin_parallel_block(self, code):
"""
Each OpenMP thread in a parallel section that contains a with gil block
......@@ -7722,6 +7724,32 @@ class ParallelStatNode(StatNode, ParallelNode):
"}") # end if
code.end_block() # end parallel control flow block
self.redef_builtin_expect_apple_gcc_bug(code)
# FIXME: improve with version number for OS X Lion
buggy_platform_macro_condition = "(defined(__APPLE__) || defined(__OSX__))"
have_expect_condition = "(defined(__GNUC__) && " \
"(__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))))"
redef_condition = "(%s && %s)" % (buggy_platform_macro_condition, have_expect_condition)
def undef_builtin_expect_apple_gcc_bug(self, code):
"""
A bug on OS X Lion disallows __builtin_expect macros. This code avoids them
"""
code.putln("#if %s" % self.redef_condition)
code.putln(" #undef likely")
code.putln(" #undef unlikely")
code.putln(" #define likely(x) (x)")
code.putln(" #define unlikely(x) (x)")
code.putln("#endif")
def redef_builtin_expect_apple_gcc_bug(self, code):
code.putln("#if %s" % self.redef_condition)
code.putln(" #undef likely")
code.putln(" #undef unlikely")
code.putln(" #define likely(x) __builtin_expect(!!(x), 1)")
code.putln(" #define unlikely(x) __builtin_expect(!!(x), 0)")
code.putln("#endif")
class ParallelWithBlockNode(ParallelStatNode):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment