r344205 - [WebAssembly] Saturating float-to-int builtins
Thomas Lively via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 10 17:07:55 PDT 2018
Author: tlively
Date: Wed Oct 10 17:07:55 2018
New Revision: 344205
URL: http://llvm.org/viewvc/llvm-project?rev=344205&view=rev
Log:
[WebAssembly] Saturating float-to-int builtins
Summary: Depends on D53007 and D53004.
Reviewers: aheejin, dschuff
Subscribers: sbc100, jgravelle-google, sunfish, kristina, cfe-commits
Differential Revision: https://reviews.llvm.org/D53009
Modified:
cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGen/builtins-wasm.c
Modified: cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def?rev=344205&r1=344204&r2=344205&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsWebAssembly.def Wed Oct 10 17:07:55 2018
@@ -39,6 +39,16 @@ BUILTIN(__builtin_wasm_atomic_wait_i32,
BUILTIN(__builtin_wasm_atomic_wait_i64, "iLLi*LLiLLi", "n")
BUILTIN(__builtin_wasm_atomic_notify, "Uii*i", "n")
+// Saturating fp-to-int conversions
+BUILTIN(__builtin_wasm_trunc_saturate_s_i32_f32, "if", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_i32_f32, "if", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_s_i32_f64, "id", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_i32_f64, "id", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_s_i64_f32, "LLif", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_i64_f32, "LLif", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_s_i64_f64, "LLid", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_i64_f64, "LLid", "nc")
+
// SIMD builtins
BUILTIN(__builtin_wasm_extract_lane_s_i8x16, "iV16cIi", "nc")
BUILTIN(__builtin_wasm_extract_lane_u_i8x16, "iV16cIi", "nc")
@@ -81,4 +91,9 @@ BUILTIN(__builtin_wasm_abs_f64x2, "V2dV2
BUILTIN(__builtin_wasm_sqrt_f32x4, "V4fV4f", "nc")
BUILTIN(__builtin_wasm_sqrt_f64x2, "V2dV2d", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_s_v4i32_v4f32, "V4iV4f", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_v4i32_v4f32, "V4iV4f", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_s_v2i64_v2f64, "V2LLiV2d", "nc")
+BUILTIN(__builtin_wasm_trunc_saturate_u_v2i64_v2f64, "V2LLiV2d", "nc")
+
#undef BUILTIN
Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=344205&r1=344204&r2=344205&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed Oct 10 17:07:55 2018
@@ -12456,6 +12456,30 @@ Value *CodeGenFunction::EmitWebAssemblyB
Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_atomic_notify);
return Builder.CreateCall(Callee, {Addr, Count});
}
+ case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32_f32:
+ case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i32_f64:
+ case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f32:
+ case WebAssembly::BI__builtin_wasm_trunc_saturate_s_i64_f64:
+ case WebAssembly::BI__builtin_wasm_trunc_saturate_s_v4i32_v4f32:
+ case WebAssembly::BI__builtin_wasm_trunc_saturate_s_v2i64_v2f64: {
+ Value *Src = EmitScalarExpr(E->getArg(0));
+ llvm::Type *ResT = ConvertType(E->getType());
+ Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_trunc_saturate_signed,
+ {ResT, Src->getType()});
+ return Builder.CreateCall(Callee, {Src});
+ }
+ case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32_f32:
+ case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i32_f64:
+ case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f32:
+ case WebAssembly::BI__builtin_wasm_trunc_saturate_u_i64_f64:
+ case WebAssembly::BI__builtin_wasm_trunc_saturate_u_v4i32_v4f32:
+ case WebAssembly::BI__builtin_wasm_trunc_saturate_u_v2i64_v2f64: {
+ Value *Src = EmitScalarExpr(E->getArg(0));
+ llvm::Type *ResT = ConvertType(E->getType());
+ Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_trunc_saturate_unsigned,
+ {ResT, Src->getType()});
+ return Builder.CreateCall(Callee, {Src});
+ }
case WebAssembly::BI__builtin_wasm_extract_lane_s_i8x16:
case WebAssembly::BI__builtin_wasm_extract_lane_u_i8x16:
case WebAssembly::BI__builtin_wasm_extract_lane_s_i16x8:
Modified: cfe/trunk/test/CodeGen/builtins-wasm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-wasm.c?rev=344205&r1=344204&r2=344205&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/builtins-wasm.c (original)
+++ cfe/trunk/test/CodeGen/builtins-wasm.c Wed Oct 10 17:07:55 2018
@@ -83,6 +83,54 @@ unsigned int atomic_notify(int *addr, in
// WEBASSEMBLY64: call i32 @llvm.wasm.atomic.notify(i32* %{{.*}}, i32 %{{.*}})
}
+int trunc_saturate_s_i32_f32(float f) {
+ return __builtin_wasm_trunc_saturate_s_i32_f32(f);
+ // WEBASSEMBLY: call i32 @llvm.wasm.trunc.saturate.signed.i32.f32(float %f)
+ // WEBASSEMBLY-NEXT: ret
+}
+
+int trunc_saturate_u_i32_f32(float f) {
+ return __builtin_wasm_trunc_saturate_u_i32_f32(f);
+ // WEBASSEMBLY: call i32 @llvm.wasm.trunc.saturate.unsigned.i32.f32(float %f)
+ // WEBASSEMBLY-NEXT: ret
+}
+
+int trunc_saturate_s_i32_f64(double f) {
+ return __builtin_wasm_trunc_saturate_s_i32_f64(f);
+ // WEBASSEMBLY: call i32 @llvm.wasm.trunc.saturate.signed.i32.f64(double %f)
+ // WEBASSEMBLY-NEXT: ret
+}
+
+int trunc_saturate_u_i32_f64(double f) {
+ return __builtin_wasm_trunc_saturate_u_i32_f64(f);
+ // WEBASSEMBLY: call i32 @llvm.wasm.trunc.saturate.unsigned.i32.f64(double %f)
+ // WEBASSEMBLY-NEXT: ret
+}
+
+long long trunc_saturate_s_i64_f32(float f) {
+ return __builtin_wasm_trunc_saturate_s_i64_f32(f);
+ // WEBASSEMBLY: call i64 @llvm.wasm.trunc.saturate.signed.i64.f32(float %f)
+ // WEBASSEMBLY-NEXT: ret
+}
+
+long long trunc_saturate_u_i64_f32(float f) {
+ return __builtin_wasm_trunc_saturate_u_i64_f32(f);
+ // WEBASSEMBLY: call i64 @llvm.wasm.trunc.saturate.unsigned.i64.f32(float %f)
+ // WEBASSEMBLY-NEXT: ret
+}
+
+long long trunc_saturate_s_i64_f64(double f) {
+ return __builtin_wasm_trunc_saturate_s_i64_f64(f);
+ // WEBASSEMBLY: call i64 @llvm.wasm.trunc.saturate.signed.i64.f64(double %f)
+ // WEBASSEMBLY-NEXT: ret
+}
+
+long long trunc_saturate_u_i64_f64(double f) {
+ return __builtin_wasm_trunc_saturate_u_i64_f64(f);
+ // WEBASSEMBLY: call i64 @llvm.wasm.trunc.saturate.unsigned.i64.f64(double %f)
+ // WEBASSEMBLY-NEXT: ret
+}
+
int extract_lane_s_i8x16(i8x16 v) {
return __builtin_wasm_extract_lane_s_i8x16(v, 13);
// WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
@@ -300,3 +348,27 @@ f64x2 sqrt_f64x2(f64x2 x) {
// WEBASSEMBLY: call <2 x double> @llvm.sqrt.v2f64(<2 x double> %x)
// WEBASSEMBLY: ret
}
+
+i32x4 trunc_saturate_s_v4i32_v4f32(f32x4 f) {
+ return __builtin_wasm_trunc_saturate_s_v4i32_v4f32(f);
+ // WEBASSEMBLY: call <4 x i32> @llvm.wasm.trunc.saturate.signed.v4i32.v4f32(<4 x float> %f)
+ // WEBASSEMBLY-NEXT: ret
+}
+
+i32x4 trunc_saturate_u_v4i32_v4f32(f32x4 f) {
+ return __builtin_wasm_trunc_saturate_u_v4i32_v4f32(f);
+ // WEBASSEMBLY: call <4 x i32> @llvm.wasm.trunc.saturate.unsigned.v4i32.v4f32(<4 x float> %f)
+ // WEBASSEMBLY-NEXT: ret
+}
+
+i64x2 trunc_saturate_s_v2i64_v2f64(f64x2 f) {
+ return __builtin_wasm_trunc_saturate_s_v2i64_v2f64(f);
+ // WEBASSEMBLY: call <2 x i64> @llvm.wasm.trunc.saturate.signed.v2i64.v2f64(<2 x double> %f)
+ // WEBASSEMBLY-NEXT: ret
+}
+
+i64x2 trunc_saturate_u_v2i64_v2f64(f64x2 f) {
+ return __builtin_wasm_trunc_saturate_u_v2i64_v2f64(f);
+ // WEBASSEMBLY: call <2 x i64> @llvm.wasm.trunc.saturate.unsigned.v2i64.v2f64(<2 x double> %f)
+ // WEBASSEMBLY-NEXT: ret
+}
More information about the cfe-commits
mailing list