1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.renderscript.cts; 18 19 import android.util.Log; 20 21 public class CoreMathVerifier { 22 static { 23 System.loadLibrary("coremathtestcpp_jni"); 24 } 25 26 /* The level of precision we expect out of the half_* functions. floats (f32) have 23 bits of 27 * mantissa and halfs (f16) have 10 bits. 8192 = 2 ^ (23 - 10). 28 */ 29 private static final int HALF_PRECISION = 8192; 30 // The level of precision we expect out of the fast_* functions. 31 private static final int FAST_PRECISION = 8192; 32 // The level of precision we expect out of the native_* functions. 33 private static final int NATIVE_PRECISION = 8192; 34 35 // Static classes used to return multiple values from a few JNI functions. 36 static public class FrexpResult { 37 public float significand; 38 public int exponent; 39 } 40 41 static public class LgammaResult { 42 public float lgamma; 43 public int gammaSign; 44 } 45 46 static public class RemquoResult { 47 public float remainder; 48 public int quotient; 49 } 50 51 /* We're calling into native: 52 * - not all functions are available in Java, notably gamma and erf, 53 * - Java lacks float version of these functions, so we can compare implementations with 54 * similar constraints, and 55 * - handling unsigned integers, especially longs, is painful and error prone in Java. 56 */ 57 static native float acos(float x); 58 static native float acosh(float x); 59 static native float asin(float x); 60 static native float asinh(float x); 61 static native float atan(float x); 62 static native float atan2(float x, float y); 63 static native float atanh(float x); 64 static native float cbrt(float x); 65 static native float ceil(float x); 66 static native float cos(float x); 67 static native float cosh(float x); 68 static native float erf(float x); 69 static native float erfc(float x); 70 static native float exp(float x); 71 static native float exp10(float x); 72 static native float exp2(float x); 73 static native float expm1(float x); 74 static native float floor(float x); 75 static native FrexpResult frexp(float x); 76 static native float hypot(float x, float y); 77 static native int ilogb(float x); 78 static native float ldexp(float x, int exp); 79 static native float lgamma(float x); 80 static native LgammaResult lgamma2(float x); 81 static native float log(float x); 82 static native float logb(float x); 83 static native float log10(float x); 84 static native float log1p(float x); 85 static native float log2(float x); 86 static native byte maxI8(byte x, byte y); 87 static native byte maxU8(byte x, byte y); 88 static native short maxI16(short x, short y); 89 static native short maxU16(short x, short y); 90 static native int maxI32(int x, int y); 91 static native int maxU32(int x, int y); 92 static native long maxI64(long x, long y); 93 static native long maxU64(long x, long y); 94 static native byte minI8(byte x, byte y); 95 static native byte minU8(byte x, byte y); 96 static native short minI16(short x, short y); 97 static native short minU16(short x, short y); 98 static native int minI32(int x, int y); 99 static native int minU32(int x, int y); 100 static native long minI64(long x, long y); 101 static native long minU64(long x, long y); 102 static native float pow(float x, float y); 103 static native RemquoResult remquo(float numerator, float denominator); 104 static native float rint(float x); 105 static native float round(float x); 106 static native float sin(float x); 107 static native float sinh(float x); 108 static native float sqrt(float x); 109 static native float tan(float x); 110 static native float tanh(float x); 111 static native float tgamma(float x); 112 static native float trunc(float x); 113 114 static native byte convertCharToChar(byte x); 115 static native byte convertCharToUchar(byte x); 116 static native short convertCharToShort(byte x); 117 static native short convertCharToUshort(byte x); 118 static native int convertCharToInt(byte x); 119 static native int convertCharToUint(byte x); 120 static native long convertCharToLong(byte x); 121 static native long convertCharToUlong(byte x); 122 static native float convertCharToFloat(byte x); 123 static native double convertCharToDouble(byte x); 124 125 static native byte convertUcharToChar(byte x); 126 static native byte convertUcharToUchar(byte x); 127 static native short convertUcharToShort(byte x); 128 static native short convertUcharToUshort(byte x); 129 static native int convertUcharToInt(byte x); 130 static native int convertUcharToUint(byte x); 131 static native long convertUcharToLong(byte x); 132 static native long convertUcharToUlong(byte x); 133 static native float convertUcharToFloat(byte x); 134 static native double convertUcharToDouble(byte x); 135 136 static native byte convertShortToChar(short x); 137 static native byte convertShortToUchar(short x); 138 static native short convertShortToShort(short x); 139 static native short convertShortToUshort(short x); 140 static native int convertShortToInt(short x); 141 static native int convertShortToUint(short x); 142 static native long convertShortToLong(short x); 143 static native long convertShortToUlong(short x); 144 static native float convertShortToFloat(short x); 145 static native double convertShortToDouble(short x); 146 147 static native byte convertUshortToChar(short x); 148 static native byte convertUshortToUchar(short x); 149 static native short convertUshortToShort(short x); 150 static native short convertUshortToUshort(short x); 151 static native int convertUshortToInt(short x); 152 static native int convertUshortToUint(short x); 153 static native long convertUshortToLong(short x); 154 static native long convertUshortToUlong(short x); 155 static native float convertUshortToFloat(short x); 156 static native double convertUshortToDouble(short x); 157 158 static native byte convertIntToChar(int x); 159 static native byte convertIntToUchar(int x); 160 static native short convertIntToShort(int x); 161 static native short convertIntToUshort(int x); 162 static native int convertIntToInt(int x); 163 static native int convertIntToUint(int x); 164 static native long convertIntToLong(int x); 165 static native long convertIntToUlong(int x); 166 static native float convertIntToFloat(int x); 167 static native double convertIntToDouble(int x); 168 169 static native byte convertUintToChar(int x); 170 static native byte convertUintToUchar(int x); 171 static native short convertUintToShort(int x); 172 static native short convertUintToUshort(int x); 173 static native int convertUintToInt(int x); 174 static native int convertUintToUint(int x); 175 static native long convertUintToLong(int x); 176 static native long convertUintToUlong(int x); 177 static native float convertUintToFloat(int x); 178 static native double convertUintToDouble(int x); 179 180 static native byte convertLongToChar(long x); 181 static native byte convertLongToUchar(long x); 182 static native short convertLongToShort(long x); 183 static native short convertLongToUshort(long x); 184 static native int convertLongToInt(long x); 185 static native int convertLongToUint(long x); 186 static native long convertLongToLong(long x); 187 static native long convertLongToUlong(long x); 188 static native float convertLongToFloat(long x); 189 static native double convertLongToDouble(long x); 190 191 static native byte convertUlongToChar(long x); 192 static native byte convertUlongToUchar(long x); 193 static native short convertUlongToShort(long x); 194 static native short convertUlongToUshort(long x); 195 static native int convertUlongToInt(long x); 196 static native int convertUlongToUint(long x); 197 static native long convertUlongToLong(long x); 198 static native long convertUlongToUlong(long x); 199 static native float convertUlongToFloat(long x); 200 static native double convertUlongToDouble(long x); 201 202 static native byte convertFloatToChar(float x); 203 static native byte convertFloatToUchar(float x); 204 static native short convertFloatToShort(float x); 205 static native short convertFloatToUshort(float x); 206 static native int convertFloatToInt(float x); 207 static native int convertFloatToUint(float x); 208 static native long convertFloatToLong(float x); 209 static native long convertFloatToUlong(float x); 210 static native float convertFloatToFloat(float x); 211 static native double convertFloatToDouble(float x); 212 213 static native byte convertDoubleToChar(double x); 214 static native byte convertDoubleToUchar(double x); 215 static native short convertDoubleToShort(double x); 216 static native short convertDoubleToUshort(double x); 217 static native int convertDoubleToInt(double x); 218 static native int convertDoubleToUint(double x); 219 static native long convertDoubleToLong(double x); 220 static native long convertDoubleToUlong(double x); 221 static native float convertDoubleToFloat(double x); 222 static native double convertDoubleToDouble(double x); 223 224 static private Target.Floaty pi32(Target t) { 225 return t.new32((float) Math.PI); 226 } 227 228 static private Target.Floaty any32(Target t) { 229 return t.new32(Float.NEGATIVE_INFINITY, Float.NaN, Float.POSITIVE_INFINITY); 230 } 231 232 static private Target.Floaty acos(float f, Target t) { 233 Target.Floaty in = t.new32(f); 234 return t.new32( 235 acos(in.mid32()), 236 acos(in.min32()), 237 acos(in.max32())); 238 } 239 240 static private Target.Floaty acosh(float f, Target t) { 241 Target.Floaty in = t.new32(f); 242 return t.new32( 243 acosh(in.mid32()), 244 acosh(in.min32()), 245 acosh(in.max32())); 246 } 247 248 static private Target.Floaty acospi(float f, Target t) { 249 return t.divide(acos(f, t), pi32(t)); 250 } 251 252 static private Target.Floaty asin(float f, Target t) { 253 Target.Floaty in = t.new32(f); 254 return t.new32( 255 asin(in.mid32()), 256 asin(in.min32()), 257 asin(in.max32())); 258 } 259 260 static private Target.Floaty asinh(float f, Target t) { 261 Target.Floaty in = t.new32(f); 262 return t.new32( 263 asinh(in.mid32()), 264 asinh(in.min32()), 265 asinh(in.max32())); 266 } 267 268 static private Target.Floaty asinpi(float f, Target t) { 269 return t.divide(asin(f, t), pi32(t)); 270 } 271 272 static private Target.Floaty atan(float f, Target t) { 273 Target.Floaty in = t.new32(f); 274 return t.new32( 275 atan(in.mid32()), 276 atan(in.min32()), 277 atan(in.max32())); 278 } 279 280 static private Target.Floaty atanh(float f, Target t) { 281 Target.Floaty in = t.new32(f); 282 return t.new32( 283 atanh(in.mid32()), 284 atanh(in.min32()), 285 atanh(in.max32())); 286 } 287 288 static private Target.Floaty atanpi(float f, Target t) { 289 return t.divide(atan(f, t), pi32(t)); 290 } 291 292 static private Target.Floaty atan2(float y, float x, Target t) { 293 Target.Floaty inY = t.new32(y); 294 Target.Floaty inX = t.new32(x); 295 return t.new32( 296 atan2(inY.mid32(), inX.mid32()), 297 atan2(inY.min32(), inX.min32()), 298 atan2(inY.min32(), inX.max32()), 299 atan2(inY.max32(), inX.min32()), 300 atan2(inY.max32(), inX.max32())); 301 } 302 303 static private Target.Floaty atan2pi(float y, float x, Target t) { 304 return t.divide(atan2(y, x, t), pi32(t)); 305 } 306 307 static private Target.Floaty cbrt(float f, Target t) { 308 Target.Floaty in = t.new32(f); 309 return t.new32( 310 cbrt(in.mid32()), 311 cbrt(in.min32()), 312 cbrt(in.max32())); 313 } 314 315 static private Target.Floaty cos(float f, Target t) { 316 Target.Floaty in = t.new32(f); 317 return t.new32( 318 cos(in.mid32()), 319 cos(in.min32()), 320 cos(in.max32())); 321 } 322 323 static private Target.Floaty cosh(float f, Target t) { 324 Target.Floaty in = t.new32(f); 325 return t.new32( 326 cosh(in.mid32()), 327 cosh(in.min32()), 328 cosh(in.max32())); 329 } 330 331 static private Target.Floaty cospi(float f, Target t) { 332 Target.Floaty in = t.multiply(t.new32(f), pi32(t)); 333 return t.new32( 334 cos(in.mid32()), 335 cos(in.min32()), 336 cos(in.max32())); 337 } 338 339 // Computes the cross product of two 3D vectors. 340 static private void cross(float[] v1, float[] v2, Target.Floaty[] out, Target t) { 341 Target.Floaty a12 = t.multiply(t.new32(v1[1]), t.new32(v2[2])); 342 Target.Floaty a21 = t.multiply(t.new32(v1[2]), t.new32(v2[1])); 343 out[0] = t.subtract(a12, a21); 344 Target.Floaty a02 = t.multiply(t.new32(v1[0]), t.new32(v2[2])); 345 Target.Floaty a20 = t.multiply(t.new32(v1[2]), t.new32(v2[0])); 346 out[1] = t.subtract(a20, a02); 347 Target.Floaty a01 = t.multiply(t.new32(v1[0]), t.new32(v2[1])); 348 Target.Floaty a10 = t.multiply(t.new32(v1[1]), t.new32(v2[0])); 349 out[2] = t.subtract(a01, a10); 350 if (out.length == 4) { 351 out[3] = t.new32(0.f); 352 } 353 } 354 355 // Returns the distance between two points in n-dimensional space. 356 static private Target.Floaty distance(float[] point1, float[] point2, Target t) { 357 Target.Floaty sum = t.new32(0.f); 358 for (int i = 0; i < point1.length; i++) { 359 Target.Floaty diff = t.subtract(t.new32(point1[i]), t.new32(point2[i])); 360 sum = t.add(sum, t.multiply(diff, diff)); 361 } 362 Target.Floaty d = t.sqrt(sum); 363 return d; 364 } 365 366 static private Target.Floaty exp(float f, Target t) { 367 Target.Floaty in = t.new32(f); 368 return t.new32( 369 exp(in.mid32()), 370 exp(in.min32()), 371 exp(in.max32())); 372 } 373 374 static private Target.Floaty exp10(float f, Target t) { 375 Target.Floaty in = t.new32(f); 376 return t.new32( 377 exp10(in.mid32()), 378 exp10(in.min32()), 379 exp10(in.max32())); 380 } 381 382 static private Target.Floaty exp2(float f, Target t) { 383 Target.Floaty in = t.new32(f); 384 return t.new32( 385 exp2(in.mid32()), 386 exp2(in.min32()), 387 exp2(in.max32())); 388 } 389 390 static private Target.Floaty expm1(float f, Target t) { 391 Target.Floaty in = t.new32(f); 392 return t.new32( 393 expm1(in.mid32()), 394 expm1(in.min32()), 395 expm1(in.max32())); 396 } 397 398 static private Target.Floaty hypot(float x, float y, Target t) { 399 Target.Floaty inX = t.new32(x); 400 Target.Floaty inY = t.new32(y); 401 return t.new32( 402 hypot(inX.mid32(), inY.mid32()), 403 hypot(inX.min32(), inY.min32()), 404 hypot(inX.min32(), inY.max32()), 405 hypot(inX.max32(), inY.min32()), 406 hypot(inX.max32(), inY.max32())); 407 } 408 409 // Returns the length of the n-dimensional vector. 410 static private Target.Floaty length(float[] array, Target t) { 411 Target.Floaty sum = t.new32(0.f); 412 for (int i = 0; i < array.length; i++) { 413 Target.Floaty f = t.new32(array[i]); 414 sum = t.add(sum, t.multiply(f, f)); 415 } 416 Target.Floaty l = t.sqrt(sum); 417 return l; 418 } 419 420 static private Target.Floaty log(float f, Target t) { 421 Target.Floaty in = t.new32(f); 422 return t.new32( 423 log(in.mid32()), 424 log(in.min32()), 425 log(in.max32())); 426 } 427 428 static private Target.Floaty log10(float f, Target t) { 429 Target.Floaty in = t.new32(f); 430 return t.new32( 431 log10(in.mid32()), 432 log10(in.min32()), 433 log10(in.max32())); 434 } 435 436 static private Target.Floaty log1p(float f, Target t) { 437 Target.Floaty in = t.new32(f); 438 return t.new32( 439 log1p(in.mid32()), 440 log1p(in.min32()), 441 log1p(in.max32())); 442 } 443 444 static private Target.Floaty log2(float f, Target t) { 445 Target.Floaty in = t.new32(f); 446 return t.new32( 447 log2(in.mid32()), 448 log2(in.min32()), 449 log2(in.max32())); 450 } 451 452 // Normalizes the n-dimensional vector, i.e. makes it length 1. 453 static private void normalize(float[] in, Target.Floaty[] out, Target t) { 454 Target.Floaty l = length(in, t); 455 boolean isZero = l.get32() == 0.f; 456 for (int i = 0; i < in.length; i++) { 457 out[i] = t.new32(in[i]); 458 if (!isZero) { 459 out[i] = t.divide(out[i], l); 460 } 461 } 462 } 463 464 static private Target.Floaty powr(float x, float y, Target t) { 465 Target.Floaty inX = t.new32(x); 466 Target.Floaty inY = t.new32(y); 467 return t.new32( 468 pow(inX.mid32(), inY.mid32()), 469 pow(inX.min32(), inY.min32()), 470 pow(inX.min32(), inY.max32()), 471 pow(inX.max32(), inY.min32()), 472 pow(inX.max32(), inY.max32())); 473 } 474 475 static private Target.Floaty recip(float f, Target t) { 476 Target.Floaty in = t.new32(f); 477 return t.divide(t.new32(1.f), in); 478 } 479 480 static private Target.Floaty rootn(float inV, int inN, Target t) { 481 /* Rootn of a negative number should be possible only if the number 482 * is odd. In cases where the int is very large, our approach will 483 * lose whether the int is odd, and we'll get a NaN for weird cases 484 * like rootn(-3.95, 818181881), which should return 1. We handle the 485 * case by handling the sign ourselves. We use copysign to handle the 486 * negative zero case. 487 */ 488 float value; 489 if ((inN & 0x1) == 0x1) { 490 value = Math.copySign(pow(Math.abs(inV), 1.f / inN), 491 inV); 492 } else { 493 value = pow(inV, 1.f / inN); 494 } 495 if (inN == 0) { 496 return t.new32(value, Float.NaN); 497 } else { 498 return t.new32(value); 499 } 500 } 501 502 static private Target.Floaty rsqrt(float f, Target t) { 503 Target.Floaty in = t.new32(f); 504 return t.divide(t.new32(1.f), t.sqrt(in)); 505 } 506 507 static private Target.Floaty sin(float f, Target t) { 508 Target.Floaty in = t.new32(f); 509 return t.new32( 510 sin(in.mid32()), 511 sin(in.min32()), 512 sin(in.max32())); 513 } 514 515 static private Target.Floaty sinh(float f, Target t) { 516 Target.Floaty in = t.new32(f); 517 return t.new32( 518 sinh(in.mid32()), 519 sinh(in.min32()), 520 sinh(in.max32())); 521 } 522 523 static private Target.Floaty sinpi(float f, Target t) { 524 Target.Floaty in = t.multiply(t.new32(f), pi32(t)); 525 return t.new32( 526 sin(in.mid32()), 527 sin(in.min32()), 528 sin(in.max32())); 529 } 530 531 static private Target.Floaty sqrt(float f, Target t) { 532 Target.Floaty in = t.new32(f); 533 return t.sqrt(in); 534 } 535 536 static private Target.Floaty tan(float f, Target t) { 537 Target.Floaty in = t.new32(f); 538 float min = tan(in.min32()); 539 float max = tan(in.max32()); 540 /* If the tan of the min is greater than that of the max, 541 * we spanned a discontinuity. 542 */ 543 if (min > max) { 544 return any32(t); 545 } else { 546 return t.new32(tan(f), min, max); 547 } 548 } 549 550 static private Target.Floaty tanh(float f, Target t) { 551 Target.Floaty in = t.new32(f); 552 return t.new32( 553 tanh(in.mid32()), 554 tanh(in.min32()), 555 tanh(in.max32())); 556 } 557 558 static private Target.Floaty tanpi(float f, Target t) { 559 Target.Floaty in = t.multiply(t.new32(f), pi32(t)); 560 float min = tan(in.min32()); 561 float max = tan(in.max32()); 562 /* If the tan of the min is greater than that of the max, 563 * we spanned a discontinuity. 564 */ 565 if (min > max) { 566 return any32(t); 567 } else { 568 return t.new32(tan(in.mid32()), min, max); 569 } 570 } 571 572 static public void computeAbs(TestAbs.ArgumentsCharUchar args) { 573 args.out = (byte)Math.abs(args.inValue); 574 } 575 576 static public void computeAbs(TestAbs.ArgumentsShortUshort args) { 577 args.out = (short)Math.abs(args.inValue); 578 } 579 580 static public void computeAbs(TestAbs.ArgumentsIntUint args) { 581 args.out = Math.abs(args.inValue); 582 } 583 584 static public void computeAcos(TestAcos.ArgumentsFloatFloat args, Target t) { 585 t.setPrecision(4, 128, false); 586 args.out = acos(args.inV, t); 587 } 588 589 static public void computeAcosh(TestAcosh.ArgumentsFloatFloat args, Target t) { 590 t.setPrecision(4, 128, false); 591 args.out = acosh(args.in, t); 592 } 593 594 static public void computeAcospi(TestAcospi.ArgumentsFloatFloat args, Target t) { 595 t.setPrecision(5, 128, false); 596 args.out = acospi(args.inV, t); 597 } 598 599 static public void computeAsin(TestAsin.ArgumentsFloatFloat args, Target t) { 600 t.setPrecision(4, 128, false); 601 args.out = asin(args.inV, t); 602 } 603 604 static public void computeAsinh(TestAsinh.ArgumentsFloatFloat args, Target t) { 605 t.setPrecision(4, 128, false); 606 args.out = asinh(args.in, t); 607 } 608 609 static public void computeAsinpi(TestAsinpi.ArgumentsFloatFloat args, Target t) { 610 t.setPrecision(5, 128, false); 611 args.out = asinpi(args.inV, t); 612 } 613 614 static public void computeAtan(TestAtan.ArgumentsFloatFloat args, Target t) { 615 t.setPrecision(5, 128, false); 616 args.out = atan(args.inV, t); 617 } 618 619 static public void computeAtanh(TestAtanh.ArgumentsFloatFloat args, Target t) { 620 t.setPrecision(5, 128, false); 621 args.out = atanh(args.inV, t); 622 } 623 624 static public void computeAtanpi(TestAtanpi.ArgumentsFloatFloat args, Target t) { 625 t.setPrecision(5, 128, false); 626 args.out = atanpi(args.inV, t); 627 } 628 629 static public void computeAtan2(TestAtan2.ArgumentsFloatFloatFloat args, Target t) { 630 t.setPrecision(6, 128, false); 631 args.out = atan2(args.inY, args.inX, t); 632 } 633 634 static public void computeAtan2pi(TestAtan2pi.ArgumentsFloatFloatFloat args, Target t) { 635 t.setPrecision(6, 128, false); 636 args.out = atan2pi(args.inY, args.inX, t); 637 } 638 639 static public void computeCbrt(TestCbrt.ArgumentsFloatFloat args, Target t) { 640 t.setPrecision(2, 128, false); 641 args.out = cbrt(args.in, t); 642 } 643 644 static public void computeCeil(TestCeil.ArgumentsFloatFloat args, Target t) { 645 t.setPrecision(0, 1, false); 646 Target.Floaty in = t.new32(args.in); 647 args.out = t.new32( 648 ceil(in.mid32()), 649 ceil(in.min32()), 650 ceil(in.max32())); 651 } 652 653 static public void computeClamp(TestClamp.ArgumentsCharCharCharChar args) { 654 args.out = minI8(args.inMaxValue, maxI8(args.inValue, args.inMinValue)); 655 } 656 657 static public void computeClamp(TestClamp.ArgumentsUcharUcharUcharUchar args) { 658 args.out = minU8(args.inMaxValue, maxU8(args.inValue, args.inMinValue)); 659 } 660 661 static public void computeClamp(TestClamp.ArgumentsShortShortShortShort args) { 662 args.out = minI16(args.inMaxValue, maxI16(args.inValue, args.inMinValue)); 663 } 664 665 static public void computeClamp(TestClamp.ArgumentsUshortUshortUshortUshort args) { 666 args.out = minU16(args.inMaxValue, maxU16(args.inValue, args.inMinValue)); 667 } 668 669 static public void computeClamp(TestClamp.ArgumentsIntIntIntInt args) { 670 args.out = minI32(args.inMaxValue, maxI32(args.inValue, args.inMinValue)); 671 } 672 673 static public void computeClamp(TestClamp.ArgumentsUintUintUintUint args) { 674 args.out = minU32(args.inMaxValue, maxU32(args.inValue, args.inMinValue)); 675 } 676 677 static public void computeClamp(TestClamp.ArgumentsFloatFloatFloatFloat args, Target t) { 678 t.setPrecision(0, 0, false); 679 args.out = t.new32(Math.min(args.inMaxValue, 680 Math.max(args.inValue, args.inMinValue))); 681 } 682 683 static public void computeClamp(TestClamp.ArgumentsLongLongLongLong args) { 684 args.out = minI64(args.inMaxValue, maxI64(args.inValue, args.inMinValue)); 685 } 686 687 static public void computeClamp(TestClamp.ArgumentsUlongUlongUlongUlong args) { 688 args.out = minU64(args.inMaxValue, maxU64(args.inValue, args.inMinValue)); 689 } 690 691 static public void computeClz(TestClz.ArgumentsCharChar args) { 692 int x = args.inValue; 693 args.out = (byte) (Integer.numberOfLeadingZeros(x & 0xff) - 24); 694 } 695 696 static public void computeClz(TestClz.ArgumentsUcharUchar args) { 697 int x = args.inValue; 698 args.out = (byte) (Integer.numberOfLeadingZeros(x & 0xff) - 24); 699 } 700 701 static public void computeClz(TestClz.ArgumentsShortShort args) { 702 args.out = (short) (Integer.numberOfLeadingZeros(args.inValue & 0xffff) - 16); 703 } 704 705 static public void computeClz(TestClz.ArgumentsUshortUshort args) { 706 args.out = (short) (Integer.numberOfLeadingZeros(args.inValue & 0xffff) - 16); 707 } 708 709 static public void computeClz(TestClz.ArgumentsIntInt args) { 710 args.out = (int) Integer.numberOfLeadingZeros(args.inValue); 711 } 712 713 static public void computeClz(TestClz.ArgumentsUintUint args) { 714 args.out = (int) Integer.numberOfLeadingZeros(args.inValue); 715 } 716 717 718 static public void computeConvert(TestConvert.ArgumentsCharChar args) { 719 args.out = convertCharToChar(args.inV); 720 } 721 static public void computeConvert(TestConvert.ArgumentsCharUchar args) { 722 args.out = convertCharToUchar(args.inV); 723 } 724 static public void computeConvert(TestConvert.ArgumentsCharShort args) { 725 args.out = convertCharToShort(args.inV); 726 } 727 static public void computeConvert(TestConvert.ArgumentsCharUshort args) { 728 args.out = convertCharToUshort(args.inV); 729 } 730 static public void computeConvert(TestConvert.ArgumentsCharInt args) { 731 args.out = convertCharToInt(args.inV); 732 } 733 static public void computeConvert(TestConvert.ArgumentsCharUint args) { 734 args.out = convertCharToUint(args.inV); 735 } 736 static public void computeConvert(TestConvert.ArgumentsCharLong args) { 737 args.out = convertCharToLong(args.inV); 738 } 739 static public void computeConvert(TestConvert.ArgumentsCharUlong args) { 740 args.out = convertCharToUlong(args.inV); 741 } 742 static public void computeConvert(TestConvert.ArgumentsCharFloat args, Target t) { 743 t.setPrecision(0, 0, false); 744 args.out = t.new32(convertCharToFloat(args.inV)); 745 } 746 static public void computeConvert(TestConvert.ArgumentsCharDouble args, Target t) { 747 t.setPrecision(0, 0, false); 748 args.out = t.new64(convertCharToDouble(args.inV)); 749 } 750 751 static public void computeConvert(TestConvert.ArgumentsUcharChar args) { 752 args.out = convertUcharToChar(args.inV); 753 } 754 static public void computeConvert(TestConvert.ArgumentsUcharUchar args) { 755 args.out = convertUcharToUchar(args.inV); 756 } 757 static public void computeConvert(TestConvert.ArgumentsUcharShort args) { 758 args.out = convertUcharToShort(args.inV); 759 } 760 static public void computeConvert(TestConvert.ArgumentsUcharUshort args) { 761 args.out = convertUcharToUshort(args.inV); 762 } 763 static public void computeConvert(TestConvert.ArgumentsUcharInt args) { 764 args.out = convertUcharToInt(args.inV); 765 } 766 static public void computeConvert(TestConvert.ArgumentsUcharUint args) { 767 args.out = convertUcharToUint(args.inV); 768 } 769 static public void computeConvert(TestConvert.ArgumentsUcharLong args) { 770 args.out = convertUcharToLong(args.inV); 771 } 772 static public void computeConvert(TestConvert.ArgumentsUcharUlong args) { 773 args.out = convertUcharToUlong(args.inV); 774 } 775 static public void computeConvert(TestConvert.ArgumentsUcharFloat args, Target t) { 776 t.setPrecision(0, 0, false); 777 args.out = t.new32(convertUcharToFloat(args.inV)); 778 } 779 static public void computeConvert(TestConvert.ArgumentsUcharDouble args, Target t) { 780 t.setPrecision(0, 0, false); 781 args.out = t.new64(convertUcharToDouble(args.inV)); 782 } 783 784 static public void computeConvert(TestConvert.ArgumentsShortChar args) { 785 args.out = convertShortToChar(args.inV); 786 } 787 static public void computeConvert(TestConvert.ArgumentsShortUchar args) { 788 args.out = convertShortToUchar(args.inV); 789 } 790 static public void computeConvert(TestConvert.ArgumentsShortShort args) { 791 args.out = convertShortToShort(args.inV); 792 } 793 static public void computeConvert(TestConvert.ArgumentsShortUshort args) { 794 args.out = convertShortToUshort(args.inV); 795 } 796 static public void computeConvert(TestConvert.ArgumentsShortInt args) { 797 args.out = convertShortToInt(args.inV); 798 } 799 static public void computeConvert(TestConvert.ArgumentsShortUint args) { 800 args.out = convertShortToUint(args.inV); 801 } 802 static public void computeConvert(TestConvert.ArgumentsShortLong args) { 803 args.out = convertShortToLong(args.inV); 804 } 805 static public void computeConvert(TestConvert.ArgumentsShortUlong args) { 806 args.out = convertShortToUlong(args.inV); 807 } 808 static public void computeConvert(TestConvert.ArgumentsShortFloat args, Target t) { 809 t.setPrecision(0, 0, false); 810 args.out = t.new32(convertShortToFloat(args.inV)); 811 } 812 static public void computeConvert(TestConvert.ArgumentsShortDouble args, Target t) { 813 t.setPrecision(0, 0, false); 814 args.out = t.new64(convertShortToDouble(args.inV)); 815 } 816 817 static public void computeConvert(TestConvert.ArgumentsUshortChar args) { 818 args.out = convertUshortToChar(args.inV); 819 } 820 static public void computeConvert(TestConvert.ArgumentsUshortUchar args) { 821 args.out = convertUshortToUchar(args.inV); 822 } 823 static public void computeConvert(TestConvert.ArgumentsUshortShort args) { 824 args.out = convertUshortToShort(args.inV); 825 } 826 static public void computeConvert(TestConvert.ArgumentsUshortUshort args) { 827 args.out = convertUshortToUshort(args.inV); 828 } 829 static public void computeConvert(TestConvert.ArgumentsUshortInt args) { 830 args.out = convertUshortToInt(args.inV); 831 } 832 static public void computeConvert(TestConvert.ArgumentsUshortUint args) { 833 args.out = convertUshortToUint(args.inV); 834 } 835 static public void computeConvert(TestConvert.ArgumentsUshortLong args) { 836 args.out = convertUshortToLong(args.inV); 837 } 838 static public void computeConvert(TestConvert.ArgumentsUshortUlong args) { 839 args.out = convertUshortToUlong(args.inV); 840 } 841 static public void computeConvert(TestConvert.ArgumentsUshortFloat args, Target t) { 842 t.setPrecision(0, 0, false); 843 args.out = t.new32(convertUshortToFloat(args.inV)); 844 } 845 static public void computeConvert(TestConvert.ArgumentsUshortDouble args, Target t) { 846 t.setPrecision(0, 0, false); 847 args.out = t.new64(convertUshortToDouble(args.inV)); 848 } 849 850 static public void computeConvert(TestConvert.ArgumentsIntChar args) { 851 args.out = convertIntToChar(args.inV); 852 } 853 static public void computeConvert(TestConvert.ArgumentsIntUchar args) { 854 args.out = convertIntToUchar(args.inV); 855 } 856 static public void computeConvert(TestConvert.ArgumentsIntShort args) { 857 args.out = convertIntToShort(args.inV); 858 } 859 static public void computeConvert(TestConvert.ArgumentsIntUshort args) { 860 args.out = convertIntToUshort(args.inV); 861 } 862 static public void computeConvert(TestConvert.ArgumentsIntInt args) { 863 args.out = convertIntToInt(args.inV); 864 } 865 static public void computeConvert(TestConvert.ArgumentsIntUint args) { 866 args.out = convertIntToUint(args.inV); 867 } 868 static public void computeConvert(TestConvert.ArgumentsIntLong args) { 869 args.out = convertIntToLong(args.inV); 870 } 871 static public void computeConvert(TestConvert.ArgumentsIntUlong args) { 872 args.out = convertIntToUlong(args.inV); 873 } 874 static public void computeConvert(TestConvert.ArgumentsIntFloat args, Target t) { 875 t.setPrecision(1, 1, false); 876 args.out = t.new32(convertIntToFloat(args.inV)); 877 } 878 static public void computeConvert(TestConvert.ArgumentsIntDouble args, Target t) { 879 t.setPrecision(0, 0, false); 880 args.out = t.new64(convertIntToDouble(args.inV)); 881 } 882 883 static public void computeConvert(TestConvert.ArgumentsUintChar args) { 884 args.out = convertUintToChar(args.inV); 885 } 886 static public void computeConvert(TestConvert.ArgumentsUintUchar args) { 887 args.out = convertUintToUchar(args.inV); 888 } 889 static public void computeConvert(TestConvert.ArgumentsUintShort args) { 890 args.out = convertUintToShort(args.inV); 891 } 892 static public void computeConvert(TestConvert.ArgumentsUintUshort args) { 893 args.out = convertUintToUshort(args.inV); 894 } 895 static public void computeConvert(TestConvert.ArgumentsUintInt args) { 896 args.out = convertUintToInt(args.inV); 897 } 898 static public void computeConvert(TestConvert.ArgumentsUintUint args) { 899 args.out = convertUintToUint(args.inV); 900 } 901 static public void computeConvert(TestConvert.ArgumentsUintLong args) { 902 args.out = convertUintToLong(args.inV); 903 } 904 static public void computeConvert(TestConvert.ArgumentsUintUlong args) { 905 args.out = convertUintToUlong(args.inV); 906 } 907 static public void computeConvert(TestConvert.ArgumentsUintFloat args, Target t) { 908 t.setPrecision(1, 1, false); 909 args.out = t.new32(convertUintToFloat(args.inV)); 910 } 911 static public void computeConvert(TestConvert.ArgumentsUintDouble args, Target t) { 912 t.setPrecision(0, 0, false); 913 args.out = t.new64(convertUintToDouble(args.inV)); 914 } 915 916 static public void computeConvert(TestConvert.ArgumentsLongChar args) { 917 args.out = convertLongToChar(args.inV); 918 } 919 static public void computeConvert(TestConvert.ArgumentsLongUchar args) { 920 args.out = convertLongToUchar(args.inV); 921 } 922 static public void computeConvert(TestConvert.ArgumentsLongShort args) { 923 args.out = convertLongToShort(args.inV); 924 } 925 static public void computeConvert(TestConvert.ArgumentsLongUshort args) { 926 args.out = convertLongToUshort(args.inV); 927 } 928 static public void computeConvert(TestConvert.ArgumentsLongInt args) { 929 args.out = convertLongToInt(args.inV); 930 } 931 static public void computeConvert(TestConvert.ArgumentsLongUint args) { 932 args.out = convertLongToUint(args.inV); 933 } 934 static public void computeConvert(TestConvert.ArgumentsLongLong args) { 935 args.out = convertLongToLong(args.inV); 936 } 937 static public void computeConvert(TestConvert.ArgumentsLongUlong args) { 938 args.out = convertLongToUlong(args.inV); 939 } 940 static public void computeConvert(TestConvert.ArgumentsLongFloat args, Target t) { 941 t.setPrecision(1, 1, false); 942 args.out = t.new32(convertLongToFloat(args.inV)); 943 } 944 static public void computeConvert(TestConvert.ArgumentsLongDouble args, Target t) { 945 t.setPrecision(1, 1, false); 946 args.out = t.new64(convertLongToDouble(args.inV)); 947 } 948 949 static public void computeConvert(TestConvert.ArgumentsUlongChar args) { 950 args.out = convertUlongToChar(args.inV); 951 } 952 static public void computeConvert(TestConvert.ArgumentsUlongUchar args) { 953 args.out = convertUlongToUchar(args.inV); 954 } 955 static public void computeConvert(TestConvert.ArgumentsUlongShort args) { 956 args.out = convertUlongToShort(args.inV); 957 } 958 static public void computeConvert(TestConvert.ArgumentsUlongUshort args) { 959 args.out = convertUlongToUshort(args.inV); 960 } 961 static public void computeConvert(TestConvert.ArgumentsUlongInt args) { 962 args.out = convertUlongToInt(args.inV); 963 } 964 static public void computeConvert(TestConvert.ArgumentsUlongUint args) { 965 args.out = convertUlongToUint(args.inV); 966 } 967 static public void computeConvert(TestConvert.ArgumentsUlongLong args) { 968 args.out = convertUlongToLong(args.inV); 969 } 970 static public void computeConvert(TestConvert.ArgumentsUlongUlong args) { 971 args.out = convertUlongToUlong(args.inV); 972 } 973 static public void computeConvert(TestConvert.ArgumentsUlongFloat args, Target t) { 974 t.setPrecision(1, 1, false); 975 args.out = t.new32(convertUlongToFloat(args.inV)); 976 } 977 static public void computeConvert(TestConvert.ArgumentsUlongDouble args, Target t) { 978 t.setPrecision(1, 1, false); 979 args.out = t.new64(convertUlongToDouble(args.inV)); 980 } 981 982 static public void computeConvert(TestConvert.ArgumentsFloatChar args) { 983 args.out = convertFloatToChar(args.inV); 984 } 985 static public void computeConvert(TestConvert.ArgumentsFloatUchar args) { 986 args.out = convertFloatToUchar(args.inV); 987 } 988 static public void computeConvert(TestConvert.ArgumentsFloatShort args) { 989 args.out = convertFloatToShort(args.inV); 990 } 991 static public void computeConvert(TestConvert.ArgumentsFloatUshort args) { 992 args.out = convertFloatToUshort(args.inV); 993 } 994 static public void computeConvert(TestConvert.ArgumentsFloatInt args) { 995 args.out = convertFloatToInt(args.inV); 996 } 997 static public void computeConvert(TestConvert.ArgumentsFloatUint args) { 998 args.out = convertFloatToUint(args.inV); 999 } 1000 static public void computeConvert(TestConvert.ArgumentsFloatLong args) { 1001 args.out = convertFloatToLong(args.inV); 1002 } 1003 static public void computeConvert(TestConvert.ArgumentsFloatUlong args) { 1004 args.out = convertFloatToUlong(args.inV); 1005 } 1006 static public void computeConvert(TestConvert.ArgumentsFloatFloat args, Target t) { 1007 t.setPrecision(0, 0, false); 1008 args.out = t.new32(convertFloatToFloat(args.inV)); 1009 } 1010 static public void computeConvert(TestConvert.ArgumentsFloatDouble args, Target t) { 1011 t.setPrecision(0, 0, false); 1012 args.out = t.new64(convertFloatToDouble(args.inV)); 1013 } 1014 1015 static public void computeConvert(TestConvert.ArgumentsDoubleChar args) { 1016 args.out = convertDoubleToChar(args.inV); 1017 } 1018 static public void computeConvert(TestConvert.ArgumentsDoubleUchar args) { 1019 args.out = convertDoubleToUchar(args.inV); 1020 } 1021 static public void computeConvert(TestConvert.ArgumentsDoubleShort args) { 1022 args.out = convertDoubleToShort(args.inV); 1023 } 1024 static public void computeConvert(TestConvert.ArgumentsDoubleUshort args) { 1025 args.out = convertDoubleToUshort(args.inV); 1026 } 1027 static public void computeConvert(TestConvert.ArgumentsDoubleInt args) { 1028 args.out = convertDoubleToInt(args.inV); 1029 } 1030 static public void computeConvert(TestConvert.ArgumentsDoubleUint args) { 1031 args.out = convertDoubleToUint(args.inV); 1032 } 1033 static public void computeConvert(TestConvert.ArgumentsDoubleLong args) { 1034 args.out = convertDoubleToLong(args.inV); 1035 } 1036 static public void computeConvert(TestConvert.ArgumentsDoubleUlong args) { 1037 args.out = convertDoubleToUlong(args.inV); 1038 } 1039 static public void computeConvert(TestConvert.ArgumentsDoubleFloat args, Target t) { 1040 t.setPrecision(1, 1, false); 1041 args.out = t.new32(convertDoubleToFloat(args.inV)); 1042 } 1043 static public void computeConvert(TestConvert.ArgumentsDoubleDouble args, Target t) { 1044 t.setPrecision(0, 0, false); 1045 args.out = t.new64(convertDoubleToDouble(args.inV)); 1046 } 1047 1048 static public void computeCopysign(TestCopysign.ArgumentsFloatFloatFloat args, Target t) { 1049 t.setPrecision(0, 0, false); 1050 args.out = t.new32(Math.copySign(args.inX, args.inY)); 1051 } 1052 1053 static public void computeCos(TestCos.ArgumentsFloatFloat args, Target t) { 1054 t.setPrecision(4, 128, false); 1055 args.out = cos(args.in, t); 1056 } 1057 1058 static public void computeCosh(TestCosh.ArgumentsFloatFloat args, Target t) { 1059 t.setPrecision(4, 128, false); 1060 args.out = cosh(args.in, t); 1061 } 1062 1063 static public void computeCospi(TestCospi.ArgumentsFloatFloat args, Target t) { 1064 t.setPrecision(4, 128, false); 1065 args.out = cospi(args.in, t); 1066 } 1067 1068 static public void computeCross(TestCross.ArgumentsFloatNFloatNFloatN args, Target t) { 1069 t.setPrecision(1, 4, false); 1070 cross(args.inLhs, args.inRhs, args.out, t); 1071 } 1072 1073 static public void computeDegrees(TestDegrees.ArgumentsFloatFloat args, Target t) { 1074 t.setPrecision(3, 3, false); 1075 Target.Floaty in = t.new32(args.inValue); 1076 Target.Floaty k = t.new32((float)(180.0 / Math.PI)); 1077 args.out = t.multiply(in, k); 1078 } 1079 1080 static public void computeDistance(TestDistance.ArgumentsFloatFloatFloat args, Target t) { 1081 t.setPrecision(1, 1, false); 1082 args.out = distance(new float[] {args.inLhs}, new float[] {args.inRhs}, t); 1083 } 1084 1085 static public void computeDistance(TestDistance.ArgumentsFloatNFloatNFloat args, Target t) { 1086 t.setPrecision(1, 1, false); 1087 args.out = distance(args.inLhs, args.inRhs, t); 1088 } 1089 1090 static public void computeDot(TestDot.ArgumentsFloatFloatFloat args, Target t) { 1091 t.setPrecision(1, 4, false); 1092 Target.Floaty a = t.new32(args.inLhs); 1093 Target.Floaty b = t.new32(args.inRhs); 1094 args.out = t.multiply(a, b); 1095 } 1096 1097 static public void computeDot(TestDot.ArgumentsFloatNFloatNFloat args, Target t) { 1098 t.setPrecision(1, 4, false); 1099 Target.Floaty sum = t.new32(0.f); 1100 for (int i = 0; i < args.inLhs.length; i++) { 1101 Target.Floaty a = t.new32(args.inLhs[i]); 1102 Target.Floaty b = t.new32(args.inRhs[i]); 1103 sum = t.add(sum, t.multiply(a, b)); 1104 } 1105 args.out = sum; 1106 } 1107 1108 static public void computeErf(TestErf.ArgumentsFloatFloat args, Target t) { 1109 t.setPrecision(16, 128, false); 1110 Target.Floaty in = t.new32(args.in); 1111 args.out = t.new32( 1112 erf(args.in), 1113 erf(in.min32()), 1114 erf(in.max32())); 1115 } 1116 1117 static public void computeErfc(TestErfc.ArgumentsFloatFloat args, Target t) { 1118 t.setPrecision(16, 128, false); 1119 Target.Floaty in = t.new32(args.in); 1120 args.out = t.new32( 1121 erfc(args.in), 1122 erfc(in.min32()), 1123 erfc(in.max32())); 1124 } 1125 1126 static public void computeExp(TestExp.ArgumentsFloatFloat args, Target t) { 1127 t.setPrecision(3, 16, false); 1128 args.out = exp(args.in, t); 1129 } 1130 1131 static public void computeExp10(TestExp10.ArgumentsFloatFloat args, Target t) { 1132 t.setPrecision(3, 32, false); 1133 args.out = exp10(args.in, t); 1134 } 1135 1136 static public void computeExp2(TestExp2.ArgumentsFloatFloat args, Target t) { 1137 t.setPrecision(3, 16, false); 1138 args.out = exp2(args.in, t); 1139 } 1140 1141 static public void computeExpm1(TestExpm1.ArgumentsFloatFloat args, Target t) { 1142 t.setPrecision(3, 16, false); 1143 args.out = expm1(args.in, t); 1144 } 1145 1146 static public void computeFabs(TestFabs.ArgumentsFloatFloat args, Target t) { 1147 t.setPrecision(0, 0, false); 1148 Target.Floaty in = t.new32(args.in); 1149 args.out = t.new32( 1150 Math.abs(args.in), 1151 Math.abs(in.min32()), 1152 Math.abs(in.max32())); 1153 } 1154 1155 static public void computeFastDistance(TestFastDistance.ArgumentsFloatFloatFloat args, Target t) { 1156 t.setPrecision(FAST_PRECISION, FAST_PRECISION, false); 1157 args.out = distance(new float[] {args.inLhs}, new float[] {args.inRhs}, t); 1158 } 1159 1160 static public void computeFastDistance(TestFastDistance.ArgumentsFloatNFloatNFloat args, Target t) { 1161 t.setPrecision(FAST_PRECISION, FAST_PRECISION, false); 1162 args.out = distance(args.inLhs, args.inRhs, t); 1163 } 1164 1165 static public void computeFastLength(TestFastLength.ArgumentsFloatFloat args, Target t) { 1166 t.setPrecision(FAST_PRECISION, FAST_PRECISION, false); 1167 args.out = length(new float[] {args.inV}, t); 1168 } 1169 1170 static public void computeFastLength(TestFastLength.ArgumentsFloatNFloat args, Target t) { 1171 t.setPrecision(FAST_PRECISION, FAST_PRECISION, false); 1172 args.out = length(args.inV, t); 1173 } 1174 1175 static public void computeFastNormalize(TestFastNormalize.ArgumentsFloatFloat args, Target t) { 1176 t.setPrecision(FAST_PRECISION, FAST_PRECISION, false); 1177 Target.Floaty[] out = new Target.Floaty[1]; 1178 normalize(new float[] {args.inV}, out, t); 1179 args.out = out[0]; 1180 } 1181 1182 static public void computeFastNormalize(TestFastNormalize.ArgumentsFloatNFloatN args, Target t) { 1183 t.setPrecision(FAST_PRECISION, FAST_PRECISION, false); 1184 normalize(args.inV, args.out, t); 1185 } 1186 1187 static public void computeFdim(TestFdim.ArgumentsFloatFloatFloat args, Target t) { 1188 t.setPrecision(1, 1, false); 1189 Target.Floaty inA = t.new32(args.inA); 1190 Target.Floaty inB = t.new32(args.inB); 1191 Target.Floaty r = t.subtract(inA, inB); 1192 args.out = t.new32( 1193 Math.max(0.f, r.mid32()), 1194 Math.max(0.f, r.min32()), 1195 Math.max(0.f, r.max32())); 1196 } 1197 1198 static public void computeFloor(TestFloor.ArgumentsFloatFloat args, Target t) { 1199 t.setPrecision(0, 0, false); 1200 Target.Floaty in = t.new32(args.in); 1201 args.out = t.new32( 1202 floor(args.in), 1203 floor(in.min32()), 1204 floor(in.max32())); 1205 } 1206 1207 static public void computeFma(TestFma.ArgumentsFloatFloatFloatFloat args, Target t) { 1208 t.setPrecision(1, 1, false); 1209 Target.Floaty ab = t.multiply(t.new32(args.inA), t.new32(args.inB)); 1210 args.out = t.add(ab, t.new32(args.inC)); 1211 } 1212 1213 static public void computeFmax(TestFmax.ArgumentsFloatFloatFloat args, Target t) { 1214 t.setPrecision(0, 0, false); 1215 Target.Floaty inX = t.new32(args.inX); 1216 Target.Floaty inY = t.new32(args.inY); 1217 args.out = t.new32( 1218 Math.max(args.inX, args.inY), 1219 Math.max(inX.min32(), inY.min32()), 1220 Math.max(inX.min32(), inY.max32()), 1221 Math.max(inX.max32(), inY.min32()), 1222 Math.max(inX.max32(), inY.max32())); 1223 } 1224 1225 static public void computeFmin(TestFmin.ArgumentsFloatFloatFloat args, Target t) { 1226 t.setPrecision(0, 0, false); 1227 Target.Floaty inX = t.new32(args.inX); 1228 Target.Floaty inY = t.new32(args.inY); 1229 args.out = t.new32( 1230 Math.min(args.inX, args.inY), 1231 Math.min(inX.min32(), inY.min32()), 1232 Math.min(inX.min32(), inY.max32()), 1233 Math.min(inX.max32(), inY.min32()), 1234 Math.min(inX.max32(), inY.max32())); 1235 } 1236 1237 static public void computeFmod(TestFmod.ArgumentsFloatFloatFloat args, Target t) { 1238 t.setPrecision(1, 1, false); 1239 Target.Floaty inX = t.new32(args.inX); 1240 Target.Floaty inY = t.new32(args.inY); 1241 args.out = t.new32( 1242 args.inX % args.inY, 1243 inX.min32() % inY.min32(), 1244 inX.min32() % inY.max32(), 1245 inX.max32() % inY.min32(), 1246 inX.max32() % inY.max32()); 1247 } 1248 1249 static public void computeFract(TestFract.ArgumentsFloatFloatFloat args, Target t) { 1250 t.setPrecision(1, 1, false); 1251 float floor = floor(args.inV); 1252 args.outFloor = t.new32(floor); 1253 // 0x1.fffffep-1f is 0.999999... 1254 args.out = t.new32(Math.min(args.inV - floor, 0x1.fffffep-1f)); 1255 } 1256 1257 static public void computeFract(TestFract.ArgumentsFloatFloat args, Target t) { 1258 t.setPrecision(1, 1, false); 1259 float floor = floor(args.inV); 1260 // 0x1.fffffep-1f is 0.999999... 1261 args.out = t.new32(Math.min(args.inV - floor, 0x1.fffffep-1f)); 1262 } 1263 1264 static public void computeFrexp(TestFrexp.ArgumentsFloatIntFloat args, Target t) { 1265 t.setPrecision(0, 0, false); 1266 FrexpResult result = frexp(args.inV); 1267 args.out = t.new32(result.significand); 1268 args.outIptr = result.exponent; 1269 } 1270 1271 static public void computeHalfRecip(TestHalfRecip.ArgumentsFloatFloat args, Target t) { 1272 t.setPrecision(HALF_PRECISION, HALF_PRECISION, false); 1273 args.out = recip(args.inV, t); 1274 } 1275 1276 static public void computeHalfRsqrt(TestHalfRsqrt.ArgumentsFloatFloat args, Target t) { 1277 t.setPrecision(HALF_PRECISION, HALF_PRECISION, false); 1278 args.out = rsqrt(args.inV, t); 1279 } 1280 1281 static public void computeHalfSqrt(TestHalfSqrt.ArgumentsFloatFloat args, Target t) { 1282 t.setPrecision(HALF_PRECISION, HALF_PRECISION, false); 1283 args.out = sqrt(args.inV, t); 1284 } 1285 1286 static public void computeHypot(TestHypot.ArgumentsFloatFloatFloat args, Target t) { 1287 t.setPrecision(4, 4, false); 1288 args.out = hypot(args.inX, args.inY, t); 1289 } 1290 1291 static public String verifyIlogb(TestIlogb.ArgumentsFloatInt args) { 1292 // Special case when the input is 0. We accept two different answers. 1293 if (args.in == 0.f) { 1294 if (args.out != -Integer.MAX_VALUE && args.out != Integer.MIN_VALUE) { 1295 return "Expected " + Integer.toString(-Integer.MAX_VALUE) + " or " + 1296 Integer.toString(Integer.MIN_VALUE); 1297 } 1298 } else { 1299 int result = ilogb(args.in); 1300 if (args.out != result) { 1301 return "Expected " + Integer.toString(result); 1302 } 1303 } 1304 return null; 1305 } 1306 1307 static public void computeLdexp(TestLdexp.ArgumentsFloatIntFloat args, Target t) { 1308 t.setPrecision(1, 1, false); 1309 Target.Floaty inX = t.new32(args.inX); 1310 args.out = t.new32( 1311 ldexp(inX.mid32(), args.inY), 1312 ldexp(inX.min32(), args.inY), 1313 ldexp(inX.max32(), args.inY)); 1314 } 1315 1316 static public void computeLength(TestLength.ArgumentsFloatFloat args, Target t) { 1317 t.setPrecision(1, 1, false); 1318 args.out = length(new float[]{args.inV}, t); 1319 } 1320 1321 static public void computeLength(TestLength.ArgumentsFloatNFloat args, Target t) { 1322 t.setPrecision(1, 1, false); 1323 args.out = length(args.inV, t); 1324 } 1325 1326 static public void computeLgamma(TestLgamma.ArgumentsFloatFloat args, Target t) { 1327 t.setPrecision(16, 128, false); 1328 Target.Floaty in = t.new32(args.in); 1329 args.out = t.new32( 1330 lgamma(in.mid32()), 1331 lgamma(in.min32()), 1332 lgamma(in.max32())); 1333 } 1334 1335 /* TODO Until -0 handling is corrected in bionic & associated drivers, we temporarily 1336 * disable the verification of -0. We do this with a custom verifier. Once bionic 1337 * is fixed, we can restore computeLgamma and remove verifyLgamma. 1338 static public void computeLgamma(TestLgamma.ArgumentsFloatIntFloat args, Target t) { 1339 t.setPrecision(16, 128, false); 1340 Target.Floaty in = t.new32(args.inX); 1341 LgammaResult result = lgamma2(in.mid32()); 1342 LgammaResult resultMin = lgamma2(in.min32()); 1343 LgammaResult resultMax = lgamma2(in.max32()); 1344 args.out = t.new32(result.lgamma, resultMin.lgamma, resultMax.lgamma); 1345 args.outY = result.gammaSign; 1346 } 1347 */ 1348 static public String verifyLgamma(TestLgamma.ArgumentsFloatIntFloat args, Target t) { 1349 t.setPrecision(16, 128, false); 1350 Target.Floaty in = t.new32(args.inX); 1351 LgammaResult result = lgamma2(in.mid32()); 1352 LgammaResult resultMin = lgamma2(in.min32()); 1353 LgammaResult resultMax = lgamma2(in.max32()); 1354 Target.Floaty expectedOut = t.new32(result.lgamma, resultMin.lgamma, resultMax.lgamma); 1355 boolean isNegativeZero = args.inX == 0.f && 1.f / args.inX < 0.f; 1356 /* TODO The current implementation of bionic does not handle the -0.f case correctly. 1357 * It should set the sign to -1 but sets it to 1. 1358 */ 1359 if (!expectedOut.couldBe(args.out) || 1360 (args.outY != result.gammaSign && !isNegativeZero)) { 1361 StringBuilder message = new StringBuilder(); 1362 message.append(String.format("Input in %14.8g {%8x}:\n", args.inX, Float.floatToRawIntBits(args.inX))); 1363 message.append("Expected out: "); 1364 message.append(expectedOut.toString()); 1365 message.append("\n"); 1366 message.append(String.format("Actual out: %14.8g {%8x}", args.out, Float.floatToRawIntBits(args.out))); 1367 message.append(String.format("Expected outY: %d\n", result.gammaSign)); 1368 message.append(String.format("Actual outY: %d\n", args.outY)); 1369 return message.toString(); 1370 } 1371 1372 return null; 1373 } 1374 1375 // TODO The relaxed ulf for the various log are taken from the old tests. 1376 // They are not consistent. 1377 static public void computeLog(TestLog.ArgumentsFloatFloat args, Target t) { 1378 t.setPrecision(3, 16, false); 1379 args.out = log(args.in, t); 1380 } 1381 1382 static public void computeLog10(TestLog10.ArgumentsFloatFloat args, Target t) { 1383 t.setPrecision(3, 16, false); 1384 args.out = log10(args.in, t); 1385 } 1386 1387 static public void computeLog1p(TestLog1p.ArgumentsFloatFloat args, Target t) { 1388 t.setPrecision(2, 16, false); 1389 args.out = log1p(args.in, t); 1390 } 1391 1392 static public void computeLog2(TestLog2.ArgumentsFloatFloat args, Target t) { 1393 t.setPrecision(3, 128, false); 1394 args.out = log2(args.in, t); 1395 } 1396 1397 static public void computeLogb(TestLogb.ArgumentsFloatFloat args, Target t) { 1398 t.setPrecision(0, 0, false); 1399 Target.Floaty in = t.new32(args.in); 1400 args.out = t.new32( 1401 logb(in.mid32()), 1402 logb(in.min32()), 1403 logb(in.max32())); 1404 } 1405 1406 static public void computeMad(TestMad.ArgumentsFloatFloatFloatFloat args, Target t) { 1407 t.setPrecision(1, 4, false); 1408 Target.Floaty ab = t.multiply(t.new32(args.inA), t.new32(args.inB)); 1409 args.out = t.add(ab, t.new32(args.inC)); 1410 } 1411 1412 static public void computeMax(TestMax.ArgumentsCharCharChar args) { 1413 args.out = maxI8(args.inV1, args.inV2); 1414 } 1415 1416 static public void computeMax(TestMax.ArgumentsUcharUcharUchar args) { 1417 args.out = maxU8(args.inV1, args.inV2); 1418 } 1419 1420 static public void computeMax(TestMax.ArgumentsShortShortShort args) { 1421 args.out = maxI16(args.inV1, args.inV2); 1422 } 1423 1424 static public void computeMax(TestMax.ArgumentsUshortUshortUshort args) { 1425 args.out = maxU16(args.inV1, args.inV2); 1426 } 1427 1428 static public void computeMax(TestMax.ArgumentsIntIntInt args) { 1429 args.out = maxI32(args.inV1, args.inV2); 1430 } 1431 1432 static public void computeMax(TestMax.ArgumentsUintUintUint args) { 1433 args.out = maxU32(args.inV1, args.inV2); 1434 } 1435 1436 static public void computeMax(TestMax.ArgumentsLongLongLong args) { 1437 args.out = maxI64(args.inV1, args.inV2); 1438 } 1439 1440 static public void computeMax(TestMax.ArgumentsUlongUlongUlong args) { 1441 args.out = maxU64(args.inV1, args.inV2); 1442 } 1443 1444 static public void computeMax(TestMax.ArgumentsFloatFloatFloat args, Target t) { 1445 t.setPrecision(0, 0, false); 1446 Target.Floaty in = t.new32(args.in); 1447 Target.Floaty in1 = t.new32(args.in1); 1448 args.out = t.new32( 1449 Math.max(in.mid32(), in1.mid32()), 1450 Math.max(in.min32(), in1.min32()), 1451 Math.max(in.min32(), in1.max32()), 1452 Math.max(in.max32(), in1.min32()), 1453 Math.max(in.max32(), in1.max32())); 1454 } 1455 1456 static public void computeMin(TestMin.ArgumentsCharCharChar args) { 1457 args.out = minI8(args.inV1, args.inV2); 1458 } 1459 1460 static public void computeMin(TestMin.ArgumentsUcharUcharUchar args) { 1461 args.out = minU8(args.inV1, args.inV2); 1462 } 1463 1464 static public void computeMin(TestMin.ArgumentsShortShortShort args) { 1465 args.out = minI16(args.inV1, args.inV2); 1466 } 1467 1468 static public void computeMin(TestMin.ArgumentsUshortUshortUshort args) { 1469 args.out = minU16(args.inV1, args.inV2); 1470 } 1471 1472 static public void computeMin(TestMin.ArgumentsIntIntInt args) { 1473 args.out = minI32(args.inV1, args.inV2); 1474 } 1475 1476 static public void computeMin(TestMin.ArgumentsUintUintUint args) { 1477 args.out = minU32(args.inV1, args.inV2); 1478 } 1479 1480 static public void computeMin(TestMin.ArgumentsLongLongLong args) { 1481 args.out = minI64(args.inV1, args.inV2); 1482 } 1483 1484 static public void computeMin(TestMin.ArgumentsUlongUlongUlong args) { 1485 args.out = minU64(args.inV1, args.inV2); 1486 } 1487 1488 static public void computeMin(TestMin.ArgumentsFloatFloatFloat args, Target t) { 1489 t.setPrecision(0, 0, false); 1490 args.out = t.new32(Math.min(args.in, args.in1)); 1491 } 1492 1493 static public void computeMix(TestMix.ArgumentsFloatFloatFloatFloat args, Target t) { 1494 t.setPrecision(1, 4, false); 1495 Target.Floaty start = t.new32(args.inStart); 1496 Target.Floaty stop = t.new32(args.inStop); 1497 Target.Floaty diff = t.subtract(stop, start); 1498 args.out = t.add(start, t.multiply(diff, t.new32(args.inAmount))); 1499 } 1500 1501 static public void computeModf(TestModf.ArgumentsFloatFloatFloat args, Target t) { 1502 t.setPrecision(0, 0, false); 1503 float ret = (float)(int)args.inX; 1504 args.outIret = t.new32(ret); 1505 args.out = t.new32(args.inX - ret); 1506 } 1507 1508 static public void computeNan(TestNan.ArgumentsUintFloat args, Target t) { 1509 t.setPrecision(0, 0, false); 1510 args.out = t.new32(Float.NaN); 1511 } 1512 1513 static public void computeNativeAcos(TestNativeAcos.ArgumentsFloatFloat args, Target t) { 1514 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1515 args.out = acos(args.inV, t); 1516 } 1517 1518 static public void computeNativeAcosh(TestNativeAcosh.ArgumentsFloatFloat args, Target t) { 1519 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1520 args.out = acosh(args.in, t); 1521 } 1522 1523 static public void computeNativeAcospi(TestNativeAcospi.ArgumentsFloatFloat args, Target t) { 1524 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1525 args.out = acospi(args.inV, t); 1526 } 1527 1528 static public void computeNativeAsin(TestNativeAsin.ArgumentsFloatFloat args, Target t) { 1529 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1530 args.out = asin(args.inV, t); 1531 } 1532 1533 static public void computeNativeAsinh(TestNativeAsinh.ArgumentsFloatFloat args, Target t) { 1534 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1535 args.out = asinh(args.in, t); 1536 } 1537 1538 static public void computeNativeAsinpi(TestNativeAsinpi.ArgumentsFloatFloat args, Target t) { 1539 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1540 args.out = asinpi(args.inV, t); 1541 } 1542 1543 static public void computeNativeAtan(TestNativeAtan.ArgumentsFloatFloat args, Target t) { 1544 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1545 args.out = atan(args.inV, t); 1546 } 1547 1548 static public void computeNativeAtanh(TestNativeAtanh.ArgumentsFloatFloat args, Target t) { 1549 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1550 args.out = atanh(args.inIn, t); 1551 } 1552 1553 static public void computeNativeAtanpi(TestNativeAtanpi.ArgumentsFloatFloat args, Target t) { 1554 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1555 args.out = atanpi(args.inV, t); 1556 } 1557 1558 static public void computeNativeAtan2(TestNativeAtan2.ArgumentsFloatFloatFloat args, Target t) { 1559 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1560 args.out = atan2(args.inY, args.inX, t); 1561 } 1562 1563 static public void computeNativeAtan2pi(TestNativeAtan2pi.ArgumentsFloatFloatFloat args, Target t) { 1564 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1565 args.out = atan2pi(args.inY, args.inX, t); 1566 } 1567 1568 static public void computeNativeCbrt(TestNativeCbrt.ArgumentsFloatFloat args, Target t) { 1569 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1570 args.out = cbrt(args.in, t); 1571 } 1572 1573 static public void computeNativeCos(TestNativeCos.ArgumentsFloatFloat args, Target t) { 1574 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1575 args.out = cos(args.in, t); 1576 } 1577 1578 static public void computeNativeCosh(TestNativeCosh.ArgumentsFloatFloat args, Target t) { 1579 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1580 args.out = cosh(args.in, t); 1581 } 1582 1583 static public void computeNativeCospi(TestNativeCospi.ArgumentsFloatFloat args, Target t) { 1584 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1585 args.out = cospi(args.in, t); 1586 } 1587 1588 static public void computeNativeDistance(TestNativeDistance.ArgumentsFloatFloatFloat args, Target t) { 1589 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1590 args.out = distance(new float[]{args.inLhs}, new float[]{args.inRhs}, t); 1591 } 1592 1593 static public void computeNativeDistance(TestNativeDistance.ArgumentsFloatNFloatNFloat args, Target t) { 1594 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1595 args.out = distance(args.inLhs, args.inRhs, t); 1596 } 1597 1598 static public void computeNativeDivide(TestNativeDivide.ArgumentsFloatFloatFloat args, Target t) { 1599 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1600 args.out = t.divide(t.new32(args.inLhs), t.new32(args.inRhs)); 1601 } 1602 1603 static public void computeNativeExp(TestNativeExp.ArgumentsFloatFloat args, Target t) { 1604 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1605 args.out = exp(args.inV, t); 1606 } 1607 1608 static public void computeNativeExp10(TestNativeExp10.ArgumentsFloatFloat args, Target t) { 1609 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1610 args.out = exp10(args.inV, t); 1611 } 1612 1613 static public void computeNativeExp2(TestNativeExp2.ArgumentsFloatFloat args, Target t) { 1614 // TODO we would like to use NATIVE_PRECISION, NATIVE_PRECISION 1615 t.setPrecision(13000, 13000, true); 1616 args.out = exp2(args.inV, t); 1617 } 1618 1619 static public void computeNativeExpm1(TestNativeExpm1.ArgumentsFloatFloat args, Target t) { 1620 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1621 args.out = expm1(args.in, t); 1622 } 1623 1624 static public void computeNativeHypot(TestNativeHypot.ArgumentsFloatFloatFloat args, Target t) { 1625 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1626 args.out = hypot(args.inX, args.inY, t); 1627 } 1628 1629 static public void computeNativeLength(TestNativeLength.ArgumentsFloatFloat args, Target t) { 1630 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1631 args.out = length(new float[] {args.inV}, t); 1632 } 1633 1634 static public void computeNativeLength(TestNativeLength.ArgumentsFloatNFloat args, Target t) { 1635 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1636 args.out = length(args.inV, t); 1637 } 1638 1639 static public void computeNativeLog(TestNativeLog.ArgumentsFloatFloat args, Target t) { 1640 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1641 // For very small values, allow anything. 1642 if (Math.abs(args.inV) < 1.e-20) { 1643 args.out = any32(t); 1644 } else { 1645 args.out = log(args.inV, t); 1646 } 1647 } 1648 1649 static public void computeNativeLog10(TestNativeLog10.ArgumentsFloatFloat args, Target t) { 1650 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1651 // For very small values, allow anything. 1652 if (Math.abs(args.inV) < 1.e-20) { 1653 args.out = any32(t); 1654 } else { 1655 args.out = log10(args.inV, t); 1656 } 1657 } 1658 1659 static public void computeNativeLog1p(TestNativeLog1p.ArgumentsFloatFloat args, Target t) { 1660 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1661 args.out = log1p(args.in, t); 1662 } 1663 1664 static public void computeNativeLog2(TestNativeLog2.ArgumentsFloatFloat args, Target t) { 1665 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1666 // For very small values, allow anything. 1667 if (Math.abs(args.inV) < 1.e-20) { 1668 args.out = any32(t); 1669 } else { 1670 args.out = log2(args.inV, t); 1671 } 1672 } 1673 1674 static public void computeNativeNormalize(TestNativeNormalize.ArgumentsFloatFloat args, Target t) { 1675 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1676 Target.Floaty[] out = new Target.Floaty[1]; 1677 normalize(new float[] {args.inV}, out, t); 1678 args.out = out[0]; 1679 } 1680 1681 static public void computeNativeNormalize(TestNativeNormalize.ArgumentsFloatNFloatN args, Target t) { 1682 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1683 normalize(args.inV, args.out, t); 1684 } 1685 1686 static public void computeNativePowr(TestNativePowr.ArgumentsFloatFloatFloat args, Target t) { 1687 // TODO we would like to use NATIVE_PRECISION, NATIVE_PRECISION 1688 t.setPrecision(32000, 32000, true); 1689 // For very small values, allow anything. 1690 if (Math.abs(args.inV) < 1.e-20) { 1691 args.out = any32(t); 1692 } else { 1693 args.out = powr(args.inV, args.inY, t); 1694 } 1695 } 1696 1697 static public void computeNativeRecip(TestNativeRecip.ArgumentsFloatFloat args, Target t) { 1698 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1699 args.out = recip(args.inV, t); 1700 } 1701 1702 static public void computeNativeRootn(TestNativeRootn.ArgumentsFloatIntFloat args, Target t) { 1703 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1704 // Allow anything for zero. 1705 if (args.inN == 0) { 1706 args.out = any32(t); 1707 } else { 1708 args.out = rootn(args.inV, args.inN, t); 1709 } 1710 } 1711 1712 static public void computeNativeRsqrt(TestNativeRsqrt.ArgumentsFloatFloat args, Target t) { 1713 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1714 args.out = rsqrt(args.in, t); 1715 } 1716 1717 static public void computeNativeSin(TestNativeSin.ArgumentsFloatFloat args, Target t) { 1718 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1719 args.out = sin(args.in, t); 1720 } 1721 1722 static public void computeNativeSincos(TestNativeSincos.ArgumentsFloatFloatFloat args, Target t) { 1723 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1724 args.outCosptr = cos(args.inV, t); 1725 args.out = sin(args.inV, t); 1726 } 1727 1728 static public void computeNativeSinh(TestNativeSinh.ArgumentsFloatFloat args, Target t) { 1729 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1730 args.out = sinh(args.in, t); 1731 } 1732 1733 static public void computeNativeSinpi(TestNativeSinpi.ArgumentsFloatFloat args, Target t) { 1734 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1735 args.out = sinpi(args.in, t); 1736 } 1737 1738 static public void computeNativeSqrt(TestNativeSqrt.ArgumentsFloatFloat args, Target t) { 1739 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1740 args.out = sqrt(args.in, t); 1741 } 1742 1743 static public void computeNativeTan(TestNativeTan.ArgumentsFloatFloat args, Target t) { 1744 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1745 args.out = tan(args.in, t); 1746 } 1747 1748 static public void computeNativeTanh(TestNativeTanh.ArgumentsFloatFloat args, Target t) { 1749 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1750 args.out = tanh(args.in, t); 1751 } 1752 1753 static public void computeNativeTanpi(TestNativeTanpi.ArgumentsFloatFloat args, Target t) { 1754 t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION, true); 1755 args.out = tanpi(args.in, t); 1756 } 1757 1758 static public void computeNextafter(TestNextafter.ArgumentsFloatFloatFloat args, Target t) { 1759 t.setPrecision(0, 0, false); 1760 args.out = t.new32(Math.nextAfter(args.inX, args.inY)); 1761 } 1762 1763 static public void computeNormalize(TestNormalize.ArgumentsFloatFloat args, Target t) { 1764 t.setPrecision(1, 1, false); 1765 Target.Floaty[] out = new Target.Floaty[1]; 1766 normalize(new float[] {args.inV}, out, t); 1767 args.out = out[0]; 1768 } 1769 1770 static public void computeNormalize(TestNormalize.ArgumentsFloatNFloatN args, Target t) { 1771 t.setPrecision(1, 1, false); 1772 normalize(args.inV, args.out, t); 1773 } 1774 1775 static public void computePow(TestPow.ArgumentsFloatFloatFloat args, Target t) { 1776 t.setPrecision(16, 128, false); 1777 Target.Floaty inX = t.new32(args.inX); 1778 Target.Floaty inY = t.new32(args.inY); 1779 args.out = t.new32( 1780 pow(inX.mid32(), inY.mid32()), 1781 pow(inX.min32(), inY.min32()), 1782 pow(inX.min32(), inY.max32()), 1783 pow(inX.max32(), inY.min32()), 1784 pow(inX.max32(), inY.max32())); 1785 } 1786 1787 static public void computePown(TestPown.ArgumentsFloatIntFloat args, Target t) { 1788 t.setPrecision(16, 128, false); 1789 Target.Floaty in = t.new32(args.inX); 1790 // We use double for the calculations because floats does not have enough 1791 // mantissa bits. Knowing if an int is odd or even will matter for negative 1792 // numbers. Using a float loses the lowest bit. 1793 final double y = (double) args.inY; 1794 args.out = t.new32( 1795 (float) Math.pow(in.mid32(), y), 1796 (float) Math.pow(in.min32(), y), 1797 (float) Math.pow(in.max32(), y)); 1798 } 1799 1800 static public void computePowr(TestPowr.ArgumentsFloatFloatFloat args, Target t) { 1801 t.setPrecision(16, 128, false); 1802 args.out = powr(args.inX, args.inY, t); 1803 } 1804 1805 static public void computeRadians(TestRadians.ArgumentsFloatFloat args, Target t) { 1806 t.setPrecision(3, 3, false); 1807 Target.Floaty in = t.new32(args.inValue); 1808 Target.Floaty k = t.new32((float)(Math.PI / 180.0)); 1809 args.out = t.multiply(in, k); 1810 } 1811 1812 static public void computeRemainder(TestRemainder.ArgumentsFloatFloatFloat args, Target t) { 1813 t.setPrecision(0, 0, false); 1814 RemquoResult result = remquo(args.inX, args.inY); 1815 args.out = t.new32(result.remainder); 1816 } 1817 1818 static public String verifyRemquo(TestRemquo.ArgumentsFloatFloatIntFloat args, Target t) { 1819 t.setPrecision(0, 0, false); 1820 RemquoResult expected = remquo(args.inB, args.inC); 1821 // If the expected remainder is NaN, we don't validate the quotient. It's because of 1822 // a division by zero. 1823 if (expected.remainder != expected.remainder) { 1824 // Check that the value we got is NaN too. 1825 if (args.out == args.out) { 1826 return "Expected a remainder of NaN but got " + Float.toString(args.out); 1827 } 1828 } else { 1829 // The quotient should have the same lowest three bits. 1830 if ((args.outD & 0x07) != (expected.quotient & 0x07)) { 1831 return "Quotient returned " + Integer.toString(args.outD) + 1832 " does not have the same lower three bits as the expected " + 1833 Integer.toString(expected.quotient); 1834 } 1835 Target.Floaty remainder = t.new32(expected.remainder); 1836 if (!remainder.couldBe(args.out)) { 1837 return "Remainder returned " + Float.toString(args.out) + 1838 " is not similar to the expected " + 1839 remainder.toString(); 1840 } 1841 } 1842 return null; 1843 } 1844 1845 static public void computeRint(TestRint.ArgumentsFloatFloat args, Target t) { 1846 t.setPrecision(0, 0, false); 1847 Target.Floaty in = t.new32(args.in); 1848 args.out = t.new32( 1849 rint(in.mid32()), 1850 rint(in.min32()), 1851 rint(in.max32())); 1852 } 1853 1854 static public void computeRootn(TestRootn.ArgumentsFloatIntFloat args, Target t) { 1855 t.setPrecision(16, 16, false); 1856 args.out = rootn(args.inV, args.inN, t); 1857 } 1858 1859 static public void computeRound(TestRound.ArgumentsFloatFloat args, Target t) { 1860 t.setPrecision(0, 0, false); 1861 Target.Floaty in = t.new32(args.in); 1862 args.out = t.new32( 1863 round(in.mid32()), 1864 round(in.min32()), 1865 round(in.max32())); 1866 } 1867 1868 static public void computeRsqrt(TestRsqrt.ArgumentsFloatFloat args, Target t) { 1869 t.setPrecision(2, 2, false); 1870 args.out = rsqrt(args.in, t); 1871 } 1872 1873 static public void computeSign(TestSign.ArgumentsFloatFloat args, Target t) { 1874 t.setPrecision(0, 0, false); 1875 args.out = t.new32(Math.signum(args.inV)); 1876 } 1877 1878 static public void computeSin(TestSin.ArgumentsFloatFloat args, Target t) { 1879 t.setPrecision(4, 128, false); 1880 args.out = sin(args.in, t); 1881 } 1882 1883 static public void computeSincos(TestSincos.ArgumentsFloatFloatFloat args, Target t) { 1884 t.setPrecision(4, 128, false); 1885 args.outCosptr = cos(args.inV,t ); 1886 args.out = sin(args.inV, t); 1887 } 1888 1889 static public void computeSinh(TestSinh.ArgumentsFloatFloat args, Target t) { 1890 t.setPrecision(4, 128, false); 1891 args.out = sinh(args.in, t); 1892 } 1893 1894 static public void computeSinpi(TestSinpi.ArgumentsFloatFloat args, Target t) { 1895 t.setPrecision(4, 128, false); 1896 args.out = sinpi(args.in, t); 1897 } 1898 1899 static public void computeSqrt(TestSqrt.ArgumentsFloatFloat args, Target t) { 1900 t.setPrecision(3, 3, false); 1901 args.out = sqrt(args.in, t); 1902 } 1903 1904 static public void computeStep(TestStep.ArgumentsFloatFloatFloat args, Target t) { 1905 t.setPrecision(0, 0, false); 1906 args.out = t.new32(args.inV < args.inEdge ? 0.f : 1.f); 1907 } 1908 1909 static public void computeTan(TestTan.ArgumentsFloatFloat args, Target t) { 1910 t.setPrecision(5, 128, false); 1911 args.out = tan(args.in, t); 1912 } 1913 1914 static public void computeTanh(TestTanh.ArgumentsFloatFloat args, Target t) { 1915 t.setPrecision(5, 128, false); 1916 args.out = tanh(args.in, t); 1917 } 1918 1919 static public void computeTanpi(TestTanpi.ArgumentsFloatFloat args, Target t) { 1920 t.setPrecision(4, 128, false); 1921 args.out = tanpi(args.in, t); 1922 } 1923 1924 static public void computeTgamma(TestTgamma.ArgumentsFloatFloat args, Target t) { 1925 t.setPrecision(16, 128, false); 1926 Target.Floaty in = t.new32(args.in); 1927 args.out = t.new32( 1928 tgamma(in.mid32()), 1929 tgamma(in.min32()), 1930 tgamma(in.max32())); 1931 } 1932 1933 static public void computeTrunc(TestTrunc.ArgumentsFloatFloat args, Target t) { 1934 t.setPrecision(0, 0, false); 1935 Target.Floaty in = t.new32(args.in); 1936 args.out = t.new32( 1937 trunc(in.mid32()), 1938 trunc(in.min32()), 1939 trunc(in.max32())); 1940 } 1941 } 1942