OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [gcc.dg/] [torture/] [builtin-frexp-1.c] - Blame information for rev 754

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 689 jeremybenn
/* Copyright (C) 2007  Free Software Foundation.
2
 
3
   Verify that built-in folding of frexp is correctly performed by the
4
   compiler.
5
 
6
   Origin: Kaveh R. Ghazi,  February 21, 2007.  */
7
 
8
/* { dg-do link } */
9
/* { dg-options "-fno-finite-math-only" { target sh*-*-* } } */
10
/* In order to fold algebraic exprs below, targets with "composite"
11
   floating point formats need -funsafe-math-optimizations.  */
12
/* { dg-options "-funsafe-math-optimizations" { target mips*-*-irix6* powerpc*-*-* } } */
13
 
14
extern void link_error(int);
15
 
16
/* Return TRUE if the sign of X != sign of Y.  This is important when
17
   comparing signed zeros.  */
18
#define CKSGN_F(X,Y) \
19
  (__builtin_copysignf(1.0F,(X)) != __builtin_copysignf(1.0F,(Y)))
20
#define CKSGN(X,Y) \
21
  (__builtin_copysign(1.0,(X)) != __builtin_copysign(1.0,(Y)))
22
#define CKSGN_L(X,Y) \
23
  (__builtin_copysignl(1.0L,(X)) != __builtin_copysignl(1.0L,(Y)))
24
 
25
/* We can only check the exponent when optimizing since we rely on
26
   other optimizations to propagate the value.  TRUE means an error
27
   occurred.  */
28
#ifdef __OPTIMIZE__
29
#define CKEXP(X,Y) X != Y
30
#else
31
#define CKEXP(X,Y) 0
32
#endif
33
 
34
/* Test that frexp(ARG,&i) == RES && i == EXP.  Check the sign in
35
   case we get -0.0.  */
36
#define TESTIT_FREXP(ARG,RES,EXP) do { \
37
  int i = 12345; \
