Skip to content

Commit bcd0d97

Browse files
authored
[libclc] Simplify unary_def_scalarize.inc's use in __clc_erf/erfc/tgamma (#150181)
Also delete unary_def_via_fp32.inc. There are small changes in amdgcn--amdhsa.bc due to vector conversion is scalarized, e.g. %2 = fpext <4 x half> %0 to <4 x float> %3 = extractelement <4 x float> %2, i64 0 %4 = tail call float @llvm.fabs.f32(float %3) -> %2 = extractelement <4 x half> %0, i64 0 %3 = tail call half @llvm.fabs.f16(half %2) %4 = fpext half %3 to float
1 parent f3761ab commit bcd0d97

File tree

4 files changed

+21
-66
lines changed

4 files changed

+21
-66
lines changed

libclc/clc/include/clc/math/unary_def_via_fp32.inc

Lines changed: 0 additions & 11 deletions
This file was deleted.

libclc/clc/lib/generic/math/clc_erf.cl

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <clc/clcmacro.h>
109
#include <clc/internal/clc.h>
1110
#include <clc/math/clc_exp.h>
1211
#include <clc/math/clc_fabs.h>
@@ -211,12 +210,6 @@ _CLC_OVERLOAD _CLC_DEF float __clc_erf(float x) {
211210
return ret;
212211
}
213212

214-
#define __FLOAT_ONLY
215-
#define FUNCTION __clc_erf
216-
#define __CLC_BODY <clc/shared/unary_def_scalarize.inc>
217-
#include <clc/math/gentype.inc>
218-
#undef FUNCTION
219-
220213
#ifdef cl_khr_fp64
221214

222215
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
@@ -500,24 +493,19 @@ _CLC_OVERLOAD _CLC_DEF double __clc_erf(double y) {
500493
return y < 0.0 ? -ret : ret;
501494
}
502495

503-
#define __DOUBLE_ONLY
504-
#define FUNCTION __clc_erf
505-
#define __CLC_BODY <clc/shared/unary_def_scalarize.inc>
506-
#include <clc/math/gentype.inc>
507-
#undef FUNCTION
508-
509496
#endif
510497

511498
#ifdef cl_khr_fp16
512499

513-
#include <clc/clc_convert.h>
514-
515500
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
516501

517502
// Forward the half version of this builtin onto the float one
518-
#define __HALF_ONLY
519-
#define FUNCTION __clc_erf
520-
#define __CLC_BODY <clc/math/unary_def_via_fp32.inc>
521-
#include <clc/math/gentype.inc>
503+
_CLC_OVERLOAD _CLC_DEF half __clc_erf(half x) {
504+
return (half)__clc_erf((float)x);
505+
}
522506

523507
#endif
508+
509+
#define FUNCTION __clc_erf
510+
#define __CLC_BODY <clc/shared/unary_def_scalarize.inc>
511+
#include <clc/math/gentype.inc>

libclc/clc/lib/generic/math/clc_erfc.cl

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <clc/clcmacro.h>
109
#include <clc/internal/clc.h>
1110
#include <clc/math/clc_exp.h>
1211
#include <clc/math/clc_fabs.h>
@@ -211,12 +210,6 @@ _CLC_OVERLOAD _CLC_DEF float __clc_erfc(float x) {
211210
return ret;
212211
}
213212

214-
#define __FLOAT_ONLY
215-
#define FUNCTION __clc_erfc
216-
#define __CLC_BODY <clc/shared/unary_def_scalarize.inc>
217-
#include <clc/math/gentype.inc>
218-
#undef FUNCTION
219-
220213
#ifdef cl_khr_fp64
221214

222215
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
@@ -509,12 +502,6 @@ _CLC_OVERLOAD _CLC_DEF double __clc_erfc(double x) {
509502
return ret;
510503
}
511504

512-
#define __DOUBLE_ONLY
513-
#define FUNCTION __clc_erfc
514-
#define __CLC_BODY <clc/shared/unary_def_scalarize.inc>
515-
#include <clc/math/gentype.inc>
516-
#undef FUNCTION
517-
518505
#endif
519506

520507
#ifdef cl_khr_fp16
@@ -524,9 +511,12 @@ _CLC_OVERLOAD _CLC_DEF double __clc_erfc(double x) {
524511
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
525512

526513
// Forward the half version of this builtin onto the float one
527-
#define __HALF_ONLY
528-
#define FUNCTION __clc_erfc
529-
#define __CLC_BODY <clc/math/unary_def_via_fp32.inc>
530-
#include <clc/math/gentype.inc>
514+
_CLC_OVERLOAD _CLC_DEF half __clc_erfc(half x) {
515+
return (half)__clc_erfc((float)x);
516+
}
531517

532518
#endif
519+
520+
#define FUNCTION __clc_erfc
521+
#define __CLC_BODY <clc/shared/unary_def_scalarize.inc>
522+
#include <clc/math/gentype.inc>

libclc/clc/lib/generic/math/clc_tgamma.cl

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <clc/clcmacro.h>
109
#include <clc/float/definitions.h>
1110
#include <clc/internal/clc.h>
1211
#include <clc/math/clc_exp.h>
@@ -32,12 +31,6 @@ _CLC_OVERLOAD _CLC_DEF float __clc_tgamma(float x) {
3231
return g;
3332
}
3433

35-
#define __FLOAT_ONLY
36-
#define FUNCTION __clc_tgamma
37-
#define __CLC_BODY <clc/shared/unary_def_scalarize.inc>
38-
#include <clc/math/gentype.inc>
39-
#undef FUNCTION
40-
4134
#ifdef cl_khr_fp64
4235

4336
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
@@ -59,24 +52,19 @@ _CLC_OVERLOAD _CLC_DEF double __clc_tgamma(double x) {
5952
return g;
6053
}
6154

62-
#define __DOUBLE_ONLY
63-
#define FUNCTION __clc_tgamma
64-
#define __CLC_BODY <clc/shared/unary_def_scalarize.inc>
65-
#include <clc/math/gentype.inc>
66-
#undef FUNCTION
67-
6855
#endif
6956

7057
#ifdef cl_khr_fp16
7158

72-
#include <clc/clc_convert.h>
73-
7459
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
7560

7661
// Forward the half version of this builtin onto the float one
77-
#define __HALF_ONLY
78-
#define FUNCTION __clc_tgamma
79-
#define __CLC_BODY <clc/math/unary_def_via_fp32.inc>
80-
#include <clc/math/gentype.inc>
62+
_CLC_OVERLOAD _CLC_DEF half __clc_tgamma(half x) {
63+
return (half)__clc_tgamma((float)x);
64+
}
8165

8266
#endif
67+
68+
#define FUNCTION __clc_tgamma
69+
#define __CLC_BODY <clc/shared/unary_def_scalarize.inc>
70+
#include <clc/math/gentype.inc>

0 commit comments

Comments
 (0)