PandA-2024.02
dfsin.c
Go to the documentation of this file.
1 /*
2 +--------------------------------------------------------------------------+
3 | CHStone : a suite of benchmark programs for C-based High-Level Synthesis |
4 | ======================================================================== |
5 | |
6 | * Collected and Modified : Y. Hara, H. Tomiyama, S. Honda, |
7 | H. Takada and K. Ishii |
8 | Nagoya University, Japan |
9 | |
10 | * Remark : |
11 | 1. This source code is modified to unify the formats of the benchmark |
12 | programs in CHStone. |
13 | 2. Test vectors are added for CHStone. |
14 | 3. If "main_result" is 0 at the end of the program, the program is |
15 | correctly executed. |
16 | 4. Please follow the copyright of each benchmark program. |
17 +--------------------------------------------------------------------------+
18 */
19 /*
20  * Copyright (C) 2008
21  * Y. Hara, H. Tomiyama, S. Honda, H. Takada and K. Ishii
22  * Nagoya University, Japan
23  * All rights reserved.
24  *
25  * Disclaimer of Warranty
26  *
27  * These software programs are available to the user without any license fee or
28  * royalty on an "as is" basis. The authors disclaims any and all warranties,
29  * whether express, implied, or statuary, including any implied warranties or
30  * merchantability or of fitness for a particular purpose. In no event shall the
31  * copyright-holder be liable for any incidental, punitive, or consequential damages
32  * of any kind whatsoever arising from the use of these programs. This disclaimer
33  * of warranty extends to the user of these programs and user's customers, employees,
34  * agents, transferees, successors, and assigns.
35  *
36  */
37 #include <stdio.h>
38 #include "softfloat.c"
39 
40 float64
42 {
43  return (x & 0x7fffffffffffffffULL);
44 }
45 
46 float64
48 {
49  float64 app;
50  float64 diff;
51  float64 m_rad2;
52  int inc;
53 
54  app = diff = rad;
55  inc = 1;
56  m_rad2 = float64_neg (float64_mul (rad, rad));
57  do
58  {
59  diff = float64_div (float64_mul (diff, m_rad2),
60  int32_to_float64 ((2 * inc) * (2 * inc + 1)));
61  app = float64_add (app, diff);
62  inc++;
63  }
64  while (float64_ge (float64_abs (diff), 0x3ee4f8b588e368f1ULL)); /* 0.00001 */
65  return app;
66 }
67 
68 double
69 ullong_to_double (unsigned long long x)
70 {
71  union
72  {
73  double d;
74  unsigned long long ll;
75  } t;
76 
77  t.ll = x;
78  return t.d;
79 }
80 
81 /*
82 +--------------------------------------------------------------------------+
83 | * Test Vectors (added for CHStone) |
84 | test_in : input data |
85 | test_out : expected output data |
86 +--------------------------------------------------------------------------+
87 */
88 #define N 36
89 const float64 test_in[N] = {
90  0x0000000000000000ULL, /* 0 */
91  0x3fc65717fced55c1ULL, /* PI/18 */
92  0x3fd65717fced55c1ULL, /* PI/9 */
93  0x3fe0c151fdb20051ULL, /* PI/6 */
94  0x3fe65717fced55c1ULL, /* 2PI/9 */
95  0x3febecddfc28ab31ULL, /* 5PI/18 */
96  0x3ff0c151fdb20051ULL, /* PI/3 */
97  0x3ff38c34fd4fab09ULL, /* 7PI/18 */
98  0x3ff65717fced55c1ULL, /* 4PI/9 */
99  0x3ff921fafc8b0079ULL, /* PI/2 */
100  0x3ffbecddfc28ab31ULL, /* 5PI/9 */
101  0x3ffeb7c0fbc655e9ULL, /* 11PI/18 */
102  0x4000c151fdb20051ULL, /* 2PI/3 */
103  0x400226c37d80d5adULL, /* 13PI/18 */
104  0x40038c34fd4fab09ULL, /* 7PI/9 */
105  0x4004f1a67d1e8065ULL, /* 5PI/6 */
106  0x40065717fced55c1ULL, /* 8PI/9 */
107  0x4007bc897cbc2b1dULL, /* 17PI/18 */
108  0x400921fafc8b0079ULL, /* PI */
109  0x400a876c7c59d5d5ULL, /* 19PI/18 */
110  0x400becddfc28ab31ULL, /* 10PI/9 */
111  0x400d524f7bf7808dULL, /* 7PI/6 */
112  0x400eb7c0fbc655e9ULL, /* 11PI/9 */
113  0x40100e993dca95a3ULL, /* 23PI/18 */
114  0x4010c151fdb20051ULL, /* 8PI/6 */
115  0x4011740abd996affULL, /* 25PI/18 */
116  0x401226c37d80d5adULL, /* 13PI/9 */
117  0x4012d97c3d68405bULL, /* 3PI/2 */
118  0x40138c34fd4fab09ULL, /* 14PI/9 */
119  0x40143eedbd3715b7ULL, /* 29PI/18 */
120  0x4014f1a67d1e8065ULL, /* 15PI/9 */
121  0x4015a45f3d05eb13ULL, /* 31PI/18 */
122  0x40165717fced55c1ULL, /* 16PI/9 */
123  0x401709d0bcd4c06fULL, /* 33PI/18 */
124  0x4017bc897cbc2b1dULL, /* 17PI/9 */
125  0x40186f423ca395cbULL
126 }; /* 35PI/18 */
127 
128 const float64 test_out[N] = {
129  0x0000000000000000ULL, /* 0.000000 */
130  0x3fc63a1a335aadcdULL, /* 0.173648 */
131  0x3fd5e3a82b09bf3eULL, /* 0.342020 */
132  0x3fdfffff91f9aa91ULL, /* 0.500000 */
133  0x3fe491b716c242e3ULL, /* 0.642787 */
134  0x3fe8836f672614a6ULL, /* 0.766044 */
135  0x3febb67ac40b2bedULL, /* 0.866025 */
136  0x3fee11f6127e28adULL, /* 0.939693 */
137  0x3fef838b6adffac0ULL, /* 0.984808 */
138  0x3fefffffe1cbd7aaULL, /* 1.000000 */
139  0x3fef838bb0147989ULL, /* 0.984808 */
140  0x3fee11f692d962b4ULL, /* 0.939693 */
141  0x3febb67b77c0142dULL, /* 0.866026 */
142  0x3fe883709d4ea869ULL, /* 0.766045 */
143  0x3fe491b81d72d8e8ULL, /* 0.642788 */
144  0x3fe00000ea5f43c8ULL, /* 0.500000 */
145  0x3fd5e3aa4e0590c5ULL, /* 0.342021 */
146  0x3fc63a1d2189552cULL, /* 0.173648 */
147  0x3ea6aedffc454b91ULL, /* 0.000001 */
148  0xbfc63a1444ddb37cULL, /* -0.173647 */
149  0xbfd5e3a4e68f8f3eULL, /* -0.342019 */
150  0xbfdffffd494cf96bULL, /* -0.499999 */
151  0xbfe491b61cb9a3d3ULL, /* -0.642787 */
152  0xbfe8836eb2dcf815ULL, /* -0.766044 */
153  0xbfebb67a740aae32ULL, /* -0.866025 */
154  0xbfee11f5912d2157ULL, /* -0.939692 */
155  0xbfef838b1ac64afcULL, /* -0.984808 */
156  0xbfefffffc2e5dc8fULL, /* -1.000000 */
157  0xbfef838b5ea2e7eaULL, /* -0.984808 */
158  0xbfee11f7112dae27ULL, /* -0.939693 */
159  0xbfebb67c2c31cb4aULL, /* -0.866026 */
160  0xbfe883716e6fd781ULL, /* -0.766045 */
161  0xbfe491b9cd1b5d56ULL, /* -0.642789 */
162  0xbfe000021d0ca30dULL, /* -0.500001 */
163  0xbfd5e3ad0a69caf7ULL, /* -0.342021 */
164  0xbfc63a23c48863ddULL
165 }; /* -0.173649 */
166 
167 int
169 {
170  int main_result;
171  int i;
172  main_result = 0;
173  for (i = 0; i < N; i++)
174  {
175  float64 result;
176  result = local_sin (test_in[i]);
177  main_result += (result != test_out[i]);
178 
179  printf
180  ("input=%016llx expected=%016llx output=%016llx (%lf)\n",
181  test_in[i], test_out[i], result, ullong_to_double (result));
182  }
183  printf ("%d\n", main_result);
184  return main_result;
185  }
float64 float64_div(float64 a, float64 b)
Definition: softfloat.c:241
const float64 test_in[N]
Definition: dfsin.c:89
flag float64_ge(float64 a, float64 b)
Definition: softfloat.c:640
float64 int32_to_float64(int32 a)
Definition: softfloat.c:260
int main_result
Definition: mips.c:38
int main()
Definition: dfsin.c:168
#define N
Definition: dfsin.c:88
float64 float64_mul(float64 a, float64 b)
Definition: softfloat.c:241
float64 float64_add(float64 a, float64 b)
Definition: softfloat.c:406
int result[SIZE]
Definition: adpcm.c:800
float64 local_sin(float64 rad)
Definition: dfsin.c:47
const float64 test_out[N]
Definition: dfsin.c:128
double ullong_to_double(unsigned long long x)
Definition: dfsin.c:69
unsigned long long float64
Definition: softfloat.h:54
float64 float64_abs(float64 x)
Definition: dfsin.c:41
float64 float64_neg(float64 x)
Definition: softfloat.c:647
x
Return the smallest n such that 2^n >= _x.

Generated on Mon Feb 12 2024 13:02:49 for PandA-2024.02 by doxygen 1.8.13