<commit_before>/*
 * Adapted from OpenImageIO library with this license:
 *
 * Copyright 2008-2014 <NAME> and the other authors and contributors.
 * All Rights Reserved.

 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * * Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 * * Neither the name of the software's owners nor the names of its
 *   contributors may be used to endorse or promote products derived from
 *   this software without specific prior written permission.
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * (This is the Modified BSD License)
 *
 * A few bits here are based upon code from NVIDIA that was also released
 * under the same modified BSD license, and marked as:
 *    Copyright 2004 NVIDIA Corporation. All Rights Reserved.
 *
 * Some parts of this file were first open-sourced in Open Shading Language,
 * then later moved here. The original copyright notice was:
 *    Copyright (c) 2009-2014 Sony Pictures Imageworks Inc., et al.
 *
 * Many of the math functions were copied from or inspired by other
 * public domain sources or open source packages with compatible licenses.
 * The individual functions give references were applicable.
 */

#ifndef __UTIL_FAST_MATH__
#define __UTIL_FAST_MATH__

CCL_NAMESPACE_BEGIN

ccl_device_inline float madd(const float a, const float b, const float c)
{
  /* NOTE: In the future we may want to explicitly ask for a fused
   * multiply-add in a specialized version for float.
   *
   * NOTE: GCC/ICC will turn this (for float) into a FMA unless
   * explicitly asked not to, clang seems to leave the code alone.
   */
  return a * b + c;
}

ccl_device_inline float4 madd4(const float4 a, const float4 b, const float4 c)
{
  return a * b + c;
}

/*
 * FAST & APPROXIMATE MATH
 *
 * The functions named "fast_*" provide a set of replacements to libm that
 * are much faster at the expense of some accuracy and robust handling of
 * extreme values. One design goal for these approximation was to avoid
 * branches as much as possible and operate on single precision values only
 * so that SIMD versions should be straightforward ports We also try to
 * implement "safe" semantics (ie: clamp to valid range where possible)
 * natively since wrapping these inline calls in another layer would be
 * wasteful.
 *
 * Some functions are fast_safe_*, which is both a faster approximation as
 * well as clamped input domain to ensure no NaN, Inf, or divide by zero.
 */

/* Round to nearest integer, returning as an int. */
ccl_device_inline int fast_rint(float x)
{
  /* used by sin/cos/tan range reduction. */
#ifdef __KERNEL_SSE4__
  /* Single roundps instruction on SSE4.1+ (for gcc/clang at least). */
  return float_to_int(rintf(x));
#else
  /* emulate rounding by adding/substracting 0.5. */
  return float_to_int(x + copysignf(0.5f, x));
#endif
}

ccl_device float fast_sinf(float x)
{
  /* Very accurate argument reduction from SLEEF,
   * starts failing around x=262000
   *
   * Results on: [-2pi,2pi].
   *
   * Examined 2173837240 values of sin: 0.00662760244 avg ulp diff, 2 max ulp,
   * 1.19209e-07 max error
   */
  int q = fast_rint(x * M_1_PI_F);
  float qf = q;
  x = madd(qf, -0.78515625f * 4, x);
  x = madd(qf, -0.00024187564849853515625f * 4, x);
  x = madd(qf, -3.7747668102383613586e-08f * 4, x);<commit_msg>Cleanup: typos & co in UI messages (and some other places)<commit_after>/*
 * Adapted from OpenImageIO library with this license:
 *
 * Copyright 2008-2014 <NAME> and the other authors and contributors.
 * All Rights Reserved.

 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * * Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 * * Neither the name of the software's owners nor the names of its
 *   contributors may be used to endorse or promote products derived from
 *   this software without specific prior written permission.
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * (This is the Modified BSD License)
 *
 * A few bits here are based upon code from NVIDIA that was also released
 * under the same modified BSD license, and marked as:
 *    Copyright 2004 NVIDIA Corporation. All Rights Reserved.
 *
 * Some parts of this file were first open-sourced in Open Shading Language,
 * then later moved here. The original copyright notice was:
 *    Copyright (c) 2009-2014 Sony Pictures Imageworks Inc., et al.
 *
 * Many of the math functions were copied from or inspired by other
 * public domain sources or open source packages with compatible licenses.
 * The individual functions give references were applicable.
 */

#ifndef __UTIL_FAST_MATH__
#define __UTIL_FAST_MATH__

CCL_NAMESPACE_BEGIN

ccl_device_inline float madd(const float a, const float b, const float c)
{
  /* NOTE: In the future we may want to explicitly ask for a fused
   * multiply-add in a specialized version for float.
   *
   * NOTE: GCC/ICC will turn this (for float) into a FMA unless
   * explicitly asked not to, clang seems to leave the code alone.
   */
  return a * b + c;
}

ccl_device_inline float4 madd4(const float4 a, const float4 b, const float4 c)
{
  return a * b + c;
}

/*
 * FAST & APPROXIMATE MATH
 *
 * The functions named "fast_*" provide a set of replacements to libm that
 * are much faster at the expense of some accuracy and robust handling of
 * extreme values. One design goal for these approximation was to avoid
 * branches as much as possible and operate on single precision values only
 * so that SIMD versions should be straightforward ports We also try to
 * implement "safe" semantics (ie: clamp to valid range where possible)
 * natively since wrapping these inline calls in another layer would be
 * wasteful.
 *
 * Some functions are fast_safe_*, which is both a faster approximation as
 * well as clamped input domain to ensure no NaN, Inf, or divide by zero.
 */

/* Round to nearest integer, returning as an int. */
ccl_device_inline int fast_rint(float x)
{
  /* used by sin/cos/tan range reduction. */
#ifdef __KERNEL_SSE4__
  /* Single roundps instruction on SSE4.1+ (for gcc/clang at least). */
  return float_to_int(rintf(x));
#else
  /* emulate rounding by adding/subtracting 0.5. */
  return float_to_int(x + copysignf(0.5f, x));
#endif
}

ccl_device float fast_sinf(float x)
{
  /* Very accurate argument reduction from SLEEF,
   * starts failing around x=262000
   *
   * Results on: [-2pi,2pi].
   *
   * Examined 2173837240 values of sin: 0.00662760244 avg ulp diff, 2 max ulp,
   * 1.19209e-07 max error
   */
  int q = fast_rint(x * M_1_PI_F);
  float qf = q;
  x = madd(qf, -0.78515625f * 4, x);
  x = madd(qf, -0.00024187564849853515625f * 4, x);
  x = madd(qf, -3.7747668102383613586e-08f * 4, x);
{'fraction_non_alphanumeric': 0.06581598388179986, 'fraction_numerical': 0.02910230579807477, 'mean_word_length': 3.832341806381828, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '326577', 'n_tokens_mistral': 2766, 'n_tokens_neox': 2472, 'n_words': 1228}