This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
c207a0105422732634563f248e948fd1fda0742e
[metaconfig.git] / U / perl / d_builtin.U
1 ?RCS: Copyright (c) 2006-2007, H.Merijn Brand
2 ?RCS:
3 ?RCS: You may redistribute only under the terms of the Artistic Licence,
4 ?RCS: as specified in the README file that comes with the distribution.
5 ?RCS: You may reuse parts of this distribution only within the terms of
6 ?RCS: that same Artistic Licence; a copy of which may be found at the root
7 ?RCS: of the source tree for dist 3.0.
8 ?RCS:
9 ?MAKE:d_builtin_choose_expr d_builtin_expect : Compile Setvar cat run rm_try
10 ?MAKE:  -pick add $@ %<
11 ?S:d_builtin_choose_expr:
12 ?S:     This conditionally defines HAS_BUILTIN_CHOOSE_EXPR, which
13 ?S:     indicates that the compiler supports __builtin_choose_expr(x,y,z).
14 ?S:     This built-in function is analogous to the "x?y:z" operator in C,
15 ?S:     except that the expression returned has its type unaltered by
16 ?S:     promotion rules. Also, the built-in function does not evaluate
17 ?S:     the expression that was not chosen.
18 ?S:.
19 ?S:d_builtin_expect:
20 ?S:     This conditionally defines HAS_BUILTIN_EXPECT, which indicates
21 ?S:     that the compiler supports __builtin_expect(exp,c).  You may use
22 ?S:     __builtin_expect to provide the compiler with branch prediction
23 ?S:     information.
24 ?S:.
25 ?C:HAS_BUILTIN_CHOOSE_EXPR:
26 ?C:     Can we handle GCC builtin for compile-time ternary-like expressions
27 ?C:.
28 ?C:HAS_BUILTIN_EXPECT:
29 ?C:     Can we handle GCC builtin for telling that certain values are more
30 ?C:     likely
31 ?C:.
32 ?H:#$d_builtin_expect HAS_BUILTIN_EXPECT        /**/
33 ?H:#$d_builtin_choose_expr HAS_BUILTIN_CHOOSE_EXPR      /**/
34 ?H:.
35 ?LINT:set d_builtin_expect d_builtin_choose_expr
36 : Look for GCC-style __builtin_choose_expr
37 case "$d_builtin_choose_expr" in
38 '')
39     echo " "
40     echo "Checking whether your compiler can handle __builtin_choose_expr ..." >&4
41     $cat >try.c <<'EOCP'
42 #include <assert.h>
43 #include <stdlib.h>
44 #include <stdio.h>
45
46 #define SYRINX(x) __builtin_choose_expr( x, (1056*2), (103*50) )
47
48 int main(void) {
49     assert( SYRINX(1) == 2112 );
50     assert( SYRINX(1) != 5150 );
51     assert( SYRINX(0) == 5150 );
52     assert( SYRINX(0) != 2112 );
53     puts( "All good!" );
54     exit(0);
55 }
56
57 EOCP
58     set try
59     if eval $compile && $run ./try; then
60         echo "Your C compiler supports __builtin_choose_expr."
61         val="$define"
62     else
63         echo "Your C compiler doesn't seem to understand __builtin_choose_expr."
64         val="$undef"
65     fi
66 ;;
67 *) val="$d_builtin_choose_expr" ;;
68 esac
69
70 set d_builtin_choose_expr
71 eval $setvar
72 $rm_try
73
74 : Look for GCC-style __builtin_expect
75 case "$d_builtin_expect" in
76 '')
77     echo " "
78     echo "Checking whether your compiler can handle __builtin_expect ..." >&4
79     $cat >try.c <<'EOCP'
80 int main(void) {
81     int n = 50;
82     if ( __builtin_expect(n, 0) ) n = 1;
83     /* Remember shell exit code truth is 0, C truth is non-zero */
84     return !(n == 1);
85 }
86 EOCP
87     set try
88     if eval $compile && $run ./try; then
89         echo "Your C compiler supports __builtin_expect."
90         val="$define"
91     else
92         echo "Your C compiler doesn't seem to understand __builtin_expect."
93         val="$undef"
94     fi
95     ;;
96 *) val="$d_builtin_expect" ;;
97 esac
98
99 set d_builtin_expect
100 eval $setvar
101 $rm_try
102