LCOV - code coverage report
Current view: top level - test/cctest - test-diy-fp.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 35 35 100.0 %
Date: 2019-02-19 Functions: 4 4 100.0 %

          Line data    Source code
       1             : // Copyright 2006-2008 the V8 project authors. All rights reserved.
       2             : // Redistribution and use in source and binary forms, with or without
       3             : // modification, are permitted provided that the following conditions are
       4             : // met:
       5             : //
       6             : //     * Redistributions of source code must retain the above copyright
       7             : //       notice, this list of conditions and the following disclaimer.
       8             : //     * Redistributions in binary form must reproduce the above
       9             : //       copyright notice, this list of conditions and the following
      10             : //       disclaimer in the documentation and/or other materials provided
      11             : //       with the distribution.
      12             : //     * Neither the name of Google Inc. nor the names of its
      13             : //       contributors may be used to endorse or promote products derived
      14             : //       from this software without specific prior written permission.
      15             : //
      16             : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
      17             : // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
      18             : // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
      19             : // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
      20             : // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      21             : // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
      22             : // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      23             : // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      24             : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      25             : // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
      26             : // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      27             : 
      28             : #include <stdlib.h>
      29             : 
      30             : #include "src/v8.h"
      31             : 
      32             : #include "src/base/platform/platform.h"
      33             : #include "src/diy-fp.h"
      34             : #include "test/cctest/cctest.h"
      35             : 
      36             : namespace v8 {
      37             : namespace internal {
      38             : 
      39       25880 : TEST(Subtract) {
      40             :   DiyFp diy_fp1 = DiyFp(3, 0);
      41             :   DiyFp diy_fp2 = DiyFp(1, 0);
      42             :   DiyFp diff = DiyFp::Minus(diy_fp1, diy_fp2);
      43             : 
      44           5 :   CHECK_EQ(2, diff.f());
      45           5 :   CHECK_EQ(0, diff.e());
      46             :   diy_fp1.Subtract(diy_fp2);
      47           5 :   CHECK_EQ(2, diy_fp1.f());
      48           5 :   CHECK_EQ(0, diy_fp1.e());
      49           5 : }
      50             : 
      51             : 
      52       25880 : TEST(Multiply) {
      53             :   DiyFp diy_fp1 = DiyFp(3, 0);
      54             :   DiyFp diy_fp2 = DiyFp(2, 0);
      55           5 :   DiyFp product = DiyFp::Times(diy_fp1, diy_fp2);
      56             : 
      57           5 :   CHECK_EQ(0, product.f());
      58           5 :   CHECK_EQ(64, product.e());
      59           5 :   diy_fp1.Multiply(diy_fp2);
      60          10 :   CHECK_EQ(0, diy_fp1.f());
      61           5 :   CHECK_EQ(64, diy_fp1.e());
      62             : 
      63           5 :   diy_fp1 = DiyFp(V8_2PART_UINT64_C(0x80000000, 00000000), 11);
      64           5 :   diy_fp2 = DiyFp(2, 13);
      65           5 :   product = DiyFp::Times(diy_fp1, diy_fp2);
      66           5 :   CHECK_EQ(1, product.f());
      67           5 :   CHECK_EQ(11 + 13 + 64, product.e());
      68             : 
      69             :   // Test rounding.
      70           5 :   diy_fp1 = DiyFp(V8_2PART_UINT64_C(0x80000000, 00000001), 11);
      71           5 :   diy_fp2 = DiyFp(1, 13);
      72           5 :   product = DiyFp::Times(diy_fp1, diy_fp2);
      73           5 :   CHECK_EQ(1, product.f());
      74           5 :   CHECK_EQ(11 + 13 + 64, product.e());
      75             : 
      76           5 :   diy_fp1 = DiyFp(V8_2PART_UINT64_C(0x7FFFFFFF, FFFFFFFF), 11);
      77           5 :   diy_fp2 = DiyFp(1, 13);
      78           5 :   product = DiyFp::Times(diy_fp1, diy_fp2);
      79           5 :   CHECK_EQ(0, product.f());
      80           5 :   CHECK_EQ(11 + 13 + 64, product.e());
      81             : 
      82             :   // Halfway cases are allowed to round either way. So don't check for it.
      83             : 
      84             :   // Big numbers.
      85           5 :   diy_fp1 = DiyFp(V8_2PART_UINT64_C(0xFFFFFFFF, FFFFFFFF), 11);
      86           5 :   diy_fp2 = DiyFp(V8_2PART_UINT64_C(0xFFFFFFFF, FFFFFFFF), 13);
      87             :   // 128bit result: 0xFFFFFFFFFFFFFFFE0000000000000001
      88           5 :   product = DiyFp::Times(diy_fp1, diy_fp2);
      89           5 :   CHECK(V8_2PART_UINT64_C(0xFFFFFFFF, FFFFFFFE) == product.f());
      90           5 :   CHECK_EQ(11 + 13 + 64, product.e());
      91           5 : }
      92             : 
      93             : }  // namespace internal
      94       77625 : }  // namespace v8

Generated by: LCOV version 1.10