38
  if (__builtin_frexpf(ARG##f,&i) != RES##f \
39
      || CKEXP(i,EXP) \
40
      || CKSGN_F(__builtin_frexpf(ARG##f,&i),RES##f)) \
41
    link_error(__LINE__); \
42
  i = 12345; \
43
  if (__builtin_frexp(ARG,&i) != RES \
44
      || CKEXP(i,EXP) \
45
      || CKSGN(__builtin_frexp(ARG,&i),RES)) \
46
    link_error(__LINE__); \
47
  i = 12345; \
48
  if (__builtin_frexpl(ARG##l,&i) != RES##l \
49
      || CKEXP(i,EXP) \
50
      || CKSGN_L(__builtin_frexpl(ARG##l,&i),RES##l)) \
51
    link_error(__LINE__); \
52
  } while (0)
53
 
54
/* Test that FUNCRES(frexp(NEG FUNCARG(ARGARG),&i)) is false.  Check
55
   the sign as well.  Ensure side-effects are evaluated in i.  */
56
#ifndef __SPU__
57
#define TESTIT_FREXP2(NEG,FUNCARG,ARGARG,FUNCRES) do { \
58
  int i=5; \
59
  if (!__builtin_##FUNCRES##f(__builtin_frexpf(NEG __builtin_##FUNCARG##f(ARGARG),&i)) \
60
      || CKSGN_F(__builtin_frexpf(NEG __builtin_##FUNCARG##f(ARGARG),(i++,&i)), NEG __builtin_##FUNCARG##f(ARGARG)) \
61
      || CKEXP(i,6)) \
62
    link_error(__LINE__); \
63
  if (!__builtin_##FUNCRES(__builtin_frexp(NEG __builtin_##FUNCARG(ARGARG),&i)) \
64
      || CKSGN(__builtin_frexp(NEG __builtin_##FUNCARG(ARGARG),(i++,&i)), NEG __builtin_##FUNCARG(ARGARG)) \
65
      || CKEXP(i,7)) \
66
    link_error(__LINE__); \
67
  if (!__builtin_##FUNCRES##l(__builtin_frexpl(NEG __builtin_##FUNCARG##l(ARGARG),&i)) \
68
      || CKSGN_L(__builtin_frexpl(NEG __builtin_##FUNCARG##l(ARGARG),(i++,&i)), NEG __builtin_##FUNCARG##l(ARGARG)) \
69
      || CKEXP(i,8)) \
70
    link_error(__LINE__); \
71
  } while (0)
72
#else
73
#define TESTIT_FREXP2(NEG,FUNCARG,ARGARG,FUNCRES) do { \
74
  int i=6; \
75
  /* SPU single-precision floating point format does not support Inf or Nan.  */ \
76
  if (!__builtin_##FUNCRES(__builtin_frexp(NEG __builtin_##FUNCARG(ARGARG),&i)) \
77
      || CKSGN(__builtin_frexp(NEG __builtin_##FUNCARG(ARGARG),(i++,&i)), NEG __builtin_##FUNCARG(ARGARG)) \
78
      || CKEXP(i,7)) \
79
    link_error(__LINE__); \
80
  if (!__builtin_##FUNCRES##l(__builtin_frexpl(NEG __builtin_##FUNCARG##l(ARGARG),&i)) \
81
      || CKSGN_L(__builtin_frexpl(NEG __builtin_##FUNCARG##l(ARGARG),(i++,&i)), NEG __builtin_##FUNCARG##l(ARGARG)) \
82
      || CKEXP(i,8)) \
83
    link_error(__LINE__); \
84
  } while (0)
85
#endif
86
 
87
void __attribute__ ((__noinline__))
88
foo(void)
89
{
90
  /* Test that frexp(ARG1,&i) -> ARG2 && i == ARG3.  */
91
  TESTIT_FREXP (-0x1p40, -0.5, 41);
92
  TESTIT_FREXP (-0x1p30, -0.5, 31);
93
  TESTIT_FREXP (-0x1p20, -0.5, 21);
94
  TESTIT_FREXP (-0x1p10, -0.5, 11);
95
  TESTIT_FREXP (-0x1p5, -0.5, 6);
96
  TESTIT_FREXP (-100/3.0, -100/192.0, 6);
97
  TESTIT_FREXP (-1.5, -0.75, 1);
98
  TESTIT_FREXP (-1.0, -0.5, 1);
99
  TESTIT_FREXP (-1/3.0, -2/3.0, -1);
100
  TESTIT_FREXP (-1/9.0, -8/9.0, -3);
101
  TESTIT_FREXP (-0x1p-5, -0.5, -4);
102
  TESTIT_FREXP (-0x1p-10, -0.5, -9);
103
  TESTIT_FREXP (-0x1p-20, -0.5, -19);
104
  TESTIT_FREXP (-0x1p-30, -0.5, -29);
105
  TESTIT_FREXP (-0x1p-40, -0.5, -39);
106
  TESTIT_FREXP (-0.0, -0.0, 0);
107
  TESTIT_FREXP (0.0, 0.0, 0);
108
  TESTIT_FREXP (0x1p-40, 0.5, -39);
109
  TESTIT_FREXP (0x1p-30, 0.5, -29);
110
  TESTIT_FREXP (0x1p-20, 0.5, -19);
111
  TESTIT_FREXP (0x1p-10, 0.5, -9);
112
  TESTIT_FREXP (0x1p-5, 0.5, -4);
113
  TESTIT_FREXP (1/9.0, 8/9.0, -3);
114
  TESTIT_FREXP (1/3.0, 2/3.0, -1);
115
  TESTIT_FREXP (1.0, 0.5, 1);
116
  TESTIT_FREXP (1.5, 0.75, 1);
117
  TESTIT_FREXP (100/3.0, 100/192.0, 6);
118
  TESTIT_FREXP (0x1p5, 0.5, 6);
119
  TESTIT_FREXP (0x1p10, 0.5, 11);
120
  TESTIT_FREXP (0x1p20, 0.5, 21);
121
  TESTIT_FREXP (0x1p30, 0.5, 31);
122
  TESTIT_FREXP (0x1p40, 0.5, 41);
123
 
124
  /* Test for frexp(+-Inf,&i) -> +-Inf and frexp(+-NaN,&i) -> +-NaN.
125
     Exponent is left unspecified, but we test for side-effects.  */
126
  TESTIT_FREXP2 ( ,inf, , isinf);
127
  TESTIT_FREXP2 (- ,inf, , isinf);
128
  TESTIT_FREXP2 ( ,nan, "", isnan);
129
  TESTIT_FREXP2 (- ,nan, "", isnan);
130
}
131
 
132
int main()
133
{
134
  foo ();
135
 
136
  return 0;
137
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.