Skip to content

Commit d8f58bf

Browse files
committed
[WebAssembly] Prototype i16x8.q15mulr_sat_s
This saturating, rounding, Q-format multiplication instruction is proposed in WebAssembly/simd#365. Differential Revision: https://reviews.llvm.org/D88968
1 parent 2dc9b26 commit d8f58bf

File tree

7 files changed

+42
-0
lines changed

7 files changed

+42
-0
lines changed

clang/include/clang/Basic/BuiltinsWebAssembly.def

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ TARGET_BUILTIN(__builtin_wasm_max_u_i32x4, "V4UiV4UiV4Ui", "nc", "simd128")
114114
TARGET_BUILTIN(__builtin_wasm_avgr_u_i8x16, "V16UcV16UcV16Uc", "nc", "simd128")
115115
TARGET_BUILTIN(__builtin_wasm_avgr_u_i16x8, "V8UsV8UsV8Us", "nc", "simd128")
116116

117+
TARGET_BUILTIN(__builtin_wasm_q15mulr_saturate_s_i8x16, "V8sV8sV8s", "nc", "simd128")
118+
117119
TARGET_BUILTIN(__builtin_wasm_bitselect, "V4iV4iV4iV4i", "nc", "simd128")
118120
TARGET_BUILTIN(__builtin_wasm_shuffle_v8x16, "V16ScV16ScV16ScIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIi", "nc", "simd128")
119121

clang/lib/CodeGen/CGBuiltin.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -16545,6 +16545,13 @@ Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
1654516545
ConvertType(E->getType()));
1654616546
return Builder.CreateCall(Callee, {LHS, RHS});
1654716547
}
16548+
case WebAssembly::BI__builtin_wasm_q15mulr_saturate_s_i8x16: {
16549+
Value *LHS = EmitScalarExpr(E->getArg(0));
16550+
Value *RHS = EmitScalarExpr(E->getArg(1));
16551+
Function *Callee =
16552+
CGM.getIntrinsic(Intrinsic::wasm_q15mulr_saturate_signed);
16553+
return Builder.CreateCall(Callee, {LHS, RHS});
16554+
}
1654816555
case WebAssembly::BI__builtin_wasm_bitselect: {
1654916556
Value *V1 = EmitScalarExpr(E->getArg(0));
1655016557
Value *V2 = EmitScalarExpr(E->getArg(1));

clang/test/CodeGen/builtins-wasm.c

+7
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,13 @@ u16x8 avgr_u_i16x8(u16x8 x, u16x8 y) {
462462
// WEBASSEMBLY-NEXT: ret
463463
}
464464

465+
i16x8 q15mulr_saturate_s_i16x8(i16x8 x, i16x8 y) {
466+
return __builtin_wasm_q15mulr_saturate_s_i8x16(x, y);
467+
// WEBASSEMBLY: call <8 x i16> @llvm.wasm.q15mulr.saturate.signed(
468+
// WEBASSEMBLY-SAME: <8 x i16> %x, <8 x i16> %y)
469+
// WEBASSEMBLY-NEXT: ret
470+
}
471+
465472
i32x4 dot_i16x8_s(i16x8 x, i16x8 y) {
466473
return __builtin_wasm_dot_s_i32x4_i16x8(x, y);
467474
// WEBASSEMBLY: call <4 x i32> @llvm.wasm.dot(<8 x i16> %x, <8 x i16> %y)

llvm/include/llvm/IR/IntrinsicsWebAssembly.td

+4
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ def int_wasm_narrow_unsigned :
159159
Intrinsic<[llvm_anyvector_ty],
160160
[llvm_anyvector_ty, LLVMMatchType<1>],
161161
[IntrNoMem, IntrSpeculatable]>;
162+
def int_wasm_q15mulr_saturate_signed :
163+
Intrinsic<[llvm_v8i16_ty],
164+
[llvm_v8i16_ty, llvm_v8i16_ty],
165+
[IntrNoMem, IntrSpeculatable]>;
162166

163167
// TODO: Replace these intrinsics with normal ISel patterns
164168
def int_wasm_pmin :

llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td

+8
Original file line numberDiff line numberDiff line change
@@ -1093,3 +1093,11 @@ multiclass SIMDQFM<ValueType vec_t, string vec, bits<32> simdopA,
10931093

10941094
defm "" : SIMDQFM<v4f32, "f32x4", 180, 212>;
10951095
defm "" : SIMDQFM<v2f64, "f64x2", 254, 255>;
1096+
1097+
//===----------------------------------------------------------------------===//
1098+
// Saturating Rounding Q-Format Multiplication
1099+
//===----------------------------------------------------------------------===//
1100+
1101+
defm Q15MULR_SAT_S :
1102+
SIMDBinary<v8i16, "i16x8", int_wasm_q15mulr_saturate_signed, "q15mulr_sat_s",
1103+
156>;

llvm/test/CodeGen/WebAssembly/simd-intrinsics.ll

+11
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,17 @@ define <8 x i16> @avgr_u_v8i16(<8 x i16> %x, <8 x i16> %y) {
228228
ret <8 x i16> %a
229229
}
230230

231+
; CHECK-LABEL: q15mulr_sat_s_v8i16:
232+
; SIMD128-NEXT: .functype q15mulr_sat_s_v8i16 (v128, v128) -> (v128){{$}}
233+
; SIMD128-NEXT: i16x8.q15mulr_sat_s $push[[R:[0-9]+]]=, $0, $1{{$}}
234+
; SIMD128-NEXT: return $pop[[R]]{{$}}
235+
declare <8 x i16> @llvm.wasm.q15mulr.saturate.signed(<8 x i16>, <8 x i16>)
236+
define <8 x i16> @q15mulr_sat_s_v8i16(<8 x i16> %x, <8 x i16> %y) {
237+
%a = call <8 x i16> @llvm.wasm.q15mulr.saturate.signed(<8 x i16> %x,
238+
<8 x i16> %y)
239+
ret <8 x i16> %a
240+
}
241+
231242
; CHECK-LABEL: any_v8i16:
232243
; SIMD128-NEXT: .functype any_v8i16 (v128) -> (i32){{$}}
233244
; SIMD128-NEXT: i16x8.any_true $push[[R:[0-9]+]]=, $0{{$}}

llvm/test/MC/WebAssembly/simd-encodings.s

+3
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ main:
421421
# CHECK: i16x8.avgr_u # encoding: [0xfd,0x9b,0x01]
422422
i16x8.avgr_u
423423

424+
# CHECK: i16x8.q15mulr_sat_s # encoding: [0xfd,0x9c,0x01]
425+
i16x8.q15mulr_sat_s
426+
424427
# CHECK: i32x4.abs # encoding: [0xfd,0xa0,0x01]
425428
i32x4.abs
426429

0 commit comments

Comments
 (0)