brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 3a4310b Raw
51 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#include <clc/internal/clc.h>10#include <clc/math/clc_fma.h>11#include <clc/math/clc_ldexp.h>12 13#ifdef cl_khr_fp6414 15#pragma OPENCL EXTENSION cl_khr_fp64 : enable16 17#ifdef __AMDGCN__18#define __clc_builtin_rsq __builtin_amdgcn_rsq19#else20#define __clc_builtin_rsq __builtin_r600_recipsqrt_ieee21#endif22 23_CLC_OVERLOAD _CLC_DEF double __clc_sqrt(double x) {24  uint vcc = x < 0x1p-767;25  uint exp0 = vcc ? 0x100 : 0;26  unsigned exp1 = vcc ? 0xffffff80 : 0;27 28  double v01 = __clc_ldexp(x, exp0);29  double v23 = __clc_builtin_rsq(v01);30  double v45 = v01 * v23;31  v23 = v23 * 0.5;32 33  double v67 = __clc_fma(-v23, v45, 0.5);34  v45 = __clc_fma(v45, v67, v45);35  double v89 = __clc_fma(-v45, v45, v01);36  v23 = __clc_fma(v23, v67, v23);37  v45 = __clc_fma(v89, v23, v45);38  v67 = __clc_fma(-v45, v45, v01);39  v23 = __clc_fma(v67, v23, v45);40 41  v23 = __clc_ldexp(v23, exp1);42  return (x == __builtin_inf() || (x == 0.0)) ? v01 : v23;43}44 45#define __CLC_DOUBLE_ONLY46#define __CLC_FUNCTION __clc_sqrt47#define __CLC_BODY <clc/shared/unary_def_scalarize.inc>48#include <clc/math/gentype.inc>49 50#endif51