1bbbf1280Sopenharmony_ci/* 2bbbf1280Sopenharmony_ci * dotest.c - actually generate mathlib test cases 3bbbf1280Sopenharmony_ci * 4bbbf1280Sopenharmony_ci * Copyright (c) 1999-2019, Arm Limited. 5bbbf1280Sopenharmony_ci * SPDX-License-Identifier: MIT 6bbbf1280Sopenharmony_ci */ 7bbbf1280Sopenharmony_ci 8bbbf1280Sopenharmony_ci#include <stdio.h> 9bbbf1280Sopenharmony_ci#include <string.h> 10bbbf1280Sopenharmony_ci#include <stdlib.h> 11bbbf1280Sopenharmony_ci#include <stdint.h> 12bbbf1280Sopenharmony_ci#include <assert.h> 13bbbf1280Sopenharmony_ci#include <limits.h> 14bbbf1280Sopenharmony_ci 15bbbf1280Sopenharmony_ci#include "semi.h" 16bbbf1280Sopenharmony_ci#include "intern.h" 17bbbf1280Sopenharmony_ci#include "random.h" 18bbbf1280Sopenharmony_ci 19bbbf1280Sopenharmony_ci#define MPFR_PREC 96 /* good enough for float or double + a few extra bits */ 20bbbf1280Sopenharmony_ci 21bbbf1280Sopenharmony_ciextern int lib_fo, lib_no_arith, ntests; 22bbbf1280Sopenharmony_ci 23bbbf1280Sopenharmony_ci/* 24bbbf1280Sopenharmony_ci * Prototypes. 25bbbf1280Sopenharmony_ci */ 26bbbf1280Sopenharmony_cistatic void cases_biased(uint32 *, uint32, uint32); 27bbbf1280Sopenharmony_cistatic void cases_biased_positive(uint32 *, uint32, uint32); 28bbbf1280Sopenharmony_cistatic void cases_biased_float(uint32 *, uint32, uint32); 29bbbf1280Sopenharmony_cistatic void cases_uniform(uint32 *, uint32, uint32); 30bbbf1280Sopenharmony_cistatic void cases_uniform_positive(uint32 *, uint32, uint32); 31bbbf1280Sopenharmony_cistatic void cases_uniform_float(uint32 *, uint32, uint32); 32bbbf1280Sopenharmony_cistatic void cases_uniform_float_positive(uint32 *, uint32, uint32); 33bbbf1280Sopenharmony_cistatic void log_cases(uint32 *, uint32, uint32); 34bbbf1280Sopenharmony_cistatic void log_cases_float(uint32 *, uint32, uint32); 35bbbf1280Sopenharmony_cistatic void log1p_cases(uint32 *, uint32, uint32); 36bbbf1280Sopenharmony_cistatic void log1p_cases_float(uint32 *, uint32, uint32); 37bbbf1280Sopenharmony_cistatic void minmax_cases(uint32 *, uint32, uint32); 38bbbf1280Sopenharmony_cistatic void minmax_cases_float(uint32 *, uint32, uint32); 39bbbf1280Sopenharmony_cistatic void atan2_cases(uint32 *, uint32, uint32); 40bbbf1280Sopenharmony_cistatic void atan2_cases_float(uint32 *, uint32, uint32); 41bbbf1280Sopenharmony_cistatic void pow_cases(uint32 *, uint32, uint32); 42bbbf1280Sopenharmony_cistatic void pow_cases_float(uint32 *, uint32, uint32); 43bbbf1280Sopenharmony_cistatic void rred_cases(uint32 *, uint32, uint32); 44bbbf1280Sopenharmony_cistatic void rred_cases_float(uint32 *, uint32, uint32); 45bbbf1280Sopenharmony_cistatic void cases_semi1(uint32 *, uint32, uint32); 46bbbf1280Sopenharmony_cistatic void cases_semi1_float(uint32 *, uint32, uint32); 47bbbf1280Sopenharmony_cistatic void cases_semi2(uint32 *, uint32, uint32); 48bbbf1280Sopenharmony_cistatic void cases_semi2_float(uint32 *, uint32, uint32); 49bbbf1280Sopenharmony_cistatic void cases_ldexp(uint32 *, uint32, uint32); 50bbbf1280Sopenharmony_cistatic void cases_ldexp_float(uint32 *, uint32, uint32); 51bbbf1280Sopenharmony_ci 52bbbf1280Sopenharmony_cistatic void complex_cases_uniform(uint32 *, uint32, uint32); 53bbbf1280Sopenharmony_cistatic void complex_cases_uniform_float(uint32 *, uint32, uint32); 54bbbf1280Sopenharmony_cistatic void complex_cases_biased(uint32 *, uint32, uint32); 55bbbf1280Sopenharmony_cistatic void complex_cases_biased_float(uint32 *, uint32, uint32); 56bbbf1280Sopenharmony_cistatic void complex_log_cases(uint32 *, uint32, uint32); 57bbbf1280Sopenharmony_cistatic void complex_log_cases_float(uint32 *, uint32, uint32); 58bbbf1280Sopenharmony_cistatic void complex_pow_cases(uint32 *, uint32, uint32); 59bbbf1280Sopenharmony_cistatic void complex_pow_cases_float(uint32 *, uint32, uint32); 60bbbf1280Sopenharmony_cistatic void complex_arithmetic_cases(uint32 *, uint32, uint32); 61bbbf1280Sopenharmony_cistatic void complex_arithmetic_cases_float(uint32 *, uint32, uint32); 62bbbf1280Sopenharmony_ci 63bbbf1280Sopenharmony_cistatic uint32 doubletop(int x, int scale); 64bbbf1280Sopenharmony_cistatic uint32 floatval(int x, int scale); 65bbbf1280Sopenharmony_ci 66bbbf1280Sopenharmony_ci/* 67bbbf1280Sopenharmony_ci * Convert back and forth between IEEE bit patterns and the 68bbbf1280Sopenharmony_ci * mpfr_t/mpc_t types. 69bbbf1280Sopenharmony_ci */ 70bbbf1280Sopenharmony_cistatic void set_mpfr_d(mpfr_t x, uint32 h, uint32 l) 71bbbf1280Sopenharmony_ci{ 72bbbf1280Sopenharmony_ci uint64_t hl = ((uint64_t)h << 32) | l; 73bbbf1280Sopenharmony_ci uint32 exp = (hl >> 52) & 0x7ff; 74bbbf1280Sopenharmony_ci int64_t mantissa = hl & (((uint64_t)1 << 52) - 1); 75bbbf1280Sopenharmony_ci int sign = (hl >> 63) ? -1 : +1; 76bbbf1280Sopenharmony_ci if (exp == 0x7ff) { 77bbbf1280Sopenharmony_ci if (mantissa == 0) 78bbbf1280Sopenharmony_ci mpfr_set_inf(x, sign); 79bbbf1280Sopenharmony_ci else 80bbbf1280Sopenharmony_ci mpfr_set_nan(x); 81bbbf1280Sopenharmony_ci } else if (exp == 0 && mantissa == 0) { 82bbbf1280Sopenharmony_ci mpfr_set_ui(x, 0, GMP_RNDN); 83bbbf1280Sopenharmony_ci mpfr_setsign(x, x, sign < 0, GMP_RNDN); 84bbbf1280Sopenharmony_ci } else { 85bbbf1280Sopenharmony_ci if (exp != 0) 86bbbf1280Sopenharmony_ci mantissa |= ((uint64_t)1 << 52); 87bbbf1280Sopenharmony_ci else 88bbbf1280Sopenharmony_ci exp++; 89bbbf1280Sopenharmony_ci mpfr_set_sj_2exp(x, mantissa * sign, (int)exp - 0x3ff - 52, GMP_RNDN); 90bbbf1280Sopenharmony_ci } 91bbbf1280Sopenharmony_ci} 92bbbf1280Sopenharmony_cistatic void set_mpfr_f(mpfr_t x, uint32 f) 93bbbf1280Sopenharmony_ci{ 94bbbf1280Sopenharmony_ci uint32 exp = (f >> 23) & 0xff; 95bbbf1280Sopenharmony_ci int32 mantissa = f & ((1 << 23) - 1); 96bbbf1280Sopenharmony_ci int sign = (f >> 31) ? -1 : +1; 97bbbf1280Sopenharmony_ci if (exp == 0xff) { 98bbbf1280Sopenharmony_ci if (mantissa == 0) 99bbbf1280Sopenharmony_ci mpfr_set_inf(x, sign); 100bbbf1280Sopenharmony_ci else 101bbbf1280Sopenharmony_ci mpfr_set_nan(x); 102bbbf1280Sopenharmony_ci } else if (exp == 0 && mantissa == 0) { 103bbbf1280Sopenharmony_ci mpfr_set_ui(x, 0, GMP_RNDN); 104bbbf1280Sopenharmony_ci mpfr_setsign(x, x, sign < 0, GMP_RNDN); 105bbbf1280Sopenharmony_ci } else { 106bbbf1280Sopenharmony_ci if (exp != 0) 107bbbf1280Sopenharmony_ci mantissa |= (1 << 23); 108bbbf1280Sopenharmony_ci else 109bbbf1280Sopenharmony_ci exp++; 110bbbf1280Sopenharmony_ci mpfr_set_sj_2exp(x, mantissa * sign, (int)exp - 0x7f - 23, GMP_RNDN); 111bbbf1280Sopenharmony_ci } 112bbbf1280Sopenharmony_ci} 113bbbf1280Sopenharmony_cistatic void set_mpc_d(mpc_t z, uint32 rh, uint32 rl, uint32 ih, uint32 il) 114bbbf1280Sopenharmony_ci{ 115bbbf1280Sopenharmony_ci mpfr_t x, y; 116bbbf1280Sopenharmony_ci mpfr_init2(x, MPFR_PREC); 117bbbf1280Sopenharmony_ci mpfr_init2(y, MPFR_PREC); 118bbbf1280Sopenharmony_ci set_mpfr_d(x, rh, rl); 119bbbf1280Sopenharmony_ci set_mpfr_d(y, ih, il); 120bbbf1280Sopenharmony_ci mpc_set_fr_fr(z, x, y, MPC_RNDNN); 121bbbf1280Sopenharmony_ci mpfr_clear(x); 122bbbf1280Sopenharmony_ci mpfr_clear(y); 123bbbf1280Sopenharmony_ci} 124bbbf1280Sopenharmony_cistatic void set_mpc_f(mpc_t z, uint32 r, uint32 i) 125bbbf1280Sopenharmony_ci{ 126bbbf1280Sopenharmony_ci mpfr_t x, y; 127bbbf1280Sopenharmony_ci mpfr_init2(x, MPFR_PREC); 128bbbf1280Sopenharmony_ci mpfr_init2(y, MPFR_PREC); 129bbbf1280Sopenharmony_ci set_mpfr_f(x, r); 130bbbf1280Sopenharmony_ci set_mpfr_f(y, i); 131bbbf1280Sopenharmony_ci mpc_set_fr_fr(z, x, y, MPC_RNDNN); 132bbbf1280Sopenharmony_ci mpfr_clear(x); 133bbbf1280Sopenharmony_ci mpfr_clear(y); 134bbbf1280Sopenharmony_ci} 135bbbf1280Sopenharmony_cistatic void get_mpfr_d(const mpfr_t x, uint32 *h, uint32 *l, uint32 *extra) 136bbbf1280Sopenharmony_ci{ 137bbbf1280Sopenharmony_ci uint32_t sign, expfield, mantfield; 138bbbf1280Sopenharmony_ci mpfr_t significand; 139bbbf1280Sopenharmony_ci int exp; 140bbbf1280Sopenharmony_ci 141bbbf1280Sopenharmony_ci if (mpfr_nan_p(x)) { 142bbbf1280Sopenharmony_ci *h = 0x7ff80000; 143bbbf1280Sopenharmony_ci *l = 0; 144bbbf1280Sopenharmony_ci *extra = 0; 145bbbf1280Sopenharmony_ci return; 146bbbf1280Sopenharmony_ci } 147bbbf1280Sopenharmony_ci 148bbbf1280Sopenharmony_ci sign = mpfr_signbit(x) ? 0x80000000U : 0; 149bbbf1280Sopenharmony_ci 150bbbf1280Sopenharmony_ci if (mpfr_inf_p(x)) { 151bbbf1280Sopenharmony_ci *h = 0x7ff00000 | sign; 152bbbf1280Sopenharmony_ci *l = 0; 153bbbf1280Sopenharmony_ci *extra = 0; 154bbbf1280Sopenharmony_ci return; 155bbbf1280Sopenharmony_ci } 156bbbf1280Sopenharmony_ci 157bbbf1280Sopenharmony_ci if (mpfr_zero_p(x)) { 158bbbf1280Sopenharmony_ci *h = 0x00000000 | sign; 159bbbf1280Sopenharmony_ci *l = 0; 160bbbf1280Sopenharmony_ci *extra = 0; 161bbbf1280Sopenharmony_ci return; 162bbbf1280Sopenharmony_ci } 163bbbf1280Sopenharmony_ci 164bbbf1280Sopenharmony_ci mpfr_init2(significand, MPFR_PREC); 165bbbf1280Sopenharmony_ci mpfr_set(significand, x, GMP_RNDN); 166bbbf1280Sopenharmony_ci exp = mpfr_get_exp(significand); 167bbbf1280Sopenharmony_ci mpfr_set_exp(significand, 0); 168bbbf1280Sopenharmony_ci 169bbbf1280Sopenharmony_ci /* Now significand is in [1/2,1), and significand * 2^exp == x. 170bbbf1280Sopenharmony_ci * So the IEEE exponent corresponding to exp==0 is 0x3fe. */ 171bbbf1280Sopenharmony_ci if (exp > 0x400) { 172bbbf1280Sopenharmony_ci /* overflow to infinity anyway */ 173bbbf1280Sopenharmony_ci *h = 0x7ff00000 | sign; 174bbbf1280Sopenharmony_ci *l = 0; 175bbbf1280Sopenharmony_ci *extra = 0; 176bbbf1280Sopenharmony_ci mpfr_clear(significand); 177bbbf1280Sopenharmony_ci return; 178bbbf1280Sopenharmony_ci } 179bbbf1280Sopenharmony_ci 180bbbf1280Sopenharmony_ci if (exp <= -0x3fe || mpfr_zero_p(x)) 181bbbf1280Sopenharmony_ci exp = -0x3fd; /* denormalise */ 182bbbf1280Sopenharmony_ci expfield = exp + 0x3fd; /* offset to cancel leading mantissa bit */ 183bbbf1280Sopenharmony_ci 184bbbf1280Sopenharmony_ci mpfr_div_2si(significand, x, exp - 21, GMP_RNDN); 185bbbf1280Sopenharmony_ci mpfr_abs(significand, significand, GMP_RNDN); 186bbbf1280Sopenharmony_ci mantfield = mpfr_get_ui(significand, GMP_RNDZ); 187bbbf1280Sopenharmony_ci *h = sign + ((uint64_t)expfield << 20) + mantfield; 188bbbf1280Sopenharmony_ci mpfr_sub_ui(significand, significand, mantfield, GMP_RNDN); 189bbbf1280Sopenharmony_ci mpfr_mul_2ui(significand, significand, 32, GMP_RNDN); 190bbbf1280Sopenharmony_ci mantfield = mpfr_get_ui(significand, GMP_RNDZ); 191bbbf1280Sopenharmony_ci *l = mantfield; 192bbbf1280Sopenharmony_ci mpfr_sub_ui(significand, significand, mantfield, GMP_RNDN); 193bbbf1280Sopenharmony_ci mpfr_mul_2ui(significand, significand, 32, GMP_RNDN); 194bbbf1280Sopenharmony_ci mantfield = mpfr_get_ui(significand, GMP_RNDZ); 195bbbf1280Sopenharmony_ci *extra = mantfield; 196bbbf1280Sopenharmony_ci 197bbbf1280Sopenharmony_ci mpfr_clear(significand); 198bbbf1280Sopenharmony_ci} 199bbbf1280Sopenharmony_cistatic void get_mpfr_f(const mpfr_t x, uint32 *f, uint32 *extra) 200bbbf1280Sopenharmony_ci{ 201bbbf1280Sopenharmony_ci uint32_t sign, expfield, mantfield; 202bbbf1280Sopenharmony_ci mpfr_t significand; 203bbbf1280Sopenharmony_ci int exp; 204bbbf1280Sopenharmony_ci 205bbbf1280Sopenharmony_ci if (mpfr_nan_p(x)) { 206bbbf1280Sopenharmony_ci *f = 0x7fc00000; 207bbbf1280Sopenharmony_ci *extra = 0; 208bbbf1280Sopenharmony_ci return; 209bbbf1280Sopenharmony_ci } 210bbbf1280Sopenharmony_ci 211bbbf1280Sopenharmony_ci sign = mpfr_signbit(x) ? 0x80000000U : 0; 212bbbf1280Sopenharmony_ci 213bbbf1280Sopenharmony_ci if (mpfr_inf_p(x)) { 214bbbf1280Sopenharmony_ci *f = 0x7f800000 | sign; 215bbbf1280Sopenharmony_ci *extra = 0; 216bbbf1280Sopenharmony_ci return; 217bbbf1280Sopenharmony_ci } 218bbbf1280Sopenharmony_ci 219bbbf1280Sopenharmony_ci if (mpfr_zero_p(x)) { 220bbbf1280Sopenharmony_ci *f = 0x00000000 | sign; 221bbbf1280Sopenharmony_ci *extra = 0; 222bbbf1280Sopenharmony_ci return; 223bbbf1280Sopenharmony_ci } 224bbbf1280Sopenharmony_ci 225bbbf1280Sopenharmony_ci mpfr_init2(significand, MPFR_PREC); 226bbbf1280Sopenharmony_ci mpfr_set(significand, x, GMP_RNDN); 227bbbf1280Sopenharmony_ci exp = mpfr_get_exp(significand); 228bbbf1280Sopenharmony_ci mpfr_set_exp(significand, 0); 229bbbf1280Sopenharmony_ci 230bbbf1280Sopenharmony_ci /* Now significand is in [1/2,1), and significand * 2^exp == x. 231bbbf1280Sopenharmony_ci * So the IEEE exponent corresponding to exp==0 is 0x7e. */ 232bbbf1280Sopenharmony_ci if (exp > 0x80) { 233bbbf1280Sopenharmony_ci /* overflow to infinity anyway */ 234bbbf1280Sopenharmony_ci *f = 0x7f800000 | sign; 235bbbf1280Sopenharmony_ci *extra = 0; 236bbbf1280Sopenharmony_ci mpfr_clear(significand); 237bbbf1280Sopenharmony_ci return; 238bbbf1280Sopenharmony_ci } 239bbbf1280Sopenharmony_ci 240bbbf1280Sopenharmony_ci if (exp <= -0x7e || mpfr_zero_p(x)) 241bbbf1280Sopenharmony_ci exp = -0x7d; /* denormalise */ 242bbbf1280Sopenharmony_ci expfield = exp + 0x7d; /* offset to cancel leading mantissa bit */ 243bbbf1280Sopenharmony_ci 244bbbf1280Sopenharmony_ci mpfr_div_2si(significand, x, exp - 24, GMP_RNDN); 245bbbf1280Sopenharmony_ci mpfr_abs(significand, significand, GMP_RNDN); 246bbbf1280Sopenharmony_ci mantfield = mpfr_get_ui(significand, GMP_RNDZ); 247bbbf1280Sopenharmony_ci *f = sign + ((uint64_t)expfield << 23) + mantfield; 248bbbf1280Sopenharmony_ci mpfr_sub_ui(significand, significand, mantfield, GMP_RNDN); 249bbbf1280Sopenharmony_ci mpfr_mul_2ui(significand, significand, 32, GMP_RNDN); 250bbbf1280Sopenharmony_ci mantfield = mpfr_get_ui(significand, GMP_RNDZ); 251bbbf1280Sopenharmony_ci *extra = mantfield; 252bbbf1280Sopenharmony_ci 253bbbf1280Sopenharmony_ci mpfr_clear(significand); 254bbbf1280Sopenharmony_ci} 255bbbf1280Sopenharmony_cistatic void get_mpc_d(const mpc_t z, 256bbbf1280Sopenharmony_ci uint32 *rh, uint32 *rl, uint32 *rextra, 257bbbf1280Sopenharmony_ci uint32 *ih, uint32 *il, uint32 *iextra) 258bbbf1280Sopenharmony_ci{ 259bbbf1280Sopenharmony_ci mpfr_t x, y; 260bbbf1280Sopenharmony_ci mpfr_init2(x, MPFR_PREC); 261bbbf1280Sopenharmony_ci mpfr_init2(y, MPFR_PREC); 262bbbf1280Sopenharmony_ci mpc_real(x, z, GMP_RNDN); 263bbbf1280Sopenharmony_ci mpc_imag(y, z, GMP_RNDN); 264bbbf1280Sopenharmony_ci get_mpfr_d(x, rh, rl, rextra); 265bbbf1280Sopenharmony_ci get_mpfr_d(y, ih, il, iextra); 266bbbf1280Sopenharmony_ci mpfr_clear(x); 267bbbf1280Sopenharmony_ci mpfr_clear(y); 268bbbf1280Sopenharmony_ci} 269bbbf1280Sopenharmony_cistatic void get_mpc_f(const mpc_t z, 270bbbf1280Sopenharmony_ci uint32 *r, uint32 *rextra, 271bbbf1280Sopenharmony_ci uint32 *i, uint32 *iextra) 272bbbf1280Sopenharmony_ci{ 273bbbf1280Sopenharmony_ci mpfr_t x, y; 274bbbf1280Sopenharmony_ci mpfr_init2(x, MPFR_PREC); 275bbbf1280Sopenharmony_ci mpfr_init2(y, MPFR_PREC); 276bbbf1280Sopenharmony_ci mpc_real(x, z, GMP_RNDN); 277bbbf1280Sopenharmony_ci mpc_imag(y, z, GMP_RNDN); 278bbbf1280Sopenharmony_ci get_mpfr_f(x, r, rextra); 279bbbf1280Sopenharmony_ci get_mpfr_f(y, i, iextra); 280bbbf1280Sopenharmony_ci mpfr_clear(x); 281bbbf1280Sopenharmony_ci mpfr_clear(y); 282bbbf1280Sopenharmony_ci} 283bbbf1280Sopenharmony_ci 284bbbf1280Sopenharmony_ci/* 285bbbf1280Sopenharmony_ci * Implementation of mathlib functions that aren't trivially 286bbbf1280Sopenharmony_ci * implementable using an existing mpfr or mpc function. 287bbbf1280Sopenharmony_ci */ 288bbbf1280Sopenharmony_ciint test_rred(mpfr_t ret, const mpfr_t x, int *quadrant) 289bbbf1280Sopenharmony_ci{ 290bbbf1280Sopenharmony_ci mpfr_t halfpi; 291bbbf1280Sopenharmony_ci long quo; 292bbbf1280Sopenharmony_ci int status; 293bbbf1280Sopenharmony_ci 294bbbf1280Sopenharmony_ci /* 295bbbf1280Sopenharmony_ci * In the worst case of range reduction, we get an input of size 296bbbf1280Sopenharmony_ci * around 2^1024, and must find its remainder mod pi, which means 297bbbf1280Sopenharmony_ci * we need 1024 bits of pi at least. Plus, the remainder might 298bbbf1280Sopenharmony_ci * happen to come out very very small if we're unlucky. How 299bbbf1280Sopenharmony_ci * unlucky can we be? Well, conveniently, I once went through and 300bbbf1280Sopenharmony_ci * actually worked that out using Paxson's modular minimisation 301bbbf1280Sopenharmony_ci * algorithm, and it turns out that the smallest exponent you can 302bbbf1280Sopenharmony_ci * get out of a nontrivial[1] double precision range reduction is 303bbbf1280Sopenharmony_ci * 0x3c2, i.e. of the order of 2^-61. So we need 1024 bits of pi 304bbbf1280Sopenharmony_ci * to get us down to the units digit, another 61 or so bits (say 305bbbf1280Sopenharmony_ci * 64) to get down to the highest set bit of the output, and then 306bbbf1280Sopenharmony_ci * some bits to make the actual mantissa big enough. 307bbbf1280Sopenharmony_ci * 308bbbf1280Sopenharmony_ci * [1] of course the output of range reduction can have an 309bbbf1280Sopenharmony_ci * arbitrarily small exponent in the trivial case, where the 310bbbf1280Sopenharmony_ci * input is so small that it's the identity function. That 311bbbf1280Sopenharmony_ci * doesn't count. 312bbbf1280Sopenharmony_ci */ 313bbbf1280Sopenharmony_ci mpfr_init2(halfpi, MPFR_PREC + 1024 + 64); 314bbbf1280Sopenharmony_ci mpfr_const_pi(halfpi, GMP_RNDN); 315bbbf1280Sopenharmony_ci mpfr_div_ui(halfpi, halfpi, 2, GMP_RNDN); 316bbbf1280Sopenharmony_ci 317bbbf1280Sopenharmony_ci status = mpfr_remquo(ret, &quo, x, halfpi, GMP_RNDN); 318bbbf1280Sopenharmony_ci *quadrant = quo & 3; 319bbbf1280Sopenharmony_ci 320bbbf1280Sopenharmony_ci mpfr_clear(halfpi); 321bbbf1280Sopenharmony_ci 322bbbf1280Sopenharmony_ci return status; 323bbbf1280Sopenharmony_ci} 324bbbf1280Sopenharmony_ciint test_lgamma(mpfr_t ret, const mpfr_t x, mpfr_rnd_t rnd) 325bbbf1280Sopenharmony_ci{ 326bbbf1280Sopenharmony_ci /* 327bbbf1280Sopenharmony_ci * mpfr_lgamma takes an extra int * parameter to hold the output 328bbbf1280Sopenharmony_ci * sign. We don't bother testing that, so this wrapper throws away 329bbbf1280Sopenharmony_ci * the sign and hence fits into the same function prototype as all 330bbbf1280Sopenharmony_ci * the other real->real mpfr functions. 331bbbf1280Sopenharmony_ci * 332bbbf1280Sopenharmony_ci * There is also mpfr_lngamma which has no sign output and hence 333bbbf1280Sopenharmony_ci * has the right prototype already, but unfortunately it returns 334bbbf1280Sopenharmony_ci * NaN in cases where gamma(x) < 0, so it's no use to us. 335bbbf1280Sopenharmony_ci */ 336bbbf1280Sopenharmony_ci int sign; 337bbbf1280Sopenharmony_ci return mpfr_lgamma(ret, &sign, x, rnd); 338bbbf1280Sopenharmony_ci} 339bbbf1280Sopenharmony_ciint test_cpow(mpc_t ret, const mpc_t x, const mpc_t y, mpc_rnd_t rnd) 340bbbf1280Sopenharmony_ci{ 341bbbf1280Sopenharmony_ci /* 342bbbf1280Sopenharmony_ci * For complex pow, we must bump up the precision by a huge amount 343bbbf1280Sopenharmony_ci * if we want it to get the really difficult cases right. (Not 344bbbf1280Sopenharmony_ci * that we expect the library under test to be getting those cases 345bbbf1280Sopenharmony_ci * right itself, but we'd at least like the test suite to report 346bbbf1280Sopenharmony_ci * them as wrong for the _right reason_.) 347bbbf1280Sopenharmony_ci * 348bbbf1280Sopenharmony_ci * This works around a bug in mpc_pow(), fixed by r1455 in the MPC 349bbbf1280Sopenharmony_ci * svn repository (2014-10-14) and expected to be in any MPC 350bbbf1280Sopenharmony_ci * release after 1.0.2 (which was the latest release already made 351bbbf1280Sopenharmony_ci * at the time of the fix). So as and when we update to an MPC 352bbbf1280Sopenharmony_ci * with the fix in it, we could remove this workaround. 353bbbf1280Sopenharmony_ci * 354bbbf1280Sopenharmony_ci * For the reasons for choosing this amount of extra precision, 355bbbf1280Sopenharmony_ci * see analysis in complex/cpownotes.txt for the rationale for the 356bbbf1280Sopenharmony_ci * amount. 357bbbf1280Sopenharmony_ci */ 358bbbf1280Sopenharmony_ci mpc_t xbig, ybig, retbig; 359bbbf1280Sopenharmony_ci int status; 360bbbf1280Sopenharmony_ci 361bbbf1280Sopenharmony_ci mpc_init2(xbig, 1034 + 53 + 60 + MPFR_PREC); 362bbbf1280Sopenharmony_ci mpc_init2(ybig, 1034 + 53 + 60 + MPFR_PREC); 363bbbf1280Sopenharmony_ci mpc_init2(retbig, 1034 + 53 + 60 + MPFR_PREC); 364bbbf1280Sopenharmony_ci 365bbbf1280Sopenharmony_ci mpc_set(xbig, x, MPC_RNDNN); 366bbbf1280Sopenharmony_ci mpc_set(ybig, y, MPC_RNDNN); 367bbbf1280Sopenharmony_ci status = mpc_pow(retbig, xbig, ybig, rnd); 368bbbf1280Sopenharmony_ci mpc_set(ret, retbig, rnd); 369bbbf1280Sopenharmony_ci 370bbbf1280Sopenharmony_ci mpc_clear(xbig); 371bbbf1280Sopenharmony_ci mpc_clear(ybig); 372bbbf1280Sopenharmony_ci mpc_clear(retbig); 373bbbf1280Sopenharmony_ci 374bbbf1280Sopenharmony_ci return status; 375bbbf1280Sopenharmony_ci} 376bbbf1280Sopenharmony_ci 377bbbf1280Sopenharmony_ci/* 378bbbf1280Sopenharmony_ci * Identify 'hard' values (NaN, Inf, nonzero denormal) for deciding 379bbbf1280Sopenharmony_ci * whether microlib will decline to run a test. 380bbbf1280Sopenharmony_ci */ 381bbbf1280Sopenharmony_ci#define is_shard(in) ( \ 382bbbf1280Sopenharmony_ci (((in)[0] & 0x7F800000) == 0x7F800000 || \ 383bbbf1280Sopenharmony_ci (((in)[0] & 0x7F800000) == 0 && ((in)[0]&0x7FFFFFFF) != 0))) 384bbbf1280Sopenharmony_ci 385bbbf1280Sopenharmony_ci#define is_dhard(in) ( \ 386bbbf1280Sopenharmony_ci (((in)[0] & 0x7FF00000) == 0x7FF00000 || \ 387bbbf1280Sopenharmony_ci (((in)[0] & 0x7FF00000) == 0 && (((in)[0] & 0xFFFFF) | (in)[1]) != 0))) 388bbbf1280Sopenharmony_ci 389bbbf1280Sopenharmony_ci/* 390bbbf1280Sopenharmony_ci * Identify integers. 391bbbf1280Sopenharmony_ci */ 392bbbf1280Sopenharmony_ciint is_dinteger(uint32 *in) 393bbbf1280Sopenharmony_ci{ 394bbbf1280Sopenharmony_ci uint32 out[3]; 395bbbf1280Sopenharmony_ci if ((0x7FF00000 & ~in[0]) == 0) 396bbbf1280Sopenharmony_ci return 0; /* not finite, hence not integer */ 397bbbf1280Sopenharmony_ci test_ceil(in, out); 398bbbf1280Sopenharmony_ci return in[0] == out[0] && in[1] == out[1]; 399bbbf1280Sopenharmony_ci} 400bbbf1280Sopenharmony_ciint is_sinteger(uint32 *in) 401bbbf1280Sopenharmony_ci{ 402bbbf1280Sopenharmony_ci uint32 out[3]; 403bbbf1280Sopenharmony_ci if ((0x7F800000 & ~in[0]) == 0) 404bbbf1280Sopenharmony_ci return 0; /* not finite, hence not integer */ 405bbbf1280Sopenharmony_ci test_ceilf(in, out); 406bbbf1280Sopenharmony_ci return in[0] == out[0]; 407bbbf1280Sopenharmony_ci} 408bbbf1280Sopenharmony_ci 409bbbf1280Sopenharmony_ci/* 410bbbf1280Sopenharmony_ci * Identify signalling NaNs. 411bbbf1280Sopenharmony_ci */ 412bbbf1280Sopenharmony_ciint is_dsnan(const uint32 *in) 413bbbf1280Sopenharmony_ci{ 414bbbf1280Sopenharmony_ci if ((in[0] & 0x7FF00000) != 0x7FF00000) 415bbbf1280Sopenharmony_ci return 0; /* not the inf/nan exponent */ 416bbbf1280Sopenharmony_ci if ((in[0] << 12) == 0 && in[1] == 0) 417bbbf1280Sopenharmony_ci return 0; /* inf */ 418bbbf1280Sopenharmony_ci if (in[0] & 0x00080000) 419bbbf1280Sopenharmony_ci return 0; /* qnan */ 420bbbf1280Sopenharmony_ci return 1; 421bbbf1280Sopenharmony_ci} 422bbbf1280Sopenharmony_ciint is_ssnan(const uint32 *in) 423bbbf1280Sopenharmony_ci{ 424bbbf1280Sopenharmony_ci if ((in[0] & 0x7F800000) != 0x7F800000) 425bbbf1280Sopenharmony_ci return 0; /* not the inf/nan exponent */ 426bbbf1280Sopenharmony_ci if ((in[0] << 9) == 0) 427bbbf1280Sopenharmony_ci return 0; /* inf */ 428bbbf1280Sopenharmony_ci if (in[0] & 0x00400000) 429bbbf1280Sopenharmony_ci return 0; /* qnan */ 430bbbf1280Sopenharmony_ci return 1; 431bbbf1280Sopenharmony_ci} 432bbbf1280Sopenharmony_ciint is_snan(const uint32 *in, int size) 433bbbf1280Sopenharmony_ci{ 434bbbf1280Sopenharmony_ci return size == 2 ? is_dsnan(in) : is_ssnan(in); 435bbbf1280Sopenharmony_ci} 436bbbf1280Sopenharmony_ci 437bbbf1280Sopenharmony_ci/* 438bbbf1280Sopenharmony_ci * Wrapper functions called to fix up unusual results after the main 439bbbf1280Sopenharmony_ci * test function has run. 440bbbf1280Sopenharmony_ci */ 441bbbf1280Sopenharmony_civoid universal_wrapper(wrapperctx *ctx) 442bbbf1280Sopenharmony_ci{ 443bbbf1280Sopenharmony_ci /* 444bbbf1280Sopenharmony_ci * Any SNaN input gives rise to a QNaN output. 445bbbf1280Sopenharmony_ci */ 446bbbf1280Sopenharmony_ci int op; 447bbbf1280Sopenharmony_ci for (op = 0; op < wrapper_get_nops(ctx); op++) { 448bbbf1280Sopenharmony_ci int size = wrapper_get_size(ctx, op); 449bbbf1280Sopenharmony_ci 450bbbf1280Sopenharmony_ci if (!wrapper_is_complex(ctx, op) && 451bbbf1280Sopenharmony_ci is_snan(wrapper_get_ieee(ctx, op), size)) { 452bbbf1280Sopenharmony_ci wrapper_set_nan(ctx); 453bbbf1280Sopenharmony_ci } 454bbbf1280Sopenharmony_ci } 455bbbf1280Sopenharmony_ci} 456bbbf1280Sopenharmony_ci 457bbbf1280Sopenharmony_ciTestable functions[] = { 458bbbf1280Sopenharmony_ci /* 459bbbf1280Sopenharmony_ci * Trig functions: sin, cos, tan. We test the core function 460bbbf1280Sopenharmony_ci * between -16 and +16: we assume that range reduction exists 461bbbf1280Sopenharmony_ci * and will be used for larger arguments, and we'll test that 462bbbf1280Sopenharmony_ci * separately. Also we only go down to 2^-27 in magnitude, 463bbbf1280Sopenharmony_ci * because below that sin(x)=tan(x)=x and cos(x)=1 as far as 464bbbf1280Sopenharmony_ci * double precision can tell, which is boring. 465bbbf1280Sopenharmony_ci */ 466bbbf1280Sopenharmony_ci {"sin", (funcptr)mpfr_sin, args1, {NULL}, 467bbbf1280Sopenharmony_ci cases_uniform, 0x3e400000, 0x40300000}, 468bbbf1280Sopenharmony_ci {"sinf", (funcptr)mpfr_sin, args1f, {NULL}, 469bbbf1280Sopenharmony_ci cases_uniform_float, 0x39800000, 0x41800000}, 470bbbf1280Sopenharmony_ci {"cos", (funcptr)mpfr_cos, args1, {NULL}, 471bbbf1280Sopenharmony_ci cases_uniform, 0x3e400000, 0x40300000}, 472bbbf1280Sopenharmony_ci {"cosf", (funcptr)mpfr_cos, args1f, {NULL}, 473bbbf1280Sopenharmony_ci cases_uniform_float, 0x39800000, 0x41800000}, 474bbbf1280Sopenharmony_ci {"tan", (funcptr)mpfr_tan, args1, {NULL}, 475bbbf1280Sopenharmony_ci cases_uniform, 0x3e400000, 0x40300000}, 476bbbf1280Sopenharmony_ci {"tanf", (funcptr)mpfr_tan, args1f, {NULL}, 477bbbf1280Sopenharmony_ci cases_uniform_float, 0x39800000, 0x41800000}, 478bbbf1280Sopenharmony_ci {"sincosf_sinf", (funcptr)mpfr_sin, args1f, {NULL}, 479bbbf1280Sopenharmony_ci cases_uniform_float, 0x39800000, 0x41800000}, 480bbbf1280Sopenharmony_ci {"sincosf_cosf", (funcptr)mpfr_cos, args1f, {NULL}, 481bbbf1280Sopenharmony_ci cases_uniform_float, 0x39800000, 0x41800000}, 482bbbf1280Sopenharmony_ci /* 483bbbf1280Sopenharmony_ci * Inverse trig: asin, acos. Between 1 and -1, of course. acos 484bbbf1280Sopenharmony_ci * goes down to 2^-54, asin to 2^-27. 485bbbf1280Sopenharmony_ci */ 486bbbf1280Sopenharmony_ci {"asin", (funcptr)mpfr_asin, args1, {NULL}, 487bbbf1280Sopenharmony_ci cases_uniform, 0x3e400000, 0x3fefffff}, 488bbbf1280Sopenharmony_ci {"asinf", (funcptr)mpfr_asin, args1f, {NULL}, 489bbbf1280Sopenharmony_ci cases_uniform_float, 0x39800000, 0x3f7fffff}, 490bbbf1280Sopenharmony_ci {"acos", (funcptr)mpfr_acos, args1, {NULL}, 491bbbf1280Sopenharmony_ci cases_uniform, 0x3c900000, 0x3fefffff}, 492bbbf1280Sopenharmony_ci {"acosf", (funcptr)mpfr_acos, args1f, {NULL}, 493bbbf1280Sopenharmony_ci cases_uniform_float, 0x33800000, 0x3f7fffff}, 494bbbf1280Sopenharmony_ci /* 495bbbf1280Sopenharmony_ci * Inverse trig: atan. atan is stable (in double prec) with 496bbbf1280Sopenharmony_ci * argument magnitude past 2^53, so we'll test up to there. 497bbbf1280Sopenharmony_ci * atan(x) is boringly just x below 2^-27. 498bbbf1280Sopenharmony_ci */ 499bbbf1280Sopenharmony_ci {"atan", (funcptr)mpfr_atan, args1, {NULL}, 500bbbf1280Sopenharmony_ci cases_uniform, 0x3e400000, 0x43400000}, 501bbbf1280Sopenharmony_ci {"atanf", (funcptr)mpfr_atan, args1f, {NULL}, 502bbbf1280Sopenharmony_ci cases_uniform_float, 0x39800000, 0x4b800000}, 503bbbf1280Sopenharmony_ci /* 504bbbf1280Sopenharmony_ci * atan2. Interesting cases arise when the exponents of the 505bbbf1280Sopenharmony_ci * arguments differ by at most about 50. 506bbbf1280Sopenharmony_ci */ 507bbbf1280Sopenharmony_ci {"atan2", (funcptr)mpfr_atan2, args2, {NULL}, 508bbbf1280Sopenharmony_ci atan2_cases, 0}, 509bbbf1280Sopenharmony_ci {"atan2f", (funcptr)mpfr_atan2, args2f, {NULL}, 510bbbf1280Sopenharmony_ci atan2_cases_float, 0}, 511bbbf1280Sopenharmony_ci /* 512bbbf1280Sopenharmony_ci * The exponentials: exp, sinh, cosh. They overflow at around 513bbbf1280Sopenharmony_ci * 710. exp and sinh are boring below 2^-54, cosh below 2^-27. 514bbbf1280Sopenharmony_ci */ 515bbbf1280Sopenharmony_ci {"exp", (funcptr)mpfr_exp, args1, {NULL}, 516bbbf1280Sopenharmony_ci cases_uniform, 0x3c900000, 0x40878000}, 517bbbf1280Sopenharmony_ci {"expf", (funcptr)mpfr_exp, args1f, {NULL}, 518bbbf1280Sopenharmony_ci cases_uniform_float, 0x33800000, 0x42dc0000}, 519bbbf1280Sopenharmony_ci {"sinh", (funcptr)mpfr_sinh, args1, {NULL}, 520bbbf1280Sopenharmony_ci cases_uniform, 0x3c900000, 0x40878000}, 521bbbf1280Sopenharmony_ci {"sinhf", (funcptr)mpfr_sinh, args1f, {NULL}, 522bbbf1280Sopenharmony_ci cases_uniform_float, 0x33800000, 0x42dc0000}, 523bbbf1280Sopenharmony_ci {"cosh", (funcptr)mpfr_cosh, args1, {NULL}, 524bbbf1280Sopenharmony_ci cases_uniform, 0x3e400000, 0x40878000}, 525bbbf1280Sopenharmony_ci {"coshf", (funcptr)mpfr_cosh, args1f, {NULL}, 526bbbf1280Sopenharmony_ci cases_uniform_float, 0x39800000, 0x42dc0000}, 527bbbf1280Sopenharmony_ci /* 528bbbf1280Sopenharmony_ci * tanh is stable past around 20. It's boring below 2^-27. 529bbbf1280Sopenharmony_ci */ 530bbbf1280Sopenharmony_ci {"tanh", (funcptr)mpfr_tanh, args1, {NULL}, 531bbbf1280Sopenharmony_ci cases_uniform, 0x3e400000, 0x40340000}, 532bbbf1280Sopenharmony_ci {"tanhf", (funcptr)mpfr_tanh, args1f, {NULL}, 533bbbf1280Sopenharmony_ci cases_uniform, 0x39800000, 0x41100000}, 534bbbf1280Sopenharmony_ci /* 535bbbf1280Sopenharmony_ci * log must be tested only on positive numbers, but can cover 536bbbf1280Sopenharmony_ci * the whole range of positive nonzero finite numbers. It never 537bbbf1280Sopenharmony_ci * gets boring. 538bbbf1280Sopenharmony_ci */ 539bbbf1280Sopenharmony_ci {"log", (funcptr)mpfr_log, args1, {NULL}, log_cases, 0}, 540bbbf1280Sopenharmony_ci {"logf", (funcptr)mpfr_log, args1f, {NULL}, log_cases_float, 0}, 541bbbf1280Sopenharmony_ci {"log10", (funcptr)mpfr_log10, args1, {NULL}, log_cases, 0}, 542bbbf1280Sopenharmony_ci {"log10f", (funcptr)mpfr_log10, args1f, {NULL}, log_cases_float, 0}, 543bbbf1280Sopenharmony_ci /* 544bbbf1280Sopenharmony_ci * pow. 545bbbf1280Sopenharmony_ci */ 546bbbf1280Sopenharmony_ci {"pow", (funcptr)mpfr_pow, args2, {NULL}, pow_cases, 0}, 547bbbf1280Sopenharmony_ci {"powf", (funcptr)mpfr_pow, args2f, {NULL}, pow_cases_float, 0}, 548bbbf1280Sopenharmony_ci /* 549bbbf1280Sopenharmony_ci * Trig range reduction. We are able to test this for all 550bbbf1280Sopenharmony_ci * finite values, but will only bother for things between 2^-3 551bbbf1280Sopenharmony_ci * and 2^+52. 552bbbf1280Sopenharmony_ci */ 553bbbf1280Sopenharmony_ci {"rred", (funcptr)test_rred, rred, {NULL}, rred_cases, 0}, 554bbbf1280Sopenharmony_ci {"rredf", (funcptr)test_rred, rredf, {NULL}, rred_cases_float, 0}, 555bbbf1280Sopenharmony_ci /* 556bbbf1280Sopenharmony_ci * Square and cube root. 557bbbf1280Sopenharmony_ci */ 558bbbf1280Sopenharmony_ci {"sqrt", (funcptr)mpfr_sqrt, args1, {NULL}, log_cases, 0}, 559bbbf1280Sopenharmony_ci {"sqrtf", (funcptr)mpfr_sqrt, args1f, {NULL}, log_cases_float, 0}, 560bbbf1280Sopenharmony_ci {"cbrt", (funcptr)mpfr_cbrt, args1, {NULL}, log_cases, 0}, 561bbbf1280Sopenharmony_ci {"cbrtf", (funcptr)mpfr_cbrt, args1f, {NULL}, log_cases_float, 0}, 562bbbf1280Sopenharmony_ci {"hypot", (funcptr)mpfr_hypot, args2, {NULL}, atan2_cases, 0}, 563bbbf1280Sopenharmony_ci {"hypotf", (funcptr)mpfr_hypot, args2f, {NULL}, atan2_cases_float, 0}, 564bbbf1280Sopenharmony_ci /* 565bbbf1280Sopenharmony_ci * Seminumerical functions. 566bbbf1280Sopenharmony_ci */ 567bbbf1280Sopenharmony_ci {"ceil", (funcptr)test_ceil, semi1, {NULL}, cases_semi1}, 568bbbf1280Sopenharmony_ci {"ceilf", (funcptr)test_ceilf, semi1f, {NULL}, cases_semi1_float}, 569bbbf1280Sopenharmony_ci {"floor", (funcptr)test_floor, semi1, {NULL}, cases_semi1}, 570bbbf1280Sopenharmony_ci {"floorf", (funcptr)test_floorf, semi1f, {NULL}, cases_semi1_float}, 571bbbf1280Sopenharmony_ci {"fmod", (funcptr)test_fmod, semi2, {NULL}, cases_semi2}, 572bbbf1280Sopenharmony_ci {"fmodf", (funcptr)test_fmodf, semi2f, {NULL}, cases_semi2_float}, 573bbbf1280Sopenharmony_ci {"ldexp", (funcptr)test_ldexp, t_ldexp, {NULL}, cases_ldexp}, 574bbbf1280Sopenharmony_ci {"ldexpf", (funcptr)test_ldexpf, t_ldexpf, {NULL}, cases_ldexp_float}, 575bbbf1280Sopenharmony_ci {"frexp", (funcptr)test_frexp, t_frexp, {NULL}, cases_semi1}, 576bbbf1280Sopenharmony_ci {"frexpf", (funcptr)test_frexpf, t_frexpf, {NULL}, cases_semi1_float}, 577bbbf1280Sopenharmony_ci {"modf", (funcptr)test_modf, t_modf, {NULL}, cases_semi1}, 578bbbf1280Sopenharmony_ci {"modff", (funcptr)test_modff, t_modff, {NULL}, cases_semi1_float}, 579bbbf1280Sopenharmony_ci 580bbbf1280Sopenharmony_ci /* 581bbbf1280Sopenharmony_ci * Classification and more semi-numericals 582bbbf1280Sopenharmony_ci */ 583bbbf1280Sopenharmony_ci {"copysign", (funcptr)test_copysign, semi2, {NULL}, cases_semi2}, 584bbbf1280Sopenharmony_ci {"copysignf", (funcptr)test_copysignf, semi2f, {NULL}, cases_semi2_float}, 585bbbf1280Sopenharmony_ci {"isfinite", (funcptr)test_isfinite, classify, {NULL}, cases_uniform, 0, 0x7fffffff}, 586bbbf1280Sopenharmony_ci {"isfinitef", (funcptr)test_isfinitef, classifyf, {NULL}, cases_uniform_float, 0, 0x7fffffff}, 587bbbf1280Sopenharmony_ci {"isinf", (funcptr)test_isinf, classify, {NULL}, cases_uniform, 0, 0x7fffffff}, 588bbbf1280Sopenharmony_ci {"isinff", (funcptr)test_isinff, classifyf, {NULL}, cases_uniform_float, 0, 0x7fffffff}, 589bbbf1280Sopenharmony_ci {"isnan", (funcptr)test_isnan, classify, {NULL}, cases_uniform, 0, 0x7fffffff}, 590bbbf1280Sopenharmony_ci {"isnanf", (funcptr)test_isnanf, classifyf, {NULL}, cases_uniform_float, 0, 0x7fffffff}, 591bbbf1280Sopenharmony_ci {"isnormal", (funcptr)test_isnormal, classify, {NULL}, cases_uniform, 0, 0x7fffffff}, 592bbbf1280Sopenharmony_ci {"isnormalf", (funcptr)test_isnormalf, classifyf, {NULL}, cases_uniform_float, 0, 0x7fffffff}, 593bbbf1280Sopenharmony_ci {"signbit", (funcptr)test_signbit, classify, {NULL}, cases_uniform, 0, 0x7fffffff}, 594bbbf1280Sopenharmony_ci {"signbitf", (funcptr)test_signbitf, classifyf, {NULL}, cases_uniform_float, 0, 0x7fffffff}, 595bbbf1280Sopenharmony_ci {"fpclassify", (funcptr)test_fpclassify, classify, {NULL}, cases_uniform, 0, 0x7fffffff}, 596bbbf1280Sopenharmony_ci {"fpclassifyf", (funcptr)test_fpclassifyf, classifyf, {NULL}, cases_uniform_float, 0, 0x7fffffff}, 597bbbf1280Sopenharmony_ci /* 598bbbf1280Sopenharmony_ci * Comparisons 599bbbf1280Sopenharmony_ci */ 600bbbf1280Sopenharmony_ci {"isgreater", (funcptr)test_isgreater, compare, {NULL}, cases_uniform, 0, 0x7fffffff}, 601bbbf1280Sopenharmony_ci {"isgreaterequal", (funcptr)test_isgreaterequal, compare, {NULL}, cases_uniform, 0, 0x7fffffff}, 602bbbf1280Sopenharmony_ci {"isless", (funcptr)test_isless, compare, {NULL}, cases_uniform, 0, 0x7fffffff}, 603bbbf1280Sopenharmony_ci {"islessequal", (funcptr)test_islessequal, compare, {NULL}, cases_uniform, 0, 0x7fffffff}, 604bbbf1280Sopenharmony_ci {"islessgreater", (funcptr)test_islessgreater, compare, {NULL}, cases_uniform, 0, 0x7fffffff}, 605bbbf1280Sopenharmony_ci {"isunordered", (funcptr)test_isunordered, compare, {NULL}, cases_uniform, 0, 0x7fffffff}, 606bbbf1280Sopenharmony_ci 607bbbf1280Sopenharmony_ci {"isgreaterf", (funcptr)test_isgreaterf, comparef, {NULL}, cases_uniform_float, 0, 0x7fffffff}, 608bbbf1280Sopenharmony_ci {"isgreaterequalf", (funcptr)test_isgreaterequalf, comparef, {NULL}, cases_uniform_float, 0, 0x7fffffff}, 609bbbf1280Sopenharmony_ci {"islessf", (funcptr)test_islessf, comparef, {NULL}, cases_uniform_float, 0, 0x7fffffff}, 610bbbf1280Sopenharmony_ci {"islessequalf", (funcptr)test_islessequalf, comparef, {NULL}, cases_uniform_float, 0, 0x7fffffff}, 611bbbf1280Sopenharmony_ci {"islessgreaterf", (funcptr)test_islessgreaterf, comparef, {NULL}, cases_uniform_float, 0, 0x7fffffff}, 612bbbf1280Sopenharmony_ci {"isunorderedf", (funcptr)test_isunorderedf, comparef, {NULL}, cases_uniform_float, 0, 0x7fffffff}, 613bbbf1280Sopenharmony_ci 614bbbf1280Sopenharmony_ci /* 615bbbf1280Sopenharmony_ci * Inverse Hyperbolic functions 616bbbf1280Sopenharmony_ci */ 617bbbf1280Sopenharmony_ci {"atanh", (funcptr)mpfr_atanh, args1, {NULL}, cases_uniform, 0x3e400000, 0x3fefffff}, 618bbbf1280Sopenharmony_ci {"asinh", (funcptr)mpfr_asinh, args1, {NULL}, cases_uniform, 0x3e400000, 0x3fefffff}, 619bbbf1280Sopenharmony_ci {"acosh", (funcptr)mpfr_acosh, args1, {NULL}, cases_uniform_positive, 0x3ff00000, 0x7fefffff}, 620bbbf1280Sopenharmony_ci 621bbbf1280Sopenharmony_ci {"atanhf", (funcptr)mpfr_atanh, args1f, {NULL}, cases_uniform_float, 0x32000000, 0x3f7fffff}, 622bbbf1280Sopenharmony_ci {"asinhf", (funcptr)mpfr_asinh, args1f, {NULL}, cases_uniform_float, 0x32000000, 0x3f7fffff}, 623bbbf1280Sopenharmony_ci {"acoshf", (funcptr)mpfr_acosh, args1f, {NULL}, cases_uniform_float_positive, 0x3f800000, 0x7f800000}, 624bbbf1280Sopenharmony_ci 625bbbf1280Sopenharmony_ci /* 626bbbf1280Sopenharmony_ci * Everything else (sitting in a section down here at the bottom 627bbbf1280Sopenharmony_ci * because historically they were not tested because we didn't 628bbbf1280Sopenharmony_ci * have reference implementations for them) 629bbbf1280Sopenharmony_ci */ 630bbbf1280Sopenharmony_ci {"csin", (funcptr)mpc_sin, args1c, {NULL}, complex_cases_uniform, 0x3f000000, 0x40300000}, 631bbbf1280Sopenharmony_ci {"csinf", (funcptr)mpc_sin, args1fc, {NULL}, complex_cases_uniform_float, 0x38000000, 0x41800000}, 632bbbf1280Sopenharmony_ci {"ccos", (funcptr)mpc_cos, args1c, {NULL}, complex_cases_uniform, 0x3f000000, 0x40300000}, 633bbbf1280Sopenharmony_ci {"ccosf", (funcptr)mpc_cos, args1fc, {NULL}, complex_cases_uniform_float, 0x38000000, 0x41800000}, 634bbbf1280Sopenharmony_ci {"ctan", (funcptr)mpc_tan, args1c, {NULL}, complex_cases_uniform, 0x3f000000, 0x40300000}, 635bbbf1280Sopenharmony_ci {"ctanf", (funcptr)mpc_tan, args1fc, {NULL}, complex_cases_uniform_float, 0x38000000, 0x41800000}, 636bbbf1280Sopenharmony_ci 637bbbf1280Sopenharmony_ci {"casin", (funcptr)mpc_asin, args1c, {NULL}, complex_cases_uniform, 0x3f000000, 0x40300000}, 638bbbf1280Sopenharmony_ci {"casinf", (funcptr)mpc_asin, args1fc, {NULL}, complex_cases_uniform_float, 0x38000000, 0x41800000}, 639bbbf1280Sopenharmony_ci {"cacos", (funcptr)mpc_acos, args1c, {NULL}, complex_cases_uniform, 0x3f000000, 0x40300000}, 640bbbf1280Sopenharmony_ci {"cacosf", (funcptr)mpc_acos, args1fc, {NULL}, complex_cases_uniform_float, 0x38000000, 0x41800000}, 641bbbf1280Sopenharmony_ci {"catan", (funcptr)mpc_atan, args1c, {NULL}, complex_cases_uniform, 0x3f000000, 0x40300000}, 642bbbf1280Sopenharmony_ci {"catanf", (funcptr)mpc_atan, args1fc, {NULL}, complex_cases_uniform_float, 0x38000000, 0x41800000}, 643bbbf1280Sopenharmony_ci 644bbbf1280Sopenharmony_ci {"csinh", (funcptr)mpc_sinh, args1c, {NULL}, complex_cases_uniform, 0x3f000000, 0x40300000}, 645bbbf1280Sopenharmony_ci {"csinhf", (funcptr)mpc_sinh, args1fc, {NULL}, complex_cases_uniform_float, 0x38000000, 0x41800000}, 646bbbf1280Sopenharmony_ci {"ccosh", (funcptr)mpc_cosh, args1c, {NULL}, complex_cases_uniform, 0x3f000000, 0x40300000}, 647bbbf1280Sopenharmony_ci {"ccoshf", (funcptr)mpc_cosh, args1fc, {NULL}, complex_cases_uniform_float, 0x38000000, 0x41800000}, 648bbbf1280Sopenharmony_ci {"ctanh", (funcptr)mpc_tanh, args1c, {NULL}, complex_cases_uniform, 0x3f000000, 0x40300000}, 649bbbf1280Sopenharmony_ci {"ctanhf", (funcptr)mpc_tanh, args1fc, {NULL}, complex_cases_uniform_float, 0x38000000, 0x41800000}, 650bbbf1280Sopenharmony_ci 651bbbf1280Sopenharmony_ci {"casinh", (funcptr)mpc_asinh, args1c, {NULL}, complex_cases_uniform, 0x3f000000, 0x40300000}, 652bbbf1280Sopenharmony_ci {"casinhf", (funcptr)mpc_asinh, args1fc, {NULL}, complex_cases_uniform_float, 0x38000000, 0x41800000}, 653bbbf1280Sopenharmony_ci {"cacosh", (funcptr)mpc_acosh, args1c, {NULL}, complex_cases_uniform, 0x3f000000, 0x40300000}, 654bbbf1280Sopenharmony_ci {"cacoshf", (funcptr)mpc_acosh, args1fc, {NULL}, complex_cases_uniform_float, 0x38000000, 0x41800000}, 655bbbf1280Sopenharmony_ci {"catanh", (funcptr)mpc_atanh, args1c, {NULL}, complex_cases_uniform, 0x3f000000, 0x40300000}, 656bbbf1280Sopenharmony_ci {"catanhf", (funcptr)mpc_atanh, args1fc, {NULL}, complex_cases_uniform_float, 0x38000000, 0x41800000}, 657bbbf1280Sopenharmony_ci 658bbbf1280Sopenharmony_ci {"cexp", (funcptr)mpc_exp, args1c, {NULL}, complex_cases_uniform, 0x3c900000, 0x40862000}, 659bbbf1280Sopenharmony_ci {"cpow", (funcptr)test_cpow, args2c, {NULL}, complex_pow_cases, 0x3fc00000, 0x40000000}, 660bbbf1280Sopenharmony_ci {"clog", (funcptr)mpc_log, args1c, {NULL}, complex_log_cases, 0, 0}, 661bbbf1280Sopenharmony_ci {"csqrt", (funcptr)mpc_sqrt, args1c, {NULL}, complex_log_cases, 0, 0}, 662bbbf1280Sopenharmony_ci 663bbbf1280Sopenharmony_ci {"cexpf", (funcptr)mpc_exp, args1fc, {NULL}, complex_cases_uniform_float, 0x24800000, 0x42b00000}, 664bbbf1280Sopenharmony_ci {"cpowf", (funcptr)test_cpow, args2fc, {NULL}, complex_pow_cases_float, 0x3e000000, 0x41000000}, 665bbbf1280Sopenharmony_ci {"clogf", (funcptr)mpc_log, args1fc, {NULL}, complex_log_cases_float, 0, 0}, 666bbbf1280Sopenharmony_ci {"csqrtf", (funcptr)mpc_sqrt, args1fc, {NULL}, complex_log_cases_float, 0, 0}, 667bbbf1280Sopenharmony_ci 668bbbf1280Sopenharmony_ci {"cdiv", (funcptr)mpc_div, args2c, {NULL}, complex_arithmetic_cases, 0, 0}, 669bbbf1280Sopenharmony_ci {"cmul", (funcptr)mpc_mul, args2c, {NULL}, complex_arithmetic_cases, 0, 0}, 670bbbf1280Sopenharmony_ci {"cadd", (funcptr)mpc_add, args2c, {NULL}, complex_arithmetic_cases, 0, 0}, 671bbbf1280Sopenharmony_ci {"csub", (funcptr)mpc_sub, args2c, {NULL}, complex_arithmetic_cases, 0, 0}, 672bbbf1280Sopenharmony_ci 673bbbf1280Sopenharmony_ci {"cdivf", (funcptr)mpc_div, args2fc, {NULL}, complex_arithmetic_cases_float, 0, 0}, 674bbbf1280Sopenharmony_ci {"cmulf", (funcptr)mpc_mul, args2fc, {NULL}, complex_arithmetic_cases_float, 0, 0}, 675bbbf1280Sopenharmony_ci {"caddf", (funcptr)mpc_add, args2fc, {NULL}, complex_arithmetic_cases_float, 0, 0}, 676bbbf1280Sopenharmony_ci {"csubf", (funcptr)mpc_sub, args2fc, {NULL}, complex_arithmetic_cases_float, 0, 0}, 677bbbf1280Sopenharmony_ci 678bbbf1280Sopenharmony_ci {"cabsf", (funcptr)mpc_abs, args1fcr, {NULL}, complex_arithmetic_cases_float, 0, 0}, 679bbbf1280Sopenharmony_ci {"cabs", (funcptr)mpc_abs, args1cr, {NULL}, complex_arithmetic_cases, 0, 0}, 680bbbf1280Sopenharmony_ci {"cargf", (funcptr)mpc_arg, args1fcr, {NULL}, complex_arithmetic_cases_float, 0, 0}, 681bbbf1280Sopenharmony_ci {"carg", (funcptr)mpc_arg, args1cr, {NULL}, complex_arithmetic_cases, 0, 0}, 682bbbf1280Sopenharmony_ci {"cimagf", (funcptr)mpc_imag, args1fcr, {NULL}, complex_arithmetic_cases_float, 0, 0}, 683bbbf1280Sopenharmony_ci {"cimag", (funcptr)mpc_imag, args1cr, {NULL}, complex_arithmetic_cases, 0, 0}, 684bbbf1280Sopenharmony_ci {"conjf", (funcptr)mpc_conj, args1fc, {NULL}, complex_arithmetic_cases_float, 0, 0}, 685bbbf1280Sopenharmony_ci {"conj", (funcptr)mpc_conj, args1c, {NULL}, complex_arithmetic_cases, 0, 0}, 686bbbf1280Sopenharmony_ci {"cprojf", (funcptr)mpc_proj, args1fc, {NULL}, complex_arithmetic_cases_float, 0, 0}, 687bbbf1280Sopenharmony_ci {"cproj", (funcptr)mpc_proj, args1c, {NULL}, complex_arithmetic_cases, 0, 0}, 688bbbf1280Sopenharmony_ci {"crealf", (funcptr)mpc_real, args1fcr, {NULL}, complex_arithmetic_cases_float, 0, 0}, 689bbbf1280Sopenharmony_ci {"creal", (funcptr)mpc_real, args1cr, {NULL}, complex_arithmetic_cases, 0, 0}, 690bbbf1280Sopenharmony_ci {"erfcf", (funcptr)mpfr_erfc, args1f, {NULL}, cases_biased_float, 0x1e800000, 0x41000000}, 691bbbf1280Sopenharmony_ci {"erfc", (funcptr)mpfr_erfc, args1, {NULL}, cases_biased, 0x3bd00000, 0x403c0000}, 692bbbf1280Sopenharmony_ci {"erff", (funcptr)mpfr_erf, args1f, {NULL}, cases_biased_float, 0x03800000, 0x40700000}, 693bbbf1280Sopenharmony_ci {"erf", (funcptr)mpfr_erf, args1, {NULL}, cases_biased, 0x00800000, 0x40200000}, 694bbbf1280Sopenharmony_ci {"exp2f", (funcptr)mpfr_exp2, args1f, {NULL}, cases_uniform_float, 0x33800000, 0x43c00000}, 695bbbf1280Sopenharmony_ci {"exp2", (funcptr)mpfr_exp2, args1, {NULL}, cases_uniform, 0x3ca00000, 0x40a00000}, 696bbbf1280Sopenharmony_ci {"expm1f", (funcptr)mpfr_expm1, args1f, {NULL}, cases_uniform_float, 0x33000000, 0x43800000}, 697bbbf1280Sopenharmony_ci {"expm1", (funcptr)mpfr_expm1, args1, {NULL}, cases_uniform, 0x3c900000, 0x409c0000}, 698bbbf1280Sopenharmony_ci {"fmaxf", (funcptr)mpfr_max, args2f, {NULL}, minmax_cases_float, 0, 0x7f7fffff}, 699bbbf1280Sopenharmony_ci {"fmax", (funcptr)mpfr_max, args2, {NULL}, minmax_cases, 0, 0x7fefffff}, 700bbbf1280Sopenharmony_ci {"fminf", (funcptr)mpfr_min, args2f, {NULL}, minmax_cases_float, 0, 0x7f7fffff}, 701bbbf1280Sopenharmony_ci {"fmin", (funcptr)mpfr_min, args2, {NULL}, minmax_cases, 0, 0x7fefffff}, 702bbbf1280Sopenharmony_ci {"lgammaf", (funcptr)test_lgamma, args1f, {NULL}, cases_uniform_float, 0x01800000, 0x7f800000}, 703bbbf1280Sopenharmony_ci {"lgamma", (funcptr)test_lgamma, args1, {NULL}, cases_uniform, 0x00100000, 0x7ff00000}, 704bbbf1280Sopenharmony_ci {"log1pf", (funcptr)mpfr_log1p, args1f, {NULL}, log1p_cases_float, 0, 0}, 705bbbf1280Sopenharmony_ci {"log1p", (funcptr)mpfr_log1p, args1, {NULL}, log1p_cases, 0, 0}, 706bbbf1280Sopenharmony_ci {"log2f", (funcptr)mpfr_log2, args1f, {NULL}, log_cases_float, 0, 0}, 707bbbf1280Sopenharmony_ci {"log2", (funcptr)mpfr_log2, args1, {NULL}, log_cases, 0, 0}, 708bbbf1280Sopenharmony_ci {"tgammaf", (funcptr)mpfr_gamma, args1f, {NULL}, cases_uniform_float, 0x2f800000, 0x43000000}, 709bbbf1280Sopenharmony_ci {"tgamma", (funcptr)mpfr_gamma, args1, {NULL}, cases_uniform, 0x3c000000, 0x40800000}, 710bbbf1280Sopenharmony_ci}; 711bbbf1280Sopenharmony_ci 712bbbf1280Sopenharmony_ciconst int nfunctions = ( sizeof(functions)/sizeof(*functions) ); 713bbbf1280Sopenharmony_ci 714bbbf1280Sopenharmony_ci#define random_sign ( random_upto(1) ? 0x80000000 : 0 ) 715bbbf1280Sopenharmony_ci 716bbbf1280Sopenharmony_cistatic int iszero(uint32 *x) { 717bbbf1280Sopenharmony_ci return !((x[0] & 0x7FFFFFFF) || x[1]); 718bbbf1280Sopenharmony_ci} 719bbbf1280Sopenharmony_ci 720bbbf1280Sopenharmony_ci 721bbbf1280Sopenharmony_cistatic void complex_log_cases(uint32 *out, uint32 param1, 722bbbf1280Sopenharmony_ci uint32 param2) { 723bbbf1280Sopenharmony_ci cases_uniform(out,0x00100000,0x7fefffff); 724bbbf1280Sopenharmony_ci cases_uniform(out+2,0x00100000,0x7fefffff); 725bbbf1280Sopenharmony_ci} 726bbbf1280Sopenharmony_ci 727bbbf1280Sopenharmony_ci 728bbbf1280Sopenharmony_cistatic void complex_log_cases_float(uint32 *out, uint32 param1, 729bbbf1280Sopenharmony_ci uint32 param2) { 730bbbf1280Sopenharmony_ci cases_uniform_float(out,0x00800000,0x7f7fffff); 731bbbf1280Sopenharmony_ci cases_uniform_float(out+2,0x00800000,0x7f7fffff); 732bbbf1280Sopenharmony_ci} 733bbbf1280Sopenharmony_ci 734bbbf1280Sopenharmony_cistatic void complex_cases_biased(uint32 *out, uint32 lowbound, 735bbbf1280Sopenharmony_ci uint32 highbound) { 736bbbf1280Sopenharmony_ci cases_biased(out,lowbound,highbound); 737bbbf1280Sopenharmony_ci cases_biased(out+2,lowbound,highbound); 738bbbf1280Sopenharmony_ci} 739bbbf1280Sopenharmony_ci 740bbbf1280Sopenharmony_cistatic void complex_cases_biased_float(uint32 *out, uint32 lowbound, 741bbbf1280Sopenharmony_ci uint32 highbound) { 742bbbf1280Sopenharmony_ci cases_biased_float(out,lowbound,highbound); 743bbbf1280Sopenharmony_ci cases_biased_float(out+2,lowbound,highbound); 744bbbf1280Sopenharmony_ci} 745bbbf1280Sopenharmony_ci 746bbbf1280Sopenharmony_cistatic void complex_cases_uniform(uint32 *out, uint32 lowbound, 747bbbf1280Sopenharmony_ci uint32 highbound) { 748bbbf1280Sopenharmony_ci cases_uniform(out,lowbound,highbound); 749bbbf1280Sopenharmony_ci cases_uniform(out+2,lowbound,highbound); 750bbbf1280Sopenharmony_ci} 751bbbf1280Sopenharmony_ci 752bbbf1280Sopenharmony_cistatic void complex_cases_uniform_float(uint32 *out, uint32 lowbound, 753bbbf1280Sopenharmony_ci uint32 highbound) { 754bbbf1280Sopenharmony_ci cases_uniform_float(out,lowbound,highbound); 755bbbf1280Sopenharmony_ci cases_uniform(out+2,lowbound,highbound); 756bbbf1280Sopenharmony_ci} 757bbbf1280Sopenharmony_ci 758bbbf1280Sopenharmony_cistatic void complex_pow_cases(uint32 *out, uint32 lowbound, 759bbbf1280Sopenharmony_ci uint32 highbound) { 760bbbf1280Sopenharmony_ci /* 761bbbf1280Sopenharmony_ci * Generating non-overflowing cases for complex pow: 762bbbf1280Sopenharmony_ci * 763bbbf1280Sopenharmony_ci * Our base has both parts within the range [1/2,2], and hence 764bbbf1280Sopenharmony_ci * its magnitude is within [1/2,2*sqrt(2)]. The magnitude of its 765bbbf1280Sopenharmony_ci * logarithm in base 2 is therefore at most the magnitude of 766bbbf1280Sopenharmony_ci * (log2(2*sqrt(2)) + i*pi/log(2)), or in other words 767bbbf1280Sopenharmony_ci * hypot(3/2,pi/log(2)) = 4.77. So the magnitude of the exponent 768bbbf1280Sopenharmony_ci * input must be at most our output magnitude limit (as a power 769bbbf1280Sopenharmony_ci * of two) divided by that. 770bbbf1280Sopenharmony_ci * 771bbbf1280Sopenharmony_ci * I also set the output magnitude limit a bit low, because we 772bbbf1280Sopenharmony_ci * don't guarantee (and neither does glibc) to prevent internal 773bbbf1280Sopenharmony_ci * overflow in cases where the output _magnitude_ overflows but 774bbbf1280Sopenharmony_ci * scaling it back down by cos and sin of the argument brings it 775bbbf1280Sopenharmony_ci * back in range. 776bbbf1280Sopenharmony_ci */ 777bbbf1280Sopenharmony_ci cases_uniform(out,0x3fe00000, 0x40000000); 778bbbf1280Sopenharmony_ci cases_uniform(out+2,0x3fe00000, 0x40000000); 779bbbf1280Sopenharmony_ci cases_uniform(out+4,0x3f800000, 0x40600000); 780bbbf1280Sopenharmony_ci cases_uniform(out+6,0x3f800000, 0x40600000); 781bbbf1280Sopenharmony_ci} 782bbbf1280Sopenharmony_ci 783bbbf1280Sopenharmony_cistatic void complex_pow_cases_float(uint32 *out, uint32 lowbound, 784bbbf1280Sopenharmony_ci uint32 highbound) { 785bbbf1280Sopenharmony_ci /* 786bbbf1280Sopenharmony_ci * Reasoning as above, though of course the detailed numbers are 787bbbf1280Sopenharmony_ci * all different. 788bbbf1280Sopenharmony_ci */ 789bbbf1280Sopenharmony_ci cases_uniform_float(out,0x3f000000, 0x40000000); 790bbbf1280Sopenharmony_ci cases_uniform_float(out+2,0x3f000000, 0x40000000); 791bbbf1280Sopenharmony_ci cases_uniform_float(out+4,0x3d600000, 0x41900000); 792bbbf1280Sopenharmony_ci cases_uniform_float(out+6,0x3d600000, 0x41900000); 793bbbf1280Sopenharmony_ci} 794bbbf1280Sopenharmony_ci 795bbbf1280Sopenharmony_cistatic void complex_arithmetic_cases(uint32 *out, uint32 lowbound, 796bbbf1280Sopenharmony_ci uint32 highbound) { 797bbbf1280Sopenharmony_ci cases_uniform(out,0,0x7fefffff); 798bbbf1280Sopenharmony_ci cases_uniform(out+2,0,0x7fefffff); 799bbbf1280Sopenharmony_ci cases_uniform(out+4,0,0x7fefffff); 800bbbf1280Sopenharmony_ci cases_uniform(out+6,0,0x7fefffff); 801bbbf1280Sopenharmony_ci} 802bbbf1280Sopenharmony_ci 803bbbf1280Sopenharmony_cistatic void complex_arithmetic_cases_float(uint32 *out, uint32 lowbound, 804bbbf1280Sopenharmony_ci uint32 highbound) { 805bbbf1280Sopenharmony_ci cases_uniform_float(out,0,0x7f7fffff); 806bbbf1280Sopenharmony_ci cases_uniform_float(out+2,0,0x7f7fffff); 807bbbf1280Sopenharmony_ci cases_uniform_float(out+4,0,0x7f7fffff); 808bbbf1280Sopenharmony_ci cases_uniform_float(out+6,0,0x7f7fffff); 809bbbf1280Sopenharmony_ci} 810bbbf1280Sopenharmony_ci 811bbbf1280Sopenharmony_ci/* 812bbbf1280Sopenharmony_ci * Included from fplib test suite, in a compact self-contained 813bbbf1280Sopenharmony_ci * form. 814bbbf1280Sopenharmony_ci */ 815bbbf1280Sopenharmony_ci 816bbbf1280Sopenharmony_civoid float32_case(uint32 *ret) { 817bbbf1280Sopenharmony_ci int n, bits; 818bbbf1280Sopenharmony_ci uint32 f; 819bbbf1280Sopenharmony_ci static int premax, preptr; 820bbbf1280Sopenharmony_ci static uint32 *specifics = NULL; 821bbbf1280Sopenharmony_ci 822bbbf1280Sopenharmony_ci if (!ret) { 823bbbf1280Sopenharmony_ci if (specifics) 824bbbf1280Sopenharmony_ci free(specifics); 825bbbf1280Sopenharmony_ci specifics = NULL; 826bbbf1280Sopenharmony_ci premax = preptr = 0; 827bbbf1280Sopenharmony_ci return; 828bbbf1280Sopenharmony_ci } 829bbbf1280Sopenharmony_ci 830bbbf1280Sopenharmony_ci if (!specifics) { 831bbbf1280Sopenharmony_ci int exps[] = { 832bbbf1280Sopenharmony_ci -127, -126, -125, -24, -4, -3, -2, -1, 0, 1, 2, 3, 4, 833bbbf1280Sopenharmony_ci 24, 29, 30, 31, 32, 61, 62, 63, 64, 126, 127, 128 834bbbf1280Sopenharmony_ci }; 835bbbf1280Sopenharmony_ci int sign, eptr; 836bbbf1280Sopenharmony_ci uint32 se, j; 837bbbf1280Sopenharmony_ci /* 838bbbf1280Sopenharmony_ci * We want a cross product of: 839bbbf1280Sopenharmony_ci * - each of two sign bits (2) 840bbbf1280Sopenharmony_ci * - each of the above (unbiased) exponents (25) 841bbbf1280Sopenharmony_ci * - the following list of fraction parts: 842bbbf1280Sopenharmony_ci * * zero (1) 843bbbf1280Sopenharmony_ci * * all bits (1) 844bbbf1280Sopenharmony_ci * * one-bit-set (23) 845bbbf1280Sopenharmony_ci * * one-bit-clear (23) 846bbbf1280Sopenharmony_ci * * one-bit-and-above (20: 3 are duplicates) 847bbbf1280Sopenharmony_ci * * one-bit-and-below (20: 3 are duplicates) 848bbbf1280Sopenharmony_ci * (total 88) 849bbbf1280Sopenharmony_ci * (total 4400) 850bbbf1280Sopenharmony_ci */ 851bbbf1280Sopenharmony_ci specifics = malloc(4400 * sizeof(*specifics)); 852bbbf1280Sopenharmony_ci preptr = 0; 853bbbf1280Sopenharmony_ci for (sign = 0; sign <= 1; sign++) { 854bbbf1280Sopenharmony_ci for (eptr = 0; eptr < sizeof(exps)/sizeof(*exps); eptr++) { 855bbbf1280Sopenharmony_ci se = (sign ? 0x80000000 : 0) | ((exps[eptr]+127) << 23); 856bbbf1280Sopenharmony_ci /* 857bbbf1280Sopenharmony_ci * Zero. 858bbbf1280Sopenharmony_ci */ 859bbbf1280Sopenharmony_ci specifics[preptr++] = se | 0; 860bbbf1280Sopenharmony_ci /* 861bbbf1280Sopenharmony_ci * All bits. 862bbbf1280Sopenharmony_ci */ 863bbbf1280Sopenharmony_ci specifics[preptr++] = se | 0x7FFFFF; 864bbbf1280Sopenharmony_ci /* 865bbbf1280Sopenharmony_ci * One-bit-set. 866bbbf1280Sopenharmony_ci */ 867bbbf1280Sopenharmony_ci for (j = 1; j && j <= 0x400000; j <<= 1) 868bbbf1280Sopenharmony_ci specifics[preptr++] = se | j; 869bbbf1280Sopenharmony_ci /* 870bbbf1280Sopenharmony_ci * One-bit-clear. 871bbbf1280Sopenharmony_ci */ 872bbbf1280Sopenharmony_ci for (j = 1; j && j <= 0x400000; j <<= 1) 873bbbf1280Sopenharmony_ci specifics[preptr++] = se | (0x7FFFFF ^ j); 874bbbf1280Sopenharmony_ci /* 875bbbf1280Sopenharmony_ci * One-bit-and-everything-below. 876bbbf1280Sopenharmony_ci */ 877bbbf1280Sopenharmony_ci for (j = 2; j && j <= 0x100000; j <<= 1) 878bbbf1280Sopenharmony_ci specifics[preptr++] = se | (2*j-1); 879bbbf1280Sopenharmony_ci /* 880bbbf1280Sopenharmony_ci * One-bit-and-everything-above. 881bbbf1280Sopenharmony_ci */ 882bbbf1280Sopenharmony_ci for (j = 4; j && j <= 0x200000; j <<= 1) 883bbbf1280Sopenharmony_ci specifics[preptr++] = se | (0x7FFFFF ^ (j-1)); 884bbbf1280Sopenharmony_ci /* 885bbbf1280Sopenharmony_ci * Done. 886bbbf1280Sopenharmony_ci */ 887bbbf1280Sopenharmony_ci } 888bbbf1280Sopenharmony_ci } 889bbbf1280Sopenharmony_ci assert(preptr == 4400); 890bbbf1280Sopenharmony_ci premax = preptr; 891bbbf1280Sopenharmony_ci } 892bbbf1280Sopenharmony_ci 893bbbf1280Sopenharmony_ci /* 894bbbf1280Sopenharmony_ci * Decide whether to return a pre or a random case. 895bbbf1280Sopenharmony_ci */ 896bbbf1280Sopenharmony_ci n = random32() % (premax+1); 897bbbf1280Sopenharmony_ci if (n < preptr) { 898bbbf1280Sopenharmony_ci /* 899bbbf1280Sopenharmony_ci * Return pre[n]. 900bbbf1280Sopenharmony_ci */ 901bbbf1280Sopenharmony_ci uint32 t; 902bbbf1280Sopenharmony_ci t = specifics[n]; 903bbbf1280Sopenharmony_ci specifics[n] = specifics[preptr-1]; 904bbbf1280Sopenharmony_ci specifics[preptr-1] = t; /* (not really needed) */ 905bbbf1280Sopenharmony_ci preptr--; 906bbbf1280Sopenharmony_ci *ret = t; 907bbbf1280Sopenharmony_ci } else { 908bbbf1280Sopenharmony_ci /* 909bbbf1280Sopenharmony_ci * Random case. 910bbbf1280Sopenharmony_ci * Sign and exponent: 911bbbf1280Sopenharmony_ci * - FIXME 912bbbf1280Sopenharmony_ci * Significand: 913bbbf1280Sopenharmony_ci * - with prob 1/5, a totally random bit pattern 914bbbf1280Sopenharmony_ci * - with prob 1/5, all 1s down to some point and then random 915bbbf1280Sopenharmony_ci * - with prob 1/5, all 1s up to some point and then random 916bbbf1280Sopenharmony_ci * - with prob 1/5, all 0s down to some point and then random 917bbbf1280Sopenharmony_ci * - with prob 1/5, all 0s up to some point and then random 918bbbf1280Sopenharmony_ci */ 919bbbf1280Sopenharmony_ci n = random32() % 5; 920bbbf1280Sopenharmony_ci f = random32(); /* some random bits */ 921bbbf1280Sopenharmony_ci bits = random32() % 22 + 1; /* 1-22 */ 922bbbf1280Sopenharmony_ci switch (n) { 923bbbf1280Sopenharmony_ci case 0: 924bbbf1280Sopenharmony_ci break; /* leave f alone */ 925bbbf1280Sopenharmony_ci case 1: 926bbbf1280Sopenharmony_ci f |= (1<<bits)-1; 927bbbf1280Sopenharmony_ci break; 928bbbf1280Sopenharmony_ci case 2: 929bbbf1280Sopenharmony_ci f &= ~((1<<bits)-1); 930bbbf1280Sopenharmony_ci break; 931bbbf1280Sopenharmony_ci case 3: 932bbbf1280Sopenharmony_ci f |= ~((1<<bits)-1); 933bbbf1280Sopenharmony_ci break; 934bbbf1280Sopenharmony_ci case 4: 935bbbf1280Sopenharmony_ci f &= (1<<bits)-1; 936bbbf1280Sopenharmony_ci break; 937bbbf1280Sopenharmony_ci } 938bbbf1280Sopenharmony_ci f &= 0x7FFFFF; 939bbbf1280Sopenharmony_ci f |= (random32() & 0xFF800000);/* FIXME - do better */ 940bbbf1280Sopenharmony_ci *ret = f; 941bbbf1280Sopenharmony_ci } 942bbbf1280Sopenharmony_ci} 943bbbf1280Sopenharmony_cistatic void float64_case(uint32 *ret) { 944bbbf1280Sopenharmony_ci int n, bits; 945bbbf1280Sopenharmony_ci uint32 f, g; 946bbbf1280Sopenharmony_ci static int premax, preptr; 947bbbf1280Sopenharmony_ci static uint32 (*specifics)[2] = NULL; 948bbbf1280Sopenharmony_ci 949bbbf1280Sopenharmony_ci if (!ret) { 950bbbf1280Sopenharmony_ci if (specifics) 951bbbf1280Sopenharmony_ci free(specifics); 952bbbf1280Sopenharmony_ci specifics = NULL; 953bbbf1280Sopenharmony_ci premax = preptr = 0; 954bbbf1280Sopenharmony_ci return; 955bbbf1280Sopenharmony_ci } 956bbbf1280Sopenharmony_ci 957bbbf1280Sopenharmony_ci if (!specifics) { 958bbbf1280Sopenharmony_ci int exps[] = { 959bbbf1280Sopenharmony_ci -1023, -1022, -1021, -129, -128, -127, -126, -53, -4, -3, -2, 960bbbf1280Sopenharmony_ci -1, 0, 1, 2, 3, 4, 29, 30, 31, 32, 53, 61, 62, 63, 64, 127, 961bbbf1280Sopenharmony_ci 128, 129, 1022, 1023, 1024 962bbbf1280Sopenharmony_ci }; 963bbbf1280Sopenharmony_ci int sign, eptr; 964bbbf1280Sopenharmony_ci uint32 se, j; 965bbbf1280Sopenharmony_ci /* 966bbbf1280Sopenharmony_ci * We want a cross product of: 967bbbf1280Sopenharmony_ci * - each of two sign bits (2) 968bbbf1280Sopenharmony_ci * - each of the above (unbiased) exponents (32) 969bbbf1280Sopenharmony_ci * - the following list of fraction parts: 970bbbf1280Sopenharmony_ci * * zero (1) 971bbbf1280Sopenharmony_ci * * all bits (1) 972bbbf1280Sopenharmony_ci * * one-bit-set (52) 973bbbf1280Sopenharmony_ci * * one-bit-clear (52) 974bbbf1280Sopenharmony_ci * * one-bit-and-above (49: 3 are duplicates) 975bbbf1280Sopenharmony_ci * * one-bit-and-below (49: 3 are duplicates) 976bbbf1280Sopenharmony_ci * (total 204) 977bbbf1280Sopenharmony_ci * (total 13056) 978bbbf1280Sopenharmony_ci */ 979bbbf1280Sopenharmony_ci specifics = malloc(13056 * sizeof(*specifics)); 980bbbf1280Sopenharmony_ci preptr = 0; 981bbbf1280Sopenharmony_ci for (sign = 0; sign <= 1; sign++) { 982bbbf1280Sopenharmony_ci for (eptr = 0; eptr < sizeof(exps)/sizeof(*exps); eptr++) { 983bbbf1280Sopenharmony_ci se = (sign ? 0x80000000 : 0) | ((exps[eptr]+1023) << 20); 984bbbf1280Sopenharmony_ci /* 985bbbf1280Sopenharmony_ci * Zero. 986bbbf1280Sopenharmony_ci */ 987bbbf1280Sopenharmony_ci specifics[preptr][0] = 0; 988bbbf1280Sopenharmony_ci specifics[preptr][1] = 0; 989bbbf1280Sopenharmony_ci specifics[preptr++][0] |= se; 990bbbf1280Sopenharmony_ci /* 991bbbf1280Sopenharmony_ci * All bits. 992bbbf1280Sopenharmony_ci */ 993bbbf1280Sopenharmony_ci specifics[preptr][0] = 0xFFFFF; 994bbbf1280Sopenharmony_ci specifics[preptr][1] = ~0; 995bbbf1280Sopenharmony_ci specifics[preptr++][0] |= se; 996bbbf1280Sopenharmony_ci /* 997bbbf1280Sopenharmony_ci * One-bit-set. 998bbbf1280Sopenharmony_ci */ 999bbbf1280Sopenharmony_ci for (j = 1; j && j <= 0x80000000; j <<= 1) { 1000bbbf1280Sopenharmony_ci specifics[preptr][0] = 0; 1001bbbf1280Sopenharmony_ci specifics[preptr][1] = j; 1002bbbf1280Sopenharmony_ci specifics[preptr++][0] |= se; 1003bbbf1280Sopenharmony_ci if (j & 0xFFFFF) { 1004bbbf1280Sopenharmony_ci specifics[preptr][0] = j; 1005bbbf1280Sopenharmony_ci specifics[preptr][1] = 0; 1006bbbf1280Sopenharmony_ci specifics[preptr++][0] |= se; 1007bbbf1280Sopenharmony_ci } 1008bbbf1280Sopenharmony_ci } 1009bbbf1280Sopenharmony_ci /* 1010bbbf1280Sopenharmony_ci * One-bit-clear. 1011bbbf1280Sopenharmony_ci */ 1012bbbf1280Sopenharmony_ci for (j = 1; j && j <= 0x80000000; j <<= 1) { 1013bbbf1280Sopenharmony_ci specifics[preptr][0] = 0xFFFFF; 1014bbbf1280Sopenharmony_ci specifics[preptr][1] = ~j; 1015bbbf1280Sopenharmony_ci specifics[preptr++][0] |= se; 1016bbbf1280Sopenharmony_ci if (j & 0xFFFFF) { 1017bbbf1280Sopenharmony_ci specifics[preptr][0] = 0xFFFFF ^ j; 1018bbbf1280Sopenharmony_ci specifics[preptr][1] = ~0; 1019bbbf1280Sopenharmony_ci specifics[preptr++][0] |= se; 1020bbbf1280Sopenharmony_ci } 1021bbbf1280Sopenharmony_ci } 1022bbbf1280Sopenharmony_ci /* 1023bbbf1280Sopenharmony_ci * One-bit-and-everything-below. 1024bbbf1280Sopenharmony_ci */ 1025bbbf1280Sopenharmony_ci for (j = 2; j && j <= 0x80000000; j <<= 1) { 1026bbbf1280Sopenharmony_ci specifics[preptr][0] = 0; 1027bbbf1280Sopenharmony_ci specifics[preptr][1] = 2*j-1; 1028bbbf1280Sopenharmony_ci specifics[preptr++][0] |= se; 1029bbbf1280Sopenharmony_ci } 1030bbbf1280Sopenharmony_ci for (j = 1; j && j <= 0x20000; j <<= 1) { 1031bbbf1280Sopenharmony_ci specifics[preptr][0] = 2*j-1; 1032bbbf1280Sopenharmony_ci specifics[preptr][1] = ~0; 1033bbbf1280Sopenharmony_ci specifics[preptr++][0] |= se; 1034bbbf1280Sopenharmony_ci } 1035bbbf1280Sopenharmony_ci /* 1036bbbf1280Sopenharmony_ci * One-bit-and-everything-above. 1037bbbf1280Sopenharmony_ci */ 1038bbbf1280Sopenharmony_ci for (j = 4; j && j <= 0x80000000; j <<= 1) { 1039bbbf1280Sopenharmony_ci specifics[preptr][0] = 0xFFFFF; 1040bbbf1280Sopenharmony_ci specifics[preptr][1] = ~(j-1); 1041bbbf1280Sopenharmony_ci specifics[preptr++][0] |= se; 1042bbbf1280Sopenharmony_ci } 1043bbbf1280Sopenharmony_ci for (j = 1; j && j <= 0x40000; j <<= 1) { 1044bbbf1280Sopenharmony_ci specifics[preptr][0] = 0xFFFFF ^ (j-1); 1045bbbf1280Sopenharmony_ci specifics[preptr][1] = 0; 1046bbbf1280Sopenharmony_ci specifics[preptr++][0] |= se; 1047bbbf1280Sopenharmony_ci } 1048bbbf1280Sopenharmony_ci /* 1049bbbf1280Sopenharmony_ci * Done. 1050bbbf1280Sopenharmony_ci */ 1051bbbf1280Sopenharmony_ci } 1052bbbf1280Sopenharmony_ci } 1053bbbf1280Sopenharmony_ci assert(preptr == 13056); 1054bbbf1280Sopenharmony_ci premax = preptr; 1055bbbf1280Sopenharmony_ci } 1056bbbf1280Sopenharmony_ci 1057bbbf1280Sopenharmony_ci /* 1058bbbf1280Sopenharmony_ci * Decide whether to return a pre or a random case. 1059bbbf1280Sopenharmony_ci */ 1060bbbf1280Sopenharmony_ci n = (uint32) random32() % (uint32) (premax+1); 1061bbbf1280Sopenharmony_ci if (n < preptr) { 1062bbbf1280Sopenharmony_ci /* 1063bbbf1280Sopenharmony_ci * Return pre[n]. 1064bbbf1280Sopenharmony_ci */ 1065bbbf1280Sopenharmony_ci uint32 t; 1066bbbf1280Sopenharmony_ci t = specifics[n][0]; 1067bbbf1280Sopenharmony_ci specifics[n][0] = specifics[preptr-1][0]; 1068bbbf1280Sopenharmony_ci specifics[preptr-1][0] = t; /* (not really needed) */ 1069bbbf1280Sopenharmony_ci ret[0] = t; 1070bbbf1280Sopenharmony_ci t = specifics[n][1]; 1071bbbf1280Sopenharmony_ci specifics[n][1] = specifics[preptr-1][1]; 1072bbbf1280Sopenharmony_ci specifics[preptr-1][1] = t; /* (not really needed) */ 1073bbbf1280Sopenharmony_ci ret[1] = t; 1074bbbf1280Sopenharmony_ci preptr--; 1075bbbf1280Sopenharmony_ci } else { 1076bbbf1280Sopenharmony_ci /* 1077bbbf1280Sopenharmony_ci * Random case. 1078bbbf1280Sopenharmony_ci * Sign and exponent: 1079bbbf1280Sopenharmony_ci * - FIXME 1080bbbf1280Sopenharmony_ci * Significand: 1081bbbf1280Sopenharmony_ci * - with prob 1/5, a totally random bit pattern 1082bbbf1280Sopenharmony_ci * - with prob 1/5, all 1s down to some point and then random 1083bbbf1280Sopenharmony_ci * - with prob 1/5, all 1s up to some point and then random 1084bbbf1280Sopenharmony_ci * - with prob 1/5, all 0s down to some point and then random 1085bbbf1280Sopenharmony_ci * - with prob 1/5, all 0s up to some point and then random 1086bbbf1280Sopenharmony_ci */ 1087bbbf1280Sopenharmony_ci n = random32() % 5; 1088bbbf1280Sopenharmony_ci f = random32(); /* some random bits */ 1089bbbf1280Sopenharmony_ci g = random32(); /* some random bits */ 1090bbbf1280Sopenharmony_ci bits = random32() % 51 + 1; /* 1-51 */ 1091bbbf1280Sopenharmony_ci switch (n) { 1092bbbf1280Sopenharmony_ci case 0: 1093bbbf1280Sopenharmony_ci break; /* leave f alone */ 1094bbbf1280Sopenharmony_ci case 1: 1095bbbf1280Sopenharmony_ci if (bits <= 32) 1096bbbf1280Sopenharmony_ci f |= (1<<bits)-1; 1097bbbf1280Sopenharmony_ci else { 1098bbbf1280Sopenharmony_ci bits -= 32; 1099bbbf1280Sopenharmony_ci g |= (1<<bits)-1; 1100bbbf1280Sopenharmony_ci f = ~0; 1101bbbf1280Sopenharmony_ci } 1102bbbf1280Sopenharmony_ci break; 1103bbbf1280Sopenharmony_ci case 2: 1104bbbf1280Sopenharmony_ci if (bits <= 32) 1105bbbf1280Sopenharmony_ci f &= ~((1<<bits)-1); 1106bbbf1280Sopenharmony_ci else { 1107bbbf1280Sopenharmony_ci bits -= 32; 1108bbbf1280Sopenharmony_ci g &= ~((1<<bits)-1); 1109bbbf1280Sopenharmony_ci f = 0; 1110bbbf1280Sopenharmony_ci } 1111bbbf1280Sopenharmony_ci break; 1112bbbf1280Sopenharmony_ci case 3: 1113bbbf1280Sopenharmony_ci if (bits <= 32) 1114bbbf1280Sopenharmony_ci g &= (1<<bits)-1; 1115bbbf1280Sopenharmony_ci else { 1116bbbf1280Sopenharmony_ci bits -= 32; 1117bbbf1280Sopenharmony_ci f &= (1<<bits)-1; 1118bbbf1280Sopenharmony_ci g = 0; 1119bbbf1280Sopenharmony_ci } 1120bbbf1280Sopenharmony_ci break; 1121bbbf1280Sopenharmony_ci case 4: 1122bbbf1280Sopenharmony_ci if (bits <= 32) 1123bbbf1280Sopenharmony_ci g |= ~((1<<bits)-1); 1124bbbf1280Sopenharmony_ci else { 1125bbbf1280Sopenharmony_ci bits -= 32; 1126bbbf1280Sopenharmony_ci f |= ~((1<<bits)-1); 1127bbbf1280Sopenharmony_ci g = ~0; 1128bbbf1280Sopenharmony_ci } 1129bbbf1280Sopenharmony_ci break; 1130bbbf1280Sopenharmony_ci } 1131bbbf1280Sopenharmony_ci g &= 0xFFFFF; 1132bbbf1280Sopenharmony_ci g |= (random32() & 0xFFF00000);/* FIXME - do better */ 1133bbbf1280Sopenharmony_ci ret[0] = g; 1134bbbf1280Sopenharmony_ci ret[1] = f; 1135bbbf1280Sopenharmony_ci } 1136bbbf1280Sopenharmony_ci} 1137bbbf1280Sopenharmony_ci 1138bbbf1280Sopenharmony_cistatic void cases_biased(uint32 *out, uint32 lowbound, 1139bbbf1280Sopenharmony_ci uint32 highbound) { 1140bbbf1280Sopenharmony_ci do { 1141bbbf1280Sopenharmony_ci out[0] = highbound - random_upto_biased(highbound-lowbound, 8); 1142bbbf1280Sopenharmony_ci out[1] = random_upto(0xFFFFFFFF); 1143bbbf1280Sopenharmony_ci out[0] |= random_sign; 1144bbbf1280Sopenharmony_ci } while (iszero(out)); /* rule out zero */ 1145bbbf1280Sopenharmony_ci} 1146bbbf1280Sopenharmony_ci 1147bbbf1280Sopenharmony_cistatic void cases_biased_positive(uint32 *out, uint32 lowbound, 1148bbbf1280Sopenharmony_ci uint32 highbound) { 1149bbbf1280Sopenharmony_ci do { 1150bbbf1280Sopenharmony_ci out[0] = highbound - random_upto_biased(highbound-lowbound, 8); 1151bbbf1280Sopenharmony_ci out[1] = random_upto(0xFFFFFFFF); 1152bbbf1280Sopenharmony_ci } while (iszero(out)); /* rule out zero */ 1153bbbf1280Sopenharmony_ci} 1154bbbf1280Sopenharmony_ci 1155bbbf1280Sopenharmony_cistatic void cases_biased_float(uint32 *out, uint32 lowbound, 1156bbbf1280Sopenharmony_ci uint32 highbound) { 1157bbbf1280Sopenharmony_ci do { 1158bbbf1280Sopenharmony_ci out[0] = highbound - random_upto_biased(highbound-lowbound, 8); 1159bbbf1280Sopenharmony_ci out[1] = 0; 1160bbbf1280Sopenharmony_ci out[0] |= random_sign; 1161bbbf1280Sopenharmony_ci } while (iszero(out)); /* rule out zero */ 1162bbbf1280Sopenharmony_ci} 1163bbbf1280Sopenharmony_ci 1164bbbf1280Sopenharmony_cistatic void cases_semi1(uint32 *out, uint32 param1, 1165bbbf1280Sopenharmony_ci uint32 param2) { 1166bbbf1280Sopenharmony_ci float64_case(out); 1167bbbf1280Sopenharmony_ci} 1168bbbf1280Sopenharmony_ci 1169bbbf1280Sopenharmony_cistatic void cases_semi1_float(uint32 *out, uint32 param1, 1170bbbf1280Sopenharmony_ci uint32 param2) { 1171bbbf1280Sopenharmony_ci float32_case(out); 1172bbbf1280Sopenharmony_ci} 1173bbbf1280Sopenharmony_ci 1174bbbf1280Sopenharmony_cistatic void cases_semi2(uint32 *out, uint32 param1, 1175bbbf1280Sopenharmony_ci uint32 param2) { 1176bbbf1280Sopenharmony_ci float64_case(out); 1177bbbf1280Sopenharmony_ci float64_case(out+2); 1178bbbf1280Sopenharmony_ci} 1179bbbf1280Sopenharmony_ci 1180bbbf1280Sopenharmony_cistatic void cases_semi2_float(uint32 *out, uint32 param1, 1181bbbf1280Sopenharmony_ci uint32 param2) { 1182bbbf1280Sopenharmony_ci float32_case(out); 1183bbbf1280Sopenharmony_ci float32_case(out+2); 1184bbbf1280Sopenharmony_ci} 1185bbbf1280Sopenharmony_ci 1186bbbf1280Sopenharmony_cistatic void cases_ldexp(uint32 *out, uint32 param1, 1187bbbf1280Sopenharmony_ci uint32 param2) { 1188bbbf1280Sopenharmony_ci float64_case(out); 1189bbbf1280Sopenharmony_ci out[2] = random_upto(2048)-1024; 1190bbbf1280Sopenharmony_ci} 1191bbbf1280Sopenharmony_ci 1192bbbf1280Sopenharmony_cistatic void cases_ldexp_float(uint32 *out, uint32 param1, 1193bbbf1280Sopenharmony_ci uint32 param2) { 1194bbbf1280Sopenharmony_ci float32_case(out); 1195bbbf1280Sopenharmony_ci out[2] = random_upto(256)-128; 1196bbbf1280Sopenharmony_ci} 1197bbbf1280Sopenharmony_ci 1198bbbf1280Sopenharmony_cistatic void cases_uniform(uint32 *out, uint32 lowbound, 1199bbbf1280Sopenharmony_ci uint32 highbound) { 1200bbbf1280Sopenharmony_ci do { 1201bbbf1280Sopenharmony_ci out[0] = highbound - random_upto(highbound-lowbound); 1202bbbf1280Sopenharmony_ci out[1] = random_upto(0xFFFFFFFF); 1203bbbf1280Sopenharmony_ci out[0] |= random_sign; 1204bbbf1280Sopenharmony_ci } while (iszero(out)); /* rule out zero */ 1205bbbf1280Sopenharmony_ci} 1206bbbf1280Sopenharmony_cistatic void cases_uniform_float(uint32 *out, uint32 lowbound, 1207bbbf1280Sopenharmony_ci uint32 highbound) { 1208bbbf1280Sopenharmony_ci do { 1209bbbf1280Sopenharmony_ci out[0] = highbound - random_upto(highbound-lowbound); 1210bbbf1280Sopenharmony_ci out[1] = 0; 1211bbbf1280Sopenharmony_ci out[0] |= random_sign; 1212bbbf1280Sopenharmony_ci } while (iszero(out)); /* rule out zero */ 1213bbbf1280Sopenharmony_ci} 1214bbbf1280Sopenharmony_ci 1215bbbf1280Sopenharmony_cistatic void cases_uniform_positive(uint32 *out, uint32 lowbound, 1216bbbf1280Sopenharmony_ci uint32 highbound) { 1217bbbf1280Sopenharmony_ci do { 1218bbbf1280Sopenharmony_ci out[0] = highbound - random_upto(highbound-lowbound); 1219bbbf1280Sopenharmony_ci out[1] = random_upto(0xFFFFFFFF); 1220bbbf1280Sopenharmony_ci } while (iszero(out)); /* rule out zero */ 1221bbbf1280Sopenharmony_ci} 1222bbbf1280Sopenharmony_cistatic void cases_uniform_float_positive(uint32 *out, uint32 lowbound, 1223bbbf1280Sopenharmony_ci uint32 highbound) { 1224bbbf1280Sopenharmony_ci do { 1225bbbf1280Sopenharmony_ci out[0] = highbound - random_upto(highbound-lowbound); 1226bbbf1280Sopenharmony_ci out[1] = 0; 1227bbbf1280Sopenharmony_ci } while (iszero(out)); /* rule out zero */ 1228bbbf1280Sopenharmony_ci} 1229bbbf1280Sopenharmony_ci 1230bbbf1280Sopenharmony_ci 1231bbbf1280Sopenharmony_cistatic void log_cases(uint32 *out, uint32 param1, 1232bbbf1280Sopenharmony_ci uint32 param2) { 1233bbbf1280Sopenharmony_ci do { 1234bbbf1280Sopenharmony_ci out[0] = random_upto(0x7FEFFFFF); 1235bbbf1280Sopenharmony_ci out[1] = random_upto(0xFFFFFFFF); 1236bbbf1280Sopenharmony_ci } while (iszero(out)); /* rule out zero */ 1237bbbf1280Sopenharmony_ci} 1238bbbf1280Sopenharmony_ci 1239bbbf1280Sopenharmony_cistatic void log_cases_float(uint32 *out, uint32 param1, 1240bbbf1280Sopenharmony_ci uint32 param2) { 1241bbbf1280Sopenharmony_ci do { 1242bbbf1280Sopenharmony_ci out[0] = random_upto(0x7F7FFFFF); 1243bbbf1280Sopenharmony_ci out[1] = 0; 1244bbbf1280Sopenharmony_ci } while (iszero(out)); /* rule out zero */ 1245bbbf1280Sopenharmony_ci} 1246bbbf1280Sopenharmony_ci 1247bbbf1280Sopenharmony_cistatic void log1p_cases(uint32 *out, uint32 param1, uint32 param2) 1248bbbf1280Sopenharmony_ci{ 1249bbbf1280Sopenharmony_ci uint32 sign = random_sign; 1250bbbf1280Sopenharmony_ci if (sign == 0) { 1251bbbf1280Sopenharmony_ci cases_uniform_positive(out, 0x3c700000, 0x43400000); 1252bbbf1280Sopenharmony_ci } else { 1253bbbf1280Sopenharmony_ci cases_uniform_positive(out, 0x3c000000, 0x3ff00000); 1254bbbf1280Sopenharmony_ci } 1255bbbf1280Sopenharmony_ci out[0] |= sign; 1256bbbf1280Sopenharmony_ci} 1257bbbf1280Sopenharmony_ci 1258bbbf1280Sopenharmony_cistatic void log1p_cases_float(uint32 *out, uint32 param1, uint32 param2) 1259bbbf1280Sopenharmony_ci{ 1260bbbf1280Sopenharmony_ci uint32 sign = random_sign; 1261bbbf1280Sopenharmony_ci if (sign == 0) { 1262bbbf1280Sopenharmony_ci cases_uniform_float_positive(out, 0x32000000, 0x4c000000); 1263bbbf1280Sopenharmony_ci } else { 1264bbbf1280Sopenharmony_ci cases_uniform_float_positive(out, 0x30000000, 0x3f800000); 1265bbbf1280Sopenharmony_ci } 1266bbbf1280Sopenharmony_ci out[0] |= sign; 1267bbbf1280Sopenharmony_ci} 1268bbbf1280Sopenharmony_ci 1269bbbf1280Sopenharmony_cistatic void minmax_cases(uint32 *out, uint32 param1, uint32 param2) 1270bbbf1280Sopenharmony_ci{ 1271bbbf1280Sopenharmony_ci do { 1272bbbf1280Sopenharmony_ci out[0] = random_upto(0x7FEFFFFF); 1273bbbf1280Sopenharmony_ci out[1] = random_upto(0xFFFFFFFF); 1274bbbf1280Sopenharmony_ci out[0] |= random_sign; 1275bbbf1280Sopenharmony_ci out[2] = random_upto(0x7FEFFFFF); 1276bbbf1280Sopenharmony_ci out[3] = random_upto(0xFFFFFFFF); 1277bbbf1280Sopenharmony_ci out[2] |= random_sign; 1278bbbf1280Sopenharmony_ci } while (iszero(out)); /* rule out zero */ 1279bbbf1280Sopenharmony_ci} 1280bbbf1280Sopenharmony_ci 1281bbbf1280Sopenharmony_cistatic void minmax_cases_float(uint32 *out, uint32 param1, uint32 param2) 1282bbbf1280Sopenharmony_ci{ 1283bbbf1280Sopenharmony_ci do { 1284bbbf1280Sopenharmony_ci out[0] = random_upto(0x7F7FFFFF); 1285bbbf1280Sopenharmony_ci out[1] = 0; 1286bbbf1280Sopenharmony_ci out[0] |= random_sign; 1287bbbf1280Sopenharmony_ci out[2] = random_upto(0x7F7FFFFF); 1288bbbf1280Sopenharmony_ci out[3] = 0; 1289bbbf1280Sopenharmony_ci out[2] |= random_sign; 1290bbbf1280Sopenharmony_ci } while (iszero(out)); /* rule out zero */ 1291bbbf1280Sopenharmony_ci} 1292bbbf1280Sopenharmony_ci 1293bbbf1280Sopenharmony_cistatic void rred_cases(uint32 *out, uint32 param1, 1294bbbf1280Sopenharmony_ci uint32 param2) { 1295bbbf1280Sopenharmony_ci do { 1296bbbf1280Sopenharmony_ci out[0] = ((0x3fc00000 + random_upto(0x036fffff)) | 1297bbbf1280Sopenharmony_ci (random_upto(1) << 31)); 1298bbbf1280Sopenharmony_ci out[1] = random_upto(0xFFFFFFFF); 1299bbbf1280Sopenharmony_ci } while (iszero(out)); /* rule out zero */ 1300bbbf1280Sopenharmony_ci} 1301bbbf1280Sopenharmony_ci 1302bbbf1280Sopenharmony_cistatic void rred_cases_float(uint32 *out, uint32 param1, 1303bbbf1280Sopenharmony_ci uint32 param2) { 1304bbbf1280Sopenharmony_ci do { 1305bbbf1280Sopenharmony_ci out[0] = ((0x3e000000 + random_upto(0x0cffffff)) | 1306bbbf1280Sopenharmony_ci (random_upto(1) << 31)); 1307bbbf1280Sopenharmony_ci out[1] = 0; /* for iszero */ 1308bbbf1280Sopenharmony_ci } while (iszero(out)); /* rule out zero */ 1309bbbf1280Sopenharmony_ci} 1310bbbf1280Sopenharmony_ci 1311bbbf1280Sopenharmony_cistatic void atan2_cases(uint32 *out, uint32 param1, 1312bbbf1280Sopenharmony_ci uint32 param2) { 1313bbbf1280Sopenharmony_ci do { 1314bbbf1280Sopenharmony_ci int expdiff = random_upto(101)-51; 1315bbbf1280Sopenharmony_ci int swap; 1316bbbf1280Sopenharmony_ci if (expdiff < 0) { 1317bbbf1280Sopenharmony_ci expdiff = -expdiff; 1318bbbf1280Sopenharmony_ci swap = 2; 1319bbbf1280Sopenharmony_ci } else 1320bbbf1280Sopenharmony_ci swap = 0; 1321bbbf1280Sopenharmony_ci out[swap ^ 0] = random_upto(0x7FEFFFFF-((expdiff+1)<<20)); 1322bbbf1280Sopenharmony_ci out[swap ^ 2] = random_upto(((expdiff+1)<<20)-1) + out[swap ^ 0]; 1323bbbf1280Sopenharmony_ci out[1] = random_upto(0xFFFFFFFF); 1324bbbf1280Sopenharmony_ci out[3] = random_upto(0xFFFFFFFF); 1325bbbf1280Sopenharmony_ci out[0] |= random_sign; 1326bbbf1280Sopenharmony_ci out[2] |= random_sign; 1327bbbf1280Sopenharmony_ci } while (iszero(out) || iszero(out+2));/* rule out zero */ 1328bbbf1280Sopenharmony_ci} 1329bbbf1280Sopenharmony_ci 1330bbbf1280Sopenharmony_cistatic void atan2_cases_float(uint32 *out, uint32 param1, 1331bbbf1280Sopenharmony_ci uint32 param2) { 1332bbbf1280Sopenharmony_ci do { 1333bbbf1280Sopenharmony_ci int expdiff = random_upto(44)-22; 1334bbbf1280Sopenharmony_ci int swap; 1335bbbf1280Sopenharmony_ci if (expdiff < 0) { 1336bbbf1280Sopenharmony_ci expdiff = -expdiff; 1337bbbf1280Sopenharmony_ci swap = 2; 1338bbbf1280Sopenharmony_ci } else 1339bbbf1280Sopenharmony_ci swap = 0; 1340bbbf1280Sopenharmony_ci out[swap ^ 0] = random_upto(0x7F7FFFFF-((expdiff+1)<<23)); 1341bbbf1280Sopenharmony_ci out[swap ^ 2] = random_upto(((expdiff+1)<<23)-1) + out[swap ^ 0]; 1342bbbf1280Sopenharmony_ci out[0] |= random_sign; 1343bbbf1280Sopenharmony_ci out[2] |= random_sign; 1344bbbf1280Sopenharmony_ci out[1] = out[3] = 0; /* for iszero */ 1345bbbf1280Sopenharmony_ci } while (iszero(out) || iszero(out+2));/* rule out zero */ 1346bbbf1280Sopenharmony_ci} 1347bbbf1280Sopenharmony_ci 1348bbbf1280Sopenharmony_cistatic void pow_cases(uint32 *out, uint32 param1, 1349bbbf1280Sopenharmony_ci uint32 param2) { 1350bbbf1280Sopenharmony_ci /* 1351bbbf1280Sopenharmony_ci * Pick an exponent e (-0x33 to +0x7FE) for x, and here's the 1352bbbf1280Sopenharmony_ci * range of numbers we can use as y: 1353bbbf1280Sopenharmony_ci * 1354bbbf1280Sopenharmony_ci * For e < 0x3FE, the range is [-0x400/(0x3FE-e),+0x432/(0x3FE-e)] 1355bbbf1280Sopenharmony_ci * For e > 0x3FF, the range is [-0x432/(e-0x3FF),+0x400/(e-0x3FF)] 1356bbbf1280Sopenharmony_ci * 1357bbbf1280Sopenharmony_ci * For e == 0x3FE or e == 0x3FF, the range gets infinite at one 1358bbbf1280Sopenharmony_ci * end or the other, so we have to be cleverer: pick a number n 1359bbbf1280Sopenharmony_ci * of useful bits in the mantissa (1 thru 52, so 1 must imply 1360bbbf1280Sopenharmony_ci * 0x3ff00000.00000001 whereas 52 is anything at least as big 1361bbbf1280Sopenharmony_ci * as 0x3ff80000.00000000; for e == 0x3fe, 1 necessarily means 1362bbbf1280Sopenharmony_ci * 0x3fefffff.ffffffff and 52 is anything at most as big as 1363bbbf1280Sopenharmony_ci * 0x3fe80000.00000000). Then, as it happens, a sensible 1364bbbf1280Sopenharmony_ci * maximum power is 2^(63-n) for e == 0x3fe, and 2^(62-n) for 1365bbbf1280Sopenharmony_ci * e == 0x3ff. 1366bbbf1280Sopenharmony_ci * 1367bbbf1280Sopenharmony_ci * We inevitably get some overflows in approximating the log 1368bbbf1280Sopenharmony_ci * curves by these nasty step functions, but that's all right - 1369bbbf1280Sopenharmony_ci * we do want _some_ overflows to be tested. 1370bbbf1280Sopenharmony_ci * 1371bbbf1280Sopenharmony_ci * Having got that, then, it's just a matter of inventing a 1372bbbf1280Sopenharmony_ci * probability distribution for all of this. 1373bbbf1280Sopenharmony_ci */ 1374bbbf1280Sopenharmony_ci int e, n; 1375bbbf1280Sopenharmony_ci uint32 dmin, dmax; 1376bbbf1280Sopenharmony_ci const uint32 pmin = 0x3e100000; 1377bbbf1280Sopenharmony_ci 1378bbbf1280Sopenharmony_ci /* 1379bbbf1280Sopenharmony_ci * Generate exponents in a slightly biased fashion. 1380bbbf1280Sopenharmony_ci */ 1381bbbf1280Sopenharmony_ci e = (random_upto(1) ? /* is exponent small or big? */ 1382bbbf1280Sopenharmony_ci 0x3FE - random_upto_biased(0x431,2) : /* small */ 1383bbbf1280Sopenharmony_ci 0x3FF + random_upto_biased(0x3FF,2)); /* big */ 1384bbbf1280Sopenharmony_ci 1385bbbf1280Sopenharmony_ci /* 1386bbbf1280Sopenharmony_ci * Now split into cases. 1387bbbf1280Sopenharmony_ci */ 1388bbbf1280Sopenharmony_ci if (e < 0x3FE || e > 0x3FF) { 1389bbbf1280Sopenharmony_ci uint32 imin, imax; 1390bbbf1280Sopenharmony_ci if (e < 0x3FE) 1391bbbf1280Sopenharmony_ci imin = 0x40000 / (0x3FE - e), imax = 0x43200 / (0x3FE - e); 1392bbbf1280Sopenharmony_ci else 1393bbbf1280Sopenharmony_ci imin = 0x43200 / (e - 0x3FF), imax = 0x40000 / (e - 0x3FF); 1394bbbf1280Sopenharmony_ci /* Power range runs from -imin to imax. Now convert to doubles */ 1395bbbf1280Sopenharmony_ci dmin = doubletop(imin, -8); 1396bbbf1280Sopenharmony_ci dmax = doubletop(imax, -8); 1397bbbf1280Sopenharmony_ci /* Compute the number of mantissa bits. */ 1398bbbf1280Sopenharmony_ci n = (e > 0 ? 53 : 52+e); 1399bbbf1280Sopenharmony_ci } else { 1400bbbf1280Sopenharmony_ci /* Critical exponents. Generate a top bit index. */ 1401bbbf1280Sopenharmony_ci n = 52 - random_upto_biased(51, 4); 1402bbbf1280Sopenharmony_ci if (e == 0x3FE) 1403bbbf1280Sopenharmony_ci dmax = 63 - n; 1404bbbf1280Sopenharmony_ci else 1405bbbf1280Sopenharmony_ci dmax = 62 - n; 1406bbbf1280Sopenharmony_ci dmax = (dmax << 20) + 0x3FF00000; 1407bbbf1280Sopenharmony_ci dmin = dmax; 1408bbbf1280Sopenharmony_ci } 1409bbbf1280Sopenharmony_ci /* Generate a mantissa. */ 1410bbbf1280Sopenharmony_ci if (n <= 32) { 1411bbbf1280Sopenharmony_ci out[0] = 0; 1412bbbf1280Sopenharmony_ci out[1] = random_upto((1 << (n-1)) - 1) + (1 << (n-1)); 1413bbbf1280Sopenharmony_ci } else if (n == 33) { 1414bbbf1280Sopenharmony_ci out[0] = 1; 1415bbbf1280Sopenharmony_ci out[1] = random_upto(0xFFFFFFFF); 1416bbbf1280Sopenharmony_ci } else if (n > 33) { 1417bbbf1280Sopenharmony_ci out[0] = random_upto((1 << (n-33)) - 1) + (1 << (n-33)); 1418bbbf1280Sopenharmony_ci out[1] = random_upto(0xFFFFFFFF); 1419bbbf1280Sopenharmony_ci } 1420bbbf1280Sopenharmony_ci /* Negate the mantissa if e == 0x3FE. */ 1421bbbf1280Sopenharmony_ci if (e == 0x3FE) { 1422bbbf1280Sopenharmony_ci out[1] = -out[1]; 1423bbbf1280Sopenharmony_ci out[0] = -out[0]; 1424bbbf1280Sopenharmony_ci if (out[1]) out[0]--; 1425bbbf1280Sopenharmony_ci } 1426bbbf1280Sopenharmony_ci /* Put the exponent on. */ 1427bbbf1280Sopenharmony_ci out[0] &= 0xFFFFF; 1428bbbf1280Sopenharmony_ci out[0] |= ((e > 0 ? e : 0) << 20); 1429bbbf1280Sopenharmony_ci /* Generate a power. Powers don't go below 2^-30. */ 1430bbbf1280Sopenharmony_ci if (random_upto(1)) { 1431bbbf1280Sopenharmony_ci /* Positive power */ 1432bbbf1280Sopenharmony_ci out[2] = dmax - random_upto_biased(dmax-pmin, 10); 1433bbbf1280Sopenharmony_ci } else { 1434bbbf1280Sopenharmony_ci /* Negative power */ 1435bbbf1280Sopenharmony_ci out[2] = (dmin - random_upto_biased(dmin-pmin, 10)) | 0x80000000; 1436bbbf1280Sopenharmony_ci } 1437bbbf1280Sopenharmony_ci out[3] = random_upto(0xFFFFFFFF); 1438bbbf1280Sopenharmony_ci} 1439bbbf1280Sopenharmony_cistatic void pow_cases_float(uint32 *out, uint32 param1, 1440bbbf1280Sopenharmony_ci uint32 param2) { 1441bbbf1280Sopenharmony_ci /* 1442bbbf1280Sopenharmony_ci * Pick an exponent e (-0x16 to +0xFE) for x, and here's the 1443bbbf1280Sopenharmony_ci * range of numbers we can use as y: 1444bbbf1280Sopenharmony_ci * 1445bbbf1280Sopenharmony_ci * For e < 0x7E, the range is [-0x80/(0x7E-e),+0x95/(0x7E-e)] 1446bbbf1280Sopenharmony_ci * For e > 0x7F, the range is [-0x95/(e-0x7F),+0x80/(e-0x7F)] 1447bbbf1280Sopenharmony_ci * 1448bbbf1280Sopenharmony_ci * For e == 0x7E or e == 0x7F, the range gets infinite at one 1449bbbf1280Sopenharmony_ci * end or the other, so we have to be cleverer: pick a number n 1450bbbf1280Sopenharmony_ci * of useful bits in the mantissa (1 thru 23, so 1 must imply 1451bbbf1280Sopenharmony_ci * 0x3f800001 whereas 23 is anything at least as big as 1452bbbf1280Sopenharmony_ci * 0x3fc00000; for e == 0x7e, 1 necessarily means 0x3f7fffff 1453bbbf1280Sopenharmony_ci * and 23 is anything at most as big as 0x3f400000). Then, as 1454bbbf1280Sopenharmony_ci * it happens, a sensible maximum power is 2^(31-n) for e == 1455bbbf1280Sopenharmony_ci * 0x7e, and 2^(30-n) for e == 0x7f. 1456bbbf1280Sopenharmony_ci * 1457bbbf1280Sopenharmony_ci * We inevitably get some overflows in approximating the log 1458bbbf1280Sopenharmony_ci * curves by these nasty step functions, but that's all right - 1459bbbf1280Sopenharmony_ci * we do want _some_ overflows to be tested. 1460bbbf1280Sopenharmony_ci * 1461bbbf1280Sopenharmony_ci * Having got that, then, it's just a matter of inventing a 1462bbbf1280Sopenharmony_ci * probability distribution for all of this. 1463bbbf1280Sopenharmony_ci */ 1464bbbf1280Sopenharmony_ci int e, n; 1465bbbf1280Sopenharmony_ci uint32 dmin, dmax; 1466bbbf1280Sopenharmony_ci const uint32 pmin = 0x38000000; 1467bbbf1280Sopenharmony_ci 1468bbbf1280Sopenharmony_ci /* 1469bbbf1280Sopenharmony_ci * Generate exponents in a slightly biased fashion. 1470bbbf1280Sopenharmony_ci */ 1471bbbf1280Sopenharmony_ci e = (random_upto(1) ? /* is exponent small or big? */ 1472bbbf1280Sopenharmony_ci 0x7E - random_upto_biased(0x94,2) : /* small */ 1473bbbf1280Sopenharmony_ci 0x7F + random_upto_biased(0x7f,2)); /* big */ 1474bbbf1280Sopenharmony_ci 1475bbbf1280Sopenharmony_ci /* 1476bbbf1280Sopenharmony_ci * Now split into cases. 1477bbbf1280Sopenharmony_ci */ 1478bbbf1280Sopenharmony_ci if (e < 0x7E || e > 0x7F) { 1479bbbf1280Sopenharmony_ci uint32 imin, imax; 1480bbbf1280Sopenharmony_ci if (e < 0x7E) 1481bbbf1280Sopenharmony_ci imin = 0x8000 / (0x7e - e), imax = 0x9500 / (0x7e - e); 1482bbbf1280Sopenharmony_ci else 1483bbbf1280Sopenharmony_ci imin = 0x9500 / (e - 0x7f), imax = 0x8000 / (e - 0x7f); 1484bbbf1280Sopenharmony_ci /* Power range runs from -imin to imax. Now convert to doubles */ 1485bbbf1280Sopenharmony_ci dmin = floatval(imin, -8); 1486bbbf1280Sopenharmony_ci dmax = floatval(imax, -8); 1487bbbf1280Sopenharmony_ci /* Compute the number of mantissa bits. */ 1488bbbf1280Sopenharmony_ci n = (e > 0 ? 24 : 23+e); 1489bbbf1280Sopenharmony_ci } else { 1490bbbf1280Sopenharmony_ci /* Critical exponents. Generate a top bit index. */ 1491bbbf1280Sopenharmony_ci n = 23 - random_upto_biased(22, 4); 1492bbbf1280Sopenharmony_ci if (e == 0x7E) 1493bbbf1280Sopenharmony_ci dmax = 31 - n; 1494bbbf1280Sopenharmony_ci else 1495bbbf1280Sopenharmony_ci dmax = 30 - n; 1496bbbf1280Sopenharmony_ci dmax = (dmax << 23) + 0x3F800000; 1497bbbf1280Sopenharmony_ci dmin = dmax; 1498bbbf1280Sopenharmony_ci } 1499bbbf1280Sopenharmony_ci /* Generate a mantissa. */ 1500bbbf1280Sopenharmony_ci out[0] = random_upto((1 << (n-1)) - 1) + (1 << (n-1)); 1501bbbf1280Sopenharmony_ci out[1] = 0; 1502bbbf1280Sopenharmony_ci /* Negate the mantissa if e == 0x7E. */ 1503bbbf1280Sopenharmony_ci if (e == 0x7E) { 1504bbbf1280Sopenharmony_ci out[0] = -out[0]; 1505bbbf1280Sopenharmony_ci } 1506bbbf1280Sopenharmony_ci /* Put the exponent on. */ 1507bbbf1280Sopenharmony_ci out[0] &= 0x7FFFFF; 1508bbbf1280Sopenharmony_ci out[0] |= ((e > 0 ? e : 0) << 23); 1509bbbf1280Sopenharmony_ci /* Generate a power. Powers don't go below 2^-15. */ 1510bbbf1280Sopenharmony_ci if (random_upto(1)) { 1511bbbf1280Sopenharmony_ci /* Positive power */ 1512bbbf1280Sopenharmony_ci out[2] = dmax - random_upto_biased(dmax-pmin, 10); 1513bbbf1280Sopenharmony_ci } else { 1514bbbf1280Sopenharmony_ci /* Negative power */ 1515bbbf1280Sopenharmony_ci out[2] = (dmin - random_upto_biased(dmin-pmin, 10)) | 0x80000000; 1516bbbf1280Sopenharmony_ci } 1517bbbf1280Sopenharmony_ci out[3] = 0; 1518bbbf1280Sopenharmony_ci} 1519bbbf1280Sopenharmony_ci 1520bbbf1280Sopenharmony_civoid vet_for_decline(Testable *fn, uint32 *args, uint32 *result, int got_errno_in) { 1521bbbf1280Sopenharmony_ci int declined = 0; 1522bbbf1280Sopenharmony_ci 1523bbbf1280Sopenharmony_ci switch (fn->type) { 1524bbbf1280Sopenharmony_ci case args1: 1525bbbf1280Sopenharmony_ci case rred: 1526bbbf1280Sopenharmony_ci case semi1: 1527bbbf1280Sopenharmony_ci case t_frexp: 1528bbbf1280Sopenharmony_ci case t_modf: 1529bbbf1280Sopenharmony_ci case classify: 1530bbbf1280Sopenharmony_ci case t_ldexp: 1531bbbf1280Sopenharmony_ci declined |= lib_fo && is_dhard(args+0); 1532bbbf1280Sopenharmony_ci break; 1533bbbf1280Sopenharmony_ci case args1f: 1534bbbf1280Sopenharmony_ci case rredf: 1535bbbf1280Sopenharmony_ci case semi1f: 1536bbbf1280Sopenharmony_ci case t_frexpf: 1537bbbf1280Sopenharmony_ci case t_modff: 1538bbbf1280Sopenharmony_ci case classifyf: 1539bbbf1280Sopenharmony_ci declined |= lib_fo && is_shard(args+0); 1540bbbf1280Sopenharmony_ci break; 1541bbbf1280Sopenharmony_ci case args2: 1542bbbf1280Sopenharmony_ci case semi2: 1543bbbf1280Sopenharmony_ci case args1c: 1544bbbf1280Sopenharmony_ci case args1cr: 1545bbbf1280Sopenharmony_ci case compare: 1546bbbf1280Sopenharmony_ci declined |= lib_fo && is_dhard(args+0); 1547bbbf1280Sopenharmony_ci declined |= lib_fo && is_dhard(args+2); 1548bbbf1280Sopenharmony_ci break; 1549bbbf1280Sopenharmony_ci case args2f: 1550bbbf1280Sopenharmony_ci case semi2f: 1551bbbf1280Sopenharmony_ci case t_ldexpf: 1552bbbf1280Sopenharmony_ci case comparef: 1553bbbf1280Sopenharmony_ci case args1fc: 1554bbbf1280Sopenharmony_ci case args1fcr: 1555bbbf1280Sopenharmony_ci declined |= lib_fo && is_shard(args+0); 1556bbbf1280Sopenharmony_ci declined |= lib_fo && is_shard(args+2); 1557bbbf1280Sopenharmony_ci break; 1558bbbf1280Sopenharmony_ci case args2c: 1559bbbf1280Sopenharmony_ci declined |= lib_fo && is_dhard(args+0); 1560bbbf1280Sopenharmony_ci declined |= lib_fo && is_dhard(args+2); 1561bbbf1280Sopenharmony_ci declined |= lib_fo && is_dhard(args+4); 1562bbbf1280Sopenharmony_ci declined |= lib_fo && is_dhard(args+6); 1563bbbf1280Sopenharmony_ci break; 1564bbbf1280Sopenharmony_ci case args2fc: 1565bbbf1280Sopenharmony_ci declined |= lib_fo && is_shard(args+0); 1566bbbf1280Sopenharmony_ci declined |= lib_fo && is_shard(args+2); 1567bbbf1280Sopenharmony_ci declined |= lib_fo && is_shard(args+4); 1568bbbf1280Sopenharmony_ci declined |= lib_fo && is_shard(args+6); 1569bbbf1280Sopenharmony_ci break; 1570bbbf1280Sopenharmony_ci } 1571bbbf1280Sopenharmony_ci 1572bbbf1280Sopenharmony_ci switch (fn->type) { 1573bbbf1280Sopenharmony_ci case args1: /* return an extra-precise result */ 1574bbbf1280Sopenharmony_ci case args2: 1575bbbf1280Sopenharmony_ci case rred: 1576bbbf1280Sopenharmony_ci case semi1: /* return a double result */ 1577bbbf1280Sopenharmony_ci case semi2: 1578bbbf1280Sopenharmony_ci case t_ldexp: 1579bbbf1280Sopenharmony_ci case t_frexp: /* return double * int */ 1580bbbf1280Sopenharmony_ci case args1cr: 1581bbbf1280Sopenharmony_ci declined |= lib_fo && is_dhard(result); 1582bbbf1280Sopenharmony_ci break; 1583bbbf1280Sopenharmony_ci case args1f: 1584bbbf1280Sopenharmony_ci case args2f: 1585bbbf1280Sopenharmony_ci case rredf: 1586bbbf1280Sopenharmony_ci case semi1f: 1587bbbf1280Sopenharmony_ci case semi2f: 1588bbbf1280Sopenharmony_ci case t_ldexpf: 1589bbbf1280Sopenharmony_ci case args1fcr: 1590bbbf1280Sopenharmony_ci declined |= lib_fo && is_shard(result); 1591bbbf1280Sopenharmony_ci break; 1592bbbf1280Sopenharmony_ci case t_modf: /* return double * double */ 1593bbbf1280Sopenharmony_ci declined |= lib_fo && is_dhard(result+0); 1594bbbf1280Sopenharmony_ci declined |= lib_fo && is_dhard(result+2); 1595bbbf1280Sopenharmony_ci break; 1596bbbf1280Sopenharmony_ci case t_modff: /* return float * float */ 1597bbbf1280Sopenharmony_ci declined |= lib_fo && is_shard(result+2); 1598bbbf1280Sopenharmony_ci /* fall through */ 1599bbbf1280Sopenharmony_ci case t_frexpf: /* return float * int */ 1600bbbf1280Sopenharmony_ci declined |= lib_fo && is_shard(result+0); 1601bbbf1280Sopenharmony_ci break; 1602bbbf1280Sopenharmony_ci case args1c: 1603bbbf1280Sopenharmony_ci case args2c: 1604bbbf1280Sopenharmony_ci declined |= lib_fo && is_dhard(result+0); 1605bbbf1280Sopenharmony_ci declined |= lib_fo && is_dhard(result+4); 1606bbbf1280Sopenharmony_ci break; 1607bbbf1280Sopenharmony_ci case args1fc: 1608bbbf1280Sopenharmony_ci case args2fc: 1609bbbf1280Sopenharmony_ci declined |= lib_fo && is_shard(result+0); 1610bbbf1280Sopenharmony_ci declined |= lib_fo && is_shard(result+4); 1611bbbf1280Sopenharmony_ci break; 1612bbbf1280Sopenharmony_ci } 1613bbbf1280Sopenharmony_ci 1614bbbf1280Sopenharmony_ci /* Expect basic arithmetic tests to be declined if the command 1615bbbf1280Sopenharmony_ci * line said that would happen */ 1616bbbf1280Sopenharmony_ci declined |= (lib_no_arith && (fn->func == (funcptr)mpc_add || 1617bbbf1280Sopenharmony_ci fn->func == (funcptr)mpc_sub || 1618bbbf1280Sopenharmony_ci fn->func == (funcptr)mpc_mul || 1619bbbf1280Sopenharmony_ci fn->func == (funcptr)mpc_div)); 1620bbbf1280Sopenharmony_ci 1621bbbf1280Sopenharmony_ci if (!declined) { 1622bbbf1280Sopenharmony_ci if (got_errno_in) 1623bbbf1280Sopenharmony_ci ntests++; 1624bbbf1280Sopenharmony_ci else 1625bbbf1280Sopenharmony_ci ntests += 3; 1626bbbf1280Sopenharmony_ci } 1627bbbf1280Sopenharmony_ci} 1628bbbf1280Sopenharmony_ci 1629bbbf1280Sopenharmony_civoid docase(Testable *fn, uint32 *args) { 1630bbbf1280Sopenharmony_ci uint32 result[8]; /* real part in first 4, imaginary part in last 4 */ 1631bbbf1280Sopenharmony_ci char *errstr = NULL; 1632bbbf1280Sopenharmony_ci mpfr_t a, b, r; 1633bbbf1280Sopenharmony_ci mpc_t ac, bc, rc; 1634bbbf1280Sopenharmony_ci int rejected, printextra; 1635bbbf1280Sopenharmony_ci wrapperctx ctx; 1636bbbf1280Sopenharmony_ci 1637bbbf1280Sopenharmony_ci mpfr_init2(a, MPFR_PREC); 1638bbbf1280Sopenharmony_ci mpfr_init2(b, MPFR_PREC); 1639bbbf1280Sopenharmony_ci mpfr_init2(r, MPFR_PREC); 1640bbbf1280Sopenharmony_ci mpc_init2(ac, MPFR_PREC); 1641bbbf1280Sopenharmony_ci mpc_init2(bc, MPFR_PREC); 1642bbbf1280Sopenharmony_ci mpc_init2(rc, MPFR_PREC); 1643bbbf1280Sopenharmony_ci 1644bbbf1280Sopenharmony_ci printf("func=%s", fn->name); 1645bbbf1280Sopenharmony_ci 1646bbbf1280Sopenharmony_ci rejected = 0; /* FIXME */ 1647bbbf1280Sopenharmony_ci 1648bbbf1280Sopenharmony_ci switch (fn->type) { 1649bbbf1280Sopenharmony_ci case args1: 1650bbbf1280Sopenharmony_ci case rred: 1651bbbf1280Sopenharmony_ci case semi1: 1652bbbf1280Sopenharmony_ci case t_frexp: 1653bbbf1280Sopenharmony_ci case t_modf: 1654bbbf1280Sopenharmony_ci case classify: 1655bbbf1280Sopenharmony_ci printf(" op1=%08x.%08x", args[0], args[1]); 1656bbbf1280Sopenharmony_ci break; 1657bbbf1280Sopenharmony_ci case args1f: 1658bbbf1280Sopenharmony_ci case rredf: 1659bbbf1280Sopenharmony_ci case semi1f: 1660bbbf1280Sopenharmony_ci case t_frexpf: 1661bbbf1280Sopenharmony_ci case t_modff: 1662bbbf1280Sopenharmony_ci case classifyf: 1663bbbf1280Sopenharmony_ci printf(" op1=%08x", args[0]); 1664bbbf1280Sopenharmony_ci break; 1665bbbf1280Sopenharmony_ci case args2: 1666bbbf1280Sopenharmony_ci case semi2: 1667bbbf1280Sopenharmony_ci case compare: 1668bbbf1280Sopenharmony_ci printf(" op1=%08x.%08x", args[0], args[1]); 1669bbbf1280Sopenharmony_ci printf(" op2=%08x.%08x", args[2], args[3]); 1670bbbf1280Sopenharmony_ci break; 1671bbbf1280Sopenharmony_ci case args2f: 1672bbbf1280Sopenharmony_ci case semi2f: 1673bbbf1280Sopenharmony_ci case t_ldexpf: 1674bbbf1280Sopenharmony_ci case comparef: 1675bbbf1280Sopenharmony_ci printf(" op1=%08x", args[0]); 1676bbbf1280Sopenharmony_ci printf(" op2=%08x", args[2]); 1677bbbf1280Sopenharmony_ci break; 1678bbbf1280Sopenharmony_ci case t_ldexp: 1679bbbf1280Sopenharmony_ci printf(" op1=%08x.%08x", args[0], args[1]); 1680bbbf1280Sopenharmony_ci printf(" op2=%08x", args[2]); 1681bbbf1280Sopenharmony_ci break; 1682bbbf1280Sopenharmony_ci case args1c: 1683bbbf1280Sopenharmony_ci case args1cr: 1684bbbf1280Sopenharmony_ci printf(" op1r=%08x.%08x", args[0], args[1]); 1685bbbf1280Sopenharmony_ci printf(" op1i=%08x.%08x", args[2], args[3]); 1686bbbf1280Sopenharmony_ci break; 1687bbbf1280Sopenharmony_ci case args2c: 1688bbbf1280Sopenharmony_ci printf(" op1r=%08x.%08x", args[0], args[1]); 1689bbbf1280Sopenharmony_ci printf(" op1i=%08x.%08x", args[2], args[3]); 1690bbbf1280Sopenharmony_ci printf(" op2r=%08x.%08x", args[4], args[5]); 1691bbbf1280Sopenharmony_ci printf(" op2i=%08x.%08x", args[6], args[7]); 1692bbbf1280Sopenharmony_ci break; 1693bbbf1280Sopenharmony_ci case args1fc: 1694bbbf1280Sopenharmony_ci case args1fcr: 1695bbbf1280Sopenharmony_ci printf(" op1r=%08x", args[0]); 1696bbbf1280Sopenharmony_ci printf(" op1i=%08x", args[2]); 1697bbbf1280Sopenharmony_ci break; 1698bbbf1280Sopenharmony_ci case args2fc: 1699bbbf1280Sopenharmony_ci printf(" op1r=%08x", args[0]); 1700bbbf1280Sopenharmony_ci printf(" op1i=%08x", args[2]); 1701bbbf1280Sopenharmony_ci printf(" op2r=%08x", args[4]); 1702bbbf1280Sopenharmony_ci printf(" op2i=%08x", args[6]); 1703bbbf1280Sopenharmony_ci break; 1704bbbf1280Sopenharmony_ci default: 1705bbbf1280Sopenharmony_ci fprintf(stderr, "internal inconsistency?!\n"); 1706bbbf1280Sopenharmony_ci abort(); 1707bbbf1280Sopenharmony_ci } 1708bbbf1280Sopenharmony_ci 1709bbbf1280Sopenharmony_ci if (rejected == 2) { 1710bbbf1280Sopenharmony_ci printf(" - test case rejected\n"); 1711bbbf1280Sopenharmony_ci goto cleanup; 1712bbbf1280Sopenharmony_ci } 1713bbbf1280Sopenharmony_ci 1714bbbf1280Sopenharmony_ci wrapper_init(&ctx); 1715bbbf1280Sopenharmony_ci 1716bbbf1280Sopenharmony_ci if (rejected == 0) { 1717bbbf1280Sopenharmony_ci switch (fn->type) { 1718bbbf1280Sopenharmony_ci case args1: 1719bbbf1280Sopenharmony_ci set_mpfr_d(a, args[0], args[1]); 1720bbbf1280Sopenharmony_ci wrapper_op_real(&ctx, a, 2, args); 1721bbbf1280Sopenharmony_ci ((testfunc1)(fn->func))(r, a, GMP_RNDN); 1722bbbf1280Sopenharmony_ci get_mpfr_d(r, &result[0], &result[1], &result[2]); 1723bbbf1280Sopenharmony_ci wrapper_result_real(&ctx, r, 2, result); 1724bbbf1280Sopenharmony_ci if (wrapper_run(&ctx, fn->wrappers)) 1725bbbf1280Sopenharmony_ci get_mpfr_d(r, &result[0], &result[1], &result[2]); 1726bbbf1280Sopenharmony_ci break; 1727bbbf1280Sopenharmony_ci case args1cr: 1728bbbf1280Sopenharmony_ci set_mpc_d(ac, args[0], args[1], args[2], args[3]); 1729bbbf1280Sopenharmony_ci wrapper_op_complex(&ctx, ac, 2, args); 1730bbbf1280Sopenharmony_ci ((testfunc1cr)(fn->func))(r, ac, GMP_RNDN); 1731bbbf1280Sopenharmony_ci get_mpfr_d(r, &result[0], &result[1], &result[2]); 1732bbbf1280Sopenharmony_ci wrapper_result_real(&ctx, r, 2, result); 1733bbbf1280Sopenharmony_ci if (wrapper_run(&ctx, fn->wrappers)) 1734bbbf1280Sopenharmony_ci get_mpfr_d(r, &result[0], &result[1], &result[2]); 1735bbbf1280Sopenharmony_ci break; 1736bbbf1280Sopenharmony_ci case args1f: 1737bbbf1280Sopenharmony_ci set_mpfr_f(a, args[0]); 1738bbbf1280Sopenharmony_ci wrapper_op_real(&ctx, a, 1, args); 1739bbbf1280Sopenharmony_ci ((testfunc1)(fn->func))(r, a, GMP_RNDN); 1740bbbf1280Sopenharmony_ci get_mpfr_f(r, &result[0], &result[1]); 1741bbbf1280Sopenharmony_ci wrapper_result_real(&ctx, r, 1, result); 1742bbbf1280Sopenharmony_ci if (wrapper_run(&ctx, fn->wrappers)) 1743bbbf1280Sopenharmony_ci get_mpfr_f(r, &result[0], &result[1]); 1744bbbf1280Sopenharmony_ci break; 1745bbbf1280Sopenharmony_ci case args1fcr: 1746bbbf1280Sopenharmony_ci set_mpc_f(ac, args[0], args[2]); 1747bbbf1280Sopenharmony_ci wrapper_op_complex(&ctx, ac, 1, args); 1748bbbf1280Sopenharmony_ci ((testfunc1cr)(fn->func))(r, ac, GMP_RNDN); 1749bbbf1280Sopenharmony_ci get_mpfr_f(r, &result[0], &result[1]); 1750bbbf1280Sopenharmony_ci wrapper_result_real(&ctx, r, 1, result); 1751bbbf1280Sopenharmony_ci if (wrapper_run(&ctx, fn->wrappers)) 1752bbbf1280Sopenharmony_ci get_mpfr_f(r, &result[0], &result[1]); 1753bbbf1280Sopenharmony_ci break; 1754bbbf1280Sopenharmony_ci case args2: 1755bbbf1280Sopenharmony_ci set_mpfr_d(a, args[0], args[1]); 1756bbbf1280Sopenharmony_ci wrapper_op_real(&ctx, a, 2, args); 1757bbbf1280Sopenharmony_ci set_mpfr_d(b, args[2], args[3]); 1758bbbf1280Sopenharmony_ci wrapper_op_real(&ctx, b, 2, args+2); 1759bbbf1280Sopenharmony_ci ((testfunc2)(fn->func))(r, a, b, GMP_RNDN); 1760bbbf1280Sopenharmony_ci get_mpfr_d(r, &result[0], &result[1], &result[2]); 1761bbbf1280Sopenharmony_ci wrapper_result_real(&ctx, r, 2, result); 1762bbbf1280Sopenharmony_ci if (wrapper_run(&ctx, fn->wrappers)) 1763bbbf1280Sopenharmony_ci get_mpfr_d(r, &result[0], &result[1], &result[2]); 1764bbbf1280Sopenharmony_ci break; 1765bbbf1280Sopenharmony_ci case args2f: 1766bbbf1280Sopenharmony_ci set_mpfr_f(a, args[0]); 1767bbbf1280Sopenharmony_ci wrapper_op_real(&ctx, a, 1, args); 1768bbbf1280Sopenharmony_ci set_mpfr_f(b, args[2]); 1769bbbf1280Sopenharmony_ci wrapper_op_real(&ctx, b, 1, args+2); 1770bbbf1280Sopenharmony_ci ((testfunc2)(fn->func))(r, a, b, GMP_RNDN); 1771bbbf1280Sopenharmony_ci get_mpfr_f(r, &result[0], &result[1]); 1772bbbf1280Sopenharmony_ci wrapper_result_real(&ctx, r, 1, result); 1773bbbf1280Sopenharmony_ci if (wrapper_run(&ctx, fn->wrappers)) 1774bbbf1280Sopenharmony_ci get_mpfr_f(r, &result[0], &result[1]); 1775bbbf1280Sopenharmony_ci break; 1776bbbf1280Sopenharmony_ci case rred: 1777bbbf1280Sopenharmony_ci set_mpfr_d(a, args[0], args[1]); 1778bbbf1280Sopenharmony_ci wrapper_op_real(&ctx, a, 2, args); 1779bbbf1280Sopenharmony_ci ((testrred)(fn->func))(r, a, (int *)&result[3]); 1780bbbf1280Sopenharmony_ci get_mpfr_d(r, &result[0], &result[1], &result[2]); 1781bbbf1280Sopenharmony_ci wrapper_result_real(&ctx, r, 2, result); 1782bbbf1280Sopenharmony_ci /* We never need to mess about with the integer auxiliary 1783bbbf1280Sopenharmony_ci * output. */ 1784bbbf1280Sopenharmony_ci if (wrapper_run(&ctx, fn->wrappers)) 1785bbbf1280Sopenharmony_ci get_mpfr_d(r, &result[0], &result[1], &result[2]); 1786bbbf1280Sopenharmony_ci break; 1787bbbf1280Sopenharmony_ci case rredf: 1788bbbf1280Sopenharmony_ci set_mpfr_f(a, args[0]); 1789bbbf1280Sopenharmony_ci wrapper_op_real(&ctx, a, 1, args); 1790bbbf1280Sopenharmony_ci ((testrred)(fn->func))(r, a, (int *)&result[3]); 1791bbbf1280Sopenharmony_ci get_mpfr_f(r, &result[0], &result[1]); 1792bbbf1280Sopenharmony_ci wrapper_result_real(&ctx, r, 1, result); 1793bbbf1280Sopenharmony_ci /* We never need to mess about with the integer auxiliary 1794bbbf1280Sopenharmony_ci * output. */ 1795bbbf1280Sopenharmony_ci if (wrapper_run(&ctx, fn->wrappers)) 1796bbbf1280Sopenharmony_ci get_mpfr_f(r, &result[0], &result[1]); 1797bbbf1280Sopenharmony_ci break; 1798bbbf1280Sopenharmony_ci case semi1: 1799bbbf1280Sopenharmony_ci case semi1f: 1800bbbf1280Sopenharmony_ci errstr = ((testsemi1)(fn->func))(args, result); 1801bbbf1280Sopenharmony_ci break; 1802bbbf1280Sopenharmony_ci case semi2: 1803bbbf1280Sopenharmony_ci case compare: 1804bbbf1280Sopenharmony_ci errstr = ((testsemi2)(fn->func))(args, args+2, result); 1805bbbf1280Sopenharmony_ci break; 1806bbbf1280Sopenharmony_ci case semi2f: 1807bbbf1280Sopenharmony_ci case comparef: 1808bbbf1280Sopenharmony_ci case t_ldexpf: 1809bbbf1280Sopenharmony_ci errstr = ((testsemi2f)(fn->func))(args, args+2, result); 1810bbbf1280Sopenharmony_ci break; 1811bbbf1280Sopenharmony_ci case t_ldexp: 1812bbbf1280Sopenharmony_ci errstr = ((testldexp)(fn->func))(args, args+2, result); 1813bbbf1280Sopenharmony_ci break; 1814bbbf1280Sopenharmony_ci case t_frexp: 1815bbbf1280Sopenharmony_ci errstr = ((testfrexp)(fn->func))(args, result, result+2); 1816bbbf1280Sopenharmony_ci break; 1817bbbf1280Sopenharmony_ci case t_frexpf: 1818bbbf1280Sopenharmony_ci errstr = ((testfrexp)(fn->func))(args, result, result+2); 1819bbbf1280Sopenharmony_ci break; 1820bbbf1280Sopenharmony_ci case t_modf: 1821bbbf1280Sopenharmony_ci errstr = ((testmodf)(fn->func))(args, result, result+2); 1822bbbf1280Sopenharmony_ci break; 1823bbbf1280Sopenharmony_ci case t_modff: 1824bbbf1280Sopenharmony_ci errstr = ((testmodf)(fn->func))(args, result, result+2); 1825bbbf1280Sopenharmony_ci break; 1826bbbf1280Sopenharmony_ci case classify: 1827bbbf1280Sopenharmony_ci errstr = ((testclassify)(fn->func))(args, &result[0]); 1828bbbf1280Sopenharmony_ci break; 1829bbbf1280Sopenharmony_ci case classifyf: 1830bbbf1280Sopenharmony_ci errstr = ((testclassifyf)(fn->func))(args, &result[0]); 1831bbbf1280Sopenharmony_ci break; 1832bbbf1280Sopenharmony_ci case args1c: 1833bbbf1280Sopenharmony_ci set_mpc_d(ac, args[0], args[1], args[2], args[3]); 1834bbbf1280Sopenharmony_ci wrapper_op_complex(&ctx, ac, 2, args); 1835bbbf1280Sopenharmony_ci ((testfunc1c)(fn->func))(rc, ac, MPC_RNDNN); 1836bbbf1280Sopenharmony_ci get_mpc_d(rc, &result[0], &result[1], &result[2], &result[4], &result[5], &result[6]); 1837bbbf1280Sopenharmony_ci wrapper_result_complex(&ctx, rc, 2, result); 1838bbbf1280Sopenharmony_ci if (wrapper_run(&ctx, fn->wrappers)) 1839bbbf1280Sopenharmony_ci get_mpc_d(rc, &result[0], &result[1], &result[2], &result[4], &result[5], &result[6]); 1840bbbf1280Sopenharmony_ci break; 1841bbbf1280Sopenharmony_ci case args2c: 1842bbbf1280Sopenharmony_ci set_mpc_d(ac, args[0], args[1], args[2], args[3]); 1843bbbf1280Sopenharmony_ci wrapper_op_complex(&ctx, ac, 2, args); 1844bbbf1280Sopenharmony_ci set_mpc_d(bc, args[4], args[5], args[6], args[7]); 1845bbbf1280Sopenharmony_ci wrapper_op_complex(&ctx, bc, 2, args+4); 1846bbbf1280Sopenharmony_ci ((testfunc2c)(fn->func))(rc, ac, bc, MPC_RNDNN); 1847bbbf1280Sopenharmony_ci get_mpc_d(rc, &result[0], &result[1], &result[2], &result[4], &result[5], &result[6]); 1848bbbf1280Sopenharmony_ci wrapper_result_complex(&ctx, rc, 2, result); 1849bbbf1280Sopenharmony_ci if (wrapper_run(&ctx, fn->wrappers)) 1850bbbf1280Sopenharmony_ci get_mpc_d(rc, &result[0], &result[1], &result[2], &result[4], &result[5], &result[6]); 1851bbbf1280Sopenharmony_ci break; 1852bbbf1280Sopenharmony_ci case args1fc: 1853bbbf1280Sopenharmony_ci set_mpc_f(ac, args[0], args[2]); 1854bbbf1280Sopenharmony_ci wrapper_op_complex(&ctx, ac, 1, args); 1855bbbf1280Sopenharmony_ci ((testfunc1c)(fn->func))(rc, ac, MPC_RNDNN); 1856bbbf1280Sopenharmony_ci get_mpc_f(rc, &result[0], &result[1], &result[4], &result[5]); 1857bbbf1280Sopenharmony_ci wrapper_result_complex(&ctx, rc, 1, result); 1858bbbf1280Sopenharmony_ci if (wrapper_run(&ctx, fn->wrappers)) 1859bbbf1280Sopenharmony_ci get_mpc_f(rc, &result[0], &result[1], &result[4], &result[5]); 1860bbbf1280Sopenharmony_ci break; 1861bbbf1280Sopenharmony_ci case args2fc: 1862bbbf1280Sopenharmony_ci set_mpc_f(ac, args[0], args[2]); 1863bbbf1280Sopenharmony_ci wrapper_op_complex(&ctx, ac, 1, args); 1864bbbf1280Sopenharmony_ci set_mpc_f(bc, args[4], args[6]); 1865bbbf1280Sopenharmony_ci wrapper_op_complex(&ctx, bc, 1, args+4); 1866bbbf1280Sopenharmony_ci ((testfunc2c)(fn->func))(rc, ac, bc, MPC_RNDNN); 1867bbbf1280Sopenharmony_ci get_mpc_f(rc, &result[0], &result[1], &result[4], &result[5]); 1868bbbf1280Sopenharmony_ci wrapper_result_complex(&ctx, rc, 1, result); 1869bbbf1280Sopenharmony_ci if (wrapper_run(&ctx, fn->wrappers)) 1870bbbf1280Sopenharmony_ci get_mpc_f(rc, &result[0], &result[1], &result[4], &result[5]); 1871bbbf1280Sopenharmony_ci break; 1872bbbf1280Sopenharmony_ci default: 1873bbbf1280Sopenharmony_ci fprintf(stderr, "internal inconsistency?!\n"); 1874bbbf1280Sopenharmony_ci abort(); 1875bbbf1280Sopenharmony_ci } 1876bbbf1280Sopenharmony_ci } 1877bbbf1280Sopenharmony_ci 1878bbbf1280Sopenharmony_ci switch (fn->type) { 1879bbbf1280Sopenharmony_ci case args1: /* return an extra-precise result */ 1880bbbf1280Sopenharmony_ci case args2: 1881bbbf1280Sopenharmony_ci case args1cr: 1882bbbf1280Sopenharmony_ci case rred: 1883bbbf1280Sopenharmony_ci printextra = 1; 1884bbbf1280Sopenharmony_ci if (rejected == 0) { 1885bbbf1280Sopenharmony_ci errstr = NULL; 1886bbbf1280Sopenharmony_ci if (!mpfr_zero_p(a)) { 1887bbbf1280Sopenharmony_ci if ((result[0] & 0x7FFFFFFF) == 0 && result[1] == 0) { 1888bbbf1280Sopenharmony_ci /* 1889bbbf1280Sopenharmony_ci * If the output is +0 or -0 apart from the extra 1890bbbf1280Sopenharmony_ci * precision in result[2], then there's a tricky 1891bbbf1280Sopenharmony_ci * judgment call about what we require in the 1892bbbf1280Sopenharmony_ci * output. If we output the extra bits and set 1893bbbf1280Sopenharmony_ci * errstr="?underflow" then mathtest will tolerate 1894bbbf1280Sopenharmony_ci * the function under test rounding down to zero 1895bbbf1280Sopenharmony_ci * _or_ up to the minimum denormal; whereas if we 1896bbbf1280Sopenharmony_ci * suppress the extra bits and set 1897bbbf1280Sopenharmony_ci * errstr="underflow", then mathtest will enforce 1898bbbf1280Sopenharmony_ci * that the function really does underflow to zero. 1899bbbf1280Sopenharmony_ci * 1900bbbf1280Sopenharmony_ci * But where to draw the line? It seems clear to 1901bbbf1280Sopenharmony_ci * me that numbers along the lines of 1902bbbf1280Sopenharmony_ci * 00000000.00000000.7ff should be treated 1903bbbf1280Sopenharmony_ci * similarly to 00000000.00000000.801, but on the 1904bbbf1280Sopenharmony_ci * other hand, we must surely be prepared to 1905bbbf1280Sopenharmony_ci * enforce a genuine underflow-to-zero in _some_ 1906bbbf1280Sopenharmony_ci * case where the true mathematical output is 1907bbbf1280Sopenharmony_ci * nonzero but absurdly tiny. 1908bbbf1280Sopenharmony_ci * 1909bbbf1280Sopenharmony_ci * I think a reasonable place to draw the 1910bbbf1280Sopenharmony_ci * distinction is at 00000000.00000000.400, i.e. 1911bbbf1280Sopenharmony_ci * one quarter of the minimum positive denormal. 1912bbbf1280Sopenharmony_ci * If a value less than that rounds up to the 1913bbbf1280Sopenharmony_ci * minimum denormal, that must mean the function 1914bbbf1280Sopenharmony_ci * under test has managed to make an error of an 1915bbbf1280Sopenharmony_ci * entire factor of two, and that's something we 1916bbbf1280Sopenharmony_ci * should fix. Above that, you can misround within 1917bbbf1280Sopenharmony_ci * the limits of your accuracy bound if you have 1918bbbf1280Sopenharmony_ci * to. 1919bbbf1280Sopenharmony_ci */ 1920bbbf1280Sopenharmony_ci if (result[2] < 0x40000000) { 1921bbbf1280Sopenharmony_ci /* Total underflow (ERANGE + UFL) is required, 1922bbbf1280Sopenharmony_ci * and we suppress the extra bits to make 1923bbbf1280Sopenharmony_ci * mathtest enforce that the output is really 1924bbbf1280Sopenharmony_ci * zero. */ 1925bbbf1280Sopenharmony_ci errstr = "underflow"; 1926bbbf1280Sopenharmony_ci printextra = 0; 1927bbbf1280Sopenharmony_ci } else { 1928bbbf1280Sopenharmony_ci /* Total underflow is not required, but if the 1929bbbf1280Sopenharmony_ci * function rounds down to zero anyway, then 1930bbbf1280Sopenharmony_ci * we should be prepared to tolerate it. */ 1931bbbf1280Sopenharmony_ci errstr = "?underflow"; 1932bbbf1280Sopenharmony_ci } 1933bbbf1280Sopenharmony_ci } else if (!(result[0] & 0x7ff00000)) { 1934bbbf1280Sopenharmony_ci /* 1935bbbf1280Sopenharmony_ci * If the output is denormal, we usually expect a 1936bbbf1280Sopenharmony_ci * UFL exception, warning the user of partial 1937bbbf1280Sopenharmony_ci * underflow. The exception is if the denormal 1938bbbf1280Sopenharmony_ci * being returned is just one of the input values, 1939bbbf1280Sopenharmony_ci * unchanged even in principle. I bodgily handle 1940bbbf1280Sopenharmony_ci * this by just special-casing the functions in 1941bbbf1280Sopenharmony_ci * question below. 1942bbbf1280Sopenharmony_ci */ 1943bbbf1280Sopenharmony_ci if (!strcmp(fn->name, "fmax") || 1944bbbf1280Sopenharmony_ci !strcmp(fn->name, "fmin") || 1945bbbf1280Sopenharmony_ci !strcmp(fn->name, "creal") || 1946bbbf1280Sopenharmony_ci !strcmp(fn->name, "cimag")) { 1947bbbf1280Sopenharmony_ci /* no error expected */ 1948bbbf1280Sopenharmony_ci } else { 1949bbbf1280Sopenharmony_ci errstr = "u"; 1950bbbf1280Sopenharmony_ci } 1951bbbf1280Sopenharmony_ci } else if ((result[0] & 0x7FFFFFFF) > 0x7FEFFFFF) { 1952bbbf1280Sopenharmony_ci /* 1953bbbf1280Sopenharmony_ci * Infinite results are usually due to overflow, 1954bbbf1280Sopenharmony_ci * but one exception is lgamma of a negative 1955bbbf1280Sopenharmony_ci * integer. 1956bbbf1280Sopenharmony_ci */ 1957bbbf1280Sopenharmony_ci if (!strcmp(fn->name, "lgamma") && 1958bbbf1280Sopenharmony_ci (args[0] & 0x80000000) != 0 && /* negative */ 1959bbbf1280Sopenharmony_ci is_dinteger(args)) { 1960bbbf1280Sopenharmony_ci errstr = "ERANGE status=z"; 1961bbbf1280Sopenharmony_ci } else { 1962bbbf1280Sopenharmony_ci errstr = "overflow"; 1963bbbf1280Sopenharmony_ci } 1964bbbf1280Sopenharmony_ci printextra = 0; 1965bbbf1280Sopenharmony_ci } 1966bbbf1280Sopenharmony_ci } else { 1967bbbf1280Sopenharmony_ci /* lgamma(0) is also a pole. */ 1968bbbf1280Sopenharmony_ci if (!strcmp(fn->name, "lgamma")) { 1969bbbf1280Sopenharmony_ci errstr = "ERANGE status=z"; 1970bbbf1280Sopenharmony_ci printextra = 0; 1971bbbf1280Sopenharmony_ci } 1972bbbf1280Sopenharmony_ci } 1973bbbf1280Sopenharmony_ci } 1974bbbf1280Sopenharmony_ci 1975bbbf1280Sopenharmony_ci if (!printextra || (rejected && !(rejected==1 && result[2]!=0))) { 1976bbbf1280Sopenharmony_ci printf(" result=%08x.%08x", 1977bbbf1280Sopenharmony_ci result[0], result[1]); 1978bbbf1280Sopenharmony_ci } else { 1979bbbf1280Sopenharmony_ci printf(" result=%08x.%08x.%03x", 1980bbbf1280Sopenharmony_ci result[0], result[1], (result[2] >> 20) & 0xFFF); 1981bbbf1280Sopenharmony_ci } 1982bbbf1280Sopenharmony_ci if (fn->type == rred) { 1983bbbf1280Sopenharmony_ci printf(" res2=%08x", result[3]); 1984bbbf1280Sopenharmony_ci } 1985bbbf1280Sopenharmony_ci break; 1986bbbf1280Sopenharmony_ci case args1f: 1987bbbf1280Sopenharmony_ci case args2f: 1988bbbf1280Sopenharmony_ci case args1fcr: 1989bbbf1280Sopenharmony_ci case rredf: 1990bbbf1280Sopenharmony_ci printextra = 1; 1991bbbf1280Sopenharmony_ci if (rejected == 0) { 1992bbbf1280Sopenharmony_ci errstr = NULL; 1993bbbf1280Sopenharmony_ci if (!mpfr_zero_p(a)) { 1994bbbf1280Sopenharmony_ci if ((result[0] & 0x7FFFFFFF) == 0) { 1995bbbf1280Sopenharmony_ci /* 1996bbbf1280Sopenharmony_ci * Decide whether to print the extra bits based on 1997bbbf1280Sopenharmony_ci * just how close to zero the number is. See the 1998bbbf1280Sopenharmony_ci * big comment in the double-precision case for 1999bbbf1280Sopenharmony_ci * discussion. 2000bbbf1280Sopenharmony_ci */ 2001bbbf1280Sopenharmony_ci if (result[1] < 0x40000000) { 2002bbbf1280Sopenharmony_ci errstr = "underflow"; 2003bbbf1280Sopenharmony_ci printextra = 0; 2004bbbf1280Sopenharmony_ci } else { 2005bbbf1280Sopenharmony_ci errstr = "?underflow"; 2006bbbf1280Sopenharmony_ci } 2007bbbf1280Sopenharmony_ci } else if (!(result[0] & 0x7f800000)) { 2008bbbf1280Sopenharmony_ci /* 2009bbbf1280Sopenharmony_ci * Functions which do not report partial overflow 2010bbbf1280Sopenharmony_ci * are listed here as special cases. (See the 2011bbbf1280Sopenharmony_ci * corresponding double case above for a fuller 2012bbbf1280Sopenharmony_ci * comment.) 2013bbbf1280Sopenharmony_ci */ 2014bbbf1280Sopenharmony_ci if (!strcmp(fn->name, "fmaxf") || 2015bbbf1280Sopenharmony_ci !strcmp(fn->name, "fminf") || 2016bbbf1280Sopenharmony_ci !strcmp(fn->name, "crealf") || 2017bbbf1280Sopenharmony_ci !strcmp(fn->name, "cimagf")) { 2018bbbf1280Sopenharmony_ci /* no error expected */ 2019bbbf1280Sopenharmony_ci } else { 2020bbbf1280Sopenharmony_ci errstr = "u"; 2021bbbf1280Sopenharmony_ci } 2022bbbf1280Sopenharmony_ci } else if ((result[0] & 0x7FFFFFFF) > 0x7F7FFFFF) { 2023bbbf1280Sopenharmony_ci /* 2024bbbf1280Sopenharmony_ci * Infinite results are usually due to overflow, 2025bbbf1280Sopenharmony_ci * but one exception is lgamma of a negative 2026bbbf1280Sopenharmony_ci * integer. 2027bbbf1280Sopenharmony_ci */ 2028bbbf1280Sopenharmony_ci if (!strcmp(fn->name, "lgammaf") && 2029bbbf1280Sopenharmony_ci (args[0] & 0x80000000) != 0 && /* negative */ 2030bbbf1280Sopenharmony_ci is_sinteger(args)) { 2031bbbf1280Sopenharmony_ci errstr = "ERANGE status=z"; 2032bbbf1280Sopenharmony_ci } else { 2033bbbf1280Sopenharmony_ci errstr = "overflow"; 2034bbbf1280Sopenharmony_ci } 2035bbbf1280Sopenharmony_ci printextra = 0; 2036bbbf1280Sopenharmony_ci } 2037bbbf1280Sopenharmony_ci } else { 2038bbbf1280Sopenharmony_ci /* lgamma(0) is also a pole. */ 2039bbbf1280Sopenharmony_ci if (!strcmp(fn->name, "lgammaf")) { 2040bbbf1280Sopenharmony_ci errstr = "ERANGE status=z"; 2041bbbf1280Sopenharmony_ci printextra = 0; 2042bbbf1280Sopenharmony_ci } 2043bbbf1280Sopenharmony_ci } 2044bbbf1280Sopenharmony_ci } 2045bbbf1280Sopenharmony_ci 2046bbbf1280Sopenharmony_ci if (!printextra || (rejected && !(rejected==1 && result[1]!=0))) { 2047bbbf1280Sopenharmony_ci printf(" result=%08x", 2048bbbf1280Sopenharmony_ci result[0]); 2049bbbf1280Sopenharmony_ci } else { 2050bbbf1280Sopenharmony_ci printf(" result=%08x.%03x", 2051bbbf1280Sopenharmony_ci result[0], (result[1] >> 20) & 0xFFF); 2052bbbf1280Sopenharmony_ci } 2053bbbf1280Sopenharmony_ci if (fn->type == rredf) { 2054bbbf1280Sopenharmony_ci printf(" res2=%08x", result[3]); 2055bbbf1280Sopenharmony_ci } 2056bbbf1280Sopenharmony_ci break; 2057bbbf1280Sopenharmony_ci case semi1: /* return a double result */ 2058bbbf1280Sopenharmony_ci case semi2: 2059bbbf1280Sopenharmony_ci case t_ldexp: 2060bbbf1280Sopenharmony_ci printf(" result=%08x.%08x", result[0], result[1]); 2061bbbf1280Sopenharmony_ci break; 2062bbbf1280Sopenharmony_ci case semi1f: 2063bbbf1280Sopenharmony_ci case semi2f: 2064bbbf1280Sopenharmony_ci case t_ldexpf: 2065bbbf1280Sopenharmony_ci printf(" result=%08x", result[0]); 2066bbbf1280Sopenharmony_ci break; 2067bbbf1280Sopenharmony_ci case t_frexp: /* return double * int */ 2068bbbf1280Sopenharmony_ci printf(" result=%08x.%08x res2=%08x", result[0], result[1], 2069bbbf1280Sopenharmony_ci result[2]); 2070bbbf1280Sopenharmony_ci break; 2071bbbf1280Sopenharmony_ci case t_modf: /* return double * double */ 2072bbbf1280Sopenharmony_ci printf(" result=%08x.%08x res2=%08x.%08x", 2073bbbf1280Sopenharmony_ci result[0], result[1], result[2], result[3]); 2074bbbf1280Sopenharmony_ci break; 2075bbbf1280Sopenharmony_ci case t_modff: /* return float * float */ 2076bbbf1280Sopenharmony_ci /* fall through */ 2077bbbf1280Sopenharmony_ci case t_frexpf: /* return float * int */ 2078bbbf1280Sopenharmony_ci printf(" result=%08x res2=%08x", result[0], result[2]); 2079bbbf1280Sopenharmony_ci break; 2080bbbf1280Sopenharmony_ci case classify: 2081bbbf1280Sopenharmony_ci case classifyf: 2082bbbf1280Sopenharmony_ci case compare: 2083bbbf1280Sopenharmony_ci case comparef: 2084bbbf1280Sopenharmony_ci printf(" result=%x", result[0]); 2085bbbf1280Sopenharmony_ci break; 2086bbbf1280Sopenharmony_ci case args1c: 2087bbbf1280Sopenharmony_ci case args2c: 2088bbbf1280Sopenharmony_ci if (0/* errstr */) { 2089bbbf1280Sopenharmony_ci printf(" resultr=%08x.%08x", result[0], result[1]); 2090bbbf1280Sopenharmony_ci printf(" resulti=%08x.%08x", result[4], result[5]); 2091bbbf1280Sopenharmony_ci } else { 2092bbbf1280Sopenharmony_ci printf(" resultr=%08x.%08x.%03x", 2093bbbf1280Sopenharmony_ci result[0], result[1], (result[2] >> 20) & 0xFFF); 2094bbbf1280Sopenharmony_ci printf(" resulti=%08x.%08x.%03x", 2095bbbf1280Sopenharmony_ci result[4], result[5], (result[6] >> 20) & 0xFFF); 2096bbbf1280Sopenharmony_ci } 2097bbbf1280Sopenharmony_ci /* Underflow behaviour doesn't seem to be specified for complex arithmetic */ 2098bbbf1280Sopenharmony_ci errstr = "?underflow"; 2099bbbf1280Sopenharmony_ci break; 2100bbbf1280Sopenharmony_ci case args1fc: 2101bbbf1280Sopenharmony_ci case args2fc: 2102bbbf1280Sopenharmony_ci if (0/* errstr */) { 2103bbbf1280Sopenharmony_ci printf(" resultr=%08x", result[0]); 2104bbbf1280Sopenharmony_ci printf(" resulti=%08x", result[4]); 2105bbbf1280Sopenharmony_ci } else { 2106bbbf1280Sopenharmony_ci printf(" resultr=%08x.%03x", 2107bbbf1280Sopenharmony_ci result[0], (result[1] >> 20) & 0xFFF); 2108bbbf1280Sopenharmony_ci printf(" resulti=%08x.%03x", 2109bbbf1280Sopenharmony_ci result[4], (result[5] >> 20) & 0xFFF); 2110bbbf1280Sopenharmony_ci } 2111bbbf1280Sopenharmony_ci /* Underflow behaviour doesn't seem to be specified for complex arithmetic */ 2112bbbf1280Sopenharmony_ci errstr = "?underflow"; 2113bbbf1280Sopenharmony_ci break; 2114bbbf1280Sopenharmony_ci } 2115bbbf1280Sopenharmony_ci 2116bbbf1280Sopenharmony_ci if (errstr && *(errstr+1) == '\0') { 2117bbbf1280Sopenharmony_ci printf(" errno=0 status=%c",*errstr); 2118bbbf1280Sopenharmony_ci } else if (errstr && *errstr == '?') { 2119bbbf1280Sopenharmony_ci printf(" maybeerror=%s", errstr+1); 2120bbbf1280Sopenharmony_ci } else if (errstr && errstr[0] == 'E') { 2121bbbf1280Sopenharmony_ci printf(" errno=%s", errstr); 2122bbbf1280Sopenharmony_ci } else { 2123bbbf1280Sopenharmony_ci printf(" error=%s", errstr && *errstr ? errstr : "0"); 2124bbbf1280Sopenharmony_ci } 2125bbbf1280Sopenharmony_ci 2126bbbf1280Sopenharmony_ci printf("\n"); 2127bbbf1280Sopenharmony_ci 2128bbbf1280Sopenharmony_ci vet_for_decline(fn, args, result, 0); 2129bbbf1280Sopenharmony_ci 2130bbbf1280Sopenharmony_ci cleanup: 2131bbbf1280Sopenharmony_ci mpfr_clear(a); 2132bbbf1280Sopenharmony_ci mpfr_clear(b); 2133bbbf1280Sopenharmony_ci mpfr_clear(r); 2134bbbf1280Sopenharmony_ci mpc_clear(ac); 2135bbbf1280Sopenharmony_ci mpc_clear(bc); 2136bbbf1280Sopenharmony_ci mpc_clear(rc); 2137bbbf1280Sopenharmony_ci} 2138bbbf1280Sopenharmony_ci 2139bbbf1280Sopenharmony_civoid gencases(Testable *fn, int number) { 2140bbbf1280Sopenharmony_ci int i; 2141bbbf1280Sopenharmony_ci uint32 args[8]; 2142bbbf1280Sopenharmony_ci 2143bbbf1280Sopenharmony_ci float32_case(NULL); 2144bbbf1280Sopenharmony_ci float64_case(NULL); 2145bbbf1280Sopenharmony_ci 2146bbbf1280Sopenharmony_ci printf("random=on\n"); /* signal to runtests.pl that the following tests are randomly generated */ 2147bbbf1280Sopenharmony_ci for (i = 0; i < number; i++) { 2148bbbf1280Sopenharmony_ci /* generate test point */ 2149bbbf1280Sopenharmony_ci fn->cases(args, fn->caseparam1, fn->caseparam2); 2150bbbf1280Sopenharmony_ci docase(fn, args); 2151bbbf1280Sopenharmony_ci } 2152bbbf1280Sopenharmony_ci printf("random=off\n"); 2153bbbf1280Sopenharmony_ci} 2154bbbf1280Sopenharmony_ci 2155bbbf1280Sopenharmony_cistatic uint32 doubletop(int x, int scale) { 2156bbbf1280Sopenharmony_ci int e = 0x412 + scale; 2157bbbf1280Sopenharmony_ci while (!(x & 0x100000)) 2158bbbf1280Sopenharmony_ci x <<= 1, e--; 2159bbbf1280Sopenharmony_ci return (e << 20) + x; 2160bbbf1280Sopenharmony_ci} 2161bbbf1280Sopenharmony_ci 2162bbbf1280Sopenharmony_cistatic uint32 floatval(int x, int scale) { 2163bbbf1280Sopenharmony_ci int e = 0x95 + scale; 2164bbbf1280Sopenharmony_ci while (!(x & 0x800000)) 2165bbbf1280Sopenharmony_ci x <<= 1, e--; 2166bbbf1280Sopenharmony_ci return (e << 23) + x; 2167bbbf1280Sopenharmony_ci} 2168