2 * X86 FPTEST/ITEST check functions
3 * These are defined here for performance enhancement, and also
4 * because the FPTEST/ITEST checks have to use the very arithmetic
5 * ops that the FPTEST/ITEST core is trying to verify.
7 * Copyright (C) 2002 Justin David Smith, Caltech
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include "x86_runtime.h"
30 int fpitest_msg(const char *msg
) {
32 printf("check %s\n", msg
);
38 int __ext_fc_fpitest_msg(Context
*c
, Pointer
*p
, unsigned i
) {
40 return(fpitest_msg((char *)p
+ i
));
45 int fpitest_data(const void **data
) {
52 int __ext_fc_fpitest_data(Context
*c
, Pointer
*data
, unsigned i
) {
54 return(fpitest_data((const void **)data
+ i
));
59 int fpitest_check_true(const char *msg
, int value
) {
62 printf("check %s: expected true, got false\n", msg
);
69 int __ext_fc_fpitest_check_true(Context
*c
, Pointer
*p
, unsigned i
, int value
) {
71 return(fpitest_check_true((char *)p
+ i
, value
));
76 int fpitest_check_false(const char *msg
, int value
) {
79 printf("check %s: expected false, got true\n", msg
);
86 int __ext_fc_fpitest_check_false(Context
*c
, Pointer
*p
, unsigned i
, int value
) {
88 return(fpitest_check_false((char *)p
+ i
, value
));
93 static int fptest_check_tolerance(const char *msg
, long double actual
, long double expected
, long double tolerance
) {
95 long double expected_tolerance
= expected
* tolerance
;
96 long double expected_lower
;
97 long double expected_upper
;
99 if(expected_tolerance
< 0) {
100 expected_tolerance
= -expected_tolerance
;
102 expected_lower
= expected
- expected_tolerance
;
103 expected_upper
= expected
+ expected_tolerance
;
105 if(actual
< expected_lower
|| actual
> expected_upper
) {
106 printf("check %s: expected %.20Lg, got %.20Lg (tolerance [%.20Lg,%.20Lg])\n", msg
,
107 expected
, actual
, expected_lower
, expected_upper
);
114 int fptest_check_tol_float(const char *msg
, float actual
, float expected
) {
116 return(fptest_check_tolerance(msg
, actual
, expected
, 1E-6));
121 int __ext_fc_fptest_check_tol_float(Context
*c
, Pointer
*p
, unsigned i
, float actual
, float expected
) {
123 return(fptest_check_tol_float((char *)p
+ i
, actual
, expected
));
128 int fptest_check_tol_double(const char *msg
, double actual
, double expected
) {
130 return(fptest_check_tolerance(msg
, actual
, expected
, 1E-12));
135 int __ext_fc_fptest_check_tol_double(Context
*c
, Pointer
*p
, unsigned i
, double actual
, double expected
) {
137 return(fptest_check_tol_double((char *)p
+ i
, actual
, expected
));
142 int fptest_check_tol_long_double(const char *msg
, long double actual
, long double expected
) {
144 return(fptest_check_tolerance(msg
, actual
, expected
, 1E-15));
149 int __ext_fc_fptest_check_tol_long_double(Context
*c
, Pointer
*p
, unsigned i
, long double actual
, long double expected
) {
151 return(fptest_check_tol_long_double((char *)p
+ i
, actual
, expected
));