File: vec-test-data-class-8.c

package info (click to toggle)
gcc-arm-none-eabi 15%3A8-2019-q3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 571,828 kB
  • sloc: ansic: 2,937,651; cpp: 881,644; ada: 597,189; makefile: 65,528; asm: 56,499; xml: 46,621; exp: 24,747; sh: 19,684; python: 7,256; pascal: 4,370; awk: 3,497; perl: 2,695; yacc: 316; ml: 285; f90: 234; lex: 198; objc: 194; haskell: 119
file content (112 lines) | stat: -rw-r--r-- 3,424 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* { dg-do run { target { powerpc*-*-* } } } */
/* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=power9" } } */
/* { dg-require-effective-target p9vector_hw } */
/* { dg-options "-mcpu=power9" } */

#include <altivec.h>
#include <stdlib.h>

/* Flags to select tests:
    0x40    Test for NaN
    0x20    Test for +Infinity
    0x10    Test for -Infinity
    0x08    Test for +Zero
    0x04    Test for -Zero
    0x02    Test for +Denormal
    0x01    Test for -Denormal  */

__vector bool int
test_nan (__vector float *p)
{
  __vector float source = *p;

  return vec_test_data_class (source, 0x40);
}

__vector bool int
test_infinity (__vector float *p)
{
  __vector float source = *p;

  return vec_test_data_class (source, 0x30);
}

__vector bool int
test_zero (__vector float *p)
{
  __vector float source = *p;

  return vec_test_data_class (source, 0x0c);
}

__vector bool int
test_denormal (__vector float *p)
{
  __vector float source = *p;

  return vec_test_data_class (source, 0x03);
}

float
float_scalar_insert_exp (unsigned int significand, unsigned int exponent)
{
  float result;
  unsigned int *result_as_uip = (unsigned int *) &result;

  *result_as_uip = (significand & ~0x800000) | ((exponent & 0xff) << 23);
  return result;
}

int
main ()
{
  __vector float argument;
  __vector bool result;

  unsigned int signaling_significand = 0x00a00000;
  unsigned int quiet_significand = 0x00c00000;
  unsigned int one_significand = 0x00800000;
  unsigned int three_significand = 0x00c00000;
  unsigned int five_significand = 0x00a00000;
  unsigned int zero_significand = 0x00000000;
  unsigned int minus_zero_significand = 0x80000000;

  /* A NaN is represented with the maximum biased exponent value and a
   *  non-zero fraction value. The sign bit ignored.  If the
   *  high-order bit of the fraction field is 0, then the NaN
   *  is a Signaling NaN.  Otherwise, it is a Quiet NaN.  */
  argument[0] = float_scalar_insert_exp (signaling_significand, 255);
  argument[1] = float_scalar_insert_exp (quiet_significand, 255);
  argument[2] = 1.0f;
  argument[3] = -0.07f;
  result = test_nan (&argument);
  if (!result[0] || !result[1] || result[2] || result[3])
    abort ();

  /* Infinity is represented by a biased exponent value of:
   *   255 in single format
   *   2047 in double format
   * and a zero fraction value.  The difference between +infinity and
   * -infinity is the value of the sign bit.  */
  argument[2] = float_scalar_insert_exp (zero_significand, 255);
  argument[3] = float_scalar_insert_exp (minus_zero_significand, 255);
  result = test_infinity (&argument);
  if (result[0] || result[1] || !result[2] || !result[3])
    abort ();

  /* A Zero value has a biased exponent value of zero and a zero
   *   fraction value.  The sign may be either positive or negative.  */
  argument[1] = float_scalar_insert_exp (minus_zero_significand, 0);
  argument[2] = float_scalar_insert_exp (zero_significand, 0);
  result = test_zero (&argument);
  if (result[0] || !result[1] || !result[2] || result[3])
    abort ();

  /* A Denormal number has a biased exponent value of zero and a
   *   non-zero fraction value.  */
  argument[0] = float_scalar_insert_exp (five_significand, 0);
  argument[3] = float_scalar_insert_exp (three_significand, 0);
  result = test_denormal (&argument);
  if (!result[0] || result[1] || result[2] || !result[3])
    abort ();
}