Commit 3bfb0466 authored by jameslahm's avatar jameslahm Committed by V8 LUCI CQ

[test] Move cctest/test-double to unittests

... /base/double-unittest.

Bug: v8:12781
Change-Id: I13817728735a53fbc28a4e2d1babdcbd9bbf419d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3607113
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80556}
parent c819aebf
...@@ -206,7 +206,6 @@ v8_source_set("cctest_sources") { ...@@ -206,7 +206,6 @@ v8_source_set("cctest_sources") {
"test-disasm-regex-helper.cc", "test-disasm-regex-helper.cc",
"test-disasm-regex-helper.h", "test-disasm-regex-helper.h",
"test-diy-fp.cc", "test-diy-fp.cc",
"test-double.cc",
"test-dtoa.cc", "test-dtoa.cc",
"test-factory.cc", "test-factory.cc",
"test-fast-dtoa.cc", "test-fast-dtoa.cc",
......
...@@ -225,6 +225,7 @@ v8_source_set("unittests_sources") { ...@@ -225,6 +225,7 @@ v8_source_set("unittests_sources") {
"base/bits-unittest.cc", "base/bits-unittest.cc",
"base/cpu-unittest.cc", "base/cpu-unittest.cc",
"base/division-by-constant-unittest.cc", "base/division-by-constant-unittest.cc",
"base/double-unittest.cc",
"base/flags-unittest.cc", "base/flags-unittest.cc",
"base/functional-unittest.cc", "base/functional-unittest.cc",
"base/ieee754-unittest.cc", "base/ieee754-unittest.cc",
......
...@@ -25,18 +25,22 @@ ...@@ -25,18 +25,22 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "src/base/numbers/double.h"
#include <stdlib.h> #include <stdlib.h>
#include "src/base/numbers/diy-fp.h" #include "src/base/numbers/diy-fp.h"
#include "src/base/numbers/double.h"
#include "src/base/platform/platform.h" #include "src/base/platform/platform.h"
#include "src/init/v8.h" #include "src/init/v8.h"
#include "test/cctest/cctest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace v8 { namespace v8 {
using DoubleTest = ::testing::Test;
namespace base { namespace base {
TEST(Uint64Conversions) { TEST_F(DoubleTest, Uint64Conversions) {
// Start by checking the byte-order. // Start by checking the byte-order.
uint64_t ordered = 0x0123'4567'89AB'CDEF; uint64_t ordered = 0x0123'4567'89AB'CDEF;
CHECK_EQ(3512700564088504e-318, Double(ordered).value()); CHECK_EQ(3512700564088504e-318, Double(ordered).value());
...@@ -48,8 +52,7 @@ TEST(Uint64Conversions) { ...@@ -48,8 +52,7 @@ TEST(Uint64Conversions) {
CHECK_EQ(1.7976931348623157e308, Double(max_double64).value()); CHECK_EQ(1.7976931348623157e308, Double(max_double64).value());
} }
TEST_F(DoubleTest, AsDiyFp) {
TEST(AsDiyFp) {
uint64_t ordered = 0x0123'4567'89AB'CDEF; uint64_t ordered = 0x0123'4567'89AB'CDEF;
DiyFp diy_fp = Double(ordered).AsDiyFp(); DiyFp diy_fp = Double(ordered).AsDiyFp();
CHECK_EQ(0x12 - 0x3FF - 52, diy_fp.e()); CHECK_EQ(0x12 - 0x3FF - 52, diy_fp.e());
...@@ -68,8 +71,7 @@ TEST(AsDiyFp) { ...@@ -68,8 +71,7 @@ TEST(AsDiyFp) {
CHECK(0x001F'FFFF'FFFF'FFFF == diy_fp.f()); // NOLINT CHECK(0x001F'FFFF'FFFF'FFFF == diy_fp.f()); // NOLINT
} }
TEST_F(DoubleTest, AsNormalizedDiyFp) {
TEST(AsNormalizedDiyFp) {
uint64_t ordered = 0x0123'4567'89AB'CDEF; uint64_t ordered = 0x0123'4567'89AB'CDEF;
DiyFp diy_fp = Double(ordered).AsNormalizedDiyFp(); DiyFp diy_fp = Double(ordered).AsNormalizedDiyFp();
CHECK_EQ(0x12 - 0x3FF - 52 - 11, diy_fp.e()); CHECK_EQ(0x12 - 0x3FF - 52 - 11, diy_fp.e());
...@@ -87,8 +89,7 @@ TEST(AsNormalizedDiyFp) { ...@@ -87,8 +89,7 @@ TEST(AsNormalizedDiyFp) {
CHECK((uint64_t{0x001F'FFFF'FFFF'FFFF} << 11) == diy_fp.f()); CHECK((uint64_t{0x001F'FFFF'FFFF'FFFF} << 11) == diy_fp.f());
} }
TEST_F(DoubleTest, IsDenormal) {
TEST(IsDenormal) {
uint64_t min_double64 = 0x0000'0000'0000'0001; uint64_t min_double64 = 0x0000'0000'0000'0001;
CHECK(Double(min_double64).IsDenormal()); CHECK(Double(min_double64).IsDenormal());
uint64_t bits = 0x000F'FFFF'FFFF'FFFF; uint64_t bits = 0x000F'FFFF'FFFF'FFFF;
...@@ -97,8 +98,7 @@ TEST(IsDenormal) { ...@@ -97,8 +98,7 @@ TEST(IsDenormal) {
CHECK(!Double(bits).IsDenormal()); CHECK(!Double(bits).IsDenormal());
} }
TEST_F(DoubleTest, IsSpecial) {
TEST(IsSpecial) {
CHECK(Double(V8_INFINITY).IsSpecial()); CHECK(Double(V8_INFINITY).IsSpecial());
CHECK(Double(-V8_INFINITY).IsSpecial()); CHECK(Double(-V8_INFINITY).IsSpecial());
CHECK(Double(std::numeric_limits<double>::quiet_NaN()).IsSpecial()); CHECK(Double(std::numeric_limits<double>::quiet_NaN()).IsSpecial());
...@@ -120,8 +120,7 @@ TEST(IsSpecial) { ...@@ -120,8 +120,7 @@ TEST(IsSpecial) {
CHECK(!Double(-1.7976931348623157e308).IsSpecial()); CHECK(!Double(-1.7976931348623157e308).IsSpecial());
} }
TEST_F(DoubleTest, IsInfinite) {
TEST(IsInfinite) {
CHECK(Double(V8_INFINITY).IsInfinite()); CHECK(Double(V8_INFINITY).IsInfinite());
CHECK(Double(-V8_INFINITY).IsInfinite()); CHECK(Double(-V8_INFINITY).IsInfinite());
CHECK(!Double(std::numeric_limits<double>::quiet_NaN()).IsInfinite()); CHECK(!Double(std::numeric_limits<double>::quiet_NaN()).IsInfinite());
...@@ -133,8 +132,7 @@ TEST(IsInfinite) { ...@@ -133,8 +132,7 @@ TEST(IsInfinite) {
CHECK(!Double(min_double64).IsInfinite()); CHECK(!Double(min_double64).IsInfinite());
} }
TEST_F(DoubleTest, Sign) {
TEST(Sign) {
CHECK_EQ(1, Double(1.0).Sign()); CHECK_EQ(1, Double(1.0).Sign());
CHECK_EQ(1, Double(V8_INFINITY).Sign()); CHECK_EQ(1, Double(V8_INFINITY).Sign());
CHECK_EQ(-1, Double(-V8_INFINITY).Sign()); CHECK_EQ(-1, Double(-V8_INFINITY).Sign());
...@@ -144,8 +142,7 @@ TEST(Sign) { ...@@ -144,8 +142,7 @@ TEST(Sign) {
CHECK_EQ(1, Double(min_double64).Sign()); CHECK_EQ(1, Double(min_double64).Sign());
} }
TEST_F(DoubleTest, NormalizedBoundaries) {
TEST(NormalizedBoundaries) {
DiyFp boundary_plus; DiyFp boundary_plus;
DiyFp boundary_minus; DiyFp boundary_minus;
DiyFp diy_fp = Double(1.5).AsNormalizedDiyFp(); DiyFp diy_fp = Double(1.5).AsNormalizedDiyFp();
...@@ -180,8 +177,8 @@ TEST(NormalizedBoundaries) { ...@@ -180,8 +177,8 @@ TEST(NormalizedBoundaries) {
uint64_t smallest_normal64 = 0x0010'0000'0000'0000; uint64_t smallest_normal64 = 0x0010'0000'0000'0000;
diy_fp = Double(smallest_normal64).AsNormalizedDiyFp(); diy_fp = Double(smallest_normal64).AsNormalizedDiyFp();
Double(smallest_normal64).NormalizedBoundaries(&boundary_minus, Double(smallest_normal64)
&boundary_plus); .NormalizedBoundaries(&boundary_minus, &boundary_plus);
CHECK_EQ(diy_fp.e(), boundary_minus.e()); CHECK_EQ(diy_fp.e(), boundary_minus.e());
CHECK_EQ(diy_fp.e(), boundary_plus.e()); CHECK_EQ(diy_fp.e(), boundary_plus.e());
// Even though the significand is of the form 2^p (for some p), its boundaries // Even though the significand is of the form 2^p (for some p), its boundaries
...@@ -191,8 +188,8 @@ TEST(NormalizedBoundaries) { ...@@ -191,8 +188,8 @@ TEST(NormalizedBoundaries) {
uint64_t largest_denormal64 = 0x000F'FFFF'FFFF'FFFF; uint64_t largest_denormal64 = 0x000F'FFFF'FFFF'FFFF;
diy_fp = Double(largest_denormal64).AsNormalizedDiyFp(); diy_fp = Double(largest_denormal64).AsNormalizedDiyFp();
Double(largest_denormal64).NormalizedBoundaries(&boundary_minus, Double(largest_denormal64)
&boundary_plus); .NormalizedBoundaries(&boundary_minus, &boundary_plus);
CHECK_EQ(diy_fp.e(), boundary_minus.e()); CHECK_EQ(diy_fp.e(), boundary_minus.e());
CHECK_EQ(diy_fp.e(), boundary_plus.e()); CHECK_EQ(diy_fp.e(), boundary_plus.e());
CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f()); CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f());
...@@ -209,8 +206,7 @@ TEST(NormalizedBoundaries) { ...@@ -209,8 +206,7 @@ TEST(NormalizedBoundaries) {
CHECK((1 << 10) == diy_fp.f() - boundary_minus.f()); CHECK((1 << 10) == diy_fp.f() - boundary_minus.f());
} }
TEST_F(DoubleTest, NextDouble) {
TEST(NextDouble) {
CHECK_EQ(4e-324, Double(0.0).NextDouble()); CHECK_EQ(4e-324, Double(0.0).NextDouble());
CHECK_EQ(0.0, Double(-0.0).NextDouble()); CHECK_EQ(0.0, Double(-0.0).NextDouble());
CHECK_EQ(-0.0, Double(-4e-324).NextDouble()); CHECK_EQ(-0.0, Double(-4e-324).NextDouble());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment