Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/math/TestSignumIntrinsic.java
41153 views
/*1* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2020, BELLSOFT. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/*25* @test26* @summary Test compiler intrinsics for signum27* @library /test/lib28*29* @run main/othervm30* -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions31* -XX:+UseSignumIntrinsic32* compiler.intrinsics.math.TestSignumIntrinsic33* @run main/othervm34* -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions35* -XX:-UseSignumIntrinsic -XX:+UseCopySignIntrinsic36* compiler.intrinsics.math.TestSignumIntrinsic37*/3839package compiler.intrinsics.math;4041import jdk.test.lib.Asserts;4243public class TestSignumIntrinsic {4445private static final float[][] float_cases = {46{123.4f, 1.0f},47{-56.7f, -1.0f},48{7e30f, 1.0f},49{-0.3e30f, -1.0f},50{Float.MAX_VALUE, 1.0f},51{-Float.MAX_VALUE, -1.0f},52{Float.MIN_VALUE, 1.0f},53{-Float.MIN_VALUE, -1.0f},54{0.0f, 0.0f},55{-0.0f, -0.0f},56{Float.POSITIVE_INFINITY, 1.0f},57{Float.NEGATIVE_INFINITY, -1.0f},58{Float.NaN, Float.NaN},59{Float.MIN_NORMAL, 1.0f},60{-Float.MIN_NORMAL, -1.0f},61{0x0.0002P-126f, 1.0f},62{-0x0.0002P-126f, -1.0f}63};6465private static final double[][] double_cases = {66{123.4d, 1.0d},67{-56.7d, -1.0d},68{7e30d, 1.0d},69{-0.3e30d, -1.0d},70{Double.MAX_VALUE, 1.0d},71{-Double.MAX_VALUE, -1.0d},72{Double.MIN_VALUE, 1.0d},73{-Double.MIN_VALUE, -1.0d},74{0.0d, 0.0d},75{-0.0d, -0.0d},76{Double.POSITIVE_INFINITY, 1.0d},77{Double.NEGATIVE_INFINITY, -1.0d},78{Double.NaN, Double.NaN},79{Double.MIN_NORMAL, 1.0d},80{-Double.MIN_NORMAL, -1.0d},81{0x0.00000001P-1022, 1.0d},82{-0x0.00000001P-1022, -1.0d}83};8485public static void main(String[] args) throws Exception {86float fAccum = 0.0f;87double dAccum = 0.0d;88for (int i = 0; i < 100_000; i++) {89fAccum += floatTest();90dAccum += doubleTest();91}92System.out.println("SUCCESS. Accum values: " + fAccum + " and " + dAccum);93}9495private static float floatTest() {96float accum = 0.0f;97for (float[] fcase : float_cases) {98float arg = fcase[0];99float expected = fcase[1];100float calculated = Math.signum(arg);101Asserts.assertEQ(expected, calculated, "Unexpected float result from " + arg);102accum += calculated;103}104return accum;105}106107private static double doubleTest() {108double accum = 0.0d;109for (double[] dcase : double_cases) {110double arg = dcase[0];111double expected = dcase[1];112double calculated = Math.signum(arg);113Asserts.assertEQ(expected, calculated, "Unexpected double result from " + arg);114accum += calculated;115}116return accum;117}118}119120121