brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 4ccf2d1 Raw
55 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_CLC_DEF _CLC_OVERLOAD __CLC_GENTYPE __clc_exp_helper(__CLC_GENTYPE x,10                                                      __CLC_GENTYPE x_min,11                                                      __CLC_GENTYPE x_max,12                                                      __CLC_GENTYPE r,13                                                      __CLC_INTN n) {14 15  __CLC_INTN j = n & 0x3f;16  __CLC_INTN m = n >> 6;17 18  // 6 term tail of Taylor expansion of e^r19  __CLC_GENTYPE z2 =20      r * __clc_fma(21              r,22              __clc_fma(r,23                        __clc_fma(r,24                                  __clc_fma(r,25                                            __clc_fma(r, 0x1.6c16c16c16c17p-10,26                                                      0x1.1111111111111p-7),27                                            0x1.5555555555555p-5),28                                  0x1.5555555555555p-3),29                        0x1.0000000000000p-1),30              1.0);31 32  __CLC_GENTYPE tv0 = __CLC_USE_TABLE(two_to_jby64_ep_tbl_head, j);33  __CLC_GENTYPE tv1 = __CLC_USE_TABLE(two_to_jby64_ep_tbl_tail, j);34  z2 = __clc_fma(tv0 + tv1, z2, tv1) + tv0;35 36  __CLC_INTN small_value =37      (m < -1022) || ((m == -1022) && __CLC_CONVERT_INTN(z2 < 1.0));38 39  __CLC_INTN n1 = m >> 2;40  __CLC_INTN n2 = m - n1;41  __CLC_GENTYPE z3 =42      z2 * __CLC_AS_GENTYPE((__CLC_CONVERT_LONGN(n1) + 1023) << 52);43  z3 *= __CLC_AS_GENTYPE((__CLC_CONVERT_LONGN(n2) + 1023) << 52);44 45  z2 = __clc_ldexp(z2, m);46  z2 = __CLC_CONVERT_LONGN(small_value) ? z3 : z2;47 48  z2 = __clc_isnan(x) ? x : z2;49 50  z2 = x > x_max ? __CLC_AS_GENTYPE((__CLC_ULONGN)PINFBITPATT_DP64) : z2;51  z2 = x < x_min ? 0.0 : z2;52 53  return z2;54}55