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      */
acos(float x)57     static native float acos(float x);
acosh(float x)58     static native float acosh(float x);
asin(float x)59     static native float asin(float x);
asinh(float x)60     static native float asinh(float x);
atan(float x)61     static native float atan(float x);
atan2(float x, float y)62     static native float atan2(float x, float y);
atanh(float x)63     static native float atanh(float x);
cbrt(float x)64     static native float cbrt(float x);
ceil(float x)65     static native float ceil(float x);
cos(float x)66     static native float cos(float x);
cosh(float x)67     static native float cosh(float x);
erf(float x)68     static native float erf(float x);
erfc(float x)69     static native float erfc(float x);
exp(float x)70     static native float exp(float x);
exp10(float x)71     static native float exp10(float x);
exp2(float x)72     static native float exp2(float x);
expm1(float x)73     static native float expm1(float x);
floor(float x)74     static native float floor(float x);
frexp(float x)75     static native FrexpResult frexp(float x);
hypot(float x, float y)76     static native float hypot(float x, float y);
ilogb(float x)77     static native int ilogb(float x);
ldexp(float x, int exp)78     static native float ldexp(float x, int exp);
lgamma(float x)79     static native float lgamma(float x);
lgamma2(float x)80     static native LgammaResult lgamma2(float x);
log(float x)81     static native float log(float x);
logb(float x)82     static native float logb(float x);
log10(float x)83     static native float log10(float x);
log1p(float x)84     static native float log1p(float x);
log2(float x)85     static native float log2(float x);
maxI8(byte x, byte y)86     static native byte maxI8(byte x, byte y);
maxU8(byte x, byte y)87     static native byte maxU8(byte x, byte y);
maxI16(short x, short y)88     static native short maxI16(short x, short y);
maxU16(short x, short y)89     static native short maxU16(short x, short y);
maxI32(int x, int y)90     static native int maxI32(int x, int y);
maxU32(int x, int y)91     static native int maxU32(int x, int y);
maxI64(long x, long y)92     static native long maxI64(long x, long y);
maxU64(long x, long y)93     static native long maxU64(long x, long y);
minI8(byte x, byte y)94     static native byte minI8(byte x, byte y);
minU8(byte x, byte y)95     static native byte minU8(byte x, byte y);
minI16(short x, short y)96     static native short minI16(short x, short y);
minU16(short x, short y)97     static native short minU16(short x, short y);
minI32(int x, int y)98     static native int minI32(int x, int y);
minU32(int x, int y)99     static native int minU32(int x, int y);
minI64(long x, long y)100     static native long minI64(long x, long y);
minU64(long x, long y)101     static native long minU64(long x, long y);
pow(float x, float y)102     static native float pow(float x, float y);
remquo(float numerator, float denominator)103     static native RemquoResult remquo(float numerator, float denominator);
rint(float x)104     static native float rint(float x);
round(float x)105     static native float round(float x);
sin(float x)106     static native float sin(float x);
sinh(float x)107     static native float sinh(float x);
sqrt(float x)108     static native float sqrt(float x);
tan(float x)109     static native float tan(float x);
tanh(float x)110     static native float tanh(float x);
tgamma(float x)111     static native float tgamma(float x);
trunc(float x)112     static native float trunc(float x);
113 
convertCharToChar(byte x)114     static native byte   convertCharToChar(byte x);
convertCharToUchar(byte x)115     static native byte   convertCharToUchar(byte x);
convertCharToShort(byte x)116     static native short  convertCharToShort(byte x);
convertCharToUshort(byte x)117     static native short  convertCharToUshort(byte x);
convertCharToInt(byte x)118     static native int    convertCharToInt(byte x);
convertCharToUint(byte x)119     static native int    convertCharToUint(byte x);
convertCharToLong(byte x)120     static native long   convertCharToLong(byte x);
convertCharToUlong(byte x)121     static native long   convertCharToUlong(byte x);
convertCharToFloat(byte x)122     static native float  convertCharToFloat(byte x);
convertCharToDouble(byte x)123     static native double convertCharToDouble(byte x);
124 
convertUcharToChar(byte x)125     static native byte   convertUcharToChar(byte x);
convertUcharToUchar(byte x)126     static native byte   convertUcharToUchar(byte x);
convertUcharToShort(byte x)127     static native short  convertUcharToShort(byte x);
convertUcharToUshort(byte x)128     static native short  convertUcharToUshort(byte x);
convertUcharToInt(byte x)129     static native int    convertUcharToInt(byte x);
convertUcharToUint(byte x)130     static native int    convertUcharToUint(byte x);
convertUcharToLong(byte x)131     static native long   convertUcharToLong(byte x);
convertUcharToUlong(byte x)132     static native long   convertUcharToUlong(byte x);
convertUcharToFloat(byte x)133     static native float  convertUcharToFloat(byte x);
convertUcharToDouble(byte x)134     static native double convertUcharToDouble(byte x);
135 
convertShortToChar(short x)136     static native byte   convertShortToChar(short x);
convertShortToUchar(short x)137     static native byte   convertShortToUchar(short x);
convertShortToShort(short x)138     static native short  convertShortToShort(short x);
convertShortToUshort(short x)139     static native short  convertShortToUshort(short x);
convertShortToInt(short x)140     static native int    convertShortToInt(short x);
convertShortToUint(short x)141     static native int    convertShortToUint(short x);
convertShortToLong(short x)142     static native long   convertShortToLong(short x);
convertShortToUlong(short x)143     static native long   convertShortToUlong(short x);
convertShortToFloat(short x)144     static native float  convertShortToFloat(short x);
convertShortToDouble(short x)145     static native double convertShortToDouble(short x);
146 
convertUshortToChar(short x)147     static native byte   convertUshortToChar(short x);
convertUshortToUchar(short x)148     static native byte   convertUshortToUchar(short x);
convertUshortToShort(short x)149     static native short  convertUshortToShort(short x);
convertUshortToUshort(short x)150     static native short  convertUshortToUshort(short x);
convertUshortToInt(short x)151     static native int    convertUshortToInt(short x);
convertUshortToUint(short x)152     static native int    convertUshortToUint(short x);
convertUshortToLong(short x)153     static native long   convertUshortToLong(short x);
convertUshortToUlong(short x)154     static native long   convertUshortToUlong(short x);
convertUshortToFloat(short x)155     static native float  convertUshortToFloat(short x);
convertUshortToDouble(short x)156     static native double convertUshortToDouble(short x);
157 
convertIntToChar(int x)158     static native byte   convertIntToChar(int x);
convertIntToUchar(int x)159     static native byte   convertIntToUchar(int x);
convertIntToShort(int x)160     static native short  convertIntToShort(int x);
convertIntToUshort(int x)161     static native short  convertIntToUshort(int x);
convertIntToInt(int x)162     static native int    convertIntToInt(int x);
convertIntToUint(int x)163     static native int    convertIntToUint(int x);
convertIntToLong(int x)164     static native long   convertIntToLong(int x);
convertIntToUlong(int x)165     static native long   convertIntToUlong(int x);
convertIntToFloat(int x)166     static native float  convertIntToFloat(int x);
convertIntToDouble(int x)167     static native double convertIntToDouble(int x);
168 
convertUintToChar(int x)169     static native byte   convertUintToChar(int x);
convertUintToUchar(int x)170     static native byte   convertUintToUchar(int x);
convertUintToShort(int x)171     static native short  convertUintToShort(int x);
convertUintToUshort(int x)172     static native short  convertUintToUshort(int x);
convertUintToInt(int x)173     static native int    convertUintToInt(int x);
convertUintToUint(int x)174     static native int    convertUintToUint(int x);
convertUintToLong(int x)175     static native long   convertUintToLong(int x);
convertUintToUlong(int x)176     static native long   convertUintToUlong(int x);
convertUintToFloat(int x)177     static native float  convertUintToFloat(int x);
convertUintToDouble(int x)178     static native double convertUintToDouble(int x);
179 
convertLongToChar(long x)180     static native byte   convertLongToChar(long x);
convertLongToUchar(long x)181     static native byte   convertLongToUchar(long x);
convertLongToShort(long x)182     static native short  convertLongToShort(long x);
convertLongToUshort(long x)183     static native short  convertLongToUshort(long x);
convertLongToInt(long x)184     static native int    convertLongToInt(long x);
convertLongToUint(long x)185     static native int    convertLongToUint(long x);
convertLongToLong(long x)186     static native long   convertLongToLong(long x);
convertLongToUlong(long x)187     static native long   convertLongToUlong(long x);
convertLongToFloat(long x)188     static native float  convertLongToFloat(long x);
convertLongToDouble(long x)189     static native double convertLongToDouble(long x);
190 
convertUlongToChar(long x)191     static native byte   convertUlongToChar(long x);
convertUlongToUchar(long x)192     static native byte   convertUlongToUchar(long x);
convertUlongToShort(long x)193     static native short  convertUlongToShort(long x);
convertUlongToUshort(long x)194     static native short  convertUlongToUshort(long x);
convertUlongToInt(long x)195     static native int    convertUlongToInt(long x);
convertUlongToUint(long x)196     static native int    convertUlongToUint(long x);
convertUlongToLong(long x)197     static native long   convertUlongToLong(long x);
convertUlongToUlong(long x)198     static native long   convertUlongToUlong(long x);
convertUlongToFloat(long x)199     static native float  convertUlongToFloat(long x);
convertUlongToDouble(long x)200     static native double convertUlongToDouble(long x);
201 
convertFloatToChar(float x)202     static native byte   convertFloatToChar(float x);
convertFloatToUchar(float x)203     static native byte   convertFloatToUchar(float x);
convertFloatToShort(float x)204     static native short  convertFloatToShort(float x);
convertFloatToUshort(float x)205     static native short  convertFloatToUshort(float x);
convertFloatToInt(float x)206     static native int    convertFloatToInt(float x);
convertFloatToUint(float x)207     static native int    convertFloatToUint(float x);
convertFloatToLong(float x)208     static native long   convertFloatToLong(float x);
convertFloatToUlong(float x)209     static native long   convertFloatToUlong(float x);
convertFloatToFloat(float x)210     static native float  convertFloatToFloat(float x);
convertFloatToDouble(float x)211     static native double convertFloatToDouble(float x);
212 
convertDoubleToChar(double x)213     static native byte   convertDoubleToChar(double x);
convertDoubleToUchar(double x)214     static native byte   convertDoubleToUchar(double x);
convertDoubleToShort(double x)215     static native short  convertDoubleToShort(double x);
convertDoubleToUshort(double x)216     static native short  convertDoubleToUshort(double x);
convertDoubleToInt(double x)217     static native int    convertDoubleToInt(double x);
convertDoubleToUint(double x)218     static native int    convertDoubleToUint(double x);
convertDoubleToLong(double x)219     static native long   convertDoubleToLong(double x);
convertDoubleToUlong(double x)220     static native long   convertDoubleToUlong(double x);
convertDoubleToFloat(double x)221     static native float  convertDoubleToFloat(double x);
convertDoubleToDouble(double x)222     static native double convertDoubleToDouble(double x);
223 
pi(Target t)224     static private Target.Floaty pi(Target t) {
225         return t.newFloaty(Math.PI);
226     }
227 
pi32(Target t)228     static private Target.Floaty pi32(Target t) {
229         return t.new32((float) Math.PI);
230     }
231 
any(Target t)232     static private Target.Floaty any(Target t) {
233         return t.newFloaty(Double.NEGATIVE_INFINITY, Double.NaN, Double.POSITIVE_INFINITY);
234     }
235 
any32(Target t)236     static private Target.Floaty any32(Target t) {
237         return t.new32(Float.NEGATIVE_INFINITY, Float.NaN, Float.POSITIVE_INFINITY);
238     }
239 
acos(double d, Target t)240     static private Target.Floaty acos(double d, Target t) {
241         Target.Floaty in = t.newFloaty(d);
242         return t.newFloaty(
243             Math.acos(in.mid()),
244             Math.acos(in.min()),
245             Math.acos(in.max()));
246     }
247 
248     // TODO Remove this function and similar variants that take a float parameter instead of double.
acos(float f, Target t)249     static private Target.Floaty acos(float f, Target t) {
250         Target.Floaty in = t.new32(f);
251         return t.new32(
252             acos(in.mid32()),
253             acos(in.min32()),
254             acos(in.max32()));
255     }
256 
257     // NOTE: This function delegates to the floating-point version in libm.  Need to switch to the
258     // double-precision version later.
acosh(double d, Target t)259     static private Target.Floaty acosh(double d, Target t) {
260         Target.Floaty in = t.newFloaty(d);
261         return t.newFloaty(
262             acosh((float) in.mid()),
263             acosh((float) in.min()),
264             acosh((float) in.max()));
265     }
266 
acosh(float f, Target t)267     static private Target.Floaty acosh(float f, Target t) {
268         Target.Floaty in = t.new32(f);
269         return t.new32(
270             acosh(in.mid32()),
271             acosh(in.min32()),
272             acosh(in.max32()));
273     }
274 
acospi(double d, Target t)275     static private Target.Floaty acospi(double d, Target t) {
276         return t.divide(acos(d, t), pi(t));
277     }
278 
acospi(float f, Target t)279     static private Target.Floaty acospi(float f, Target t) {
280         return t.divide(acos(f, t), pi32(t));
281     }
282 
asin(double d, Target t)283     static private Target.Floaty asin(double d, Target t) {
284         Target.Floaty in = t.newFloaty(d);
285         return t.newFloaty(
286             Math.asin(in.mid()),
287             Math.asin(in.min()),
288             Math.asin(in.max()));
289     }
290 
asin(float f, Target t)291     static private Target.Floaty asin(float f, Target t) {
292         Target.Floaty in = t.new32(f);
293         return t.new32(
294             asin(in.mid32()),
295             asin(in.min32()),
296             asin(in.max32()));
297     }
298 
299     // NOTE: This function delegates to the floating-point version in libm.  Need to switch to the
300     // double-precision version later.
asinh(double d, Target t)301     static private Target.Floaty asinh(double d, Target t) {
302         Target.Floaty in = t.newFloaty(d);
303         return t.newFloaty(
304             asinh((float) in.mid()),
305             asinh((float) in.min()),
306             asinh((float) in.max()));
307     }
308 
asinh(float f, Target t)309     static private Target.Floaty asinh(float f, Target t) {
310         Target.Floaty in = t.new32(f);
311         return t.new32(
312             asinh(in.mid32()),
313             asinh(in.min32()),
314             asinh(in.max32()));
315     }
316 
asinpi(double d, Target t)317     static private Target.Floaty asinpi(double d, Target t) {
318         return t.divide(asin(d, t), pi(t));
319     }
320 
asinpi(float f, Target t)321     static private Target.Floaty asinpi(float f, Target t) {
322         return t.divide(asin(f, t), pi32(t));
323     }
324 
atan(double d, Target t)325     static private Target.Floaty atan(double d, Target t) {
326         Target.Floaty in = t.newFloaty(d);
327         return t.newFloaty(
328             Math.atan(in.mid()),
329             Math.atan(in.min()),
330             Math.atan(in.max()));
331     }
332 
atan(float f, Target t)333     static private Target.Floaty atan(float f, Target t) {
334         Target.Floaty in = t.new32(f);
335         return t.new32(
336             atan(in.mid32()),
337             atan(in.min32()),
338             atan(in.max32()));
339     }
340 
341     // NOTE: This function delegates to the floating-point version in libm.  Need to switch to the
342     // double-precision version later.
atanh(double d, Target t)343     static private Target.Floaty atanh(double d, Target t) {
344         Target.Floaty in = t.newFloaty(d);
345         return t.newFloaty(
346             atanh((float) in.mid()),
347             atanh((float) in.min()),
348             atanh((float) in.max()));
349     }
350 
atanh(float f, Target t)351     static private Target.Floaty atanh(float f, Target t) {
352         Target.Floaty in = t.new32(f);
353         return t.new32(
354             atanh(in.mid32()),
355             atanh(in.min32()),
356             atanh(in.max32()));
357     }
358 
atanpi(double d, Target t)359     static private Target.Floaty atanpi(double d, Target t) {
360         return t.divide(atan(d, t), pi(t));
361     }
362 
atanpi(float f, Target t)363     static private Target.Floaty atanpi(float f, Target t) {
364         return t.divide(atan(f, t), pi32(t));
365     }
366 
atan2(double y, double x, Target t)367     static private Target.Floaty atan2(double y, double x, Target t) {
368         Target.Floaty numerator = t.newFloaty(y);
369         Target.Floaty denominator = t.newFloaty(x);
370         return t.newFloaty(
371             Math.atan2(numerator.mid(), denominator.mid()),
372             Math.atan2(numerator.min(), denominator.min()),
373             Math.atan2(numerator.min(), denominator.max()),
374             Math.atan2(numerator.max(), denominator.min()),
375             Math.atan2(numerator.max(), denominator.max()));
376     }
377 
atan2(float y, float x, Target t)378     static private Target.Floaty atan2(float y, float x, Target t) {
379         Target.Floaty numerator = t.new32(y);
380         Target.Floaty denominator = t.new32(x);
381         return t.new32(
382             atan2(numerator.mid32(), denominator.mid32()),
383             atan2(numerator.min32(), denominator.min32()),
384             atan2(numerator.min32(), denominator.max32()),
385             atan2(numerator.max32(), denominator.min32()),
386             atan2(numerator.max32(), denominator.max32()));
387     }
388 
atan2pi(double y, double x, Target t)389     static private Target.Floaty atan2pi(double y, double x, Target t) {
390         return t.divide(atan2(y, x, t), pi(t));
391     }
392 
atan2pi(float y, float x, Target t)393     static private Target.Floaty atan2pi(float y, float x, Target t) {
394         return t.divide(atan2(y, x, t), pi32(t));
395     }
396 
cbrt(double d, Target t)397     static private Target.Floaty cbrt(double d, Target t) {
398         Target.Floaty in = t.newFloaty(d);
399         return t.newFloaty(
400             Math.cbrt(in.mid()),
401             Math.cbrt(in.min()),
402             Math.cbrt(in.max()));
403     }
404 
cbrt(float f, Target t)405     static private Target.Floaty cbrt(float f, Target t) {
406         Target.Floaty in = t.new32(f);
407         return t.new32(
408             cbrt(in.mid32()),
409             cbrt(in.min32()),
410             cbrt(in.max32()));
411     }
412 
clamp(double value, double minValue, double maxValue, Target t)413     static private Target.Floaty clamp(double value, double minValue, double maxValue, Target t) {
414         return t.newFloaty(Math.min(maxValue, Math.max(minValue, value)));
415     }
416 
copysign(double magnitude, double sign, Target t)417     static private Target.Floaty copysign(double magnitude, double sign, Target t) {
418         return t.newFloaty(Math.copySign(magnitude, sign));
419     }
420 
cos(double d, Target t)421     static private Target.Floaty cos(double d, Target t) {
422         Target.Floaty in = t.newFloaty(d);
423         return t.newFloaty(
424             Math.cos(in.mid()),
425             Math.cos(in.min()),
426             Math.cos(in.max()));
427     }
428 
cos(float f, Target t)429     static private Target.Floaty cos(float f, Target t) {
430         Target.Floaty in = t.new32(f);
431         return t.new32(
432             cos(in.mid32()),
433             cos(in.min32()),
434             cos(in.max32()));
435     }
436 
cosh(double d, Target t)437     static private Target.Floaty cosh(double d, Target t) {
438         Target.Floaty in = t.newFloaty(d);
439         return t.newFloaty(
440             Math.cosh(in.mid()),
441             Math.cosh(in.min()),
442             Math.cosh(in.max()));
443     }
444 
cosh(float f, Target t)445     static private Target.Floaty cosh(float f, Target t) {
446         Target.Floaty in = t.new32(f);
447         return t.new32(
448             cosh(in.mid32()),
449             cosh(in.min32()),
450             cosh(in.max32()));
451     }
452 
cospi(double d, Target t)453     static private Target.Floaty cospi(double d, Target t) {
454         Target.Floaty in = t.multiply(t.newFloaty(d), pi(t));
455         return t.newFloaty(
456             Math.cos(in.mid()),
457             Math.cos(in.min()),
458             Math.cos(in.max()));
459     }
460 
cospi(float f, Target t)461     static private Target.Floaty cospi(float f, Target t) {
462         Target.Floaty in = t.multiply(t.new32(f), pi32(t));
463         return t.new32(
464             cos(in.mid32()),
465             cos(in.min32()),
466             cos(in.max32()));
467     }
468 
469     // Computes the cross product of two double-precision 3D vectors.
cross(double[] v1, double[] v2, Target.Floaty[] out, Target t)470     static private void cross(double[] v1, double[] v2, Target.Floaty[] out, Target t) {
471         Target.Floaty a12 = t.multiply(t.newFloaty(v1[1]), t.newFloaty(v2[2]));
472         Target.Floaty a21 = t.multiply(t.newFloaty(v1[2]), t.newFloaty(v2[1]));
473         out[0] = t.subtract(a12, a21);
474         Target.Floaty a02 = t.multiply(t.newFloaty(v1[0]), t.newFloaty(v2[2]));
475         Target.Floaty a20 = t.multiply(t.newFloaty(v1[2]), t.newFloaty(v2[0]));
476         out[1] = t.subtract(a20, a02);
477         Target.Floaty a01 = t.multiply(t.newFloaty(v1[0]), t.newFloaty(v2[1]));
478         Target.Floaty a10 = t.multiply(t.newFloaty(v1[1]), t.newFloaty(v2[0]));
479         out[2] = t.subtract(a01, a10);
480         if (out.length == 4) {
481             out[3] = t.newFloaty(0.f);
482         }
483     }
484 
485     // Computes the cross product of two 3D vectors.
cross(float[] v1, float[] v2, Target.Floaty[] out, Target t)486     static private void cross(float[] v1, float[] v2, Target.Floaty[] out, Target t) {
487         Target.Floaty a12 = t.multiply(t.new32(v1[1]), t.new32(v2[2]));
488         Target.Floaty a21 = t.multiply(t.new32(v1[2]), t.new32(v2[1]));
489         out[0] = t.subtract(a12, a21);
490         Target.Floaty a02 = t.multiply(t.new32(v1[0]), t.new32(v2[2]));
491         Target.Floaty a20 = t.multiply(t.new32(v1[2]), t.new32(v2[0]));
492         out[1] = t.subtract(a20, a02);
493         Target.Floaty a01 = t.multiply(t.new32(v1[0]), t.new32(v2[1]));
494         Target.Floaty a10 = t.multiply(t.new32(v1[1]), t.new32(v2[0]));
495         out[2] = t.subtract(a01, a10);
496         if (out.length == 4) {
497             out[3] = t.new32(0.f);
498         }
499     }
500 
divide(double left, double right, Target t)501     static private Target.Floaty divide(double left, double right, Target t) {
502         Target.Floaty lFloaty = t.newFloaty(left);
503         Target.Floaty rFloaty = t.newFloaty(right);
504         return t.divide(lFloaty, rFloaty);
505     }
506 
507     // Convert a double-precision radian value to degrees.
degrees(double d, Target t)508     static private Target.Floaty degrees(double d, Target t) {
509         Target.Floaty in = t.newFloaty(d);
510         Target.Floaty k = t.newFloaty(180. / Math.PI);
511         return t.multiply(in, k);
512     }
513 
514     // Returns the distance between two points (in double-precision) in n-dimensional space.
distance(double[] point1, double[] point2, Target t)515     static private Target.Floaty distance(double[] point1, double[] point2, Target t) {
516         Target.Floaty sum = t.newFloaty(0.f);
517         for (int i = 0; i < point1.length; i++) {
518             Target.Floaty diff = t.subtract(t.newFloaty(point1[i]), t.newFloaty(point2[i]));
519             sum = t.add(sum, t.multiply(diff, diff));
520         }
521         Target.Floaty d = t.sqrt(sum);
522         return d;
523     }
524 
525     // Returns the distance between two points in n-dimensional space.
distance(float[] point1, float[] point2, Target t)526     static private Target.Floaty distance(float[] point1, float[] point2, Target t) {
527         Target.Floaty sum = t.new32(0.f);
528         for (int i = 0; i < point1.length; i++) {
529             Target.Floaty diff = t.subtract(t.new32(point1[i]), t.new32(point2[i]));
530             sum = t.add(sum, t.multiply(diff, diff));
531         }
532         Target.Floaty d = t.sqrt(sum);
533         return d;
534     }
535 
536     // Computes the error function for a double-precision input.
537     // NOTE: This function delegates to the floating-point version in libm.  Need to switch to the
538     // double-precision version later.
erf(double d, Target t)539     static private Target.Floaty erf(double d, Target t) {
540         Target.Floaty in = t.newFloaty(d);
541         return t.newFloaty(
542             erf((float) in.mid()),
543             erf((float) in.min()),
544             erf((float) in.max()));
545     }
546 
547     // Computes the complementary error function for a double-precision input.
548     // NOTE: This function delegates to the floating-point version in libm.  Need to switch to the
549     // double-precision version later.
erfc(double d, Target t)550     static private Target.Floaty erfc(double d, Target t) {
551         Target.Floaty in = t.newFloaty(d);
552         return t.newFloaty(
553             erfc((float) in.mid()),
554             erfc((float) in.min()),
555             erfc((float) in.max()));
556     }
557 
exp(double d, Target t)558     static private Target.Floaty exp(double d, Target t) {
559         Target.Floaty in = t.newFloaty(d);
560         return t.newFloaty(
561             Math.exp(in.mid()),
562             Math.exp(in.min()),
563             Math.exp(in.max()));
564     }
565 
exp(float f, Target t)566     static private Target.Floaty exp(float f, Target t) {
567         Target.Floaty in = t.new32(f);
568         return t.new32(
569             exp(in.mid32()),
570             exp(in.min32()),
571             exp(in.max32()));
572     }
573 
574     // NOTE: This function delegates to the floating-point version in libm.  Need to switch to the
575     // double-precision version later.
exp10(double d, Target t)576     static private Target.Floaty exp10(double d, Target t) {
577         Target.Floaty in = t.newFloaty(d);
578         return t.newFloaty(
579             exp10((float) in.mid()),
580             exp10((float) in.min()),
581             exp10((float) in.max()));
582     }
583 
exp10(float f, Target t)584     static private Target.Floaty exp10(float f, Target t) {
585         Target.Floaty in = t.new32(f);
586         return t.new32(
587             exp10(in.mid32()),
588             exp10(in.min32()),
589             exp10(in.max32()));
590     }
591 
592     // NOTE: This function delegates to the floating-point version in libm.  Need to switch to the
593     // double-precision version later.
exp2(double d, Target t)594     static private Target.Floaty exp2(double d, Target t) {
595         Target.Floaty in = t.newFloaty(d);
596         return t.newFloaty(
597             exp2((float) in.mid()),
598             exp2((float) in.min()),
599             exp2((float) in.max()));
600     }
601 
exp2(float f, Target t)602     static private Target.Floaty exp2(float f, Target t) {
603         Target.Floaty in = t.new32(f);
604         return t.new32(
605             exp2(in.mid32()),
606             exp2(in.min32()),
607             exp2(in.max32()));
608     }
609 
expm1(double d, Target t)610     static private Target.Floaty expm1(double d, Target t) {
611         Target.Floaty in = t.newFloaty(d);
612         return t.newFloaty(
613             Math.expm1(in.mid()),
614             Math.expm1(in.min()),
615             Math.expm1(in.max()));
616     }
617 
expm1(float f, Target t)618     static private Target.Floaty expm1(float f, Target t) {
619         Target.Floaty in = t.new32(f);
620         return t.new32(
621             expm1(in.mid32()),
622             expm1(in.min32()),
623             expm1(in.max32()));
624     }
625 
fabs(double d, Target t)626     static private Target.Floaty fabs(double d, Target t) {
627         Target.Floaty in = t.newFloaty(d);
628         return t.newFloaty(
629             Math.abs(in.mid()),
630             Math.abs(in.min()),
631             Math.abs(in.max()));
632     }
633 
fdim(double a, double b, Target t)634     static private Target.Floaty fdim(double a, double b, Target t) {
635         Target.Floaty inA = t.newFloaty(a);
636         Target.Floaty inB = t.newFloaty(b);
637         Target.Floaty r = t.subtract(inA, inB);
638         return t.newFloaty(
639             Math.max(0., r.mid()),
640             Math.max(0., r.min()),
641             Math.max(0., r.max()));
642     }
643 
floor(double d, Target t)644     static private Target.Floaty floor(double d, Target t) {
645         Target.Floaty in = t.newFloaty(d);
646         return t.newFloaty(
647                     Math.floor(in.mid()),
648                     Math.floor(in.min()),
649                     Math.floor(in.max()));
650     }
651 
fma(double m1, double m2, double offset, Target t)652     static private Target.Floaty fma(double m1, double m2, double offset, Target t) {
653         Target.Floaty inM1 = t.newFloaty(m1);
654         Target.Floaty inM2 = t.newFloaty(m2);
655         Target.Floaty inOffset = t.newFloaty(offset);
656 
657         return t.add(t.multiply(inM1, inM2), inOffset);
658     }
659 
fmax(double a, double b, Target t)660     static private Target.Floaty fmax(double a, double b, Target t) {
661         return t.newFloaty(Math.max(a, b));
662     }
663 
fmin(double a, double b, Target t)664     static private Target.Floaty fmin(double a, double b, Target t) {
665         return t.newFloaty(Math.min(a, b));
666     }
667 
fmod(double numerator, double denominator, Target t)668     static private Target.Floaty fmod(double numerator, double denominator, Target t) {
669         Target.Floaty inNumerator = t.newFloaty(numerator);
670         Target.Floaty inDenominator = t.newFloaty(denominator);
671         return t.newFloaty(
672             numerator % denominator,
673             inNumerator.min() % inDenominator.min(),
674             inNumerator.min() % inDenominator.max(),
675             inNumerator.max() % inDenominator.min(),
676             inNumerator.max() % inDenominator.max());
677     }
678 
679     // Compute the fractional part of a double value and returns a result that is at most
680     // 'fractUpperBound'.
fract(double d, Target t, double fractUpperBound)681     static private Target.Floaty fract(double d, Target t, double fractUpperBound) {
682         return t.newFloaty(Math.min(
683             d - Math.floor(d),
684             fractUpperBound));
685     }
686 
hypot(double x, double y, Target t)687     static private Target.Floaty hypot(double x, double y, Target t) {
688         Target.Floaty inX = t.newFloaty(x);
689         Target.Floaty inY = t.newFloaty(y);
690         return t.newFloaty(
691             Math.hypot(inX.mid(), inY.mid()),
692             Math.hypot(inX.min(), inY.min()),
693             Math.hypot(inX.min(), inY.max()),
694             Math.hypot(inX.max(), inY.min()),
695             Math.hypot(inX.max(), inY.max()));
696     }
697 
hypot(float x, float y, Target t)698     static private Target.Floaty hypot(float x, float y, Target t) {
699         Target.Floaty inX = t.new32(x);
700         Target.Floaty inY = t.new32(y);
701         return t.new32(
702             hypot(inX.mid32(), inY.mid32()),
703             hypot(inX.min32(), inY.min32()),
704             hypot(inX.min32(), inY.max32()),
705             hypot(inX.max32(), inY.min32()),
706             hypot(inX.max32(), inY.max32()));
707     }
708 
709     // Returns the length of an n-dimensional vector (in double-precision).
length(double[] array, Target t)710     static private Target.Floaty length(double[] array, Target t) {
711         Target.Floaty sum = t.newFloaty(0.);
712         for (int i = 0; i < array.length; i++) {
713             Target.Floaty f = t.newFloaty(array[i]);
714             sum = t.add(sum, t.multiply(f, f));
715         }
716         return t.sqrt(sum);
717     }
718 
719     // Returns the length of the n-dimensional vector.
length(float[] array, Target t)720     static private Target.Floaty length(float[] array, Target t) {
721         Target.Floaty sum = t.new32(0.f);
722         for (int i = 0; i < array.length; i++) {
723             Target.Floaty f = t.new32(array[i]);
724             sum = t.add(sum, t.multiply(f, f));
725         }
726         Target.Floaty l = t.sqrt(sum);
727         return l;
728     }
729 
log(double d, Target t)730     static private Target.Floaty log(double d, Target t) {
731         Target.Floaty in = t.newFloaty(d);
732         return t.newFloaty(
733             Math.log(in.mid()),
734             Math.log(in.min()),
735             Math.log(in.max()));
736     }
737 
log(float f, Target t)738     static private Target.Floaty log(float f, Target t) {
739         Target.Floaty in = t.new32(f);
740         return t.new32(
741             log(in.mid32()),
742             log(in.min32()),
743             log(in.max32()));
744     }
745 
log10(double d, Target t)746     static private Target.Floaty log10(double d, Target t) {
747         Target.Floaty in = t.newFloaty(d);
748         return t.newFloaty(
749             Math.log10(in.mid()),
750             Math.log10(in.min()),
751             Math.log10(in.max()));
752     }
753 
log10(float f, Target t)754     static private Target.Floaty log10(float f, Target t) {
755         Target.Floaty in = t.new32(f);
756         return t.new32(
757             log10(in.mid32()),
758             log10(in.min32()),
759             log10(in.max32()));
760     }
761 
log1p(double d, Target t)762     static private Target.Floaty log1p(double d, Target t) {
763         Target.Floaty in = t.newFloaty(d);
764         return t.newFloaty(
765             Math.log1p(in.mid()),
766             Math.log1p(in.min()),
767             Math.log1p(in.max()));
768     }
769 
log1p(float f, Target t)770     static private Target.Floaty log1p(float f, Target t) {
771         Target.Floaty in = t.new32(f);
772         return t.new32(
773             log1p(in.mid32()),
774             log1p(in.min32()),
775             log1p(in.max32()));
776     }
777 
778     // NOTE: This function delegates to the floating-point version in libm.  Need to switch to the
779     // double-precision version later.
log2(double d, Target t)780     static private Target.Floaty log2(double d, Target t) {
781         Target.Floaty in = t.newFloaty(d);
782         return t.newFloaty(
783             log2((float) in.mid()),
784             log2((float) in.min()),
785             log2((float) in.max()));
786     }
787 
log2(float f, Target t)788     static private Target.Floaty log2(float f, Target t) {
789         Target.Floaty in = t.new32(f);
790         return t.new32(
791             log2(in.mid32()),
792             log2(in.min32()),
793             log2(in.max32()));
794     }
795 
796     // NOTE: This function delegates to the floating-point version in libm.  Need to switch to the
797     // double-precision version later.
logb(double d, Target t)798     static private Target.Floaty logb(double d, Target t) {
799         Target.Floaty in = t.newFloaty(d);
800         return t.newFloaty(
801             logb((float) in.mid()),
802             logb((float) in.min()),
803             logb((float) in.max()));
804     }
805 
mad(double m1, double m2, double offset, Target t)806     static private Target.Floaty mad(double m1, double m2, double offset, Target t) {
807         Target.Floaty ab = t.multiply(t.newFloaty(m1), t.newFloaty(m2));
808         return t.add(ab, t.newFloaty(offset));
809     }
810 
max(double a, double b, Target t)811     static private Target.Floaty max(double a, double b, Target t) {
812         return t.newFloaty(Math.max(a, b));
813     }
814 
min(double a, double b, Target t)815     static private Target.Floaty min(double a, double b, Target t) {
816         return t.newFloaty(Math.min(a, b));
817     }
818 
mix(double start, double stop, double fraction, Target t)819     static private Target.Floaty mix(double start, double stop, double fraction, Target t) {
820         Target.Floaty inStart = t.newFloaty(start);
821         Target.Floaty inStop = t.newFloaty(stop);
822         Target.Floaty inFraction = t.newFloaty(fraction);
823 
824         Target.Floaty diff = t.subtract(inStop, inStart);
825         return t.add(inStart, t.multiply(diff, inFraction));
826     }
827 
828     // Normalizes the double-precision n-dimensional vector, i.e. makes it length 1.
normalize(double[] in, Target.Floaty[] out, Target t)829     static private void normalize(double[] in, Target.Floaty[] out, Target t) {
830         Target.Floaty l = length(in, t);
831         boolean isZero = l.get() == 0.;
832         for (int i = 0; i < in.length; i++) {
833             out[i] = t.newFloaty(in[i]);
834             if (!isZero) {
835                 out[i] = t.divide(out[i], l);
836             }
837         }
838     }
839 
840     // Normalizes the n-dimensional vector, i.e. makes it length 1.
normalize(float[] in, Target.Floaty[] out, Target t)841     static private void normalize(float[] in, Target.Floaty[] out, Target t) {
842         Target.Floaty l = length(in, t);
843         boolean isZero = l.get32() == 0.f;
844         for (int i = 0; i < in.length; i++) {
845             out[i] = t.new32(in[i]);
846             if (!isZero) {
847                 out[i] = t.divide(out[i], l);
848             }
849         }
850     }
851 
pow(double x, double y, Target t)852     static private Target.Floaty pow(double x, double y, Target t) {
853         Target.Floaty base = t.newFloaty(x);
854         Target.Floaty exponent = t.newFloaty(y);
855         return t.newFloaty(
856             Math.pow(base.mid(), exponent.mid()),
857             Math.pow(base.min(), exponent.min()),
858             Math.pow(base.min(), exponent.max()),
859             Math.pow(base.max(), exponent.min()),
860             Math.pow(base.max(), exponent.max()));
861     }
862 
powr(float x, float y, Target t)863     static private Target.Floaty powr(float x, float y, Target t) {
864         Target.Floaty base = t.new32(x);
865         Target.Floaty exponent = t.new32(y);
866         return t.new32(
867             pow(base.mid32(), exponent.mid32()),
868             pow(base.min32(), exponent.min32()),
869             pow(base.min32(), exponent.max32()),
870             pow(base.max32(), exponent.min32()),
871             pow(base.max32(), exponent.max32()));
872     }
873 
radians(double d, Target t)874     static private Target.Floaty radians(double d, Target t) {
875         Target.Floaty in = t.newFloaty(d);
876         Target.Floaty k = t.newFloaty(Math.PI / 180);
877         return t.multiply(in, k);
878     }
879 
recip(double d, Target t)880     static private Target.Floaty recip(double d, Target t) {
881         Target.Floaty in = t.newFloaty(d);
882         return t.divide(t.newFloaty(1.), in);
883     }
884 
recip(float f, Target t)885     static private Target.Floaty recip(float f, Target t) {
886         Target.Floaty in = t.new32(f);
887         return t.divide(t.new32(1.f), in);
888     }
889 
rint(double d, Target t)890     static private Target.Floaty rint(double d, Target t) {
891         Target.Floaty in = t.newFloaty(d);
892         return t.newFloaty(
893             Math.rint(in.mid()),
894             Math.rint(in.min()),
895             Math.rint(in.max()));
896     }
897 
rootn(float inV, int inN, Target t)898     static private Target.Floaty rootn(float inV, int inN, Target t) {
899         /* Rootn of a negative number should be possible only if the number
900          * is odd.  In cases where the int is very large, our approach will
901          * lose whether the int is odd, and we'll get a NaN for weird cases
902          * like rootn(-3.95, 818181881), which should return 1.  We handle the
903          * case by handling the sign ourselves.  We use copysign to handle the
904          * negative zero case.
905          */
906         float value;
907         if ((inN & 0x1) == 0x1) {
908             value = Math.copySign(pow(Math.abs(inV), 1.f / inN),
909                     inV);
910         } else {
911             value = pow(inV, 1.f / inN);
912         }
913         if (inN == 0) {
914             return t.new32(value, Float.NaN);
915         } else {
916             return t.new32(value);
917         }
918     }
919 
920     // NOTE: This function delegates to the floating-point version in libm.  Need to switch to the
921     // double-precision version later.
922     //
923     // Also, use native round() instead of Math.round() as the latter has different rounding
924     // behavior in case of ties.
round(double d, Target t)925     static private Target.Floaty round(double d, Target t) {
926         Target.Floaty in = t.newFloaty(d);
927         return t.newFloaty(
928             round((float) in.mid()),
929             round((float) in.min()),
930             round((float) in.max()));
931     }
932 
rsqrt(double d, Target t)933     static private Target.Floaty rsqrt(double d, Target t) {
934         Target.Floaty in = t.newFloaty(d);
935         return t.divide(t.newFloaty(1.), t.sqrt(in));
936     }
937 
rsqrt(float f, Target t)938     static private Target.Floaty rsqrt(float f, Target t) {
939         Target.Floaty in = t.new32(f);
940         return t.divide(t.new32(1.f), t.sqrt(in));
941     }
942 
sin(double d, Target t)943     static private Target.Floaty sin(double d, Target t) {
944         Target.Floaty in = t.newFloaty(d);
945         return t.newFloaty(
946             Math.sin(in.mid()),
947             Math.sin(in.min()),
948             Math.sin(in.max()));
949     }
950 
sin(float f, Target t)951     static private Target.Floaty sin(float f, Target t) {
952         Target.Floaty in = t.new32(f);
953         return t.new32(
954             sin(in.mid32()),
955             sin(in.min32()),
956             sin(in.max32()));
957     }
958 
sinh(double d, Target t)959     static private Target.Floaty sinh(double d, Target t) {
960         Target.Floaty in = t.newFloaty(d);
961         return t.newFloaty(
962             Math.sinh(in.mid()),
963             Math.sinh(in.min()),
964             Math.sinh(in.max()));
965     }
966 
sinh(float f, Target t)967     static private Target.Floaty sinh(float f, Target t) {
968         Target.Floaty in = t.new32(f);
969         return t.new32(
970             sinh(in.mid32()),
971             sinh(in.min32()),
972             sinh(in.max32()));
973     }
974 
sinpi(double d, Target t)975     static private Target.Floaty sinpi(double d, Target t) {
976         Target.Floaty in = t.multiply(t.newFloaty(d), pi(t));
977         return t.newFloaty(
978             Math.sin(in.mid()),
979             Math.sin(in.min()),
980             Math.sin(in.max()));
981     }
982 
sinpi(float f, Target t)983     static private Target.Floaty sinpi(float f, Target t) {
984         Target.Floaty in = t.multiply(t.new32(f), pi32(t));
985         return t.new32(
986             sin(in.mid32()),
987             sin(in.min32()),
988             sin(in.max32()));
989     }
990 
sqrt(double d, Target t)991     static private Target.Floaty sqrt(double d, Target t) {
992         Target.Floaty in = t.newFloaty(d);
993         return t.sqrt(in);
994     }
995 
sqrt(float f, Target t)996     static private Target.Floaty sqrt(float f, Target t) {
997         Target.Floaty in = t.new32(f);
998         return t.sqrt(in);
999     }
1000 
step(double v, double edge, Target t)1001     static private Target.Floaty step(double v, double edge, Target t) {
1002         return t.newFloaty(v < edge ? 0.f : 1.f);
1003     }
1004 
tan(double d, Target t)1005     static private Target.Floaty tan(double d, Target t) {
1006         Target.Floaty in = t.newFloaty(d);
1007         double min = Math.tan(in.min());
1008         double max = Math.tan(in.max());
1009         /* If difference between in.max() and in.min() is larger than PI or if the tan of the min is
1010          * greater than that of the max, we spanned a discontinuity.
1011          */
1012         if (in.max() - in.min() > Math.PI || min > max) {
1013             return any(t);
1014         } else {
1015             return t.newFloaty(Math.tan(d), min, max);
1016         }
1017     }
1018 
tan(float f, Target t)1019     static private Target.Floaty tan(float f, Target t) {
1020         Target.Floaty in = t.new32(f);
1021         float min = tan(in.min32());
1022         float max = tan(in.max32());
1023         /* If difference between in.max() and in.min() is larger than PI or if the tan of the min is
1024          * greater than that of the max, we spanned a discontinuity.
1025          */
1026         if (in.max() - in.min() > Math.PI || min > max) {
1027             return any32(t);
1028         } else {
1029             return t.new32(tan(f), min, max);
1030         }
1031     }
1032 
tanh(double d, Target t)1033     static private Target.Floaty tanh(double d, Target t) {
1034         Target.Floaty in = t.newFloaty(d);
1035         return t.newFloaty(
1036             Math.tanh(in.mid()),
1037             Math.tanh(in.min()),
1038             Math.tanh(in.max()));
1039     }
1040 
tanh(float f, Target t)1041     static private Target.Floaty tanh(float f, Target t) {
1042         Target.Floaty in = t.new32(f);
1043         return t.new32(
1044             tanh(in.mid32()),
1045             tanh(in.min32()),
1046             tanh(in.max32()));
1047     }
1048 
tanpi(double d, Target t)1049     static private Target.Floaty tanpi(double d, Target t) {
1050         Target.Floaty in = t.multiply(t.newFloaty(d), pi(t));
1051         double min = Math.tan(in.min());
1052         double max = Math.tan(in.max());
1053 
1054         /* If difference between in.max() and in.min() is larger than PI or if the tan of the min is
1055          * greater than that of the max, we spanned a discontinuity.
1056          */
1057         if (in.max() - in.min() > Math.PI || min > max) {
1058             return any(t);
1059         } else {
1060             return t.newFloaty(Math.tan(in.mid()), min, max);
1061         }
1062     }
1063 
tanpi(float f, Target t)1064     static private Target.Floaty tanpi(float f, Target t) {
1065         Target.Floaty in = t.multiply(t.new32(f), pi32(t));
1066         float min = tan(in.min32());
1067         float max = tan(in.max32());
1068         /* If difference between in.max() and in.min() is larger than PI or if the tan of the min is
1069          * greater than that of the max, we spanned a discontinuity.
1070          */
1071         if (in.max() - in.min() > Math.PI || min > max) {
1072             return any32(t);
1073         } else {
1074             return t.new32(tan(in.mid32()), min, max);
1075         }
1076     }
1077 
1078     // NOTE: This function delegates to the floating-point version in libm.  Need to switch to the
1079     // double-precision version later.
tgamma(double d, Target t)1080     static private Target.Floaty tgamma(double d, Target t) {
1081         Target.Floaty in = t.newFloaty(d);
1082         return t.newFloaty(
1083             tgamma((float) in.mid()),
1084             tgamma((float) in.min()),
1085             tgamma((float) in.max()));
1086     }
1087 
1088     // NOTE: This function delegates to the floating-point version in libm.  Need to switch to the
1089     // double-precision version later.
trunc(double d, Target t)1090     static private Target.Floaty trunc(double d, Target t) {
1091         Target.Floaty in = t.newFloaty(d);
1092         return t.newFloaty(
1093             trunc((float) in.mid()),
1094             trunc((float) in.min()),
1095             trunc((float) in.max()));
1096     }
1097 
computeAbs(TestAbs.ArgumentsCharUchar args)1098     static public void computeAbs(TestAbs.ArgumentsCharUchar args) {
1099         args.out = (byte)Math.abs(args.inV);
1100     }
1101 
computeAbs(TestAbs.ArgumentsShortUshort args)1102     static public void computeAbs(TestAbs.ArgumentsShortUshort args) {
1103         args.out = (short)Math.abs(args.inV);
1104     }
1105 
computeAbs(TestAbs.ArgumentsIntUint args)1106     static public void computeAbs(TestAbs.ArgumentsIntUint args) {
1107         args.out = Math.abs(args.inV);
1108     }
1109 
computeAcos(TestAcos.ArgumentsHalfHalf args, Target t)1110     static public void computeAcos(TestAcos.ArgumentsHalfHalf args, Target t) {
1111         t.setPrecision(4, 4);
1112         args.out = acos(args.inVDouble, t);
1113     }
1114 
computeAcos(TestAcos.ArgumentsFloatFloat args, Target t)1115     static public void computeAcos(TestAcos.ArgumentsFloatFloat args, Target t) {
1116         t.setPrecision(4, 128);
1117         args.out = acos(args.inV, t);
1118     }
1119 
computeAcosh(TestAcosh.ArgumentsHalfHalf args, Target t)1120     static public void computeAcosh(TestAcosh.ArgumentsHalfHalf args, Target t) {
1121         t.setPrecision(4, 4);
1122         args.out = acosh(args.inVDouble, t);
1123     }
1124 
computeAcosh(TestAcosh.ArgumentsFloatFloat args, Target t)1125     static public void computeAcosh(TestAcosh.ArgumentsFloatFloat args, Target t) {
1126         t.setPrecision(4, 128);
1127         args.out = acosh(args.inV, t);
1128     }
1129 
computeAcospi(TestAcospi.ArgumentsHalfHalf args, Target t)1130     static public void computeAcospi(TestAcospi.ArgumentsHalfHalf args, Target t) {
1131         t.setPrecision(5, 5);
1132         args.out = acospi(args.inVDouble, t);
1133     }
1134 
computeAcospi(TestAcospi.ArgumentsFloatFloat args, Target t)1135     static public void computeAcospi(TestAcospi.ArgumentsFloatFloat args, Target t) {
1136         t.setPrecision(5, 128);
1137         args.out = acospi(args.inV, t);
1138     }
1139 
computeAsin(TestAsin.ArgumentsHalfHalf args, Target t)1140     static public void computeAsin(TestAsin.ArgumentsHalfHalf args, Target t) {
1141         t.setPrecision(4, 4);
1142         args.out = asin(args.inVDouble, t);
1143     }
1144 
computeAsin(TestAsin.ArgumentsFloatFloat args, Target t)1145     static public void computeAsin(TestAsin.ArgumentsFloatFloat args, Target t) {
1146         t.setPrecision(4, 128);
1147         args.out = asin(args.inV, t);
1148     }
1149 
computeAsinh(TestAsinh.ArgumentsHalfHalf args, Target t)1150     static public void computeAsinh(TestAsinh.ArgumentsHalfHalf args, Target t) {
1151         t.setPrecision(4, 4);
1152         args.out = asinh(args.inVDouble, t);
1153     }
1154 
computeAsinh(TestAsinh.ArgumentsFloatFloat args, Target t)1155     static public void computeAsinh(TestAsinh.ArgumentsFloatFloat args, Target t) {
1156         t.setPrecision(4, 128);
1157         args.out = asinh(args.inV, t);
1158     }
1159 
computeAsinpi(TestAsinpi.ArgumentsHalfHalf args, Target t)1160     static public void computeAsinpi(TestAsinpi.ArgumentsHalfHalf args, Target t) {
1161         t.setPrecision(5, 5);
1162         args.out = asinpi(args.inVDouble, t);
1163     }
1164 
computeAsinpi(TestAsinpi.ArgumentsFloatFloat args, Target t)1165     static public void computeAsinpi(TestAsinpi.ArgumentsFloatFloat args, Target t) {
1166         t.setPrecision(5, 128);
1167         args.out = asinpi(args.inV, t);
1168     }
1169 
computeAtan(TestAtan.ArgumentsHalfHalf args, Target t)1170     static public void computeAtan(TestAtan.ArgumentsHalfHalf args, Target t) {
1171         t.setPrecision(5, 5);
1172         args.out = atan(args.inVDouble, t);
1173     }
1174 
computeAtan(TestAtan.ArgumentsFloatFloat args, Target t)1175     static public void computeAtan(TestAtan.ArgumentsFloatFloat args, Target t) {
1176         t.setPrecision(5, 128);
1177         args.out = atan(args.inV, t);
1178     }
1179 
computeAtanh(TestAtanh.ArgumentsHalfHalf args, Target t)1180     static public void computeAtanh(TestAtanh.ArgumentsHalfHalf args, Target t) {
1181         t.setPrecision(5, 5);
1182         args.out = atanh(args.inVDouble, t);
1183     }
1184 
computeAtanh(TestAtanh.ArgumentsFloatFloat args, Target t)1185     static public void computeAtanh(TestAtanh.ArgumentsFloatFloat args, Target t) {
1186         t.setPrecision(5, 128);
1187         args.out = atanh(args.inV, t);
1188     }
1189 
computeAtanpi(TestAtanpi.ArgumentsHalfHalf args, Target t)1190     static public void computeAtanpi(TestAtanpi.ArgumentsHalfHalf args, Target t) {
1191         t.setPrecision(5, 5);
1192         args.out = atanpi(args.inVDouble, t);
1193     }
1194 
computeAtanpi(TestAtanpi.ArgumentsFloatFloat args, Target t)1195     static public void computeAtanpi(TestAtanpi.ArgumentsFloatFloat args, Target t) {
1196         t.setPrecision(5, 128);
1197         args.out = atanpi(args.inV, t);
1198     }
1199 
computeAtan2(TestAtan2.ArgumentsHalfHalfHalf args, Target t)1200     static public void computeAtan2(TestAtan2.ArgumentsHalfHalfHalf args, Target t) {
1201         t.setPrecision(6, 6);
1202         args.out = atan2(args.inNumeratorDouble, args.inDenominatorDouble, t);
1203     }
1204 
computeAtan2(TestAtan2.ArgumentsFloatFloatFloat args, Target t)1205     static public void computeAtan2(TestAtan2.ArgumentsFloatFloatFloat args, Target t) {
1206         t.setPrecision(6, 128);
1207         args.out = atan2(args.inNumerator, args.inDenominator, t);
1208     }
1209 
computeAtan2pi(TestAtan2pi.ArgumentsHalfHalfHalf args, Target t)1210     static public void computeAtan2pi(TestAtan2pi.ArgumentsHalfHalfHalf args, Target t) {
1211         t.setPrecision(6, 6);
1212         args.out = atan2pi(args.inNumeratorDouble, args.inDenominatorDouble, t);
1213     }
1214 
computeAtan2pi(TestAtan2pi.ArgumentsFloatFloatFloat args, Target t)1215     static public void computeAtan2pi(TestAtan2pi.ArgumentsFloatFloatFloat args, Target t) {
1216         t.setPrecision(6, 128);
1217         args.out = atan2pi(args.inNumerator, args.inDenominator, t);
1218     }
1219 
computeCbrt(TestCbrt.ArgumentsHalfHalf args, Target t)1220     static public void computeCbrt(TestCbrt.ArgumentsHalfHalf args, Target t) {
1221         t.setPrecision(2, 2);
1222         args.out = cbrt(args.inVDouble, t);
1223     }
1224 
computeCbrt(TestCbrt.ArgumentsFloatFloat args, Target t)1225     static public void computeCbrt(TestCbrt.ArgumentsFloatFloat args, Target t) {
1226         t.setPrecision(2, 128);
1227         args.out = cbrt(args.inV, t);
1228     }
1229 
computeCeil(TestCeil.ArgumentsHalfHalf args, Target t)1230     static public void computeCeil(TestCeil.ArgumentsHalfHalf args, Target t) {
1231         t.setPrecision(0, 0);
1232         Target.Floaty in = t.newFloaty(args.inVDouble);
1233         args.out = t.newFloaty(
1234             Math.ceil(in.mid()),
1235             Math.ceil(in.min()),
1236             Math.ceil(in.max()));
1237     }
1238 
computeCeil(TestCeil.ArgumentsFloatFloat args, Target t)1239     static public void computeCeil(TestCeil.ArgumentsFloatFloat args, Target t) {
1240         t.setPrecision(0, 1);
1241         Target.Floaty in = t.new32(args.inV);
1242         args.out = t.new32(
1243             ceil(in.mid32()),
1244             ceil(in.min32()),
1245             ceil(in.max32()));
1246     }
1247 
computeClamp(TestClamp.ArgumentsCharCharCharChar args)1248     static public void computeClamp(TestClamp.ArgumentsCharCharCharChar args) {
1249         args.out = minI8(args.inMaxValue, maxI8(args.inValue, args.inMinValue));
1250     }
1251 
computeClamp(TestClamp.ArgumentsUcharUcharUcharUchar args)1252     static public void computeClamp(TestClamp.ArgumentsUcharUcharUcharUchar args) {
1253         args.out = minU8(args.inMaxValue, maxU8(args.inValue, args.inMinValue));
1254     }
1255 
computeClamp(TestClamp.ArgumentsShortShortShortShort args)1256     static public void computeClamp(TestClamp.ArgumentsShortShortShortShort args) {
1257         args.out = minI16(args.inMaxValue, maxI16(args.inValue, args.inMinValue));
1258     }
1259 
computeClamp(TestClamp.ArgumentsUshortUshortUshortUshort args)1260     static public void computeClamp(TestClamp.ArgumentsUshortUshortUshortUshort args) {
1261         args.out = minU16(args.inMaxValue, maxU16(args.inValue, args.inMinValue));
1262     }
1263 
computeClamp(TestClamp.ArgumentsIntIntIntInt args)1264     static public void computeClamp(TestClamp.ArgumentsIntIntIntInt args) {
1265         args.out = minI32(args.inMaxValue, maxI32(args.inValue, args.inMinValue));
1266     }
1267 
computeClamp(TestClamp.ArgumentsUintUintUintUint args)1268     static public void computeClamp(TestClamp.ArgumentsUintUintUintUint args) {
1269         args.out = minU32(args.inMaxValue, maxU32(args.inValue, args.inMinValue));
1270     }
1271 
computeClamp(TestClamp.ArgumentsHalfHalfHalfHalf args, Target t)1272     static public void computeClamp(TestClamp.ArgumentsHalfHalfHalfHalf args, Target t) {
1273         t.setPrecision(0, 0);
1274         args.out = clamp(args.inValueDouble, args.inMinValueDouble, args.inMaxValueDouble, t);
1275     }
1276 
computeClamp(TestClamp.ArgumentsFloatFloatFloatFloat args, Target t)1277     static public void computeClamp(TestClamp.ArgumentsFloatFloatFloatFloat args, Target t) {
1278         t.setPrecision(0, 0);
1279         args.out = t.new32(Math.min(args.inMaxValue,
1280                         Math.max(args.inValue, args.inMinValue)));
1281     }
1282 
computeClamp(TestClamp.ArgumentsLongLongLongLong args)1283     static public void computeClamp(TestClamp.ArgumentsLongLongLongLong args) {
1284         args.out = minI64(args.inMaxValue, maxI64(args.inValue, args.inMinValue));
1285     }
1286 
computeClamp(TestClamp.ArgumentsUlongUlongUlongUlong args)1287     static public void computeClamp(TestClamp.ArgumentsUlongUlongUlongUlong args) {
1288         args.out = minU64(args.inMaxValue, maxU64(args.inValue, args.inMinValue));
1289     }
1290 
computeClz(TestClz.ArgumentsCharChar args)1291     static public void computeClz(TestClz.ArgumentsCharChar args) {
1292         int x = args.inValue;
1293         args.out = (byte) (Integer.numberOfLeadingZeros(x & 0xff) - 24);
1294     }
1295 
computeClz(TestClz.ArgumentsUcharUchar args)1296     static public void computeClz(TestClz.ArgumentsUcharUchar args) {
1297         int x = args.inValue;
1298         args.out = (byte) (Integer.numberOfLeadingZeros(x & 0xff) - 24);
1299     }
1300 
computeClz(TestClz.ArgumentsShortShort args)1301     static public void computeClz(TestClz.ArgumentsShortShort args) {
1302         args.out = (short) (Integer.numberOfLeadingZeros(args.inValue & 0xffff) - 16);
1303     }
1304 
computeClz(TestClz.ArgumentsUshortUshort args)1305     static public void computeClz(TestClz.ArgumentsUshortUshort args) {
1306         args.out = (short) (Integer.numberOfLeadingZeros(args.inValue & 0xffff) - 16);
1307     }
1308 
computeClz(TestClz.ArgumentsIntInt args)1309     static public void computeClz(TestClz.ArgumentsIntInt args) {
1310         args.out = (int) Integer.numberOfLeadingZeros(args.inValue);
1311     }
1312 
computeClz(TestClz.ArgumentsUintUint args)1313     static public void computeClz(TestClz.ArgumentsUintUint args) {
1314         args.out = (int) Integer.numberOfLeadingZeros(args.inValue);
1315     }
1316 
1317 
computeConvert(TestConvert.ArgumentsCharChar args)1318     static public void computeConvert(TestConvert.ArgumentsCharChar args) {
1319         args.out = convertCharToChar(args.inV);
1320     }
computeConvert(TestConvert.ArgumentsCharUchar args)1321     static public void computeConvert(TestConvert.ArgumentsCharUchar args) {
1322         args.out = convertCharToUchar(args.inV);
1323     }
computeConvert(TestConvert.ArgumentsCharShort args)1324     static public void computeConvert(TestConvert.ArgumentsCharShort args) {
1325         args.out = convertCharToShort(args.inV);
1326     }
computeConvert(TestConvert.ArgumentsCharUshort args)1327     static public void computeConvert(TestConvert.ArgumentsCharUshort args) {
1328         args.out = convertCharToUshort(args.inV);
1329     }
computeConvert(TestConvert.ArgumentsCharInt args)1330     static public void computeConvert(TestConvert.ArgumentsCharInt args) {
1331         args.out = convertCharToInt(args.inV);
1332     }
computeConvert(TestConvert.ArgumentsCharUint args)1333     static public void computeConvert(TestConvert.ArgumentsCharUint args) {
1334         args.out = convertCharToUint(args.inV);
1335     }
computeConvert(TestConvert.ArgumentsCharLong args)1336     static public void computeConvert(TestConvert.ArgumentsCharLong args) {
1337         args.out = convertCharToLong(args.inV);
1338     }
computeConvert(TestConvert.ArgumentsCharUlong args)1339     static public void computeConvert(TestConvert.ArgumentsCharUlong args) {
1340         args.out = convertCharToUlong(args.inV);
1341     }
computeConvert(TestConvert.ArgumentsCharHalf args, Target t)1342     static public void computeConvert(TestConvert.ArgumentsCharHalf args, Target t) {
1343         t.setPrecision(0, 0);
1344         args.out = t.newFloaty(convertCharToDouble(args.inV));
1345     }
computeConvert(TestConvert.ArgumentsCharFloat args, Target t)1346     static public void computeConvert(TestConvert.ArgumentsCharFloat args, Target t) {
1347         t.setPrecision(0, 0);
1348         args.out = t.new32(convertCharToFloat(args.inV));
1349     }
computeConvert(TestConvert.ArgumentsCharDouble args, Target t)1350     static public void computeConvert(TestConvert.ArgumentsCharDouble args, Target t) {
1351         t.setPrecision(0, 0);
1352         args.out = t.new64(convertCharToDouble(args.inV));
1353     }
1354 
computeConvert(TestConvert.ArgumentsUcharChar args)1355     static public void computeConvert(TestConvert.ArgumentsUcharChar args) {
1356         args.out = convertUcharToChar(args.inV);
1357     }
computeConvert(TestConvert.ArgumentsUcharUchar args)1358     static public void computeConvert(TestConvert.ArgumentsUcharUchar args) {
1359         args.out = convertUcharToUchar(args.inV);
1360     }
computeConvert(TestConvert.ArgumentsUcharShort args)1361     static public void computeConvert(TestConvert.ArgumentsUcharShort args) {
1362         args.out = convertUcharToShort(args.inV);
1363     }
computeConvert(TestConvert.ArgumentsUcharUshort args)1364     static public void computeConvert(TestConvert.ArgumentsUcharUshort args) {
1365         args.out = convertUcharToUshort(args.inV);
1366     }
computeConvert(TestConvert.ArgumentsUcharInt args)1367     static public void computeConvert(TestConvert.ArgumentsUcharInt args) {
1368         args.out = convertUcharToInt(args.inV);
1369     }
computeConvert(TestConvert.ArgumentsUcharUint args)1370     static public void computeConvert(TestConvert.ArgumentsUcharUint args) {
1371         args.out = convertUcharToUint(args.inV);
1372     }
computeConvert(TestConvert.ArgumentsUcharLong args)1373     static public void computeConvert(TestConvert.ArgumentsUcharLong args) {
1374         args.out = convertUcharToLong(args.inV);
1375     }
computeConvert(TestConvert.ArgumentsUcharUlong args)1376     static public void computeConvert(TestConvert.ArgumentsUcharUlong args) {
1377         args.out = convertUcharToUlong(args.inV);
1378     }
computeConvert(TestConvert.ArgumentsUcharHalf args, Target t)1379     static public void computeConvert(TestConvert.ArgumentsUcharHalf args, Target t) {
1380         t.setPrecision(0, 0);
1381         args.out = t.newFloaty(convertUcharToDouble(args.inV));
1382     }
computeConvert(TestConvert.ArgumentsUcharFloat args, Target t)1383     static public void computeConvert(TestConvert.ArgumentsUcharFloat args, Target t) {
1384         t.setPrecision(0, 0);
1385         args.out = t.new32(convertUcharToFloat(args.inV));
1386     }
computeConvert(TestConvert.ArgumentsUcharDouble args, Target t)1387     static public void computeConvert(TestConvert.ArgumentsUcharDouble args, Target t) {
1388         t.setPrecision(0, 0);
1389         args.out = t.new64(convertUcharToDouble(args.inV));
1390     }
1391 
computeConvert(TestConvert.ArgumentsShortChar args)1392     static public void computeConvert(TestConvert.ArgumentsShortChar args) {
1393         args.out = convertShortToChar(args.inV);
1394     }
computeConvert(TestConvert.ArgumentsShortUchar args)1395     static public void computeConvert(TestConvert.ArgumentsShortUchar args) {
1396         args.out = convertShortToUchar(args.inV);
1397     }
computeConvert(TestConvert.ArgumentsShortShort args)1398     static public void computeConvert(TestConvert.ArgumentsShortShort args) {
1399         args.out = convertShortToShort(args.inV);
1400     }
computeConvert(TestConvert.ArgumentsShortUshort args)1401     static public void computeConvert(TestConvert.ArgumentsShortUshort args) {
1402         args.out = convertShortToUshort(args.inV);
1403     }
computeConvert(TestConvert.ArgumentsShortInt args)1404     static public void computeConvert(TestConvert.ArgumentsShortInt args) {
1405         args.out = convertShortToInt(args.inV);
1406     }
computeConvert(TestConvert.ArgumentsShortUint args)1407     static public void computeConvert(TestConvert.ArgumentsShortUint args) {
1408         args.out = convertShortToUint(args.inV);
1409     }
computeConvert(TestConvert.ArgumentsShortLong args)1410     static public void computeConvert(TestConvert.ArgumentsShortLong args) {
1411         args.out = convertShortToLong(args.inV);
1412     }
computeConvert(TestConvert.ArgumentsShortUlong args)1413     static public void computeConvert(TestConvert.ArgumentsShortUlong args) {
1414         args.out = convertShortToUlong(args.inV);
1415     }
computeConvert(TestConvert.ArgumentsShortHalf args, Target t)1416     static public void computeConvert(TestConvert.ArgumentsShortHalf args, Target t) {
1417         t.setPrecision(1, 1);
1418         args.out = t.newFloaty(convertShortToDouble(args.inV));
1419     }
computeConvert(TestConvert.ArgumentsShortFloat args, Target t)1420     static public void computeConvert(TestConvert.ArgumentsShortFloat args, Target t) {
1421         t.setPrecision(0, 0);
1422         args.out = t.new32(convertShortToFloat(args.inV));
1423     }
computeConvert(TestConvert.ArgumentsShortDouble args, Target t)1424     static public void computeConvert(TestConvert.ArgumentsShortDouble args, Target t) {
1425         t.setPrecision(0, 0);
1426         args.out = t.new64(convertShortToDouble(args.inV));
1427     }
1428 
computeConvert(TestConvert.ArgumentsUshortChar args)1429     static public void computeConvert(TestConvert.ArgumentsUshortChar args) {
1430         args.out = convertUshortToChar(args.inV);
1431     }
computeConvert(TestConvert.ArgumentsUshortUchar args)1432     static public void computeConvert(TestConvert.ArgumentsUshortUchar args) {
1433         args.out = convertUshortToUchar(args.inV);
1434     }
computeConvert(TestConvert.ArgumentsUshortShort args)1435     static public void computeConvert(TestConvert.ArgumentsUshortShort args) {
1436         args.out = convertUshortToShort(args.inV);
1437     }
computeConvert(TestConvert.ArgumentsUshortUshort args)1438     static public void computeConvert(TestConvert.ArgumentsUshortUshort args) {
1439         args.out = convertUshortToUshort(args.inV);
1440     }
computeConvert(TestConvert.ArgumentsUshortInt args)1441     static public void computeConvert(TestConvert.ArgumentsUshortInt args) {
1442         args.out = convertUshortToInt(args.inV);
1443     }
computeConvert(TestConvert.ArgumentsUshortUint args)1444     static public void computeConvert(TestConvert.ArgumentsUshortUint args) {
1445         args.out = convertUshortToUint(args.inV);
1446     }
computeConvert(TestConvert.ArgumentsUshortLong args)1447     static public void computeConvert(TestConvert.ArgumentsUshortLong args) {
1448         args.out = convertUshortToLong(args.inV);
1449     }
computeConvert(TestConvert.ArgumentsUshortUlong args)1450     static public void computeConvert(TestConvert.ArgumentsUshortUlong args) {
1451         args.out = convertUshortToUlong(args.inV);
1452     }
computeConvert(TestConvert.ArgumentsUshortHalf args, Target t)1453     static public void computeConvert(TestConvert.ArgumentsUshortHalf args, Target t) {
1454         t.setPrecision(1, 1);
1455         args.out = t.newFloaty(convertUshortToDouble(args.inV));
1456     }
computeConvert(TestConvert.ArgumentsUshortFloat args, Target t)1457     static public void computeConvert(TestConvert.ArgumentsUshortFloat args, Target t) {
1458         t.setPrecision(0, 0);
1459         args.out = t.new32(convertUshortToFloat(args.inV));
1460     }
computeConvert(TestConvert.ArgumentsUshortDouble args, Target t)1461     static public void computeConvert(TestConvert.ArgumentsUshortDouble args, Target t) {
1462         t.setPrecision(0, 0);
1463         args.out = t.new64(convertUshortToDouble(args.inV));
1464     }
1465 
computeConvert(TestConvert.ArgumentsIntChar args)1466     static public void computeConvert(TestConvert.ArgumentsIntChar args) {
1467         args.out = convertIntToChar(args.inV);
1468     }
computeConvert(TestConvert.ArgumentsIntUchar args)1469     static public void computeConvert(TestConvert.ArgumentsIntUchar args) {
1470         args.out = convertIntToUchar(args.inV);
1471     }
computeConvert(TestConvert.ArgumentsIntShort args)1472     static public void computeConvert(TestConvert.ArgumentsIntShort args) {
1473         args.out = convertIntToShort(args.inV);
1474     }
computeConvert(TestConvert.ArgumentsIntUshort args)1475     static public void computeConvert(TestConvert.ArgumentsIntUshort args) {
1476         args.out = convertIntToUshort(args.inV);
1477     }
computeConvert(TestConvert.ArgumentsIntInt args)1478     static public void computeConvert(TestConvert.ArgumentsIntInt args) {
1479         args.out = convertIntToInt(args.inV);
1480     }
computeConvert(TestConvert.ArgumentsIntUint args)1481     static public void computeConvert(TestConvert.ArgumentsIntUint args) {
1482         args.out = convertIntToUint(args.inV);
1483     }
computeConvert(TestConvert.ArgumentsIntLong args)1484     static public void computeConvert(TestConvert.ArgumentsIntLong args) {
1485         args.out = convertIntToLong(args.inV);
1486     }
computeConvert(TestConvert.ArgumentsIntUlong args)1487     static public void computeConvert(TestConvert.ArgumentsIntUlong args) {
1488         args.out = convertIntToUlong(args.inV);
1489     }
computeConvert(TestConvert.ArgumentsIntHalf args, Target t)1490     static public void computeConvert(TestConvert.ArgumentsIntHalf args, Target t) {
1491         t.setPrecision(1, 1);
1492         args.out = t.newFloaty(convertIntToDouble(args.inV));
1493     }
computeConvert(TestConvert.ArgumentsIntFloat args, Target t)1494     static public void computeConvert(TestConvert.ArgumentsIntFloat args, Target t) {
1495         t.setPrecision(1, 1);
1496         args.out = t.new32(convertIntToFloat(args.inV));
1497     }
computeConvert(TestConvert.ArgumentsIntDouble args, Target t)1498     static public void computeConvert(TestConvert.ArgumentsIntDouble args, Target t) {
1499         t.setPrecision(0, 0);
1500         args.out = t.new64(convertIntToDouble(args.inV));
1501     }
1502 
computeConvert(TestConvert.ArgumentsUintChar args)1503     static public void computeConvert(TestConvert.ArgumentsUintChar args) {
1504         args.out = convertUintToChar(args.inV);
1505     }
computeConvert(TestConvert.ArgumentsUintUchar args)1506     static public void computeConvert(TestConvert.ArgumentsUintUchar args) {
1507         args.out = convertUintToUchar(args.inV);
1508     }
computeConvert(TestConvert.ArgumentsUintShort args)1509     static public void computeConvert(TestConvert.ArgumentsUintShort args) {
1510         args.out = convertUintToShort(args.inV);
1511     }
computeConvert(TestConvert.ArgumentsUintUshort args)1512     static public void computeConvert(TestConvert.ArgumentsUintUshort args) {
1513         args.out = convertUintToUshort(args.inV);
1514     }
computeConvert(TestConvert.ArgumentsUintInt args)1515     static public void computeConvert(TestConvert.ArgumentsUintInt args) {
1516         args.out = convertUintToInt(args.inV);
1517     }
computeConvert(TestConvert.ArgumentsUintUint args)1518     static public void computeConvert(TestConvert.ArgumentsUintUint args) {
1519         args.out = convertUintToUint(args.inV);
1520     }
computeConvert(TestConvert.ArgumentsUintLong args)1521     static public void computeConvert(TestConvert.ArgumentsUintLong args) {
1522         args.out = convertUintToLong(args.inV);
1523     }
computeConvert(TestConvert.ArgumentsUintUlong args)1524     static public void computeConvert(TestConvert.ArgumentsUintUlong args) {
1525         args.out = convertUintToUlong(args.inV);
1526     }
computeConvert(TestConvert.ArgumentsUintHalf args, Target t)1527     static public void computeConvert(TestConvert.ArgumentsUintHalf args, Target t) {
1528         t.setPrecision(1, 1);
1529         args.out = t.newFloaty(convertUintToDouble(args.inV));
1530     }
computeConvert(TestConvert.ArgumentsUintFloat args, Target t)1531     static public void computeConvert(TestConvert.ArgumentsUintFloat args, Target t) {
1532         t.setPrecision(1, 1);
1533         args.out = t.new32(convertUintToFloat(args.inV));
1534     }
computeConvert(TestConvert.ArgumentsUintDouble args, Target t)1535     static public void computeConvert(TestConvert.ArgumentsUintDouble args, Target t) {
1536         t.setPrecision(0, 0);
1537         args.out = t.new64(convertUintToDouble(args.inV));
1538     }
1539 
computeConvert(TestConvert.ArgumentsLongChar args)1540     static public void computeConvert(TestConvert.ArgumentsLongChar args) {
1541         args.out = convertLongToChar(args.inV);
1542     }
computeConvert(TestConvert.ArgumentsLongUchar args)1543     static public void computeConvert(TestConvert.ArgumentsLongUchar args) {
1544         args.out = convertLongToUchar(args.inV);
1545     }
computeConvert(TestConvert.ArgumentsLongShort args)1546     static public void computeConvert(TestConvert.ArgumentsLongShort args) {
1547         args.out = convertLongToShort(args.inV);
1548     }
computeConvert(TestConvert.ArgumentsLongUshort args)1549     static public void computeConvert(TestConvert.ArgumentsLongUshort args) {
1550         args.out = convertLongToUshort(args.inV);
1551     }
computeConvert(TestConvert.ArgumentsLongInt args)1552     static public void computeConvert(TestConvert.ArgumentsLongInt args) {
1553         args.out = convertLongToInt(args.inV);
1554     }
computeConvert(TestConvert.ArgumentsLongUint args)1555     static public void computeConvert(TestConvert.ArgumentsLongUint args) {
1556         args.out = convertLongToUint(args.inV);
1557     }
computeConvert(TestConvert.ArgumentsLongLong args)1558     static public void computeConvert(TestConvert.ArgumentsLongLong args) {
1559         args.out = convertLongToLong(args.inV);
1560     }
computeConvert(TestConvert.ArgumentsLongUlong args)1561     static public void computeConvert(TestConvert.ArgumentsLongUlong args) {
1562         args.out = convertLongToUlong(args.inV);
1563     }
computeConvert(TestConvert.ArgumentsLongHalf args, Target t)1564     static public void computeConvert(TestConvert.ArgumentsLongHalf args, Target t) {
1565         t.setPrecision(1, 1);
1566         args.out = t.newFloaty(convertLongToDouble(args.inV));
1567     }
computeConvert(TestConvert.ArgumentsLongFloat args, Target t)1568     static public void computeConvert(TestConvert.ArgumentsLongFloat args, Target t) {
1569         t.setPrecision(1, 1);
1570         args.out = t.new32(convertLongToFloat(args.inV));
1571     }
computeConvert(TestConvert.ArgumentsLongDouble args, Target t)1572     static public void computeConvert(TestConvert.ArgumentsLongDouble args, Target t) {
1573         t.setPrecision(1, 1);
1574         args.out = t.new64(convertLongToDouble(args.inV));
1575     }
1576 
computeConvert(TestConvert.ArgumentsUlongChar args)1577     static public void computeConvert(TestConvert.ArgumentsUlongChar args) {
1578         args.out = convertUlongToChar(args.inV);
1579     }
computeConvert(TestConvert.ArgumentsUlongUchar args)1580     static public void computeConvert(TestConvert.ArgumentsUlongUchar args) {
1581         args.out = convertUlongToUchar(args.inV);
1582     }
computeConvert(TestConvert.ArgumentsUlongShort args)1583     static public void computeConvert(TestConvert.ArgumentsUlongShort args) {
1584         args.out = convertUlongToShort(args.inV);
1585     }
computeConvert(TestConvert.ArgumentsUlongUshort args)1586     static public void computeConvert(TestConvert.ArgumentsUlongUshort args) {
1587         args.out = convertUlongToUshort(args.inV);
1588     }
computeConvert(TestConvert.ArgumentsUlongInt args)1589     static public void computeConvert(TestConvert.ArgumentsUlongInt args) {
1590         args.out = convertUlongToInt(args.inV);
1591     }
computeConvert(TestConvert.ArgumentsUlongUint args)1592     static public void computeConvert(TestConvert.ArgumentsUlongUint args) {
1593         args.out = convertUlongToUint(args.inV);
1594     }
computeConvert(TestConvert.ArgumentsUlongLong args)1595     static public void computeConvert(TestConvert.ArgumentsUlongLong args) {
1596         args.out = convertUlongToLong(args.inV);
1597     }
computeConvert(TestConvert.ArgumentsUlongUlong args)1598     static public void computeConvert(TestConvert.ArgumentsUlongUlong args) {
1599         args.out = convertUlongToUlong(args.inV);
1600     }
computeConvert(TestConvert.ArgumentsUlongHalf args, Target t)1601     static public void computeConvert(TestConvert.ArgumentsUlongHalf args, Target t) {
1602         t.setPrecision(1, 1);
1603         args.out = t.newFloaty(convertUlongToDouble(args.inV));
1604     }
computeConvert(TestConvert.ArgumentsUlongFloat args, Target t)1605     static public void computeConvert(TestConvert.ArgumentsUlongFloat args, Target t) {
1606         t.setPrecision(1, 1);
1607         args.out = t.new32(convertUlongToFloat(args.inV));
1608     }
computeConvert(TestConvert.ArgumentsUlongDouble args, Target t)1609     static public void computeConvert(TestConvert.ArgumentsUlongDouble args, Target t) {
1610         t.setPrecision(1, 1);
1611         args.out = t.new64(convertUlongToDouble(args.inV));
1612     }
1613 
computeConvert(TestConvert.ArgumentsHalfChar args)1614     static public void computeConvert(TestConvert.ArgumentsHalfChar args) {
1615         args.out = convertDoubleToChar(args.inVDouble);
1616     }
computeConvert(TestConvert.ArgumentsHalfUchar args)1617     static public void computeConvert(TestConvert.ArgumentsHalfUchar args) {
1618         args.out = convertDoubleToUchar(args.inVDouble);
1619     }
computeConvert(TestConvert.ArgumentsHalfShort args)1620     static public void computeConvert(TestConvert.ArgumentsHalfShort args) {
1621         args.out = convertDoubleToShort(args.inVDouble);
1622     }
computeConvert(TestConvert.ArgumentsHalfUshort args)1623     static public void computeConvert(TestConvert.ArgumentsHalfUshort args) {
1624         args.out = convertDoubleToUshort(args.inVDouble);
1625     }
computeConvert(TestConvert.ArgumentsHalfInt args)1626     static public void computeConvert(TestConvert.ArgumentsHalfInt args) {
1627         args.out = convertDoubleToInt(args.inVDouble);
1628     }
computeConvert(TestConvert.ArgumentsHalfUint args)1629     static public void computeConvert(TestConvert.ArgumentsHalfUint args) {
1630         args.out = convertDoubleToUint(args.inVDouble);
1631     }
computeConvert(TestConvert.ArgumentsHalfLong args)1632     static public void computeConvert(TestConvert.ArgumentsHalfLong args) {
1633         args.out = convertDoubleToLong(args.inVDouble);
1634     }
computeConvert(TestConvert.ArgumentsHalfUlong args)1635     static public void computeConvert(TestConvert.ArgumentsHalfUlong args) {
1636         args.out = convertDoubleToUlong(args.inVDouble);
1637     }
computeConvert(TestConvert.ArgumentsHalfHalf args, Target t)1638     static public void computeConvert(TestConvert.ArgumentsHalfHalf args, Target t) {
1639         t.setPrecision(0, 0);
1640         args.out = t.newFloaty(args.inVDouble);
1641     }
computeConvert(TestConvert.ArgumentsHalfFloat args, Target t)1642     static public void computeConvert(TestConvert.ArgumentsHalfFloat args, Target t) {
1643         t.setPrecision(0, 0);
1644         args.out = t.newFloaty(convertDoubleToFloat(args.inVDouble));
1645     }
computeConvert(TestConvert.ArgumentsHalfDouble args, Target t)1646     static public void computeConvert(TestConvert.ArgumentsHalfDouble args, Target t) {
1647         t.setPrecision(0, 0);
1648         args.out = t.newFloaty(args.inVDouble);
1649     }
1650 
computeConvert(TestConvert.ArgumentsFloatChar args)1651     static public void computeConvert(TestConvert.ArgumentsFloatChar args) {
1652         args.out = convertFloatToChar(args.inV);
1653     }
computeConvert(TestConvert.ArgumentsFloatUchar args)1654     static public void computeConvert(TestConvert.ArgumentsFloatUchar args) {
1655         args.out = convertFloatToUchar(args.inV);
1656     }
computeConvert(TestConvert.ArgumentsFloatShort args)1657     static public void computeConvert(TestConvert.ArgumentsFloatShort args) {
1658         args.out = convertFloatToShort(args.inV);
1659     }
computeConvert(TestConvert.ArgumentsFloatUshort args)1660     static public void computeConvert(TestConvert.ArgumentsFloatUshort args) {
1661         args.out = convertFloatToUshort(args.inV);
1662     }
computeConvert(TestConvert.ArgumentsFloatInt args)1663     static public void computeConvert(TestConvert.ArgumentsFloatInt args) {
1664         args.out = convertFloatToInt(args.inV);
1665     }
computeConvert(TestConvert.ArgumentsFloatUint args)1666     static public void computeConvert(TestConvert.ArgumentsFloatUint args) {
1667         args.out = convertFloatToUint(args.inV);
1668     }
computeConvert(TestConvert.ArgumentsFloatLong args)1669     static public void computeConvert(TestConvert.ArgumentsFloatLong args) {
1670         args.out = convertFloatToLong(args.inV);
1671     }
computeConvert(TestConvert.ArgumentsFloatUlong args)1672     static public void computeConvert(TestConvert.ArgumentsFloatUlong args) {
1673         args.out = convertFloatToUlong(args.inV);
1674     }
computeConvert(TestConvert.ArgumentsFloatHalf args, Target t)1675     static public void computeConvert(TestConvert.ArgumentsFloatHalf args, Target t) {
1676         t.setPrecision(1, 1);
1677         args.out = t.newFloaty(args.inV);
1678     }
computeConvert(TestConvert.ArgumentsFloatFloat args, Target t)1679     static public void computeConvert(TestConvert.ArgumentsFloatFloat args, Target t) {
1680         t.setPrecision(0, 0);
1681         args.out = t.new32(convertFloatToFloat(args.inV));
1682     }
computeConvert(TestConvert.ArgumentsFloatDouble args, Target t)1683     static public void computeConvert(TestConvert.ArgumentsFloatDouble args, Target t) {
1684         t.setPrecision(0, 0);
1685         args.out = t.new64(convertFloatToDouble(args.inV));
1686     }
1687 
computeConvert(TestConvert.ArgumentsDoubleChar args)1688     static public void computeConvert(TestConvert.ArgumentsDoubleChar args) {
1689         args.out = convertDoubleToChar(args.inV);
1690     }
computeConvert(TestConvert.ArgumentsDoubleUchar args)1691     static public void computeConvert(TestConvert.ArgumentsDoubleUchar args) {
1692         args.out = convertDoubleToUchar(args.inV);
1693     }
computeConvert(TestConvert.ArgumentsDoubleShort args)1694     static public void computeConvert(TestConvert.ArgumentsDoubleShort args) {
1695         args.out = convertDoubleToShort(args.inV);
1696     }
computeConvert(TestConvert.ArgumentsDoubleUshort args)1697     static public void computeConvert(TestConvert.ArgumentsDoubleUshort args) {
1698         args.out = convertDoubleToUshort(args.inV);
1699     }
computeConvert(TestConvert.ArgumentsDoubleInt args)1700     static public void computeConvert(TestConvert.ArgumentsDoubleInt args) {
1701         args.out = convertDoubleToInt(args.inV);
1702     }
computeConvert(TestConvert.ArgumentsDoubleUint args)1703     static public void computeConvert(TestConvert.ArgumentsDoubleUint args) {
1704         args.out = convertDoubleToUint(args.inV);
1705     }
computeConvert(TestConvert.ArgumentsDoubleLong args)1706     static public void computeConvert(TestConvert.ArgumentsDoubleLong args) {
1707         args.out = convertDoubleToLong(args.inV);
1708     }
computeConvert(TestConvert.ArgumentsDoubleUlong args)1709     static public void computeConvert(TestConvert.ArgumentsDoubleUlong args) {
1710         args.out = convertDoubleToUlong(args.inV);
1711     }
computeConvert(TestConvert.ArgumentsDoubleHalf args, Target t)1712     static public void computeConvert(TestConvert.ArgumentsDoubleHalf args, Target t) {
1713         t.setPrecision(1, 1);
1714         args.out = t.newFloaty(args.inV);
1715     }
computeConvert(TestConvert.ArgumentsDoubleFloat args, Target t)1716     static public void computeConvert(TestConvert.ArgumentsDoubleFloat args, Target t) {
1717         t.setPrecision(1, 1);
1718         args.out = t.new32(convertDoubleToFloat(args.inV));
1719     }
computeConvert(TestConvert.ArgumentsDoubleDouble args, Target t)1720     static public void computeConvert(TestConvert.ArgumentsDoubleDouble args, Target t) {
1721         t.setPrecision(0, 0);
1722         args.out = t.new64(convertDoubleToDouble(args.inV));
1723     }
1724 
computeCopysign(TestCopysign.ArgumentsHalfHalfHalf args, Target t)1725     static public void computeCopysign(TestCopysign.ArgumentsHalfHalfHalf args, Target t) {
1726         t.setPrecision(0, 0);
1727         args.out = copysign(args.inMagnitudeValueDouble, args.inSignValueDouble, t);
1728     }
1729 
computeCopysign(TestCopysign.ArgumentsFloatFloatFloat args, Target t)1730     static public void computeCopysign(TestCopysign.ArgumentsFloatFloatFloat args, Target t) {
1731         t.setPrecision(0, 0);
1732         args.out = t.new32(Math.copySign(args.inMagnitudeValue, args.inSignValue));
1733     }
1734 
computeCos(TestCos.ArgumentsHalfHalf args, Target t)1735     static public void computeCos(TestCos.ArgumentsHalfHalf args, Target t) {
1736         t.setPrecision(4, 4);
1737         args.out = cos(args.inVDouble, t);
1738     }
1739 
computeCos(TestCos.ArgumentsFloatFloat args, Target t)1740     static public void computeCos(TestCos.ArgumentsFloatFloat args, Target t) {
1741         t.setPrecision(4, 128);
1742         args.out = cos(args.inV, t);
1743     }
1744 
computeCosh(TestCosh.ArgumentsHalfHalf args, Target t)1745     static public void computeCosh(TestCosh.ArgumentsHalfHalf args, Target t) {
1746         t.setPrecision(4, 4);
1747         args.out = cosh(args.inVDouble, t);
1748     }
1749 
computeCosh(TestCosh.ArgumentsFloatFloat args, Target t)1750     static public void computeCosh(TestCosh.ArgumentsFloatFloat args, Target t) {
1751         t.setPrecision(4, 128);
1752         args.out = cosh(args.inV, t);
1753     }
1754 
computeCospi(TestCospi.ArgumentsHalfHalf args, Target t)1755     static public void computeCospi(TestCospi.ArgumentsHalfHalf args, Target t) {
1756         t.setPrecision(4, 4);
1757         args.out = cospi(args.inVDouble, t);
1758     }
1759 
computeCospi(TestCospi.ArgumentsFloatFloat args, Target t)1760     static public void computeCospi(TestCospi.ArgumentsFloatFloat args, Target t) {
1761         t.setPrecision(4, 128);
1762         args.out = cospi(args.inV, t);
1763     }
1764 
computeCross(TestCross.ArgumentsHalfNHalfNHalfN args, Target t)1765     static public void computeCross(TestCross.ArgumentsHalfNHalfNHalfN args, Target t) {
1766         t.setPrecision(1, 4);
1767         cross(args.inLeftVectorDouble, args.inRightVectorDouble, args.out, t);
1768     }
1769 
computeCross(TestCross.ArgumentsFloatNFloatNFloatN args, Target t)1770     static public void computeCross(TestCross.ArgumentsFloatNFloatNFloatN args, Target t) {
1771         t.setPrecision(1, 4);
1772         cross(args.inLeftVector, args.inRightVector, args.out, t);
1773     }
1774 
computeDegrees(TestDegrees.ArgumentsHalfHalf args, Target t)1775     static public void computeDegrees(TestDegrees.ArgumentsHalfHalf args, Target t) {
1776         t.setPrecision(3, 3);
1777         args.out = degrees(args.inVDouble, t);
1778     }
1779 
computeDegrees(TestDegrees.ArgumentsFloatFloat args, Target t)1780     static public void computeDegrees(TestDegrees.ArgumentsFloatFloat args, Target t) {
1781         t.setPrecision(3, 3);
1782         Target.Floaty in = t.new32(args.inV);
1783         Target.Floaty k = t.new32((float)(180.0 / Math.PI));
1784         args.out = t.multiply(in, k);
1785     }
1786 
computeDistance(TestDistance.ArgumentsHalfHalfHalf args, Target t)1787     static public void computeDistance(TestDistance.ArgumentsHalfHalfHalf args, Target t) {
1788         t.setPrecision(1, 1); // TODO double-check precision
1789         args.out = distance(new double[] {args.inLeftVectorDouble},
1790                             new double[] {args.inRightVectorDouble}, t);
1791     }
computeDistance(TestDistance.ArgumentsHalfNHalfNHalf args, Target t)1792     static public void computeDistance(TestDistance.ArgumentsHalfNHalfNHalf args, Target t) {
1793         t.setPrecision(1, 1); // TODO double-check precision
1794         args.out = distance(args.inLeftVectorDouble, args.inRightVectorDouble, t);
1795     }
1796 
computeDistance(TestDistance.ArgumentsFloatFloatFloat args, Target t)1797     static public void computeDistance(TestDistance.ArgumentsFloatFloatFloat args, Target t) {
1798         t.setPrecision(1, 1);
1799         args.out = distance(new float[] {args.inLeftVector}, new float[] {args.inRightVector}, t);
1800     }
1801 
computeDistance(TestDistance.ArgumentsFloatNFloatNFloat args, Target t)1802     static public void computeDistance(TestDistance.ArgumentsFloatNFloatNFloat args, Target t) {
1803         t.setPrecision(1, 1);
1804         args.out = distance(args.inLeftVector, args.inRightVector, t);
1805     }
1806 
computeDot(TestDot.ArgumentsHalfHalfHalf args, Target t)1807     static public void computeDot(TestDot.ArgumentsHalfHalfHalf args, Target t) {
1808         t.setPrecision(1, 4); // TODO double-check precision
1809         Target.Floaty a = t.newFloaty(args.inLeftVectorDouble);
1810         Target.Floaty b = t.newFloaty(args.inRightVectorDouble);
1811         args.out = t.multiply(a, b);
1812     }
1813 
computeDot(TestDot.ArgumentsHalfNHalfNHalf args, Target t)1814     static public void computeDot(TestDot.ArgumentsHalfNHalfNHalf args, Target t) {
1815         t.setPrecision(1, 4); // TODO double-check precision
1816         Target.Floaty sum = t.newFloaty(0.);
1817         for (int i = 0; i < args.inLeftVectorDouble.length; i++) {
1818             Target.Floaty a = t.newFloaty(args.inLeftVectorDouble[i]);
1819             Target.Floaty b = t.newFloaty(args.inRightVectorDouble[i]);
1820             sum = t.add(sum, t.multiply(a, b));
1821         }
1822         args.out = sum;
1823     }
1824 
computeDot(TestDot.ArgumentsFloatFloatFloat args, Target t)1825     static public void computeDot(TestDot.ArgumentsFloatFloatFloat args, Target t) {
1826         t.setPrecision(1, 4);
1827         Target.Floaty a = t.new32(args.inLeftVector);
1828         Target.Floaty b = t.new32(args.inRightVector);
1829         args.out = t.multiply(a, b);
1830     }
1831 
computeDot(TestDot.ArgumentsFloatNFloatNFloat args, Target t)1832     static public void computeDot(TestDot.ArgumentsFloatNFloatNFloat args, Target t) {
1833         t.setPrecision(1, 4);
1834         Target.Floaty sum = t.new32(0.f);
1835         for (int i = 0; i < args.inLeftVector.length; i++) {
1836             Target.Floaty a = t.new32(args.inLeftVector[i]);
1837             Target.Floaty b = t.new32(args.inRightVector[i]);
1838             sum = t.add(sum, t.multiply(a, b));
1839         }
1840         args.out = sum;
1841     }
1842 
computeErf(TestErf.ArgumentsHalfHalf args, Target t)1843     static public void computeErf(TestErf.ArgumentsHalfHalf args, Target t) {
1844         t.setPrecision(16, 16);
1845         args.out = erf(args.inVDouble, t);
1846     }
1847 
computeErf(TestErf.ArgumentsFloatFloat args, Target t)1848     static public void computeErf(TestErf.ArgumentsFloatFloat args, Target t) {
1849         t.setPrecision(16, 128);
1850         Target.Floaty in = t.new32(args.inV);
1851         args.out = t.new32(
1852             erf(args.inV),
1853             erf(in.min32()),
1854             erf(in.max32()));
1855     }
1856 
computeErfc(TestErfc.ArgumentsHalfHalf args, Target t)1857     static public void computeErfc(TestErfc.ArgumentsHalfHalf args, Target t) {
1858         t.setPrecision(16, 16);
1859         args.out = erfc(args.inVDouble, t);
1860     }
1861 
computeErfc(TestErfc.ArgumentsFloatFloat args, Target t)1862     static public void computeErfc(TestErfc.ArgumentsFloatFloat args, Target t) {
1863         t.setPrecision(16, 128);
1864         Target.Floaty in = t.new32(args.inV);
1865         args.out = t.new32(
1866             erfc(args.inV),
1867             erfc(in.min32()),
1868             erfc(in.max32()));
1869     }
1870 
computeExp(TestExp.ArgumentsHalfHalf args, Target t)1871     static public void computeExp(TestExp.ArgumentsHalfHalf args, Target t) {
1872         t.setPrecision(3, 3);
1873         args.out = exp(args.inVDouble, t);
1874     }
1875 
computeExp(TestExp.ArgumentsFloatFloat args, Target t)1876     static public void computeExp(TestExp.ArgumentsFloatFloat args, Target t) {
1877         t.setPrecision(3, 16);
1878         args.out = exp(args.inV, t);
1879     }
1880 
computeExp10(TestExp10.ArgumentsHalfHalf args, Target t)1881     static public void computeExp10(TestExp10.ArgumentsHalfHalf args, Target t) {
1882         t.setPrecision(3, 3);
1883         args.out = exp10(args.inVDouble, t);
1884     }
1885 
computeExp10(TestExp10.ArgumentsFloatFloat args, Target t)1886     static public void computeExp10(TestExp10.ArgumentsFloatFloat args, Target t) {
1887         t.setPrecision(3, 32);
1888         args.out = exp10(args.inV, t);
1889     }
1890 
computeExp2(TestExp2.ArgumentsHalfHalf args, Target t)1891     static public void computeExp2(TestExp2.ArgumentsHalfHalf args, Target t) {
1892         t.setPrecision(3, 3);
1893         args.out = exp2(args.inVDouble, t);
1894     }
1895 
computeExp2(TestExp2.ArgumentsFloatFloat args, Target t)1896     static public void computeExp2(TestExp2.ArgumentsFloatFloat args, Target t) {
1897         t.setPrecision(3, 16);
1898         args.out = exp2(args.inV, t);
1899     }
1900 
computeExpm1(TestExpm1.ArgumentsHalfHalf args, Target t)1901     static public void computeExpm1(TestExpm1.ArgumentsHalfHalf args, Target t) {
1902         t.setPrecision(3, 3);
1903         args.out = expm1(args.inVDouble, t);
1904     }
1905 
computeExpm1(TestExpm1.ArgumentsFloatFloat args, Target t)1906     static public void computeExpm1(TestExpm1.ArgumentsFloatFloat args, Target t) {
1907         t.setPrecision(3, 16);
1908         args.out = expm1(args.inV, t);
1909     }
1910 
computeFabs(TestFabs.ArgumentsHalfHalf args, Target t)1911     static public void computeFabs(TestFabs.ArgumentsHalfHalf args, Target t) {
1912         t.setPrecision(0, 0);
1913         args.out = fabs(args.inVDouble, t);
1914     }
1915 
computeFabs(TestFabs.ArgumentsFloatFloat args, Target t)1916     static public void computeFabs(TestFabs.ArgumentsFloatFloat args, Target t) {
1917         t.setPrecision(0, 0);
1918         Target.Floaty in = t.new32(args.inV);
1919         args.out = t.new32(
1920             Math.abs(args.inV),
1921             Math.abs(in.min32()),
1922             Math.abs(in.max32()));
1923     }
1924 
computeFastDistance(TestFastDistance.ArgumentsFloatFloatFloat args, Target t)1925     static public void computeFastDistance(TestFastDistance.ArgumentsFloatFloatFloat args, Target t) {
1926         t.setPrecision(FAST_PRECISION, FAST_PRECISION);
1927         args.out = distance(new float[] {args.inLeftVector}, new float[] {args.inRightVector}, t);
1928     }
1929 
computeFastDistance(TestFastDistance.ArgumentsFloatNFloatNFloat args, Target t)1930     static public void computeFastDistance(TestFastDistance.ArgumentsFloatNFloatNFloat args, Target t) {
1931         t.setPrecision(FAST_PRECISION, FAST_PRECISION);
1932         args.out = distance(args.inLeftVector, args.inRightVector, t);
1933     }
1934 
computeFastLength(TestFastLength.ArgumentsFloatFloat args, Target t)1935     static public void computeFastLength(TestFastLength.ArgumentsFloatFloat args, Target t) {
1936         t.setPrecision(FAST_PRECISION, FAST_PRECISION);
1937         args.out = length(new float[] {args.inV}, t);
1938     }
1939 
computeFastLength(TestFastLength.ArgumentsFloatNFloat args, Target t)1940     static public void computeFastLength(TestFastLength.ArgumentsFloatNFloat args, Target t) {
1941         t.setPrecision(FAST_PRECISION, FAST_PRECISION);
1942         args.out = length(args.inV, t);
1943     }
1944 
computeFastNormalize(TestFastNormalize.ArgumentsFloatFloat args, Target t)1945     static public void computeFastNormalize(TestFastNormalize.ArgumentsFloatFloat args, Target t) {
1946         t.setPrecision(FAST_PRECISION, FAST_PRECISION);
1947         Target.Floaty[] out = new Target.Floaty[1];
1948         normalize(new float[] {args.inV}, out, t);
1949         args.out = out[0];
1950     }
1951 
computeFastNormalize(TestFastNormalize.ArgumentsFloatNFloatN args, Target t)1952     static public void computeFastNormalize(TestFastNormalize.ArgumentsFloatNFloatN args, Target t) {
1953         t.setPrecision(FAST_PRECISION, FAST_PRECISION);
1954         normalize(args.inV, args.out, t);
1955     }
1956 
computeFdim(TestFdim.ArgumentsHalfHalfHalf args, Target t)1957     static public void computeFdim(TestFdim.ArgumentsHalfHalfHalf args, Target t) {
1958         t.setPrecision(1, 1);
1959         args.out = fdim(args.inADouble, args.inBDouble, t);
1960     }
1961 
computeFdim(TestFdim.ArgumentsFloatFloatFloat args, Target t)1962     static public void computeFdim(TestFdim.ArgumentsFloatFloatFloat args, Target t) {
1963         t.setPrecision(1, 1);
1964         Target.Floaty inA = t.new32(args.inA);
1965         Target.Floaty inB = t.new32(args.inB);
1966         Target.Floaty r = t.subtract(inA, inB);
1967         args.out = t.new32(
1968             Math.max(0.f, r.mid32()),
1969             Math.max(0.f, r.min32()),
1970             Math.max(0.f, r.max32()));
1971     }
1972 
computeFloor(TestFloor.ArgumentsHalfHalf args, Target t)1973     static public void computeFloor(TestFloor.ArgumentsHalfHalf args, Target t) {
1974         t.setPrecision(0, 0);
1975         args.out = floor(args.inVDouble, t);
1976     }
1977 
computeFloor(TestFloor.ArgumentsFloatFloat args, Target t)1978     static public void computeFloor(TestFloor.ArgumentsFloatFloat args, Target t) {
1979         t.setPrecision(0, 0);
1980         Target.Floaty in = t.new32(args.inV);
1981         args.out = t.new32(
1982             floor(args.inV),
1983             floor(in.min32()),
1984             floor(in.max32()));
1985     }
1986 
computeFma(TestFma.ArgumentsHalfHalfHalfHalf args, Target t)1987     static public void computeFma(TestFma.ArgumentsHalfHalfHalfHalf args, Target t) {
1988         t.setPrecision(1, 1);
1989         args.out = fma(args.inMultiplicand1Double, args.inMultiplicand2Double,
1990             args.inOffsetDouble, t);
1991     }
1992 
computeFma(TestFma.ArgumentsFloatFloatFloatFloat args, Target t)1993     static public void computeFma(TestFma.ArgumentsFloatFloatFloatFloat args, Target t) {
1994         t.setPrecision(1, 1);
1995         Target.Floaty ab = t.multiply(t.new32(args.inMultiplicand1), t.new32(args.inMultiplicand2));
1996         args.out = t.add(ab, t.new32(args.inOffset));
1997     }
1998 
computeFmax(TestFmax.ArgumentsHalfHalfHalf args, Target t)1999     static public void computeFmax(TestFmax.ArgumentsHalfHalfHalf args, Target t) {
2000         t.setPrecision(0, 0);
2001         args.out = fmax(args.inADouble, args.inBDouble, t);
2002     }
2003 
computeFmax(TestFmax.ArgumentsFloatFloatFloat args, Target t)2004     static public void computeFmax(TestFmax.ArgumentsFloatFloatFloat args, Target t) {
2005         t.setPrecision(0, 0);
2006         Target.Floaty a = t.new32(args.inA);
2007         Target.Floaty b = t.new32(args.inB);
2008         args.out = t.new32(
2009             Math.max(args.inA, args.inB),
2010             Math.max(a.min32(), b.min32()),
2011             Math.max(a.min32(), b.max32()),
2012             Math.max(a.max32(), b.min32()),
2013             Math.max(a.max32(), b.max32()));
2014     }
2015 
computeFmin(TestFmin.ArgumentsHalfHalfHalf args, Target t)2016     static public void computeFmin(TestFmin.ArgumentsHalfHalfHalf args, Target t) {
2017         t.setPrecision(0, 0);
2018         args.out = fmin(args.inADouble, args.inBDouble, t);
2019     }
2020 
computeFmin(TestFmin.ArgumentsFloatFloatFloat args, Target t)2021     static public void computeFmin(TestFmin.ArgumentsFloatFloatFloat args, Target t) {
2022         t.setPrecision(0, 0);
2023         Target.Floaty a = t.new32(args.inA);
2024         Target.Floaty b = t.new32(args.inB);
2025         args.out = t.new32(
2026             Math.min(args.inA, args.inB),
2027             Math.min(a.min32(), b.min32()),
2028             Math.min(a.min32(), b.max32()),
2029             Math.min(a.max32(), b.min32()),
2030             Math.min(a.max32(), b.max32()));
2031     }
2032 
computeFmod(TestFmod.ArgumentsHalfHalfHalf args, Target t)2033     static public void computeFmod(TestFmod.ArgumentsHalfHalfHalf args, Target t) {
2034         t.setPrecision(1, 1);
2035         args.out = fmod(args.inNumeratorDouble, args.inDenominatorDouble, t);
2036     }
2037 
computeFmod(TestFmod.ArgumentsFloatFloatFloat args, Target t)2038     static public void computeFmod(TestFmod.ArgumentsFloatFloatFloat args, Target t) {
2039         t.setPrecision(1, 1);
2040         Target.Floaty numerator = t.new32(args.inNumerator);
2041         Target.Floaty denominator = t.new32(args.inDenominator);
2042         args.out = t.new32(
2043             args.inNumerator % args.inDenominator,
2044             numerator.min32() % denominator.min32(),
2045             numerator.min32() % denominator.max32(),
2046             numerator.max32() % denominator.min32(),
2047             numerator.max32() % denominator.max32());
2048     }
2049 
computeFract(TestFract.ArgumentsHalfHalfHalf args, Target t)2050     static public void computeFract(TestFract.ArgumentsHalfHalfHalf args, Target t) {
2051         t.setPrecision(1, 1);
2052         args.out = fract(args.inVDouble, t, 0.99951171875 /* max float16 smaller than 1.0 */);
2053         args.outFloor = floor(args.inVDouble, t);
2054     }
2055 
computeFract(TestFract.ArgumentsFloatFloatFloat args, Target t)2056     static public void computeFract(TestFract.ArgumentsFloatFloatFloat args, Target t) {
2057         t.setPrecision(1, 1);
2058         float floor = floor(args.inV);
2059         args.outFloor = t.new32(floor);
2060         // 0x1.fffffep-1f is 0.999999...
2061         args.out = t.new32(Math.min(args.inV - floor, 0x1.fffffep-1f));
2062     }
2063 
computeFract(TestFract.ArgumentsHalfHalf args, Target t)2064     static public void computeFract(TestFract.ArgumentsHalfHalf args, Target t) {
2065         t.setPrecision(1, 1);
2066         args.out = fract(args.inVDouble, t, 0.99951171875 /* max float16 smaller than 1.0 */);
2067     }
2068 
computeFract(TestFract.ArgumentsFloatFloat args, Target t)2069     static public void computeFract(TestFract.ArgumentsFloatFloat args, Target t) {
2070         t.setPrecision(1, 1);
2071         float floor = floor(args.inV);
2072         // 0x1.fffffep-1f is 0.999999...
2073         args.out = t.new32(Math.min(args.inV - floor, 0x1.fffffep-1f));
2074     }
2075 
computeFrexp(TestFrexp.ArgumentsFloatIntFloat args, Target t)2076     static public void computeFrexp(TestFrexp.ArgumentsFloatIntFloat args, Target t) {
2077         t.setPrecision(0, 0);
2078         FrexpResult result = frexp(args.inV);
2079         args.out = t.new32(result.significand);
2080         args.outExponent = result.exponent;
2081     }
2082 
computeHalfRecip(TestHalfRecip.ArgumentsFloatFloat args, Target t)2083     static public void computeHalfRecip(TestHalfRecip.ArgumentsFloatFloat args, Target t) {
2084         t.setPrecision(HALF_PRECISION, HALF_PRECISION);
2085         args.out = recip(args.inV, t);
2086     }
2087 
computeHalfRsqrt(TestHalfRsqrt.ArgumentsFloatFloat args, Target t)2088     static public void computeHalfRsqrt(TestHalfRsqrt.ArgumentsFloatFloat args, Target t) {
2089         t.setPrecision(HALF_PRECISION, HALF_PRECISION);
2090         args.out = rsqrt(args.inV, t);
2091     }
2092 
computeHalfSqrt(TestHalfSqrt.ArgumentsFloatFloat args, Target t)2093     static public void computeHalfSqrt(TestHalfSqrt.ArgumentsFloatFloat args, Target t) {
2094         t.setPrecision(HALF_PRECISION, HALF_PRECISION);
2095         args.out = sqrt(args.inV, t);
2096     }
2097 
computeHypot(TestHypot.ArgumentsHalfHalfHalf args, Target t)2098     static public void computeHypot(TestHypot.ArgumentsHalfHalfHalf args, Target t) {
2099         t.setPrecision(4, 4);
2100         args.out = hypot(args.inADouble, args.inBDouble, t);
2101     }
2102 
computeHypot(TestHypot.ArgumentsFloatFloatFloat args, Target t)2103     static public void computeHypot(TestHypot.ArgumentsFloatFloatFloat args, Target t) {
2104         t.setPrecision(4, 4);
2105         args.out = hypot(args.inA, args.inB, t);
2106     }
2107 
verifyIlogb(TestIlogb.ArgumentsFloatInt args)2108     static public String verifyIlogb(TestIlogb.ArgumentsFloatInt args) {
2109         // Special case when the input is 0.  We accept two different answers.
2110         if (args.inV == 0.f) {
2111             if (args.out != -Integer.MAX_VALUE && args.out != Integer.MIN_VALUE) {
2112                 return "Expected " + Integer.toString(-Integer.MAX_VALUE) + " or " +
2113                     Integer.toString(Integer.MIN_VALUE);
2114             }
2115         } else {
2116             int result = ilogb(args.inV);
2117             if (args.out != result) {
2118                 return "Expected " + Integer.toString(result);
2119             }
2120         }
2121         return null;
2122     }
2123 
computeLdexp(TestLdexp.ArgumentsFloatIntFloat args, Target t)2124     static public void computeLdexp(TestLdexp.ArgumentsFloatIntFloat args, Target t) {
2125         t.setPrecision(1, 1);
2126         Target.Floaty inMantissa = t.new32(args.inMantissa);
2127         args.out = t.new32(
2128             ldexp(inMantissa.mid32(), args.inExponent),
2129             ldexp(inMantissa.min32(), args.inExponent),
2130             ldexp(inMantissa.max32(), args.inExponent));
2131     }
2132 
computeLength(TestLength.ArgumentsHalfHalf args, Target t)2133     static public void computeLength(TestLength.ArgumentsHalfHalf args, Target t) {
2134         t.setPrecision(1, 1); // TODO double-check precision
2135         args.out = length(new double[]{args.inVDouble}, t);
2136     }
2137 
computeLength(TestLength.ArgumentsHalfNHalf args, Target t)2138     static public void computeLength(TestLength.ArgumentsHalfNHalf args, Target t) {
2139         t.setPrecision(1, 1); // TODO double-check precision
2140         args.out = length(args.inVDouble, t);
2141     }
2142 
computeLength(TestLength.ArgumentsFloatFloat args, Target t)2143     static public void computeLength(TestLength.ArgumentsFloatFloat args, Target t) {
2144         t.setPrecision(1, 1);
2145         args.out = length(new float[]{args.inV}, t);
2146     }
2147 
computeLength(TestLength.ArgumentsFloatNFloat args, Target t)2148     static public void computeLength(TestLength.ArgumentsFloatNFloat args, Target t) {
2149         t.setPrecision(1, 1);
2150         args.out = length(args.inV, t);
2151     }
2152 
computeLgamma(TestLgamma.ArgumentsFloatFloat args, Target t)2153     static public void computeLgamma(TestLgamma.ArgumentsFloatFloat args, Target t) {
2154         t.setPrecision(16, 128);
2155         Target.Floaty in = t.new32(args.inV);
2156         args.out = t.new32(
2157             lgamma(in.mid32()),
2158             lgamma(in.min32()),
2159             lgamma(in.max32()));
2160     }
2161 
2162     /* TODO Until -0 handling is corrected in bionic & associated drivers, we temporarily
2163      * disable the verification of -0.  We do this with a custom verifier.  Once bionic
2164      * is fixed, we can restore computeLgamma and remove verifyLgamma.
2165     static public void computeLgamma(TestLgamma.ArgumentsFloatIntFloat args, Target t) {
2166         t.setPrecision(16, 128);
2167         Target.Floaty in = t.new32(args.inV);
2168         LgammaResult result = lgamma2(in.mid32());
2169         LgammaResult resultMin = lgamma2(in.min32());
2170         LgammaResult resultMax = lgamma2(in.max32());
2171         args.out = t.new32(result.lgamma, resultMin.lgamma, resultMax.lgamma);
2172         args.outY = result.gammaSign;
2173     }
2174     */
verifyLgamma(TestLgamma.ArgumentsFloatIntFloat args, Target t)2175     static public String verifyLgamma(TestLgamma.ArgumentsFloatIntFloat args, Target t) {
2176         t.setPrecision(16, 128);
2177         Target.Floaty in = t.new32(args.inV);
2178         LgammaResult result = lgamma2(in.mid32());
2179         LgammaResult resultMin = lgamma2(in.min32());
2180         LgammaResult resultMax = lgamma2(in.max32());
2181         Target.Floaty expectedOut = t.new32(result.lgamma, resultMin.lgamma, resultMax.lgamma);
2182         boolean isNegativeZero = args.inV == 0.f && 1.f / args.inV < 0.f;
2183         /* TODO The current implementation of bionic does not handle the -0.f case correctly.
2184          * It should set the sign to -1 but sets it to 1.
2185          */
2186         if (!expectedOut.couldBe(args.out) ||
2187             (args.outSignOfGamma != result.gammaSign && !isNegativeZero)) {
2188             StringBuilder message = new StringBuilder();
2189             message.append(String.format("Input in %14.8g {%8x}:\n", args.inV, Float.floatToRawIntBits(args.inV)));
2190             message.append("Expected out: ");
2191             message.append(expectedOut.toString());
2192             message.append("\n");
2193             message.append(String.format("Actual   out: %14.8g {%8x}", args.out, Float.floatToRawIntBits(args.out)));
2194             message.append(String.format("Expected outSign: %d\n", result.gammaSign));
2195             message.append(String.format("Actual   outSign: %d\n", args.outSignOfGamma));
2196             return message.toString();
2197         }
2198 
2199         return null;
2200     }
2201 
2202     static public void computeLog(TestLog.ArgumentsHalfHalf args, Target t) {
2203         t.setPrecision(3, 3);
2204         args.out = log(args.inVDouble, t);
2205     }
2206 
2207     // TODO The relaxed ulf for the various log are taken from the old tests.
2208     // They are not consistent.
2209     static public void computeLog(TestLog.ArgumentsFloatFloat args, Target t) {
2210         t.setPrecision(3, 16);
2211         args.out = log(args.inV, t);
2212     }
2213 
2214     static public void computeLog10(TestLog10.ArgumentsHalfHalf args, Target t) {
2215         t.setPrecision(3, 3);
2216         args.out = log10(args.inVDouble, t);
2217     }
2218 
2219     static public void computeLog10(TestLog10.ArgumentsFloatFloat args, Target t) {
2220         t.setPrecision(3, 16);
2221         args.out = log10(args.inV, t);
2222     }
2223 
2224     static public void computeLog1p(TestLog1p.ArgumentsHalfHalf args, Target t) {
2225         t.setPrecision(2, 2);
2226         args.out = log1p(args.inVDouble, t);
2227     }
2228 
2229     static public void computeLog1p(TestLog1p.ArgumentsFloatFloat args, Target t) {
2230         t.setPrecision(2, 16);
2231         args.out = log1p(args.inV, t);
2232     }
2233 
2234     static public void computeLog2(TestLog2.ArgumentsHalfHalf args, Target t) {
2235         t.setPrecision(3, 3);
2236         args.out = log2(args.inVDouble, t);
2237     }
2238 
2239     static public void computeLog2(TestLog2.ArgumentsFloatFloat args, Target t) {
2240         t.setPrecision(3, 128);
2241         args.out = log2(args.inV, t);
2242     }
2243 
2244     static public void computeLogb(TestLogb.ArgumentsHalfHalf args, Target t) {
2245         t.setPrecision(0, 0);
2246         args.out = logb(args.inVDouble, t);
2247     }
2248 
2249     static public void computeLogb(TestLogb.ArgumentsFloatFloat args, Target t) {
2250         t.setPrecision(0, 0);
2251         Target.Floaty in = t.new32(args.inV);
2252         args.out = t.new32(
2253             logb(in.mid32()),
2254             logb(in.min32()),
2255             logb(in.max32()));
2256     }
2257 
2258     static public void computeMad(TestMad.ArgumentsHalfHalfHalfHalf args, Target t) {
2259         t.setPrecision(4, 4);
2260         args.out = mad(args.inMultiplicand1Double, args.inMultiplicand2Double, args.inOffsetDouble, t);
2261     }
2262 
2263     static public void computeMad(TestMad.ArgumentsFloatFloatFloatFloat args, Target t) {
2264         t.setPrecision(1, 4);
2265         Target.Floaty ab = t.multiply(t.new32(args.inMultiplicand1), t.new32(args.inMultiplicand2));
2266         args.out = t.add(ab, t.new32(args.inOffset));
2267     }
2268 
2269     static public void computeMax(TestMax.ArgumentsCharCharChar args) {
2270         args.out = maxI8(args.inA, args.inB);
2271     }
2272 
2273     static public void computeMax(TestMax.ArgumentsUcharUcharUchar args) {
2274         args.out = maxU8(args.inA, args.inB);
2275     }
2276 
2277     static public void computeMax(TestMax.ArgumentsShortShortShort args) {
2278         args.out = maxI16(args.inA, args.inB);
2279     }
2280 
2281     static public void computeMax(TestMax.ArgumentsUshortUshortUshort args) {
2282         args.out = maxU16(args.inA, args.inB);
2283     }
2284 
2285     static public void computeMax(TestMax.ArgumentsIntIntInt args) {
2286         args.out = maxI32(args.inA, args.inB);
2287     }
2288 
2289     static public void computeMax(TestMax.ArgumentsUintUintUint args) {
2290         args.out = maxU32(args.inA, args.inB);
2291     }
2292 
2293     static public void computeMax(TestMax.ArgumentsLongLongLong args) {
2294         args.out = maxI64(args.inA, args.inB);
2295     }
2296 
2297     static public void computeMax(TestMax.ArgumentsUlongUlongUlong args) {
2298         args.out = maxU64(args.inA, args.inB);
2299     }
2300 
2301     static public void computeMax(TestMax.ArgumentsHalfHalfHalf args, Target t) {
2302         t.setPrecision(0, 0);
2303         args.out = max(args.inADouble, args.inBDouble, t);
2304     }
2305 
2306     static public void computeMax(TestMax.ArgumentsFloatFloatFloat args, Target t) {
2307         t.setPrecision(0, 0);
2308         Target.Floaty a = t.new32(args.inA);
2309         Target.Floaty b = t.new32(args.inB);
2310         args.out = t.new32(
2311             Math.max(a.mid32(), b.mid32()),
2312             Math.max(a.min32(), b.min32()),
2313             Math.max(a.min32(), b.max32()),
2314             Math.max(a.max32(), b.min32()),
2315             Math.max(a.max32(), b.max32()));
2316     }
2317 
2318     static public void computeMin(TestMin.ArgumentsCharCharChar args) {
2319         args.out = minI8(args.inA, args.inB);
2320     }
2321 
2322     static public void computeMin(TestMin.ArgumentsUcharUcharUchar args) {
2323         args.out = minU8(args.inA, args.inB);
2324     }
2325 
2326     static public void computeMin(TestMin.ArgumentsShortShortShort args) {
2327         args.out = minI16(args.inA, args.inB);
2328     }
2329 
2330     static public void computeMin(TestMin.ArgumentsUshortUshortUshort args) {
2331         args.out = minU16(args.inA, args.inB);
2332     }
2333 
2334     static public void computeMin(TestMin.ArgumentsIntIntInt args) {
2335         args.out = minI32(args.inA, args.inB);
2336     }
2337 
2338     static public void computeMin(TestMin.ArgumentsUintUintUint args) {
2339         args.out = minU32(args.inA, args.inB);
2340     }
2341 
2342     static public void computeMin(TestMin.ArgumentsLongLongLong args) {
2343         args.out = minI64(args.inA, args.inB);
2344     }
2345 
2346     static public void computeMin(TestMin.ArgumentsUlongUlongUlong args) {
2347         args.out = minU64(args.inA, args.inB);
2348     }
2349 
2350     static public void computeMin(TestMin.ArgumentsHalfHalfHalf args, Target t) {
2351         t.setPrecision(0, 0);
2352         args.out = min(args.inADouble, args.inBDouble, t);
2353     }
2354 
2355     static public void computeMin(TestMin.ArgumentsFloatFloatFloat args, Target t) {
2356         t.setPrecision(0, 0);
2357         args.out = t.new32(Math.min(args.inA, args.inB));
2358     }
2359 
2360     static public void computeMix(TestMix.ArgumentsHalfHalfHalfHalf args, Target t) {
2361         t.setPrecision(1, 1);
2362         args.out = mix(args.inStartDouble, args.inStopDouble, args.inFractionDouble, t);
2363     }
2364 
2365     static public void computeMix(TestMix.ArgumentsFloatFloatFloatFloat args, Target t) {
2366         t.setPrecision(1, 4);
2367         Target.Floaty start = t.new32(args.inStart);
2368         Target.Floaty stop = t.new32(args.inStop);
2369         Target.Floaty diff = t.subtract(stop, start);
2370         args.out = t.add(start, t.multiply(diff, t.new32(args.inFraction)));
2371     }
2372 
2373     static public void computeModf(TestModf.ArgumentsFloatFloatFloat args, Target t) {
2374         t.setPrecision(0, 0);
2375         float ret = (float)(int)args.inV;
2376         args.outIntegralPart = t.new32(ret);
2377         args.out = t.new32(args.inV - ret);
2378     }
2379 
2380     static public void computeNan(TestNan.ArgumentsUintFloat args, Target t) {
2381         t.setPrecision(0, 0);
2382         // TODO(jeanluc) We're not using the input argument
2383         args.out = t.new32(Float.NaN);
2384     }
2385 
2386     static public void computeNanHalf(TestNanHalf.ArgumentsHalf args, Target t) {
2387         t.setPrecision(0, 0);
2388         args.out = t.newFloaty(Double.NaN);
2389     }
2390 
2391     static public void computeNativeAcos(TestNativeAcos.ArgumentsHalfHalf args, Target t) {
2392         t.setPrecision(0, 0); // extraAllowedError set in fw/rs/rs_math.spec and generated test files
2393         args.out = acos(args.inVDouble, t);
2394     }
2395 
2396     static public void computeNativeAcos(TestNativeAcos.ArgumentsFloatFloat args, Target t) {
2397         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2398         args.out = acos(args.inV, t);
2399     }
2400 
2401     static public void computeNativeAcosh(TestNativeAcosh.ArgumentsHalfHalf args, Target t) {
2402         t.setPrecision(4, 4);
2403         args.out = acosh(args.inVDouble, t);
2404     }
2405 
2406     static public void computeNativeAcosh(TestNativeAcosh.ArgumentsFloatFloat args, Target t) {
2407         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2408         args.out = acosh(args.inV, t);
2409     }
2410 
2411     static public void computeNativeAcospi(TestNativeAcospi.ArgumentsHalfHalf args, Target t) {
2412         t.setPrecision(0, 0); // extraAllowedError set in fw/rs/rs_math.spec and generated test files
2413         args.out = acospi(args.inVDouble, t);
2414     }
2415 
2416     static public void computeNativeAcospi(TestNativeAcospi.ArgumentsFloatFloat args, Target t) {
2417         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2418         args.out = acospi(args.inV, t);
2419     }
2420 
2421     static public void computeNativeAsin(TestNativeAsin.ArgumentsHalfHalf args, Target t) {
2422         t.setPrecision(0, 0); // extraAllowedError set in fw/rs/rs_math.spec and generated test files
2423         args.out = asin(args.inVDouble, t);
2424     }
2425 
2426     static public void computeNativeAsin(TestNativeAsin.ArgumentsFloatFloat args, Target t) {
2427         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2428         args.out = asin(args.inV, t);
2429     }
2430 
2431     static public void computeNativeAsinh(TestNativeAsinh.ArgumentsHalfHalf args, Target t) {
2432         t.setPrecision(4, 4);
2433         args.out = asinh(args.inVDouble, t);
2434     }
2435 
2436     static public void computeNativeAsinh(TestNativeAsinh.ArgumentsFloatFloat args, Target t) {
2437         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2438         args.out = asinh(args.inV, t);
2439     }
2440 
2441     static public void computeNativeAsinpi(TestNativeAsinpi.ArgumentsHalfHalf args, Target t) {
2442         t.setPrecision(0, 0); // extraAllowedError set in fw/rs/rs_math.spec and generated test files
2443         args.out = asinpi(args.inVDouble, t);
2444     }
2445 
2446     static public void computeNativeAsinpi(TestNativeAsinpi.ArgumentsFloatFloat args, Target t) {
2447         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2448         args.out = asinpi(args.inV, t);
2449     }
2450 
2451     static public void computeNativeAtan(TestNativeAtan.ArgumentsHalfHalf args, Target t) {
2452         t.setPrecision(5, 5);
2453         args.out = atan(args.inVDouble, t);
2454     }
2455 
2456     static public void computeNativeAtan(TestNativeAtan.ArgumentsFloatFloat args, Target t) {
2457         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2458         args.out = atan(args.inV, t);
2459     }
2460 
2461     static public void computeNativeAtanh(TestNativeAtanh.ArgumentsHalfHalf args, Target t) {
2462         t.setPrecision(5, 5);
2463         args.out = atanh(args.inVDouble, t);
2464     }
2465 
2466     static public void computeNativeAtanh(TestNativeAtanh.ArgumentsFloatFloat args, Target t) {
2467         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2468         args.out = atanh(args.inV, t);
2469     }
2470 
2471     static public void computeNativeAtanpi(TestNativeAtanpi.ArgumentsHalfHalf args, Target t) {
2472         t.setPrecision(5, 5);
2473         args.out = atanpi(args.inVDouble, t);
2474     }
2475 
2476     static public void computeNativeAtanpi(TestNativeAtanpi.ArgumentsFloatFloat args, Target t) {
2477         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2478         args.out = atanpi(args.inV, t);
2479     }
2480 
2481     static public void computeNativeAtan2(TestNativeAtan2.ArgumentsHalfHalfHalf args, Target t) {
2482         t.setPrecision(5, 5);
2483         args.out = atan2(args.inNumeratorDouble, args.inDenominatorDouble, t);
2484     }
2485 
2486     static public void computeNativeAtan2(TestNativeAtan2.ArgumentsFloatFloatFloat args, Target t) {
2487         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2488         args.out = atan2(args.inNumerator, args.inDenominator, t);
2489     }
2490 
2491     static public void computeNativeAtan2pi(TestNativeAtan2pi.ArgumentsHalfHalfHalf args, Target t) {
2492         t.setPrecision(5, 5);
2493         args.out = atan2pi(args.inNumeratorDouble, args.inDenominatorDouble, t);
2494     }
2495 
2496     static public void computeNativeAtan2pi(TestNativeAtan2pi.ArgumentsFloatFloatFloat args, Target t) {
2497         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2498         args.out = atan2pi(args.inNumerator, args.inDenominator, t);
2499     }
2500 
2501     static public void computeNativeCbrt(TestNativeCbrt.ArgumentsHalfHalf args, Target t) {
2502         t.setPrecision(2, 2);
2503         args.out = cbrt(args.inVDouble, t);
2504     }
2505 
2506     static public void computeNativeCbrt(TestNativeCbrt.ArgumentsFloatFloat args, Target t) {
2507         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2508         args.out = cbrt(args.inV, t);
2509     }
2510 
2511     static public void computeNativeCos(TestNativeCos.ArgumentsHalfHalf args, Target t) {
2512         t.setPrecision(0, 0); // extraAllowedError set in fw/rs/rs_math.spec and generated test files
2513         args.out = cos(args.inVDouble, t);
2514     }
2515 
2516     static public void computeNativeCos(TestNativeCos.ArgumentsFloatFloat args, Target t) {
2517         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2518         args.out = cos(args.inV, t);
2519     }
2520 
2521     static public void computeNativeCosh(TestNativeCosh.ArgumentsHalfHalf args, Target t) {
2522         t.setPrecision(4, 4);
2523         args.out = cosh(args.inVDouble, t);
2524     }
2525 
2526     static public void computeNativeCosh(TestNativeCosh.ArgumentsFloatFloat args, Target t) {
2527         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2528         args.out = cosh(args.inV, t);
2529     }
2530 
2531     static public void computeNativeCospi(TestNativeCospi.ArgumentsHalfHalf args, Target t) {
2532         t.setPrecision(0, 0); // extraAllowedError set in fw/rs/rs_math.spec and generated test files
2533         args.out = cospi(args.inVDouble, t);
2534     }
2535 
2536     static public void computeNativeCospi(TestNativeCospi.ArgumentsFloatFloat args, Target t) {
2537         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2538         args.out = cospi(args.inV, t);
2539     }
2540 
2541     static public void computeNativeDistance(TestNativeDistance.ArgumentsHalfHalfHalf args, Target t) {
2542         t.setPrecision(1, 1);
2543         args.out = distance(new double[] {args.inLeftVectorDouble},
2544                             new double[] {args.inRightVectorDouble}, t);
2545     }
2546 
2547     static public void computeNativeDistance(TestNativeDistance.ArgumentsHalfNHalfNHalf args, Target t) {
2548         t.setPrecision(1, 1);
2549         args.out = distance(args.inLeftVectorDouble, args.inRightVectorDouble, t);
2550     }
2551 
2552     static public void computeNativeDistance(TestNativeDistance.ArgumentsFloatFloatFloat args, Target t) {
2553         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2554         args.out = distance(new float[]{args.inLeftVector}, new float[]{args.inRightVector}, t);
2555     }
2556 
2557     static public void computeNativeDistance(TestNativeDistance.ArgumentsFloatNFloatNFloat args, Target t) {
2558         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2559         args.out = distance(args.inLeftVector, args.inRightVector, t);
2560     }
2561 
2562     static public void computeNativeDivide(TestNativeDivide.ArgumentsHalfHalfHalf args, Target t) {
2563         t.setPrecision(3, 3);
2564         args.out = divide(args.inLeftVectorDouble, args.inRightVectorDouble, t);
2565     }
2566 
2567     static public void computeNativeDivide(TestNativeDivide.ArgumentsFloatFloatFloat args, Target t) {
2568         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2569         args.out = t.divide(t.new32(args.inLeftVector), t.new32(args.inRightVector));
2570     }
2571 
2572     static public void computeNativeExp(TestNativeExp.ArgumentsHalfHalf args, Target t) {
2573         t.setPrecision(3, 3);
2574         args.out = exp(args.inVDouble, t);
2575     }
2576 
2577     static public void computeNativeExp(TestNativeExp.ArgumentsFloatFloat args, Target t) {
2578         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2579         args.out = exp(args.inV, t);
2580     }
2581 
2582     static public void computeNativeExp10(TestNativeExp10.ArgumentsHalfHalf args, Target t) {
2583         t.setPrecision(3, 3);
2584         args.out = exp10(args.inVDouble, t);
2585     }
2586 
2587     static public void computeNativeExp10(TestNativeExp10.ArgumentsFloatFloat args, Target t) {
2588         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2589         args.out = exp10(args.inV, t);
2590     }
2591 
2592     static public void computeNativeExp2(TestNativeExp2.ArgumentsHalfHalf args, Target t) {
2593         t.setPrecision(3, 3);
2594         args.out = exp2(args.inVDouble, t);
2595     }
2596 
2597     static public void computeNativeExp2(TestNativeExp2.ArgumentsFloatFloat args, Target t) {
2598         // TODO we would like to use NATIVE_PRECISION, NATIVE_PRECISION
2599         t.setPrecision(13000, 13000);
2600         args.out = exp2(args.inV, t);
2601     }
2602 
2603     static public String verifyNativeExpm1(TestNativeExpm1.ArgumentsHalfHalf args, Target t) {
2604         // Acceptable error for native_expm1 is:
2605         //     < 2^-11 in [-Inf, 0.6]
2606         //     3 ulp outside
2607         double extraAllowedError = 0.;
2608         int ulpFactor;
2609         if (args.inVDouble < 0.6) {
2610             ulpFactor = 0;
2611             extraAllowedError = 0.00048828125; // 2^-11
2612         } else {
2613             ulpFactor = 3;
2614         }
2615         t.setPrecision(ulpFactor, ulpFactor);
2616 
2617         Target.Floaty expectedOut = expm1(args.inVDouble, t);
2618         if (!expectedOut.couldBe(args.outDouble, extraAllowedError)) {
2619             StringBuilder message = new StringBuilder();
2620             message.append("Ulp Factor: " + Integer.toString(ulpFactor) + "\n");
2621             message.append("Extra allowed error: " + Double.toString(extraAllowedError) + "\n");
2622             message.append("Expected output out: " + expectedOut.toString() + "\n");
2623             return message.toString();
2624         }
2625         return null;
2626     }
2627 
2628     static public void computeNativeExpm1(TestNativeExpm1.ArgumentsFloatFloat args, Target t) {
2629         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2630         args.out = expm1(args.inV, t);
2631     }
2632 
2633     static public void computeNativeHypot(TestNativeHypot.ArgumentsHalfHalfHalf args, Target t) {
2634         t.setPrecision(4, 4);
2635         args.out = hypot(args.inADouble, args.inBDouble, t);
2636     }
2637 
2638     static public void computeNativeHypot(TestNativeHypot.ArgumentsFloatFloatFloat args, Target t) {
2639         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2640         args.out = hypot(args.inA, args.inB, t);
2641     }
2642 
2643     static public void computeNativeLength(TestNativeLength.ArgumentsHalfHalf args, Target t) {
2644         t.setPrecision(1, 1); // TODO double-check precision
2645         args.out = length(new double[]{args.inVDouble}, t);
2646     }
2647 
2648     static public void computeNativeLength(TestNativeLength.ArgumentsHalfNHalf args, Target t) {
2649         t.setPrecision(1, 1); // TODO double-check precision
2650         args.out = length(args.inVDouble, t);
2651     }
2652 
2653     static public void computeNativeLength(TestNativeLength.ArgumentsFloatFloat args, Target t) {
2654         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2655         args.out = length(new float[] {args.inV}, t);
2656     }
2657 
2658     static public void computeNativeLength(TestNativeLength.ArgumentsFloatNFloat args, Target t) {
2659         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2660         args.out = length(args.inV, t);
2661     }
2662 
2663     static public void computeNativeLog(TestNativeLog.ArgumentsHalfHalf args, Target t) {
2664         t.setPrecision(3, 3);
2665         // http://b/27859722 Accept anything for zero.  Negative values don't get tested (see
2666         // range() for this function in fw/rs/api/rs_math.spec.
2667         if (Math.abs(args.inVDouble) < 1.e-20) {
2668             args.out = any(t);
2669         } else {
2670             args.out = log(args.inVDouble, t);
2671         }
2672     }
2673 
2674     static public void computeNativeLog(TestNativeLog.ArgumentsFloatFloat args, Target t) {
2675         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2676         // For very small values, allow anything.
2677         if (Math.abs(args.inV) < 1.e-20) {
2678             args.out = any32(t);
2679         } else {
2680             args.out = log(args.inV, t);
2681         }
2682     }
2683 
2684     static public void computeNativeLog10(TestNativeLog10.ArgumentsHalfHalf args, Target t) {
2685         t.setPrecision(3, 3);
2686         // http://b/27859722 Accept anything for zero.  Negative values don't get tested (see
2687         // range() for this function in fw/rs/api/rs_math.spec.
2688         if (Math.abs(args.inVDouble) < 1.e-20) {
2689             args.out = any(t);
2690         } else {
2691             args.out = log10(args.inVDouble, t);
2692         }
2693     }
2694 
2695     static public void computeNativeLog10(TestNativeLog10.ArgumentsFloatFloat args, Target t) {
2696         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2697         // For very small values, allow anything.
2698         if (Math.abs(args.inV) < 1.e-20) {
2699             args.out = any32(t);
2700         } else {
2701             args.out = log10(args.inV, t);
2702         }
2703     }
2704 
2705     static public void computeNativeLog1p(TestNativeLog1p.ArgumentsHalfHalf args, Target t) {
2706         t.setPrecision(2, 2);
2707         args.out = log1p(args.inVDouble, t);
2708     }
2709 
2710     static public void computeNativeLog1p(TestNativeLog1p.ArgumentsFloatFloat args, Target t) {
2711         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2712         args.out = log1p(args.inV, t);
2713     }
2714 
2715     static public void computeNativeLog2(TestNativeLog2.ArgumentsHalfHalf args, Target t) {
2716         t.setPrecision(3, 3);
2717         // http://b/27859722 Accept anything for zero.  Negative values don't get tested (see
2718         // range() for this function in fw/rs/api/rs_math.spec.
2719         if (Math.abs(args.inVDouble) < 1.e-20) {
2720             args.out = any(t);
2721         } else {
2722             args.out = log2(args.inVDouble, t);
2723         }
2724     }
2725 
2726     static public void computeNativeLog2(TestNativeLog2.ArgumentsFloatFloat args, Target t) {
2727         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2728         // For very small values, allow anything.
2729         if (Math.abs(args.inV) < 1.e-20) {
2730             args.out = any32(t);
2731         } else {
2732             args.out = log2(args.inV, t);
2733         }
2734     }
2735 
2736     static public void computeNativeNormalize(TestNativeNormalize.ArgumentsHalfHalf args, Target t) {
2737         t.setPrecision(1, 1); // TODO double-check precision
2738         Target.Floaty[] out = new Target.Floaty[1];
2739         normalize(new double[] {args.inVDouble}, out, t);
2740         args.out = out[0];
2741     }
2742 
2743     static public void computeNativeNormalize(TestNativeNormalize.ArgumentsHalfNHalfN args, Target t) {
2744         t.setPrecision(1, 16); // TODO double-check precision.  Extra precision needed by libclcore.
2745         normalize(args.inVDouble, args.out, t);
2746     }
2747 
2748     static public void computeNativeNormalize(TestNativeNormalize.ArgumentsFloatFloat args, Target t) {
2749         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2750         Target.Floaty[] out = new Target.Floaty[1];
2751         normalize(new float[] {args.inV}, out, t);
2752         args.out = out[0];
2753     }
2754 
2755     static public void computeNativeNormalize(TestNativeNormalize.ArgumentsFloatNFloatN args, Target t) {
2756         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2757         normalize(args.inV, args.out, t);
2758     }
2759 
2760     static public void computeNativePowr(TestNativePowr.ArgumentsHalfHalfHalf args, Target t) {
2761         t.setPrecision(16, 16);
2762         // http://b/27859722 Accept anything for zero.  Negative values don't get tested (see
2763         // range() for this function in fw/rs/api/rs_math.spec.
2764         if (Math.abs(args.inBaseDouble) < 1.e-20) {
2765             args.out = any(t);
2766         } else {
2767             args.out = pow(args.inBaseDouble, args.inExponentDouble, t);
2768         }
2769     }
2770 
2771     static public void computeNativePowr(TestNativePowr.ArgumentsFloatFloatFloat args, Target t) {
2772         // TODO we would like to use NATIVE_PRECISION, NATIVE_PRECISION
2773         t.setPrecision(32000, 32000);
2774         // For very small values, allow anything.
2775         if (Math.abs(args.inBase) < 1.e-20) {
2776             args.out = any32(t);
2777         } else {
2778             args.out = powr(args.inBase, args.inExponent, t);
2779         }
2780     }
2781 
2782     static public void computeNativeRecip(TestNativeRecip.ArgumentsHalfHalf args, Target t) {
2783         t.setPrecision(3, 3);
2784         args.out = recip(args.inVDouble, t);
2785     }
2786 
2787     static public void computeNativeRecip(TestNativeRecip.ArgumentsFloatFloat args, Target t) {
2788         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2789         args.out = recip(args.inV, t);
2790     }
2791 
2792     static public void computeNativeRootn(TestNativeRootn.ArgumentsFloatIntFloat args, Target t) {
2793         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2794         // Allow anything for zero.
2795         if (args.inN == 0) {
2796             args.out = any32(t);
2797         } else {
2798             args.out = rootn(args.inV, args.inN, t);
2799         }
2800     }
2801 
2802     static public void computeNativeRsqrt(TestNativeRsqrt.ArgumentsHalfHalf args, Target t) {
2803         t.setPrecision(2, 2);
2804         args.out = rsqrt(args.inVDouble, t);
2805     }
2806 
2807     static public void computeNativeRsqrt(TestNativeRsqrt.ArgumentsFloatFloat args, Target t) {
2808         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2809         args.out = rsqrt(args.inV, t);
2810     }
2811 
2812     static public void computeNativeSin(TestNativeSin.ArgumentsHalfHalf args, Target t) {
2813         t.setPrecision(0, 0); // extraAllowedError set in fw/rs/rs_math.spec and generated test files
2814         args.out = sin(args.inVDouble, t);
2815     }
2816 
2817     static public void computeNativeSin(TestNativeSin.ArgumentsFloatFloat args, Target t) {
2818         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2819         args.out = sin(args.inV, t);
2820     }
2821 
2822     static public void computeNativeSincos(TestNativeSincos.ArgumentsHalfHalfHalf args, Target t) {
2823         t.setPrecision(0, 0); // extraAllowedError set in fw/rs/rs_math.spec and generated test files
2824         args.outCos = cos(args.inVDouble, t);
2825         args.out = sin(args.inVDouble, t);
2826     }
2827 
2828     static public void computeNativeSincos(TestNativeSincos.ArgumentsFloatFloatFloat args, Target t) {
2829         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2830         args.outCos = cos(args.inV, t);
2831         args.out = sin(args.inV, t);
2832     }
2833 
2834     static public void computeNativeSinh(TestNativeSinh.ArgumentsHalfHalf args, Target t) {
2835         t.setPrecision(4, 4);
2836         args.out = sinh(args.inVDouble, t);
2837     }
2838 
2839     static public void computeNativeSinh(TestNativeSinh.ArgumentsFloatFloat args, Target t) {
2840         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2841         args.out = sinh(args.inV, t);
2842     }
2843 
2844     static public void computeNativeSinpi(TestNativeSinpi.ArgumentsHalfHalf args, Target t) {
2845         t.setPrecision(0, 0); // extraAllowedError set in fw/rs/rs_math.spec and generated test files
2846         args.out = sinpi(args.inVDouble, t);
2847     }
2848 
2849     static public void computeNativeSinpi(TestNativeSinpi.ArgumentsFloatFloat args, Target t) {
2850         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2851         args.out = sinpi(args.inV, t);
2852     }
2853 
2854     static public void computeNativeSqrt(TestNativeSqrt.ArgumentsHalfHalf args, Target t) {
2855         t.setPrecision(3, 3);
2856         args.out = sqrt(args.inVDouble, t);
2857     }
2858 
2859     static public void computeNativeSqrt(TestNativeSqrt.ArgumentsFloatFloat args, Target t) {
2860         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2861         args.out = sqrt(args.inV, t);
2862     }
2863 
2864     static public String verifyNativeTan(TestNativeTan.ArgumentsHalfHalf args, Target t) {
2865         // Precision for native_tan is as follows:
2866         //     For integral n:
2867         //         8 ulp in [(n-0.45) pi, (n+0.45) pi]
2868         //         2048 ulp in [(n+0.45) pi, (n+0.55) pi]"
2869 
2870         // Compute the fractional part of args.inVDouble / pi
2871         double absoluteValueOverPi = Math.abs(args.inVDouble) / Math.PI;
2872         double fract = absoluteValueOverPi - Math.floor(absoluteValueOverPi);
2873 
2874         int ulpFactor;
2875         if (0.45 <= fract && fract <= 0.55) {
2876             ulpFactor = 2048;
2877         } else {
2878             ulpFactor = 8;
2879         }
2880         t.setPrecision(ulpFactor, ulpFactor);
2881 
2882         Target.Floaty expectedOut = tan(args.inVDouble, t);
2883         if (!expectedOut.couldBe(args.outDouble)) {
2884             StringBuilder message = new StringBuilder();
2885             message.append("Ulp Factor: " + Integer.toString(ulpFactor) + "\n");
2886             message.append("Expected output out: " + expectedOut.toString() + "\n");
2887             return message.toString();
2888         }
2889 
2890         return null;
2891     }
2892 
2893     static public void computeNativeTan(TestNativeTan.ArgumentsFloatFloat args, Target t) {
2894         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2895         args.out = tan(args.inV, t);
2896     }
2897 
2898     static public void computeNativeTanh(TestNativeTanh.ArgumentsHalfHalf args, Target t) {
2899         t.setPrecision(5, 5);
2900         args.out = tanh(args.inVDouble, t);
2901     }
2902 
2903     static public void computeNativeTanh(TestNativeTanh.ArgumentsFloatFloat args, Target t) {
2904         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2905         args.out = tanh(args.inV, t);
2906     }
2907 
2908     static public String verifyNativeTanpi(TestNativeTanpi.ArgumentsHalfHalf args, Target t) {
2909         // Precision for native_tan is as follows:
2910         //     For integral n:
2911         //         8 ulp in [(n-0.45), (n+0.45)]
2912         //         2048 ulp in [(n+0.45), (n+0.55)]"
2913 
2914         // Compute the fractional part of args.inVDouble
2915         double absoluteValue = Math.abs(args.inVDouble);
2916         double fract = absoluteValue - Math.floor(absoluteValue);
2917 
2918         int ulpFactor;
2919         if (0.45 <= fract && fract <= 0.55) {
2920             ulpFactor = 2048;
2921         } else {
2922             ulpFactor = 8;
2923         }
2924         t.setPrecision(ulpFactor, ulpFactor);
2925 
2926         Target.Floaty expectedOut = tanpi(args.inVDouble, t);
2927         if (!expectedOut.couldBe(args.outDouble)) {
2928             StringBuilder message = new StringBuilder();
2929             message.append("Ulp Factor: " + Integer.toString(ulpFactor) + "\n");
2930             message.append("Expected output out: " + expectedOut.toString() + "\n");
2931             return message.toString();
2932         }
2933 
2934         return null;
2935     }
2936 
2937     static public void computeNativeTanpi(TestNativeTanpi.ArgumentsFloatFloat args, Target t) {
2938         t.setPrecision(NATIVE_PRECISION, NATIVE_PRECISION);
2939         args.out = tanpi(args.inV, t);
2940     }
2941 
2942     static public void computeNextafter(TestNextafter.ArgumentsFloatFloatFloat args, Target t) {
2943         t.setPrecision(0, 0);
2944         args.out = t.new32(Math.nextAfter(args.inV, args.inTarget));
2945     }
2946 
2947     static public void computeNormalize(TestNormalize.ArgumentsHalfHalf args, Target t) {
2948         t.setPrecision(1, 1); // TODO double-check precision
2949         Target.Floaty[] out = new Target.Floaty[1];
2950         normalize(new double[] {args.inVDouble}, out, t);
2951         args.out = out[0];
2952     }
2953 
2954     static public void computeNormalize(TestNormalize.ArgumentsHalfNHalfN args, Target t) {
2955         t.setPrecision(1, 1); // TODO double-check precision
2956         normalize(args.inVDouble, args.out, t);
2957     }
2958 
2959     static public void computeNormalize(TestNormalize.ArgumentsFloatFloat args, Target t) {
2960         t.setPrecision(1, 1);
2961         Target.Floaty[] out = new Target.Floaty[1];
2962         normalize(new float[] {args.inV}, out, t);
2963         args.out = out[0];
2964     }
2965 
2966     static public void computeNormalize(TestNormalize.ArgumentsFloatNFloatN args, Target t) {
2967         t.setPrecision(1, 1);
2968         normalize(args.inV, args.out, t);
2969     }
2970 
2971     static public void computePow(TestPow.ArgumentsHalfHalfHalf args, Target t) {
2972         t.setPrecision(16, 16);
2973         args.out = pow(args.inBaseDouble, args.inExponentDouble, t);
2974     }
2975 
2976     static public void computePow(TestPow.ArgumentsFloatFloatFloat args, Target t) {
2977         t.setPrecision(16, 128);
2978         Target.Floaty base = t.new32(args.inBase);
2979         Target.Floaty exponent = t.new32(args.inExponent);
2980         args.out = t.new32(
2981             pow(base.mid32(), exponent.mid32()),
2982             pow(base.min32(), exponent.min32()),
2983             pow(base.min32(), exponent.max32()),
2984             pow(base.max32(), exponent.min32()),
2985             pow(base.max32(), exponent.max32()));
2986     }
2987 
2988     static public void computePown(TestPown.ArgumentsHalfIntHalf args, Target t) {
2989         t.setPrecision(16, 16);
2990         args.out = pow(args.inBaseDouble, (double) args.inExponent, t);
2991     }
2992 
2993     static public void computePown(TestPown.ArgumentsFloatIntFloat args, Target t) {
2994         t.setPrecision(16, 128);
2995         Target.Floaty in = t.new32(args.inBase);
2996         // We use double for the calculations because floats does not have enough
2997         // mantissa bits.  Knowing if an int is odd or even will matter for negative
2998         // numbers.  Using a float loses the lowest bit.
2999         final double y = (double) args.inExponent;
3000         args.out = t.new32(
3001             (float) Math.pow(in.mid32(), y),
3002             (float) Math.pow(in.min32(), y),
3003             (float) Math.pow(in.max32(), y));
3004     }
3005 
3006     static public void computePowr(TestPowr.ArgumentsHalfHalfHalf args, Target t) {
3007         t.setPrecision(16, 16);
3008         args.out = pow(args.inBaseDouble, args.inExponentDouble, t);
3009     }
3010 
3011     static public void computePowr(TestPowr.ArgumentsFloatFloatFloat args, Target t) {
3012         t.setPrecision(16, 128);
3013         args.out = powr(args.inBase, args.inExponent, t);
3014     }
3015 
3016     static public void computeRadians(TestRadians.ArgumentsHalfHalf args, Target t) {
3017         t.setPrecision(3, 3);
3018         args.out = radians(args.inVDouble, t);
3019     }
3020 
3021     static public void computeRadians(TestRadians.ArgumentsFloatFloat args, Target t) {
3022         t.setPrecision(3, 3);
3023         Target.Floaty in = t.new32(args.inV);
3024         Target.Floaty k = t.new32((float)(Math.PI / 180.0));
3025         args.out = t.multiply(in, k);
3026     }
3027 
3028     // NOTE: This function delegates to the floating-point version in libm.  Need to switch to the
3029     // double-precision version later.
3030     static public void computeRemainder(TestRemainder.ArgumentsHalfHalfHalf args, Target t) {
3031         t.setPrecision(0, 0);
3032         RemquoResult result = remquo((float) args.inNumeratorDouble,
3033             (float) args.inDenominatorDouble);
3034         args.out = t.newFloaty(result.remainder);
3035     }
3036 
3037     static public void computeRemainder(TestRemainder.ArgumentsFloatFloatFloat args, Target t) {
3038         t.setPrecision(0, 0);
3039         RemquoResult result = remquo(args.inNumerator, args.inDenominator);
3040         args.out = t.new32(result.remainder);
3041     }
3042 
3043     static public String verifyRemquo(TestRemquo.ArgumentsFloatFloatIntFloat args, Target t) {
3044         t.setPrecision(0, 0);
3045         RemquoResult expected = remquo(args.inNumerator, args.inDenominator);
3046         // If the expected remainder is NaN, we don't validate the quotient.  It's because of
3047         // a division by zero.
3048         if (Float.isNaN(expected.remainder)) {
3049             // Check that the value we got is NaN too.
3050             if (!Float.isNaN(args.out)) {
3051                 return "Expected a remainder of NaN but got " +  Float.toString(args.out);
3052             }
3053         } else {
3054             // The quotient should have the same lowest three bits.
3055             if ((args.outQuotient & 0x07) != (expected.quotient & 0x07)) {
3056                 return "Quotient returned " +  Integer.toString(args.outQuotient) +
3057                     " does not have the same lower three bits as the expected " +
3058                     Integer.toString(expected.quotient);
3059             }
3060             Target.Floaty remainder = t.new32(expected.remainder);
3061             if (!remainder.couldBe(args.out)) {
3062                 return "Remainder returned " + Float.toString(args.out) +
3063                     " is not similar to the expected " +
3064                     remainder.toString();
3065             }
3066         }
3067         return null;
3068     }
3069 
3070     static public void computeRint(TestRint.ArgumentsHalfHalf args, Target t) {
3071         t.setPrecision(0, 0);
3072         args.out = rint(args.inVDouble, t);
3073     }
3074 
3075     static public void computeRint(TestRint.ArgumentsFloatFloat args, Target t) {
3076         t.setPrecision(0, 0);
3077         Target.Floaty in = t.new32(args.inV);
3078         args.out = t.new32(
3079             rint(in.mid32()),
3080             rint(in.min32()),
3081             rint(in.max32()));
3082     }
3083 
3084     static public void computeRootn(TestRootn.ArgumentsFloatIntFloat args, Target t) {
3085         t.setPrecision(16, 16);
3086         args.out = rootn(args.inV, args.inN, t);
3087     }
3088 
3089     static public void computeRound(TestRound.ArgumentsHalfHalf args, Target t) {
3090         t.setPrecision(0, 0);
3091         args.out = round(args.inVDouble, t);
3092     }
3093 
3094     static public void computeRound(TestRound.ArgumentsFloatFloat args, Target t) {
3095         t.setPrecision(0, 0);
3096         Target.Floaty in = t.new32(args.inV);
3097         args.out = t.new32(
3098             round(in.mid32()),
3099             round(in.min32()),
3100             round(in.max32()));
3101     }
3102 
3103     static public void computeRsqrt(TestRsqrt.ArgumentsHalfHalf args, Target t) {
3104         t.setPrecision(2, 2);
3105         args.out = rsqrt(args.inVDouble, t);
3106     }
3107 
3108     static public void computeRsqrt(TestRsqrt.ArgumentsFloatFloat args, Target t) {
3109         t.setPrecision(2, 2);
3110         args.out = rsqrt(args.inV, t);
3111     }
3112 
3113     static public void computeSign(TestSign.ArgumentsHalfHalf args, Target t) {
3114         t.setPrecision(0, 0);
3115         args.out = t.newFloaty(Math.signum(args.inVDouble));
3116     }
3117 
3118     static public void computeSign(TestSign.ArgumentsFloatFloat args, Target t) {
3119         t.setPrecision(0, 0);
3120         args.out = t.new32(Math.signum(args.inV));
3121     }
3122 
3123     static public void computeSin(TestSin.ArgumentsHalfHalf args, Target t) {
3124         t.setPrecision(4, 4);
3125         args.out = sin(args.inVDouble, t);
3126     }
3127 
3128     static public void computeSin(TestSin.ArgumentsFloatFloat args, Target t) {
3129         t.setPrecision(4, 128);
3130         args.out = sin(args.inV, t);
3131     }
3132 
3133     static public void computeSincos(TestSincos.ArgumentsHalfHalfHalf args, Target t) {
3134         t.setPrecision(4, 128);
3135         args.outCos = cos(args.inVDouble, t );
3136         args.out = sin(args.inVDouble, t);
3137     }
3138 
3139     static public void computeSincos(TestSincos.ArgumentsFloatFloatFloat args, Target t) {
3140         t.setPrecision(4, 128);
3141         args.outCos = cos(args.inV,t );
3142         args.out = sin(args.inV, t);
3143     }
3144 
3145     static public void computeSinh(TestSinh.ArgumentsHalfHalf args, Target t) {
3146         t.setPrecision(4, 4);
3147         args.out = sinh(args.inVDouble, t);
3148     }
3149 
3150     static public void computeSinh(TestSinh.ArgumentsFloatFloat args, Target t) {
3151         t.setPrecision(4, 128);
3152         args.out = sinh(args.inV, t);
3153     }
3154 
3155     static public void computeSinpi(TestSinpi.ArgumentsHalfHalf args, Target t) {
3156         t.setPrecision(4, 4);
3157         args.out = sinpi(args.inVDouble, t);
3158     }
3159 
3160     static public void computeSinpi(TestSinpi.ArgumentsFloatFloat args, Target t) {
3161         t.setPrecision(4, 128);
3162         args.out = sinpi(args.inV, t);
3163     }
3164 
3165     static public void computeSqrt(TestSqrt.ArgumentsHalfHalf args, Target t) {
3166         t.setPrecision(3, 3);
3167         args.out = sqrt(args.inVDouble, t);
3168     }
3169 
3170     static public void computeSqrt(TestSqrt.ArgumentsFloatFloat args, Target t) {
3171         t.setPrecision(3, 3);
3172         args.out = sqrt(args.inV, t);
3173     }
3174 
3175     static public void computeStep(TestStep.ArgumentsHalfHalfHalf args, Target t) {
3176         t.setPrecision(0, 0);
3177         args.out = step(args.inVDouble, args.inEdgeDouble, t);
3178     }
3179 
3180     static public void computeStep(TestStep.ArgumentsFloatFloatFloat args, Target t) {
3181         t.setPrecision(0, 0);
3182         args.out = t.new32(args.inV < args.inEdge ? 0.f : 1.f);
3183     }
3184 
3185     static public void computeTan(TestTan.ArgumentsHalfHalf args, Target t) {
3186         t.setPrecision(5, 5);
3187         args.out = tan(args.inVDouble, t);
3188     }
3189 
3190     static public void computeTan(TestTan.ArgumentsFloatFloat args, Target t) {
3191         t.setPrecision(5, 128);
3192         args.out = tan(args.inV, t);
3193     }
3194 
3195     static public void computeTanh(TestTanh.ArgumentsHalfHalf args, Target t) {
3196         t.setPrecision(5, 5);
3197         args.out = tanh(args.inVDouble, t);
3198     }
3199 
3200     static public void computeTanh(TestTanh.ArgumentsFloatFloat args, Target t) {
3201         t.setPrecision(5, 128);
3202         args.out = tanh(args.inV, t);
3203     }
3204 
3205     static public void computeTanpi(TestTanpi.ArgumentsHalfHalf args, Target t) {
3206         t.setPrecision(4, 4);
3207         args.out = tanpi(args.inVDouble, t);
3208     }
3209 
3210     static public void computeTanpi(TestTanpi.ArgumentsFloatFloat args, Target t) {
3211         t.setPrecision(4, 128);
3212         args.out = tanpi(args.inV, t);
3213     }
3214 
3215     static public void computeTgamma(TestTgamma.ArgumentsHalfHalf args, Target t) {
3216         t.setPrecision(16, 16);
3217         args.out = tgamma(args.inVDouble, t);
3218     }
3219 
3220     static public void computeTgamma(TestTgamma.ArgumentsFloatFloat args, Target t) {
3221         t.setPrecision(16, 128);
3222         Target.Floaty in = t.new32(args.inV);
3223         args.out = t.new32(
3224             tgamma(in.mid32()),
3225             tgamma(in.min32()),
3226             tgamma(in.max32()));
3227     }
3228 
3229     static public void computeTrunc(TestTrunc.ArgumentsHalfHalf args, Target t) {
3230         t.setPrecision(0, 0);
3231         args.out = trunc(args.inVDouble, t);
3232     }
3233 
3234     static public void computeTrunc(TestTrunc.ArgumentsFloatFloat args, Target t) {
3235         t.setPrecision(0, 0);
3236         Target.Floaty in = t.new32(args.inV);
3237         args.out = t.new32(
3238             trunc(in.mid32()),
3239             trunc(in.min32()),
3240             trunc(in.max32()));
3241     }
3242 }
3243