Avoid left shift of negative value in soft-fp16

This commit is contained in:
pete
2021-09-16 23:14:52 +01:00
parent 3912146608
commit 7ee63b47f1
3 changed files with 113 additions and 31 deletions
+68
View File
@@ -0,0 +1,68 @@
// SPDX-License-Identifier: Apache-2.0
// ----------------------------------------------------------------------------
// Copyright 2020-2021 Arm Limited
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
// of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
// ----------------------------------------------------------------------------
/**
* @brief Unit tests for the vectorized SIMD functionality.
*
* This test suite is a partial implementation, focussing on 4-wide vectors.
* We're adding things as we touch related parts of the code, but there is some
* technical debt to catch up on to get full coverage.
*/
#include <limits>
#include "gtest/gtest.h"
#include "../astcenc_internal.h"
#include "../astcenc_vecmathlib.h"
namespace astcenc
{
#if (ASTCENC_F16C == 0) && (ASTCENC_NEON == 0)
/** @brief Test normal numbers. */
TEST(softfloat, FP16NormalNumbers)
{
float result = sf16_to_float((15 << 10) + 1);
EXPECT_NEAR(result, 1.00098f, 0.00005f);
}
/** @brief Test VLA loop limit round down. */
TEST(softfloat, FP16DenormalNumbers)
{
float result = sf16_to_float((0 << 10) + 1);
EXPECT_NEAR(result, 5.96046e-08f, 0.00005f);
}
/** @brief Test zero. */
TEST(softfloat, FP16Zero)
{
float result = sf16_to_float(0x0000);
EXPECT_EQ(result, 0.0f);
}
/** @brief Test NaN. */
TEST(softfloat, FP16NaN)
{
float result = sf16_to_float(0xFFFF);
EXPECT_FALSE(result == result);
}
#endif
}