"Fossies" - the Fresh Open Source Software Archive

Member "qt-everywhere-src-6.3.1/qtwebengine/src/3rdparty/chromium/third_party/fdlibm/chromium/0001-Import-a-copy-of-V8-s-fdlibm-fork-into-Chromium-thir.patch" (8 Jun 2022, 13866 Bytes) of package /linux/misc/qt-everywhere-src-6.3.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Diff source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 From 715afeb52a0c6aca1c7fcbe8c7302f20a1a2ed1a Mon Sep 17 00:00:00 2001
    2 From: Caleb Raitto <caraitto@chromium.org>
    3 Date: Wed, 9 Dec 2020 15:37:30 -0500
    4 Subject: [PATCH] Import a copy of V8's fdlibm fork into Chromium
    5  //third_party.
    6 
    7 Import a copy of v8/src/base/ieee754.[h/cc] from V8 into
    8 Chromium.
    9 
   10 This will be used to mitigate Web Audio fingerprinting by using the same
   11 math library across OS versions and platforms.
   12 
   13 We use a copy of the V8 math library rather than trying to share this
   14 library.  This adds ~8-9kb to the Android apk, according to the Android
   15 binary size trybot on the CL that switches Web Audio to use this fdlibm
   16 fork.
   17 
   18 This avoids complicating the build, and the V8 team also prefers not
   19 sharing these internal details. If further similar logic needs to be
   20 copied in the future, we could consider refactoring that into a common
   21 library that both V8 and Chromium pull in via DEPS.
   22 
   23 The V8 math library also hasn't seen much churn, but we will need to
   24 keep both copies up-to-date. crrev.com/c/2593649 has added a WATCHLISTS
   25 entry in V8 to help with this.
   26 
   27 Due to presubmit requirements, this is *not* a pristine import --
   28 changes made from upstream to add build support and functionality
   29 necessary for Web Audio are present in the commit patch in the chromium/
   30 subdirectory. A summary of these changes is also present in
   31 README.chromium.
   32 
   33 Bug:1145192
   34 ---
   35  third_party/fdlibm/BUILD.gn           | 12 +++++
   36  third_party/fdlibm/DEPS               |  6 +++
   37  third_party/fdlibm/README.chromium    | 10 ++++
   38  third_party/fdlibm/ieee754.cc         | 69 +++++++++++++++----------
   39  third_party/fdlibm/ieee754.h          | 73 +++++++++++++++------------
   40  third_party/fdlibm/overflowing-math.h | 16 +++---
   41  6 files changed, 118 insertions(+), 68 deletions(-)
   42  create mode 100644 third_party/fdlibm/BUILD.gn
   43  create mode 100644 third_party/fdlibm/DEPS
   44 
   45 diff --git a/third_party/fdlibm/BUILD.gn b/third_party/fdlibm/BUILD.gn
   46 new file mode 100644
   47 index 000000000000..9c70cbdb062c
   48 --- /dev/null
   49 +++ b/third_party/fdlibm/BUILD.gn
   50 @@ -0,0 +1,12 @@
   51 +# Copyright 2020 The Chromium Authors. All rights reserved.
   52 +# Use of this source code is governed by a BSD-style license that can be
   53 +# found in the LICENSE file.
   54 +
   55 +source_set("fdlibm") {
   56 +  sources = [
   57 +    "ieee754.cc",
   58 +    "ieee754.h",
   59 +    "overflowing-math.h",
   60 +  ]
   61 +  deps = [ "//base" ]
   62 +}
   63 diff --git a/third_party/fdlibm/DEPS b/third_party/fdlibm/DEPS
   64 new file mode 100644
   65 index 000000000000..a94f56d77fbf
   66 --- /dev/null
   67 +++ b/third_party/fdlibm/DEPS
   68 @@ -0,0 +1,6 @@
   69 +include_rules = [
   70 +    "+base/bit_cast.h",
   71 +    "+base/compiler_specific.h",
   72 +    "+base/macros.h",
   73 +    "+build/build_config.h",
   74 +]
   75 diff --git a/third_party/fdlibm/README.chromium b/third_party/fdlibm/README.chromium
   76 index eb45e2ab9438..48b3ab4bc6cc 100644
   77 --- a/third_party/fdlibm/README.chromium
   78 +++ b/third_party/fdlibm/README.chromium
   79 @@ -13,3 +13,13 @@ This library is a copy of that V8 library intended for use in Chromium.
   80  
   81  This library may be useful when mathematical consistency across OS platforms is
   82  desired.
   83 +
   84 +The initial commit is not a pristine import -- the patch in the chromium/
   85 +subdirectory documents the changes made to the original sources.
   86 +
   87 +Changes from V8 upstream:
   88 +- Changed namespace to fdlibm.
   89 +- Alter //v8/src/base usage to use Chromium //base equivalents.
   90 +- Implement 32-bit float functions (sinf(), etc.) by calling the 64-bit
   91 +  versions.
   92 +- Format the code.
   93 diff --git a/third_party/fdlibm/ieee754.cc b/third_party/fdlibm/ieee754.cc
   94 index 1706b56dfd90..4825b22fc6f5 100644
   95 --- a/third_party/fdlibm/ieee754.cc
   96 +++ b/third_party/fdlibm/ieee754.cc
   97 @@ -1,3 +1,4 @@
   98 +
   99  // The following is adapted from fdlibm (http://www.netlib.org/fdlibm).
  100  //
  101  // ====================================================
  102 @@ -12,30 +13,23 @@
  103  // The original source code covered by the above license above has been
  104  // modified significantly by Google Inc.
  105  // Copyright 2016 the V8 project authors. All rights reserved.
  106 +// Copyright 2020 The Chromium Authors. All rights reserved.
  107  
  108 -#include "src/base/ieee754.h"
  109 +#include "third_party/fdlibm/ieee754.h"
  110  
  111  #include <cmath>
  112  #include <limits>
  113  
  114 -#include "src/base/build_config.h"
  115 -#include "src/base/macros.h"
  116 -#include "src/base/overflowing-math.h"
  117 +#include "base/bit_cast.h"
  118 +#include "base/compiler_specific.h"
  119 +#include "base/macros.h"
  120 +#include "build/build_config.h"
  121 +#include "third_party/fdlibm/overflowing-math.h"
  122  
  123 -namespace v8 {
  124 -namespace base {
  125 -namespace ieee754 {
  126 +namespace fdlibm {
  127  
  128  namespace {
  129  
  130 -/* Disable "potential divide by 0" warning in Visual Studio compiler. */
  131 -
  132 -#if V8_CC_MSVC
  133 -
  134 -#pragma warning(disable : 4723)
  135 -
  136 -#endif
  137 -
  138  /*
  139   * The original fdlibm code used statements like:
  140   *  n0 = ((*(int*)&one)>>29)^1;   * index of high word *
  141 @@ -104,11 +98,11 @@ namespace {
  142      (d) = bit_cast<double>(bits);          \
  143    } while (false)
  144  
  145 -int32_t __ieee754_rem_pio2(double x, double* y) V8_WARN_UNUSED_RESULT;
  146 -double __kernel_cos(double x, double y) V8_WARN_UNUSED_RESULT;
  147 +int32_t __ieee754_rem_pio2(double x, double* y) WARN_UNUSED_RESULT;
  148 +double __kernel_cos(double x, double y) WARN_UNUSED_RESULT;
  149  int __kernel_rem_pio2(double* x, double* y, int e0, int nx, int prec,
  150 -                      const int32_t* ipio2) V8_WARN_UNUSED_RESULT;
  151 -double __kernel_sin(double x, double y, int iy) V8_WARN_UNUSED_RESULT;
  152 +                      const int32_t* ipio2) WARN_UNUSED_RESULT;
  153 +double __kernel_sin(double x, double y, int iy) WARN_UNUSED_RESULT;
  154  
  155  /* __ieee754_rem_pio2(x,y)
  156   *
  157 @@ -302,7 +296,7 @@ int32_t __ieee754_rem_pio2(double x, double *y) {
  158   *         magnitude of the latter is at least a quarter of x*x/2,
  159   *         thus, reducing the rounding error in the subtraction.
  160   */
  161 -V8_INLINE double __kernel_cos(double x, double y) {
  162 +ALWAYS_INLINE double __kernel_cos(double x, double y) {
  163    static const double
  164        one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
  165        C1 = 4.16666666666666019037e-02,  /* 0x3FA55555, 0x5555554C */
  166 @@ -670,7 +664,7 @@ recompute:
  167   *         then                   3    2
  168   *              sin(x) = x + (S1*x + (x *(r-y/2)+y))
  169   */
  170 -V8_INLINE double __kernel_sin(double x, double y, int iy) {
  171 +ALWAYS_INLINE double __kernel_sin(double x, double y, int iy) {
  172    static const double
  173        half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
  174        S1 = -1.66666666666666324348e-01,  /* 0xBFC55555, 0x55555549 */
  175 @@ -2721,7 +2715,7 @@ double pow(double x, double y) {
  176      }
  177      if (iy == 0x3ff00000) { /* y is  +-1 */
  178        if (hy < 0) {
  179 -        return base::Divide(one, x);
  180 +        return Divide(one, x);
  181        } else {
  182          return x;
  183        }
  184 @@ -2739,7 +2733,7 @@ double pow(double x, double y) {
  185    if (lx == 0) {
  186      if (ix == 0x7ff00000 || ix == 0 || ix == 0x3ff00000) {
  187        z = ax;                         /*x is +-0,+-inf,+-1*/
  188 -      if (hy < 0) z = base::Divide(one, z); /* z = (1/|x|) */
  189 +      if (hy < 0) z = Divide(one, z); /* z = (1/|x|) */
  190        if (hx < 0) {
  191          if (((ix - 0x3ff00000) | yisint) == 0) {
  192            /* (-1)**non-int is NaN */
  193 @@ -2806,7 +2800,7 @@ double pow(double x, double y) {
  194  
  195      /* compute ss = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
  196      u = ax - bp[k]; /* bp[0]=1.0, bp[1]=1.5 */
  197 -    v = base::Divide(one, ax + bp[k]);
  198 +    v = Divide(one, ax + bp[k]);
  199      ss = u * v;
  200      s_h = ss;
  201      SET_LOW_WORD(s_h, 0);
  202 @@ -2883,7 +2877,7 @@ double pow(double x, double y) {
  203    w = v - (z - u);
  204    t = z * z;
  205    t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5))));
  206 -  r = base::Divide(z * t1, (t1 - two) - (w + z * w));
  207 +  r = Divide(z * t1, (t1 - two) - (w + z * w));
  208    z = one - (r - z);
  209    GET_HIGH_WORD(j, z);
  210    j += static_cast<int>(static_cast<uint32_t>(n) << 20);
  211 @@ -3008,6 +3002,26 @@ double tanh(double x) {
  212    return (jx >= 0) ? z : -z;
  213  }
  214  
  215 +float powf(float x, float y) {
  216 +  return pow(x, y);
  217 +}
  218 +
  219 +float expf(float x) {
  220 +  return exp(x);
  221 +}
  222 +
  223 +float log10f(float x) {
  224 +  return log10(x);
  225 +}
  226 +
  227 +float sinf(double x) {
  228 +  return sin(x);
  229 +}
  230 +
  231 +float asinf(double x) {
  232 +  return asin(x);
  233 +}
  234 +
  235  #undef EXTRACT_WORDS
  236  #undef GET_HIGH_WORD
  237  #undef GET_LOW_WORD
  238 @@ -3015,6 +3029,5 @@ double tanh(double x) {
  239  #undef SET_HIGH_WORD
  240  #undef SET_LOW_WORD
  241  
  242 -}  // namespace ieee754
  243 -}  // namespace base
  244 -}  // namespace v8
  245 +}  // namespace fdlibm
  246 +
  247 diff --git a/third_party/fdlibm/ieee754.h b/third_party/fdlibm/ieee754.h
  248 index f2b3a3eb5808..27b5013818a2 100644
  249 --- a/third_party/fdlibm/ieee754.h
  250 +++ b/third_party/fdlibm/ieee754.h
  251 @@ -1,64 +1,61 @@
  252  // Copyright 2016 the V8 project authors. All rights reserved.
  253 +// Copyright 2020 The Chromium Authors. All rights reserved.
  254  // Use of this source code is governed by a BSD-style license that can be
  255  // found in the LICENSE file.
  256  
  257 -#ifndef V8_BASE_IEEE754_H_
  258 -#define V8_BASE_IEEE754_H_
  259 +#ifndef THIRD_PARTY_FDLIBM_IEEE754_H_
  260 +#define THIRD_PARTY_FDLIBM_IEEE754_H_
  261  
  262 -#include "src/base/base-export.h"
  263 -
  264 -namespace v8 {
  265 -namespace base {
  266 -namespace ieee754 {
  267 +namespace fdlibm {
  268  
  269  // Returns the arc cosine of |x|; that is the value whose cosine is |x|.
  270 -V8_BASE_EXPORT double acos(double x);
  271 +double acos(double x);
  272  
  273  // Returns the inverse hyperbolic cosine of |x|; that is the value whose
  274  // hyperbolic cosine is |x|.
  275 -V8_BASE_EXPORT double acosh(double x);
  276 +double acosh(double x);
  277  
  278  // Returns the arc sine of |x|; that is the value whose sine is |x|.
  279 -V8_BASE_EXPORT double asin(double x);
  280 +double asin(double x);
  281  
  282  // Returns the inverse hyperbolic sine of |x|; that is the value whose
  283  // hyperbolic sine is |x|.
  284 -V8_BASE_EXPORT double asinh(double x);
  285 +double asinh(double x);
  286  
  287  // Returns the principal value of the arc tangent of |x|; that is the value
  288  // whose tangent is |x|.
  289 -V8_BASE_EXPORT double atan(double x);
  290 +double atan(double x);
  291  
  292  // Returns the principal value of the arc tangent of |y/x|, using the signs of
  293  // the two arguments to determine the quadrant of the result.
  294 -V8_BASE_EXPORT double atan2(double y, double x);
  295 +double atan2(double y, double x);
  296  
  297  // Returns the cosine of |x|, where |x| is given in radians.
  298 -V8_BASE_EXPORT double cos(double x);
  299 +double cos(double x);
  300  
  301  // Returns the base-e exponential of |x|.
  302 -V8_BASE_EXPORT double exp(double x);
  303 +double exp(double x);
  304  
  305 -V8_BASE_EXPORT double atanh(double x);
  306 +double atanh(double x);
  307  
  308  // Returns the natural logarithm of |x|.
  309 -V8_BASE_EXPORT double log(double x);
  310 +double log(double x);
  311  
  312  // Returns a value equivalent to |log(1+x)|, but computed in a way that is
  313  // accurate even if the value of |x| is near zero.
  314 -V8_BASE_EXPORT double log1p(double x);
  315 +double log1p(double x);
  316  
  317  // Returns the base 2 logarithm of |x|.
  318 -V8_BASE_EXPORT double log2(double x);
  319 +double log2(double x);
  320  
  321  // Returns the base 10 logarithm of |x|.
  322 -V8_BASE_EXPORT double log10(double x);
  323 +double log10(double x);
  324  
  325  // Returns the cube root of |x|.
  326 -V8_BASE_EXPORT double cbrt(double x);
  327 +double cbrt(double x);
  328  
  329  // Returns exp(x)-1, the exponential of |x| minus 1.
  330 -V8_BASE_EXPORT double expm1(double x);
  331 +double expm1(double x);
  332  
  333  // Returns |x| to the power of |y|.
  334  // The result of base ** exponent when base is 1 or -1 and exponent is
  335 @@ -66,25 +63,37 @@ V8_BASE_EXPORT double expm1(double x);
  336  // of ECMAScript specified a result of NaN for this operation, whereas
  337  // later versions of IEEE 754-2008 specified 1. The historical ECMAScript
  338  // behaviour is preserved for compatibility reasons.
  339 -V8_BASE_EXPORT double pow(double x, double y);
  340 +double pow(double x, double y);
  341  
  342  // Returns the sine of |x|, where |x| is given in radians.
  343 -V8_BASE_EXPORT double sin(double x);
  344 +double sin(double x);
  345  
  346  // Returns the tangent of |x|, where |x| is given in radians.
  347 -V8_BASE_EXPORT double tan(double x);
  348 +double tan(double x);
  349  
  350  // Returns the hyperbolic cosine of |x|, where |x| is given radians.
  351 -V8_BASE_EXPORT double cosh(double x);
  352 +double cosh(double x);
  353  
  354  // Returns the hyperbolic sine of |x|, where |x| is given radians.
  355 -V8_BASE_EXPORT double sinh(double x);
  356 +double sinh(double x);
  357  
  358  // Returns the hyperbolic tangent of |x|, where |x| is given radians.
  359 -V8_BASE_EXPORT double tanh(double x);
  360 +double tanh(double x);
  361 +
  362 +// NOTE(caraitto): These functions are not present in the V8 math library --
  363 +// they are defined in terms of other functions.
  364 +
  365 +float powf(float x, float y);
  366 +
  367 +float expf(float x);
  368 +
  369 +float log10f(float x);
  370 +
  371 +float sinf(double x);
  372 +
  373 +float asinf(double x);
  374 +
  375 +}  // namespace fdlibm
  376  
  377 -}  // namespace ieee754
  378 -}  // namespace base
  379 -}  // namespace v8
  380 +#endif  // THIRD_PARTY_FDLIBM_IEEE754_H_
  381  
  382 -#endif  // V8_BASE_IEEE754_H_
  383 diff --git a/third_party/fdlibm/overflowing-math.h b/third_party/fdlibm/overflowing-math.h
  384 index 14dcfb10de1a..815fa624ce11 100644
  385 --- a/third_party/fdlibm/overflowing-math.h
  386 +++ b/third_party/fdlibm/overflowing-math.h
  387 @@ -1,19 +1,19 @@
  388  // Copyright 2019 the V8 project authors. All rights reserved.
  389 +// Copyright 2020 The Chromium Authors. All rights reserved.
  390  // Use of this source code is governed by a BSD-style license that can be
  391  // found in the LICENSE file.
  392  
  393 -#ifndef V8_BASE_OVERFLOWING_MATH_H_
  394 -#define V8_BASE_OVERFLOWING_MATH_H_
  395 +#ifndef THIRD_PARTY_FDLIBM_OVERFLOWING_MATH_H_
  396 +#define THIRD_PARTY_FDLIBM_OVERFLOWING_MATH_H_
  397  
  398  #include <stdint.h>
  399  
  400  #include <cmath>
  401  #include <type_traits>
  402  
  403 -#include "src/base/macros.h"
  404 +#include "base/macros.h"
  405  
  406 -namespace v8 {
  407 -namespace base {
  408 +namespace fdlibm {
  409  
  410  // Helpers for performing overflowing arithmetic operations without relying
  411  // on C++ undefined behavior.
  412 @@ -90,7 +90,7 @@ inline T RoundingAverageUnsigned(T a, T b) {
  413    return (static_cast<uint64_t>(a) + static_cast<uint64_t>(b) + 1) >> 1;
  414  }
  415  
  416 -}  // namespace base
  417 -}  // namespace v8
  418 +}  // namespace fdlibm
  419 +
  420 +#endif  // THIRD_PARTY_FDLIBM_OVERFLOWING_MATH_H_
  421  
  422 -#endif  // V8_BASE_OVERFLOWING_MATH_H_
  423 -- 
  424 2.30.0.365.g02bc693789-goog
  425