?RCS: Copyright (c) 2006-2007, H.Merijn Brand ?RCS: ?RCS: You may redistribute only under the terms of the Artistic License, ?RCS: as specified in the README file that comes with the distribution. ?RCS: You may reuse parts of this distribution only within the terms of ?RCS: that same Artistic License; a copy of which may be found at the root ?RCS: of the source tree for dist 3.0. ?RCS: ?MAKE:d_builtin_choose_expr d_builtin_expect : Compile Setvar cat run rm_try ?MAKE: -pick add $@ %< ?S:d_builtin_choose_expr: ?S: This conditionally defines HAS_BUILTIN_CHOOSE_EXPR, which ?S: indicates that the compiler supports __builtin_choose_expr(x,y,z). ?S: This built-in function is analogous to the "x?y:z" operator in C, ?S: except that the expression returned has its type unaltered by ?S: promotion rules. Also, the built-in function does not evaluate ?S: the expression that was not chosen. ?S:. ?S:d_builtin_expect: ?S: This conditionally defines HAS_BUILTIN_EXPECT, which indicates ?S: that the compiler supports __builtin_expect(exp,c). You may use ?S: __builtin_expect to provide the compiler with branch prediction ?S: information. ?S:. ?C:HAS_BUILTIN_CHOOSE_EXPR: ?C: Can we handle GCC builtin for compile-time ternary-like expressions ?C:. ?C:HAS_BUILTIN_EXPECT: ?C: Can we handle GCC builtin for telling that certain values are more ?C: likely ?C:. ?H:#$d_builtin_expect HAS_BUILTIN_EXPECT /**/ ?H:#$d_builtin_choose_expr HAS_BUILTIN_CHOOSE_EXPR /**/ ?H:. ?F:!try ?LINT:set d_builtin_expect d_builtin_choose_expr : Look for GCC-style __builtin_choose_expr case "$d_builtin_choose_expr" in '') echo " " echo "Checking whether your compiler can handle __builtin_choose_expr ..." >&4 $cat >try.c <<'EOCP' #include #include #include #define SYRINX(x) __builtin_choose_expr( x, (1056*2), (103*50) ) int main(void) { assert( SYRINX(1) == 2112 ); assert( SYRINX(1) != 5150 ); assert( SYRINX(0) == 5150 ); assert( SYRINX(0) != 2112 ); puts( "All good!" ); exit(0); } EOCP set try if eval $compile && $run ./try; then echo "Your C compiler supports __builtin_choose_expr." val="$define" else echo "Your C compiler doesn't seem to understand __builtin_choose_expr." val="$undef" fi ;; *) val="$d_builtin_choose_expr" ;; esac set d_builtin_choose_expr eval $setvar $rm_try : Look for GCC-style __builtin_expect case "$d_builtin_expect" in '') echo " " echo "Checking whether your compiler can handle __builtin_expect ..." >&4 $cat >try.c <<'EOCP' int main(void) { int n = 50; if ( __builtin_expect(n, 0) ) n = 1; /* Remember shell exit code truth is 0, C truth is non-zero */ return !(n == 1); } EOCP set try if eval $compile && $run ./try; then echo "Your C compiler supports __builtin_expect." val="$define" else echo "Your C compiler doesn't seem to understand __builtin_expect." val="$undef" fi ;; *) val="$d_builtin_expect" ;; esac set d_builtin_expect eval $setvar $rm_try