Skip to content

Commit 7662f95

Browse files
authored
[WebAssembly] Add preprocessor define for half-precision (#90528)
This adds the preprocessor define for the half-precision feature and also adds preprocessor tests.
1 parent d235369 commit 7662f95

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

clang/lib/Basic/Targets/WebAssembly.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts,
100100
Builder.defineMacro("__wasm_extended_const__");
101101
if (HasMultiMemory)
102102
Builder.defineMacro("__wasm_multimemory__");
103+
if (HasHalfPrecision)
104+
Builder.defineMacro("__wasm_half_precision__");
103105

104106
Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
105107
Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@
4343
//
4444
// EXTENDED-CONST: #define __wasm_extended_const__ 1{{$}}
4545

46+
// RUN: %clang -E -dM %s -o - 2>&1 \
47+
// RUN: -target wasm32-unknown-unknown -mhalf-precision \
48+
// RUN: | FileCheck %s -check-prefix=HALF-PRECISION
49+
// RUN: %clang -E -dM %s -o - 2>&1 \
50+
// RUN: -target wasm64-unknown-unknown -mhalf-precision \
51+
// RUN: | FileCheck %s -check-prefix=HALF-PRECISION
52+
//
53+
// HALF-PRECISION: #define __wasm_half_precision__ 1{{$}}
54+
4655
// RUN: %clang -E -dM %s -o - 2>&1 \
4756
// RUN: -target wasm32-unknown-unknown -mmultimemory \
4857
// RUN: | FileCheck %s -check-prefix=MULTIMEMORY
@@ -135,6 +144,7 @@
135144
// MVP-NOT: #define __wasm_bulk_memory__ 1{{$}}
136145
// MVP-NOT: #define __wasm_exception_handling__ 1{{$}}
137146
// MVP-NOT: #define __wasm_extended_const__ 1{{$}}
147+
// MVP-NOT: #define __wasm_half_precision__ 1{{$}}
138148
// MVP-NOT: #define __wasm_multimemory__ 1{{$}}
139149
// MVP-NOT: #define __wasm_multivalue__ 1{{$}}
140150
// MVP-NOT: #define __wasm_mutable_globals__ 1{{$}}
@@ -168,6 +178,7 @@
168178
// GENERIC-NOT: #define __wasm_bulk_memory__ 1{{$}}
169179
// GENERIC-NOT: #define __wasm_exception_handling__ 1{{$}}
170180
// GENERIC-NOT: #define __wasm_extended_const__ 1{{$}}
181+
// GENERIC-NOT: #define __wasm_half_precision__ 1{{$}}
171182
// GENERIC-NOT: #define __wasm_multimemory__ 1{{$}}
172183
// GENERIC-NOT: #define __wasm_nontrapping_fptoint__ 1{{$}}
173184
// GENERIC-NOT: #define __wasm_relaxed_simd__ 1{{$}}
@@ -183,6 +194,7 @@
183194
//
184195
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_atomics__ 1{{$}}
185196
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_bulk_memory__ 1{{$}}
197+
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_half_precision__ 1{{$}}
186198
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_multimemory__ 1{{$}}
187199
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_multivalue__ 1{{$}}
188200
// BLEEDING-EDGE-INCLUDE-DAG: #define __wasm_mutable_globals__ 1{{$}}

0 commit comments

Comments
 (0)