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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [gcc.target/] [i386/] [sse4_1-roundsd-4.c] - Blame information for rev 318

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 318 jeremybenn
/* { dg-do run } */
2
/* { dg-require-effective-target sse4 } */
3
/* { dg-options "-O2 -msse4.1" } */
4
/* { dg-skip-if "no M_PI" { vxworks_kernel } } */
5
 
6
#include "sse4_1-check.h"
7
 
8
#include <smmintrin.h>
9
#include <math.h>
10
#include <string.h>
11
 
12
#define NUM 64
13
 
14
static void
15
init_round (double *src)
16
{
17
  int i, sign = 1;
18
  double d = rand ();
19
 
20
  for (i = 0; i < NUM; i++)
21
    {
22
      src[i] = (i + 1)* d * M_PI * sign;
23
      if (i < (NUM / 2))
24
        {
25
          if ((i % 6) == 0)
26
            d = d * src[i];
27
        }
28
      else if (i == (NUM / 2))
29
        d = rand ();
30
      else if ((i % 6) == 0)
31
        d = 1 / (d * (i + 1) * src[i] * M_PI *sign);
32
      sign = -sign;
33
    }
34
}
35
 
36
static double
37
do_round (double f, int type)
38
{
39
  short saved_cw, new_cw, clr_mask;
40
  double ret;
41
 
42
  if ((type & 4))
43
    {
44
      type = 0;
45
      clr_mask = 0xFFFF;
46
    }
47
  else
48
    {
49
      type = 0x003F | ((type & 3) << 10);
50
      clr_mask = ~0x0C3F;
51
    }
52
 
53
  __asm__ ("fldl %0" : : "m" (*&f));
54
 
55
  __asm__ ("fstcw %0" : "=m" (*&saved_cw));
56
  new_cw = saved_cw & clr_mask;
57
  new_cw |= type;
58
  __asm__ ("fldcw %0" : : "m" (*&new_cw));
59
 
60
  __asm__ ("frndint\n"
61
           "fstpl %0\n" : "=m" (*&ret));
62
  __asm__ ("fldcw %0" : : "m" (*&saved_cw));
63
  return ret;
64
}
65
 
66
static void
67
sse4_1_test (void)
68
{
69
  int i;
70
  double f;
71
  union
72
    {
73
      __m128d x[NUM / 2];
74
      double d[NUM];
75
    } dst, src;
76
 
77
  init_round (src.d);
78
  memset (&dst, 0, NUM * sizeof(double));
79
 
80
  for (i = 0; i < NUM / 2 ; i++)
81
    dst.x[i] =  _mm_round_sd (dst.x[i], src.x[i], _MM_FROUND_TRUNC);
82
 
83
  for (i = 0; i < NUM; i += 2)
84
    {
85
      if (dst.d[i + 1] != 0.0)
86
        abort ();
87
 
88
      f = do_round (src.d[i], 0x03);
89
      if (f != dst.d[i])
90
        abort ();
91
    }
92
}

powered by: WebSVN 2.1.0

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