]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gcc.dg/signbit-4.c
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / signbit-4.c
CommitLineData
d70720c2
TC
1/* { dg-do run } */
2/* { dg-options "-O1 -fwrapv" } */
3
4#include <stdint.h>
5#include <limits.h>
6#include <stdio.h>
7
8#ifndef N
9#define N 65
10#endif
11
12#ifndef TYPE
13#define TYPE int32_t
14#endif
15
16#ifndef DEBUG
17#define DEBUG 1
18#endif
19
20#define BASE ((TYPE) -1 < 0 ? -126 : 4)
21
22__attribute__ ((noinline, noipa))
23void fun1(TYPE *x, int n)
24{
25 for (int i = 0; i < n; i++)
26 x[i] = (-x[i]) >> 31;
27}
28
29__attribute__ ((noinline, noipa, optimize("O0")))
30void fun2(TYPE *x, int n)
31{
32 for (int i = 0; i < n; i++)
33 x[i] = (-x[i]) >> 31;
34}
35
36int main ()
37{
38 TYPE a[N];
39 TYPE b[N];
40
41 a[0] = INT_MIN;
42 b[0] = INT_MIN;
43
44 for (int i = 1; i < N; ++i)
45 {
46 a[i] = BASE + i * 13;
47 b[i] = BASE + i * 13;
48 if (DEBUG)
49 printf ("%d: 0x%x\n", i, a[i]);
50 }
51
52 fun1 (a, N);
53 fun2 (b, N);
54
55 for (int i = 0; i < N; ++i)
56 {
57 if (DEBUG)
58 printf ("%d = 0x%x == 0x%x\n", i, a[i], b[i]);
59
60 if (a[i] != b[i])
61 __builtin_abort ();
62 }
63 return 0;
64}
65