1 /* { dg-do compile { target { powerpc*-*-linux* && lp64 } } } */
2 /* { dg-skip-if "" { powerpc*-*-darwin* } { "*" } { "" } } */
3 /* { dg-skip-if "" { powerpc*-*-*spe* } { "*" } { "" } } */
4 /* { dg-require-effective-target powerpc_p8vector_ok } */
5 /* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=power8" } } */
6 /* { dg-options "-mcpu=power8 -O2" } */
7 /* { dg-final { scan-assembler-times "bcdadd\[.\] " 4 } } */
8 /* { dg-final { scan-assembler-times "bcdsub\[.\] " 4 } } */
9 /* { dg-final { scan-assembler-not   "bl __builtin"   } } */
10 /* { dg-final { scan-assembler-not   "mtvsr"   	      } } */
11 /* { dg-final { scan-assembler-not   "mfvsr"   	      } } */
12 /* { dg-final { scan-assembler-not   "lvx"     	      } } */
13 /* { dg-final { scan-assembler-not   "lxvw4x"  	      } } */
14 /* { dg-final { scan-assembler-not   "lxvd2x"  	      } } */
15 /* { dg-final { scan-assembler-not   "stvx"    	      } } */
16 /* { dg-final { scan-assembler-not   "stxvw4x" 	      } } */
17 /* { dg-final { scan-assembler-not   "stxvd2x" 	      } } */
18 
19 typedef __int128_t __attribute__((__vector_size__(16)))	vector_128_t;
20 typedef __int128_t					scalar_128_t;
21 typedef	unsigned long long				scalar_64_t;
22 
23 /* Test whether the peephole works to allow folding a bcdadd, with a
24    bcdadd_<test> into a single instruction.  */
25 
26 vector_128_t
do_add_lt(vector_128_t a,vector_128_t b,int * p)27 do_add_lt (vector_128_t a, vector_128_t b, int *p)
28 {
29   vector_128_t ret = __builtin_bcdadd (a, b, 0);
30   if (__builtin_bcdadd_lt (a, b, 0))
31     *p = 1;
32 
33   return ret;
34 }
35 
36 vector_128_t
do_add_eq(vector_128_t a,vector_128_t b,int * p)37 do_add_eq (vector_128_t a, vector_128_t b, int *p)
38 {
39   vector_128_t ret = __builtin_bcdadd (a, b, 0);
40   if (__builtin_bcdadd_eq (a, b, 0))
41     *p = 1;
42 
43   return ret;
44 }
45 
46 vector_128_t
do_add_gt(vector_128_t a,vector_128_t b,int * p)47 do_add_gt (vector_128_t a, vector_128_t b, int *p)
48 {
49   vector_128_t ret = __builtin_bcdadd (a, b, 0);
50   if (__builtin_bcdadd_gt (a, b, 0))
51     *p = 1;
52 
53   return ret;
54 }
55 
56 vector_128_t
do_add_ov(vector_128_t a,vector_128_t b,int * p)57 do_add_ov (vector_128_t a, vector_128_t b, int *p)
58 {
59   vector_128_t ret = __builtin_bcdadd (a, b, 0);
60   if (__builtin_bcdadd_ov (a, b, 0))
61     *p = 1;
62 
63   return ret;
64 }
65 
66 vector_128_t
do_sub_lt(vector_128_t a,vector_128_t b,int * p)67 do_sub_lt (vector_128_t a, vector_128_t b, int *p)
68 {
69   vector_128_t ret = __builtin_bcdsub (a, b, 0);
70   if (__builtin_bcdsub_lt (a, b, 0))
71     *p = 1;
72 
73   return ret;
74 }
75 
76 vector_128_t
do_sub_eq(vector_128_t a,vector_128_t b,int * p)77 do_sub_eq (vector_128_t a, vector_128_t b, int *p)
78 {
79   vector_128_t ret = __builtin_bcdsub (a, b, 0);
80   if (__builtin_bcdsub_eq (a, b, 0))
81     *p = 1;
82 
83   return ret;
84 }
85 
86 vector_128_t
do_sub_gt(vector_128_t a,vector_128_t b,int * p)87 do_sub_gt (vector_128_t a, vector_128_t b, int *p)
88 {
89   vector_128_t ret = __builtin_bcdsub (a, b, 0);
90   if (__builtin_bcdsub_gt (a, b, 0))
91     *p = 1;
92 
93   return ret;
94 }
95 
96 vector_128_t
do_sub_ov(vector_128_t a,vector_128_t b,int * p)97 do_sub_ov (vector_128_t a, vector_128_t b, int *p)
98 {
99   vector_128_t ret = __builtin_bcdsub (a, b, 0);
100   if (__builtin_bcdsub_ov (a, b, 0))
101     *p = 1;
102 
103   return ret;
104 }
105