aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c
blob: 490d996bcc41a3724b3bfb4b2f20af85456a3af1 (plain)
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
/* { dg-do compile } */
/* { dg-options "-O2 -mdejagnu-cpu=power9 -mvsx" } */
/* { dg-require-effective-target powerpc_vsx } */
/* { dg-final { scan-assembler-times {\mxvmaxdp\M} 1 } } */
/* { dg-final { scan-assembler-times {\mxvmaxsp\M} 1 } } */
/* { dg-final { scan-assembler-times {\mxvmindp\M} 1 } } */
/* { dg-final { scan-assembler-times {\mxvminsp\M} 1 } } */

/* This test verifies that float or double vec_min/max are bound to
   xv[min|max][d|s]p instructions when fast-math is not set.  */


#include <altivec.h>

#ifdef _BIG_ENDIAN
   const int PREF_D = 0;
#else
   const int PREF_D = 1;
#endif

double vmaxd (double a, double b)
{
  vector double va = vec_promote (a, PREF_D);
  vector double vb = vec_promote (b, PREF_D);
  return vec_extract (vec_max (va, vb), PREF_D);
}

double vmind (double a, double b)
{
  vector double va = vec_promote (a, PREF_D);
  vector double vb = vec_promote (b, PREF_D);
  return vec_extract (vec_min (va, vb), PREF_D);
}

#ifdef _BIG_ENDIAN
   const int PREF_F = 0;
#else
   const int PREF_F = 3;
#endif

float vmaxf (float a, float b)
{
  vector float va = vec_promote (a, PREF_F);
  vector float vb = vec_promote (b, PREF_F);
  return vec_extract (vec_max (va, vb), PREF_F);
}

float vminf (float a, float b)
{
  vector float va = vec_promote (a, PREF_F);
  vector float vb = vec_promote (b, PREF_F);
  return vec_extract (vec_min (va, vb), PREF_F);
}