From 108b43301a7d90b3d1a2701edbeadf3f7ae084e3 Mon Sep 17 00:00:00 2001 From: Leonardo Banderali Date: Wed, 5 Sep 2018 15:47:28 -0400 Subject: [PATCH] Add tests for new JitBuilder ConvertBitsTo service Signed-off-by: Leonardo Banderali --- fvtest/jitbuildertest/CMakeLists.txt | 1 + fvtest/jitbuildertest/ConvertBitsTest.cpp | 112 ++++++++++++++++++++++ fvtest/jitbuildertest/Makefile | 3 +- 3 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 fvtest/jitbuildertest/ConvertBitsTest.cpp diff --git a/fvtest/jitbuildertest/CMakeLists.txt b/fvtest/jitbuildertest/CMakeLists.txt index 8a12a641fa9..79361a6cc95 100644 --- a/fvtest/jitbuildertest/CMakeLists.txt +++ b/fvtest/jitbuildertest/CMakeLists.txt @@ -33,6 +33,7 @@ add_executable(jitbuildertest SystemLinkageTest.cpp WorklistTest.cpp FieldNameTest.cpp + ConvertBitsTest.cpp ) if(OMR_HOST_ARCH STREQUAL "x86") diff --git a/fvtest/jitbuildertest/ConvertBitsTest.cpp b/fvtest/jitbuildertest/ConvertBitsTest.cpp new file mode 100644 index 00000000000..09932e03869 --- /dev/null +++ b/fvtest/jitbuildertest/ConvertBitsTest.cpp @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright (c) 2018, 2018 IBM Corp. and others + * + * This program and the accompanying materials are made available under + * the terms of the Eclipse Public License 2.0 which accompanies this + * distribution and is available at http://eclipse.org/legal/epl-2.0 + * or the Apache License, Version 2.0 which accompanies this distribution + * and is available at https://www.apache.org/licenses/LICENSE-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License, v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception [1] and GNU General Public + * License, version 2 with the OpenJDK Assembly Exception [2]. + * + * [1] https://www.gnu.org/software/classpath/license.html + * [2] http://openjdk.java.net/legal/assembly-exception.html + * + * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception + *******************************************************************************/ + +#include "JBTestUtil.hpp" + +class BitConversionTest : public JitBuilderTest {}; + +typedef float (BitConvertInt2FloatFunction)(uint32_t); + +DEFINE_BUILDER( BitConvertInt2Float, + Float, + PARAM("p", Int32) ) + { + Return( + ConvertBitsTo(Float, Load("p"))); + return true; + } + +TEST_F(BitConversionTest, Int2Float) + { + BitConvertInt2FloatFunction* int2float; + ASSERT_COMPILE(TR::TypeDictionary, BitConvertInt2Float, int2float); + + ASSERT_EQ(0.0f, int2float(0)); + ASSERT_EQ(-1.0f, int2float(0xbf800000U)); + ASSERT_EQ(3.125f, int2float(0x40480000U)); + ASSERT_NE(127.0f, int2float(127)); + } + +typedef uint32_t (BitConvertFloat2IntFunction)(float); + +DEFINE_BUILDER( BitConvertFloat2Int, + Int32, + PARAM("p", Float) ) + { + Return( + ConvertBitsTo(Int32, Load("p"))); + return true; + } + +TEST_F(BitConversionTest, Float2Int) + { + BitConvertFloat2IntFunction* float2int; + ASSERT_COMPILE(TR::TypeDictionary, BitConvertFloat2Int, float2int); + + ASSERT_EQ(0, float2int(0.0f)); + ASSERT_EQ(0xbf800000U, float2int(-1.0f)); + ASSERT_EQ(0x40480000U, float2int(3.125f)); + ASSERT_NE(127, float2int(127.0f)); + } + +typedef double (BitConvertLong2DoubleFunction)(uint64_t); + +DEFINE_BUILDER( BitConvertLong2Double, + Double, + PARAM("p", Int64) ) + { + Return( + ConvertBitsTo(Double, Load("p"))); + return true; + } + +TEST_F(BitConversionTest, Long2Double) + { + BitConvertLong2DoubleFunction* long2double; + ASSERT_COMPILE(TR::TypeDictionary, BitConvertLong2Double, long2double); + + ASSERT_EQ(0.0, long2double(0)); + ASSERT_EQ(-1.0, long2double(0xbff0000000000000ULL)); + ASSERT_EQ(3.125, long2double(0x4009000000000000ULL)); + ASSERT_NE(2047.0, long2double(2047)); + } + +typedef uint64_t (BitConvertDouble2LongFunction)(double); + +DEFINE_BUILDER( BitConvertDouble2Long, + Int64, + PARAM("p", Double) ) + { + Return( + ConvertBitsTo(Int64, Load("p"))); + return true; + } + +TEST_F(BitConversionTest, Double2Long) + { + BitConvertDouble2LongFunction* double2long; + ASSERT_COMPILE(TR::TypeDictionary, BitConvertDouble2Long, double2long); + + ASSERT_EQ(0, double2long(0.0)); + ASSERT_EQ(0xbff0000000000000ULL, double2long(-1.0)); + ASSERT_EQ(0x4009000000000000ULL, double2long(3.125f)); + ASSERT_NE(2047, double2long(2047.0f)); + } diff --git a/fvtest/jitbuildertest/Makefile b/fvtest/jitbuildertest/Makefile index 0e4c63e373b..e5b08c55d71 100644 --- a/fvtest/jitbuildertest/Makefile +++ b/fvtest/jitbuildertest/Makefile @@ -36,7 +36,8 @@ OBJECTS := \ WorklistTest \ IfThenElseTest \ CallReturnTest \ - FieldNameTest + FieldNameTest \ + ConvertBitsTest OBJECTS := $(addsuffix $(OBJEXT),$(OBJECTS))