Skip to content

Commit 7d373ce

Browse files
authored
[WebAssembly] Change half-precision feature name to fp16. (#105434)
This better aligns with how the feature is being referred to and what runtimes (V8) are calling it.
1 parent 27727d8 commit 7d373ce

File tree

17 files changed

+63
-65
lines changed

17 files changed

+63
-65
lines changed

clang/include/clang/Basic/BuiltinsWebAssembly.def

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ TARGET_BUILTIN(__builtin_wasm_min_f64x2, "V2dV2dV2d", "nc", "simd128")
135135
TARGET_BUILTIN(__builtin_wasm_max_f64x2, "V2dV2dV2d", "nc", "simd128")
136136
TARGET_BUILTIN(__builtin_wasm_pmin_f64x2, "V2dV2dV2d", "nc", "simd128")
137137
TARGET_BUILTIN(__builtin_wasm_pmax_f64x2, "V2dV2dV2d", "nc", "simd128")
138-
TARGET_BUILTIN(__builtin_wasm_min_f16x8, "V8hV8hV8h", "nc", "half-precision")
139-
TARGET_BUILTIN(__builtin_wasm_max_f16x8, "V8hV8hV8h", "nc", "half-precision")
140-
TARGET_BUILTIN(__builtin_wasm_pmin_f16x8, "V8hV8hV8h", "nc", "half-precision")
141-
TARGET_BUILTIN(__builtin_wasm_pmax_f16x8, "V8hV8hV8h", "nc", "half-precision")
138+
TARGET_BUILTIN(__builtin_wasm_min_f16x8, "V8hV8hV8h", "nc", "fp16")
139+
TARGET_BUILTIN(__builtin_wasm_max_f16x8, "V8hV8hV8h", "nc", "fp16")
140+
TARGET_BUILTIN(__builtin_wasm_pmin_f16x8, "V8hV8hV8h", "nc", "fp16")
141+
TARGET_BUILTIN(__builtin_wasm_pmax_f16x8, "V8hV8hV8h", "nc", "fp16")
142142

143143
TARGET_BUILTIN(__builtin_wasm_ceil_f32x4, "V4fV4f", "nc", "simd128")
144144
TARGET_BUILTIN(__builtin_wasm_floor_f32x4, "V4fV4f", "nc", "simd128")
@@ -170,8 +170,8 @@ TARGET_BUILTIN(__builtin_wasm_relaxed_madd_f32x4, "V4fV4fV4fV4f", "nc", "relaxed
170170
TARGET_BUILTIN(__builtin_wasm_relaxed_nmadd_f32x4, "V4fV4fV4fV4f", "nc", "relaxed-simd")
171171
TARGET_BUILTIN(__builtin_wasm_relaxed_madd_f64x2, "V2dV2dV2dV2d", "nc", "relaxed-simd")
172172
TARGET_BUILTIN(__builtin_wasm_relaxed_nmadd_f64x2, "V2dV2dV2dV2d", "nc", "relaxed-simd")
173-
TARGET_BUILTIN(__builtin_wasm_relaxed_madd_f16x8, "V8hV8hV8hV8h", "nc", "half-precision")
174-
TARGET_BUILTIN(__builtin_wasm_relaxed_nmadd_f16x8, "V8hV8hV8hV8h", "nc", "half-precision")
173+
TARGET_BUILTIN(__builtin_wasm_relaxed_madd_f16x8, "V8hV8hV8hV8h", "nc", "fp16")
174+
TARGET_BUILTIN(__builtin_wasm_relaxed_nmadd_f16x8, "V8hV8hV8hV8h", "nc", "fp16")
175175

176176
TARGET_BUILTIN(__builtin_wasm_relaxed_laneselect_i8x16, "V16ScV16ScV16ScV16Sc", "nc", "relaxed-simd")
177177
TARGET_BUILTIN(__builtin_wasm_relaxed_laneselect_i16x8, "V8sV8sV8sV8s", "nc", "relaxed-simd")
@@ -197,11 +197,11 @@ TARGET_BUILTIN(__builtin_wasm_relaxed_dot_i8x16_i7x16_add_s_i32x4, "V4iV16ScV16S
197197
TARGET_BUILTIN(__builtin_wasm_relaxed_dot_bf16x8_add_f32_f32x4, "V4fV8UsV8UsV4f", "nc", "relaxed-simd")
198198

199199
// Half-Precision (fp16)
200-
TARGET_BUILTIN(__builtin_wasm_loadf16_f32, "fh*", "nU", "half-precision")
201-
TARGET_BUILTIN(__builtin_wasm_storef16_f32, "vfh*", "n", "half-precision")
202-
TARGET_BUILTIN(__builtin_wasm_splat_f16x8, "V8hf", "nc", "half-precision")
203-
TARGET_BUILTIN(__builtin_wasm_extract_lane_f16x8, "fV8hi", "nc", "half-precision")
204-
TARGET_BUILTIN(__builtin_wasm_replace_lane_f16x8, "V8hV8hif", "nc", "half-precision")
200+
TARGET_BUILTIN(__builtin_wasm_loadf16_f32, "fh*", "nU", "fp16")
201+
TARGET_BUILTIN(__builtin_wasm_storef16_f32, "vfh*", "n", "fp16")
202+
TARGET_BUILTIN(__builtin_wasm_splat_f16x8, "V8hf", "nc", "fp16")
203+
TARGET_BUILTIN(__builtin_wasm_extract_lane_f16x8, "fV8hi", "nc", "fp16")
204+
TARGET_BUILTIN(__builtin_wasm_replace_lane_f16x8, "V8hV8hif", "nc", "fp16")
205205

206206
// Reference Types builtins
207207
// Some builtins are custom type-checked - see 't' as part of the third argument,

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5033,8 +5033,8 @@ def mexception_handing : Flag<["-"], "mexception-handling">, Group<m_wasm_Featur
50335033
def mno_exception_handing : Flag<["-"], "mno-exception-handling">, Group<m_wasm_Features_Group>;
50345034
def mextended_const : Flag<["-"], "mextended-const">, Group<m_wasm_Features_Group>;
50355035
def mno_extended_const : Flag<["-"], "mno-extended-const">, Group<m_wasm_Features_Group>;
5036-
def mhalf_precision : Flag<["-"], "mhalf-precision">, Group<m_wasm_Features_Group>;
5037-
def mno_half_precision : Flag<["-"], "mno-half-precision">, Group<m_wasm_Features_Group>;
5036+
def mfp16 : Flag<["-"], "mfp16">, Group<m_wasm_Features_Group>;
5037+
def mno_fp16 : Flag<["-"], "mno-fp16">, Group<m_wasm_Features_Group>;
50385038
def mmultimemory : Flag<["-"], "mmultimemory">, Group<m_wasm_Features_Group>;
50395039
def mno_multimemory : Flag<["-"], "mno-multimemory">, Group<m_wasm_Features_Group>;
50405040
def mmultivalue : Flag<["-"], "mmultivalue">, Group<m_wasm_Features_Group>;

clang/lib/Basic/Targets/WebAssembly.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
4949
.Case("bulk-memory", HasBulkMemory)
5050
.Case("exception-handling", HasExceptionHandling)
5151
.Case("extended-const", HasExtendedConst)
52-
.Case("half-precision", HasHalfPrecision)
52+
.Case("fp16", HasFP16)
5353
.Case("multimemory", HasMultiMemory)
5454
.Case("multivalue", HasMultivalue)
5555
.Case("mutable-globals", HasMutableGlobals)
@@ -84,8 +84,8 @@ void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts,
8484
Builder.defineMacro("__wasm_extended_const__");
8585
if (HasMultiMemory)
8686
Builder.defineMacro("__wasm_multimemory__");
87-
if (HasHalfPrecision)
88-
Builder.defineMacro("__wasm_half_precision__");
87+
if (HasFP16)
88+
Builder.defineMacro("__wasm_fp16__");
8989
if (HasMultivalue)
9090
Builder.defineMacro("__wasm_multivalue__");
9191
if (HasMutableGlobals)
@@ -162,7 +162,7 @@ bool WebAssemblyTargetInfo::initFeatureMap(
162162
Features["bulk-memory"] = true;
163163
Features["exception-handling"] = true;
164164
Features["extended-const"] = true;
165-
Features["half-precision"] = true;
165+
Features["fp16"] = true;
166166
Features["multimemory"] = true;
167167
Features["nontrapping-fptoint"] = true;
168168
Features["tail-call"] = true;
@@ -212,13 +212,13 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
212212
HasExtendedConst = false;
213213
continue;
214214
}
215-
if (Feature == "+half-precision") {
215+
if (Feature == "+fp16") {
216216
SIMDLevel = std::max(SIMDLevel, SIMD128);
217-
HasHalfPrecision = true;
217+
HasFP16 = true;
218218
continue;
219219
}
220-
if (Feature == "-half-precision") {
221-
HasHalfPrecision = false;
220+
if (Feature == "-fp16") {
221+
HasFP16 = false;
222222
continue;
223223
}
224224
if (Feature == "+multimemory") {

clang/lib/Basic/Targets/WebAssembly.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
5757
bool HasBulkMemory = false;
5858
bool HasExceptionHandling = false;
5959
bool HasExtendedConst = false;
60-
bool HasHalfPrecision = false;
60+
bool HasFP16 = false;
6161
bool HasMultiMemory = false;
6262
bool HasMultivalue = false;
6363
bool HasMutableGlobals = false;
@@ -90,9 +90,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
9090

9191
StringRef getABI() const override;
9292
bool setABI(const std::string &Name) override;
93-
bool useFP16ConversionIntrinsics() const override {
94-
return !HasHalfPrecision;
95-
}
93+
bool useFP16ConversionIntrinsics() const override { return !HasFP16; }
9694

9795
protected:
9896
void getTargetDefines(const LangOptions &Opts,

clang/test/CodeGen/builtins-wasm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %clang_cc1 -triple wasm32-unknown-unknown -target-feature +reference-types -target-feature +simd128 -target-feature +relaxed-simd -target-feature +nontrapping-fptoint -target-feature +exception-handling -target-feature +bulk-memory -target-feature +atomics -target-feature +half-precision -flax-vector-conversions=none -O3 -emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
2-
// RUN: %clang_cc1 -triple wasm64-unknown-unknown -target-feature +reference-types -target-feature +simd128 -target-feature +relaxed-simd -target-feature +nontrapping-fptoint -target-feature +exception-handling -target-feature +bulk-memory -target-feature +atomics -target-feature +half-precision -flax-vector-conversions=none -O3 -emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
1+
// RUN: %clang_cc1 -triple wasm32-unknown-unknown -target-feature +reference-types -target-feature +simd128 -target-feature +relaxed-simd -target-feature +nontrapping-fptoint -target-feature +exception-handling -target-feature +bulk-memory -target-feature +atomics -target-feature +fp16 -flax-vector-conversions=none -O3 -emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY32
2+
// RUN: %clang_cc1 -triple wasm64-unknown-unknown -target-feature +reference-types -target-feature +simd128 -target-feature +relaxed-simd -target-feature +nontrapping-fptoint -target-feature +exception-handling -target-feature +bulk-memory -target-feature +atomics -target-feature +fp16 -flax-vector-conversions=none -O3 -emit-llvm -o - %s | FileCheck %s -check-prefixes WEBASSEMBLY,WEBASSEMBLY64
33
// RUN: not %clang_cc1 -triple wasm64-unknown-unknown -target-feature +reference-types -target-feature +nontrapping-fptoint -target-feature +exception-handling -target-feature +bulk-memory -target-feature +atomics -flax-vector-conversions=none -O3 -emit-llvm -o - %s 2>&1 | FileCheck %s -check-prefixes MISSING-SIMD
44

55
// SIMD convenience types

clang/test/Driver/wasm-features.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
// EXTENDED-CONST: "-target-feature" "+extended-const"
3636
// NO-EXTENDED-CONST: "-target-feature" "-extended-const"
3737

38-
// RUN: %clang --target=wasm32-unknown-unknown -### %s -mhalf-precision 2>&1 | FileCheck %s -check-prefix=HALF-PRECISION
39-
// RUN: %clang --target=wasm32-unknown-unknown -### %s -mno-half-precision 2>&1 | FileCheck %s -check-prefix=NO-HALF-PRECISION
38+
// RUN: %clang --target=wasm32-unknown-unknown -### %s -mfp16 2>&1 | FileCheck %s -check-prefix=HALF-PRECISION
39+
// RUN: %clang --target=wasm32-unknown-unknown -### %s -mno-fp16 2>&1 | FileCheck %s -check-prefix=NO-HALF-PRECISION
4040

41-
// HALF-PRECISION: "-target-feature" "+half-precision"
42-
// NO-HALF-PRECISION: "-target-feature" "-half-precision"
41+
// HALF-PRECISION: "-target-feature" "+fp16"
42+
// NO-HALF-PRECISION: "-target-feature" "-fp16"
4343

4444
// RUN: %clang --target=wasm32-unknown-unknown -### %s -mmultimemory 2>&1 | FileCheck %s -check-prefix=MULTIMEMORY
4545
// RUN: %clang --target=wasm32-unknown-unknown -### %s -mno-multimemory 2>&1 | FileCheck %s -check-prefix=NO-MULTIMEMORY

clang/test/Preprocessor/wasm-target-features.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@
4444
// EXTENDED-CONST: #define __wasm_extended_const__ 1{{$}}
4545

4646
// RUN: %clang -E -dM %s -o - 2>&1 \
47-
// RUN: -target wasm32-unknown-unknown -mhalf-precision \
48-
// RUN: | FileCheck %s -check-prefix=HALF-PRECISION
47+
// RUN: -target wasm32-unknown-unknown -mfp16 \
48+
// RUN: | FileCheck %s -check-prefix=FP16
4949
// RUN: %clang -E -dM %s -o - 2>&1 \
50-
// RUN: -target wasm64-unknown-unknown -mhalf-precision \
51-
// RUN: | FileCheck %s -check-prefix=HALF-PRECISION
50+
// RUN: -target wasm64-unknown-unknown -mfp16 \
51+
// RUN: | FileCheck %s -check-prefix=FP16
5252
//
53-
// HALF-PRECISION: #define __wasm_half_precision__ 1{{$}}
53+
// FP16: #define __wasm_fp16__ 1{{$}}
5454

5555
// RUN: %clang -E -dM %s -o - 2>&1 \
5656
// RUN: -target wasm32-unknown-unknown -mmultimemory \
@@ -144,7 +144,7 @@
144144
// MVP-NOT: #define __wasm_bulk_memory__ 1{{$}}
145145
// MVP-NOT: #define __wasm_exception_handling__ 1{{$}}
146146
// MVP-NOT: #define __wasm_extended_const__ 1{{$}}
147-
// MVP-NOT: #define __wasm_half_precision__ 1{{$}}
147+
// MVP-NOT: #define __wasm_fp16__ 1{{$}}
148148
// MVP-NOT: #define __wasm_multimemory__ 1{{$}}
149149
// MVP-NOT: #define __wasm_multivalue__ 1{{$}}
150150
// MVP-NOT: #define __wasm_mutable_globals__ 1{{$}}
@@ -178,7 +178,7 @@
178178
// GENERIC-NOT: #define __wasm_bulk_memory__ 1{{$}}
179179
// GENERIC-NOT: #define __wasm_exception_handling__ 1{{$}}
180180
// GENERIC-NOT: #define __wasm_extended_const__ 1{{$}}
181-
// GENERIC-NOT: #define __wasm_half_precision__ 1{{$}}
181+
// GENERIC-NOT: #define __wasm__fp16__ 1{{$}}
182182
// GENERIC-NOT: #define __wasm_multimemory__ 1{{$}}
183183
// GENERIC-NOT: #define __wasm_nontrapping_fptoint__ 1{{$}}
184184
// GENERIC-NOT: #define __wasm_relaxed_simd__ 1{{$}}
@@ -196,7 +196,7 @@
196196
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_bulk_memory__ 1{{$}}
197197
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_exception_handling__ 1{{$}}
198198
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_extended_const__ 1{{$}}
199-
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_half_precision__ 1{{$}}
199+
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_fp16__ 1{{$}}
200200
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_multimemory__ 1{{$}}
201201
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_multivalue__ 1{{$}}
202202
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_mutable_globals__ 1{{$}}

llvm/lib/Target/WebAssembly/WebAssembly.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ def FeatureExtendedConst :
3737
SubtargetFeature<"extended-const", "HasExtendedConst", "true",
3838
"Enable extended const expressions">;
3939

40-
def FeatureHalfPrecision :
41-
SubtargetFeature<"half-precision", "HasHalfPrecision", "true",
42-
"Enable half precision instructions">;
40+
def FeatureFP16 :
41+
SubtargetFeature<"fp16", "HasFP16", "true",
42+
"Enable FP16 instructions">;
4343

4444
def FeatureMultiMemory :
4545
SubtargetFeature<"multimemory", "HasMultiMemory", "true",
@@ -117,7 +117,7 @@ def : ProcessorModel<"generic", NoSchedModel,
117117
def : ProcessorModel<"bleeding-edge", NoSchedModel,
118118
[FeatureAtomics, FeatureBulkMemory,
119119
FeatureExceptionHandling, FeatureExtendedConst,
120-
FeatureHalfPrecision, FeatureMultiMemory,
120+
FeatureFP16, FeatureMultiMemory,
121121
FeatureMultivalue, FeatureMutableGlobals,
122122
FeatureNontrappingFPToInt, FeatureRelaxedSIMD,
123123
FeatureReferenceTypes, FeatureSIMD128, FeatureSignExt,

llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
7070
addRegisterClass(MVT::v2i64, &WebAssembly::V128RegClass);
7171
addRegisterClass(MVT::v2f64, &WebAssembly::V128RegClass);
7272
}
73-
if (Subtarget->hasHalfPrecision()) {
73+
if (Subtarget->hasFP16()) {
7474
addRegisterClass(MVT::v8f16, &WebAssembly::V128RegClass);
7575
}
7676
if (Subtarget->hasReferenceTypes()) {
@@ -146,7 +146,7 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
146146
setTruncStoreAction(T, MVT::f16, Expand);
147147
}
148148

149-
if (Subtarget->hasHalfPrecision()) {
149+
if (Subtarget->hasFP16()) {
150150
setOperationAction(ISD::FMINIMUM, MVT::v8f16, Legal);
151151
setOperationAction(ISD::FMAXIMUM, MVT::v8f16, Legal);
152152
}

llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def HasExtendedConst :
3838
Predicate<"Subtarget->hasExtendedConst()">,
3939
AssemblerPredicate<(all_of FeatureExtendedConst), "extended-const">;
4040

41-
def HasHalfPrecision :
42-
Predicate<"Subtarget->hasHalfPrecision()">,
43-
AssemblerPredicate<(all_of FeatureHalfPrecision), "half-precision">;
41+
def HasFP16 :
42+
Predicate<"Subtarget->hasFP16()">,
43+
AssemblerPredicate<(all_of FeatureFP16), "fp16">;
4444

4545
def HasMultiMemory :
4646
Predicate<"Subtarget->hasMultiMemory()">,

0 commit comments

Comments
 (0)