brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 6da361a Raw
69 lines · plain
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#if __CLC_FPSIZE == 3210 11_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_exp2(__CLC_GENTYPE x) {12  // Reduce x13  const __CLC_GENTYPE ln2HI = 0x1.62e300p-1f;14  const __CLC_GENTYPE ln2LO = 0x1.2fefa2p-17f;15 16  __CLC_GENTYPE t = __clc_rint(x);17  __CLC_INTN p = __CLC_CONVERT_INTN(t);18  __CLC_GENTYPE tt = x - t;19  __CLC_GENTYPE hi = tt * ln2HI;20  __CLC_GENTYPE lo = tt * ln2LO;21 22  // Evaluate poly23  t = hi + lo;24  tt = t * t;25  __CLC_GENTYPE v = __clc_mad(26      tt,27      -__clc_mad(28          tt,29          __clc_mad(tt,30                    __clc_mad(tt,31                              __clc_mad(tt, 0x1.637698p-25f, -0x1.bbd41cp-20f),32                              0x1.1566aap-14f),33                    -0x1.6c16c2p-9f),34          0x1.555556p-3f),35      t);36 37  __CLC_GENTYPE y = 1.0f - (((-lo) - MATH_DIVIDE(t * v, 2.0f - v)) - hi);38 39  // Scale by 2^p40  __CLC_GENTYPE r = __CLC_AS_FLOATN(__CLC_AS_INTN(y) + (p << 23));41 42  const __CLC_GENTYPE ulim = 128.0f;43  const __CLC_GENTYPE llim = -126.0f;44 45  r = x < llim ? 0.0f : r;46  r = x < ulim ? r : __CLC_AS_FLOATN((__CLC_UINTN)0x7f800000);47  return __clc_isnan(x) ? x : r;48}49 50#elif __CLC_FPSIZE == 6451 52_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_exp2(__CLC_GENTYPE x) {53  const __CLC_GENTYPE R_LN2 = 0x1.62e42fefa39efp-1; // ln(2)54  const __CLC_GENTYPE R_1_BY_64 = 1.0 / 64.0;55 56  __CLC_INTN n = __CLC_CONVERT_INTN(x * 64.0);57  __CLC_GENTYPE r = R_LN2 * __clc_fma(-R_1_BY_64, __CLC_CONVERT_GENTYPE(n), x);58 59  return __clc_exp_helper(x, -1074.0, 1024.0, r, n);60}61 62#elif __CLC_FPSIZE == 1663 64_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_exp2(__CLC_GENTYPE x) {65  return __CLC_CONVERT_GENTYPE(__clc_exp2(__CLC_CONVERT_FLOATN(x)));66}67 68#endif69