Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add tests for new JitBuilder ConvertBitsTo service
Signed-off-by: Leonardo Banderali <leonardo2718@protonmail.com>
  • Loading branch information
Leonardo2718 committed Sep 7, 2018
1 parent 5e36e9c commit 108b433
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 1 deletion.
1 change: 1 addition & 0 deletions fvtest/jitbuildertest/CMakeLists.txt
Expand Up @@ -33,6 +33,7 @@ add_executable(jitbuildertest
SystemLinkageTest.cpp
WorklistTest.cpp
FieldNameTest.cpp
ConvertBitsTest.cpp
)

if(OMR_HOST_ARCH STREQUAL "x86")
Expand Down
112 changes: 112 additions & 0 deletions 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));
}
3 changes: 2 additions & 1 deletion fvtest/jitbuildertest/Makefile
Expand Up @@ -36,7 +36,8 @@ OBJECTS := \
WorklistTest \
IfThenElseTest \
CallReturnTest \
FieldNameTest
FieldNameTest \
ConvertBitsTest

OBJECTS := $(addsuffix $(OBJEXT),$(OBJECTS))

Expand Down

0 comments on commit 108b433

Please sign in to comment.