This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix .gitignore: only ignore 'perl' in root of repo, not U/perl subdir
[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 License,
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 License; 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 ?F:!try
36 ?LINT:set d_builtin_expect d_builtin_choose_expr
37 : Look for GCC-style __builtin_choose_expr
38 case "$d_builtin_choose_expr" in
39 '')
40     echo " "
41     echo "Checking whether your compiler can handle __builtin_choose_expr ..." >&4
42     $cat >try.c <<'EOCP'
43 #include <assert.h>
44 #include <stdlib.h>
45 #include <stdio.h>
46
47 #define SYRINX(x) __builtin_choose_expr( x, (1056*2), (103*50) )
48
49 int main(void) {
50     assert( SYRINX(1) == 2112 );
51     assert( SYRINX(1) != 5150 );
52     assert( SYRINX(0) == 5150 );
53     assert( SYRINX(0) != 2112 );
54     puts( "All good!" );
55     exit(0);
56 }
57
58 EOCP
59     set try
60     if eval $compile && $run ./try; then
61         echo "Your C compiler supports __builtin_choose_expr."
62         val="$define"
63     else
64         echo "Your C compiler doesn't seem to understand __builtin_choose_expr."
65         val="$undef"
66     fi
67 ;;
68 *) val="$d_builtin_choose_expr" ;;
69 esac
70
71 set d_builtin_choose_expr
72 eval $setvar
73 $rm_try
74
75 : Look for GCC-style __builtin_expect
76 case "$d_builtin_expect" in
77 '')
78     echo " "
79     echo "Checking whether your compiler can handle __builtin_expect ..." >&4
80     $cat >try.c <<'EOCP'
81 int main(void) {
82     int n = 50;
83     if ( __builtin_expect(n, 0) ) n = 1;
84     /* Remember shell exit code truth is 0, C truth is non-zero */
85     return !(n == 1);
86 }
87 EOCP
88     set try
89     if eval $compile && $run ./try; then
90         echo "Your C compiler supports __builtin_expect."
91         val="$define"
92     else
93         echo "Your C compiler doesn't seem to understand __builtin_expect."
94         val="$undef"
95     fi
96     ;;
97 *) val="$d_builtin_expect" ;;
98 esac
99
100 set d_builtin_expect
101 eval $setvar
102 $rm_try
103