Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | |
michael@0 | 2 | /* |
michael@0 | 3 | * Copyright 2006 The Android Open Source Project |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | |
michael@0 | 10 | #ifndef SkFloatingPoint_DEFINED |
michael@0 | 11 | #define SkFloatingPoint_DEFINED |
michael@0 | 12 | |
michael@0 | 13 | #include "SkTypes.h" |
michael@0 | 14 | |
michael@0 | 15 | #include <math.h> |
michael@0 | 16 | #include <float.h> |
michael@0 | 17 | #include "SkFloatBits.h" |
michael@0 | 18 | |
michael@0 | 19 | // C++98 cmath std::pow seems to be the earliest portable way to get float pow. |
michael@0 | 20 | // However, on Linux including cmath undefines isfinite. |
michael@0 | 21 | // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14608 |
michael@0 | 22 | static inline float sk_float_pow(float base, float exp) { |
michael@0 | 23 | return powf(base, exp); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | static inline float sk_float_copysign(float x, float y) { |
michael@0 | 27 | int32_t xbits = SkFloat2Bits(x); |
michael@0 | 28 | int32_t ybits = SkFloat2Bits(y); |
michael@0 | 29 | return SkBits2Float((xbits & 0x7FFFFFFF) | (ybits & 0x80000000)); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | #ifdef SK_BUILD_FOR_WINCE |
michael@0 | 33 | #define sk_float_sqrt(x) (float)::sqrt(x) |
michael@0 | 34 | #define sk_float_sin(x) (float)::sin(x) |
michael@0 | 35 | #define sk_float_cos(x) (float)::cos(x) |
michael@0 | 36 | #define sk_float_tan(x) (float)::tan(x) |
michael@0 | 37 | #define sk_float_acos(x) (float)::acos(x) |
michael@0 | 38 | #define sk_float_asin(x) (float)::asin(x) |
michael@0 | 39 | #define sk_float_atan2(y,x) (float)::atan2(y,x) |
michael@0 | 40 | #define sk_float_abs(x) (float)::fabs(x) |
michael@0 | 41 | #define sk_float_mod(x,y) (float)::fmod(x,y) |
michael@0 | 42 | #define sk_float_exp(x) (float)::exp(x) |
michael@0 | 43 | #define sk_float_log(x) (float)::log(x) |
michael@0 | 44 | #define sk_float_floor(x) (float)::floor(x) |
michael@0 | 45 | #define sk_float_ceil(x) (float)::ceil(x) |
michael@0 | 46 | #else |
michael@0 | 47 | #define sk_float_sqrt(x) sqrtf(x) |
michael@0 | 48 | #define sk_float_sin(x) sinf(x) |
michael@0 | 49 | #define sk_float_cos(x) cosf(x) |
michael@0 | 50 | #define sk_float_tan(x) tanf(x) |
michael@0 | 51 | #define sk_float_floor(x) floorf(x) |
michael@0 | 52 | #define sk_float_ceil(x) ceilf(x) |
michael@0 | 53 | #ifdef SK_BUILD_FOR_MAC |
michael@0 | 54 | #define sk_float_acos(x) static_cast<float>(acos(x)) |
michael@0 | 55 | #define sk_float_asin(x) static_cast<float>(asin(x)) |
michael@0 | 56 | #else |
michael@0 | 57 | #define sk_float_acos(x) acosf(x) |
michael@0 | 58 | #define sk_float_asin(x) asinf(x) |
michael@0 | 59 | #endif |
michael@0 | 60 | #define sk_float_atan2(y,x) atan2f(y,x) |
michael@0 | 61 | #define sk_float_abs(x) fabsf(x) |
michael@0 | 62 | #define sk_float_mod(x,y) fmodf(x,y) |
michael@0 | 63 | #define sk_float_exp(x) expf(x) |
michael@0 | 64 | #define sk_float_log(x) logf(x) |
michael@0 | 65 | #endif |
michael@0 | 66 | |
michael@0 | 67 | #ifdef SK_BUILD_FOR_WIN |
michael@0 | 68 | #define sk_float_isfinite(x) _finite(x) |
michael@0 | 69 | #define sk_float_isnan(x) _isnan(x) |
michael@0 | 70 | static inline int sk_float_isinf(float x) { |
michael@0 | 71 | int32_t bits = SkFloat2Bits(x); |
michael@0 | 72 | return (bits << 1) == (0xFF << 24); |
michael@0 | 73 | } |
michael@0 | 74 | #else |
michael@0 | 75 | #define sk_float_isfinite(x) isfinite(x) |
michael@0 | 76 | #define sk_float_isnan(x) isnan(x) |
michael@0 | 77 | #define sk_float_isinf(x) isinf(x) |
michael@0 | 78 | #endif |
michael@0 | 79 | |
michael@0 | 80 | #define sk_double_isnan(a) sk_float_isnan(a) |
michael@0 | 81 | |
michael@0 | 82 | #ifdef SK_USE_FLOATBITS |
michael@0 | 83 | #define sk_float_floor2int(x) SkFloatToIntFloor(x) |
michael@0 | 84 | #define sk_float_round2int(x) SkFloatToIntRound(x) |
michael@0 | 85 | #define sk_float_ceil2int(x) SkFloatToIntCeil(x) |
michael@0 | 86 | #else |
michael@0 | 87 | #define sk_float_floor2int(x) (int)sk_float_floor(x) |
michael@0 | 88 | #define sk_float_round2int(x) (int)sk_float_floor((x) + 0.5f) |
michael@0 | 89 | #define sk_float_ceil2int(x) (int)sk_float_ceil(x) |
michael@0 | 90 | #endif |
michael@0 | 91 | |
michael@0 | 92 | extern const uint32_t gIEEENotANumber; |
michael@0 | 93 | extern const uint32_t gIEEEInfinity; |
michael@0 | 94 | extern const uint32_t gIEEENegativeInfinity; |
michael@0 | 95 | |
michael@0 | 96 | #define SK_FloatNaN (*SkTCast<const float*>(&gIEEENotANumber)) |
michael@0 | 97 | #define SK_FloatInfinity (*SkTCast<const float*>(&gIEEEInfinity)) |
michael@0 | 98 | #define SK_FloatNegativeInfinity (*SkTCast<const float*>(&gIEEENegativeInfinity)) |
michael@0 | 99 | |
michael@0 | 100 | #if defined(__SSE__) |
michael@0 | 101 | #include <xmmintrin.h> |
michael@0 | 102 | #elif defined(__ARM_NEON__) |
michael@0 | 103 | #include <arm_neon.h> |
michael@0 | 104 | #endif |
michael@0 | 105 | |
michael@0 | 106 | // Fast, approximate inverse square root. |
michael@0 | 107 | // Compare to name-brand "1.0f / sk_float_sqrt(x)". Should be around 10x faster on SSE, 2x on NEON. |
michael@0 | 108 | static inline float sk_float_rsqrt(const float x) { |
michael@0 | 109 | // We want all this inlined, so we'll inline SIMD and just take the hit when we don't know we've got |
michael@0 | 110 | // it at compile time. This is going to be too fast to productively hide behind a function pointer. |
michael@0 | 111 | // |
michael@0 | 112 | // We do one step of Newton's method to refine the estimates in the NEON and null paths. No |
michael@0 | 113 | // refinement is faster, but very innacurate. Two steps is more accurate, but slower than 1/sqrt. |
michael@0 | 114 | #if defined(__SSE__) |
michael@0 | 115 | float result; |
michael@0 | 116 | _mm_store_ss(&result, _mm_rsqrt_ss(_mm_set_ss(x))); |
michael@0 | 117 | return result; |
michael@0 | 118 | #elif defined(__ARM_NEON__) |
michael@0 | 119 | // Get initial estimate. |
michael@0 | 120 | const float32x2_t xx = vdup_n_f32(x); // Clever readers will note we're doing everything 2x. |
michael@0 | 121 | float32x2_t estimate = vrsqrte_f32(xx); |
michael@0 | 122 | |
michael@0 | 123 | // One step of Newton's method to refine. |
michael@0 | 124 | const float32x2_t estimate_sq = vmul_f32(estimate, estimate); |
michael@0 | 125 | estimate = vmul_f32(estimate, vrsqrts_f32(xx, estimate_sq)); |
michael@0 | 126 | return vget_lane_f32(estimate, 0); // 1 will work fine too; the answer's in both places. |
michael@0 | 127 | #else |
michael@0 | 128 | // Get initial estimate. |
michael@0 | 129 | int i = *SkTCast<int*>(&x); |
michael@0 | 130 | i = 0x5f3759df - (i>>1); |
michael@0 | 131 | float estimate = *SkTCast<float*>(&i); |
michael@0 | 132 | |
michael@0 | 133 | // One step of Newton's method to refine. |
michael@0 | 134 | const float estimate_sq = estimate*estimate; |
michael@0 | 135 | estimate *= (1.5f-0.5f*x*estimate_sq); |
michael@0 | 136 | return estimate; |
michael@0 | 137 | #endif |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | #endif |