Skip to content

Commit 8aa8019

Browse files
authored
[WebAssembly] Implement all f16x8 relation instructions. (#93751)
All of these instructions can be generated using regular LL instructions. Specified at: https://github.com/WebAssembly/half-precision/blob/29a9b9462c9285d4ccc1a5dc39214ddfd1892658/proposals/half-precision/Overview.md
1 parent ed35a92 commit 8aa8019

File tree

3 files changed

+81
-2
lines changed

3 files changed

+81
-2
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,13 +720,19 @@ def : Pat<(vector_insert (v2f64 V128:$vec), F64:$x, undef),
720720
// Comparisons
721721
//===----------------------------------------------------------------------===//
722722

723-
multiclass SIMDCondition<Vec vec, string name, CondCode cond, bits<32> simdop> {
723+
multiclass SIMDCondition<Vec vec, string name, CondCode cond, bits<32> simdop,
724+
list<Predicate> reqs = []> {
724725
defm _#vec :
725726
SIMD_I<(outs V128:$dst), (ins V128:$lhs, V128:$rhs), (outs), (ins),
726727
[(set (vec.int_vt V128:$dst),
727728
(setcc (vec.vt V128:$lhs), (vec.vt V128:$rhs), cond))],
728729
vec.prefix#"."#name#"\t$dst, $lhs, $rhs",
729-
vec.prefix#"."#name, simdop>;
730+
vec.prefix#"."#name, simdop, reqs>;
731+
}
732+
733+
multiclass HalfPrecisionCondition<Vec vec, string name, CondCode cond,
734+
bits<32> simdop> {
735+
defm "" : SIMDCondition<vec, name, cond, simdop, [HasHalfPrecision]>;
730736
}
731737

732738
multiclass SIMDConditionInt<string name, CondCode cond, bits<32> baseInst> {
@@ -738,6 +744,7 @@ multiclass SIMDConditionInt<string name, CondCode cond, bits<32> baseInst> {
738744
multiclass SIMDConditionFP<string name, CondCode cond, bits<32> baseInst> {
739745
defm "" : SIMDCondition<F32x4, name, cond, baseInst>;
740746
defm "" : SIMDCondition<F64x2, name, cond, !add(baseInst, 6)>;
747+
defm "" : HalfPrecisionCondition<F16x8, name, cond, !add(baseInst, 255)>;
741748
}
742749

743750
// Equality: eq

llvm/test/CodeGen/WebAssembly/half-precision.ll

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,57 @@ define <8 x half> @pmax_intrinsic_v8f16(<8 x half> %a, <8 x half> %b) {
103103
%v = call <8 x half> @llvm.wasm.pmax.v8f16(<8 x half> %a, <8 x half> %b)
104104
ret <8 x half> %v
105105
}
106+
107+
; CHECK-LABEL: compare_oeq_v8f16:
108+
; CHECK-NEXT: .functype compare_oeq_v8f16 (v128, v128) -> (v128){{$}}
109+
; CHECK-NEXT: f16x8.eq $push[[R:[0-9]+]]=, $0, $1{{$}}
110+
; CHECK-NEXT: return $pop[[R]]{{$}}
111+
define <8 x i1> @compare_oeq_v8f16 (<8 x half> %x, <8 x half> %y) {
112+
%res = fcmp oeq <8 x half> %x, %y
113+
ret <8 x i1> %res
114+
}
115+
116+
; CHECK-LABEL: compare_une_v8f16:
117+
; CHECK-NEXT: .functype compare_une_v8f16 (v128, v128) -> (v128){{$}}
118+
; CHECK-NEXT: f16x8.ne $push[[R:[0-9]+]]=, $0, $1{{$}}
119+
; CHECK-NEXT: return $pop[[R]]{{$}}
120+
define <8 x i1> @compare_une_v8f16 (<8 x half> %x, <8 x half> %y) {
121+
%res = fcmp une <8 x half> %x, %y
122+
ret <8 x i1> %res
123+
}
124+
125+
; CHECK-LABEL: compare_olt_v8f16:
126+
; CHECK-NEXT: .functype compare_olt_v8f16 (v128, v128) -> (v128){{$}}
127+
; CHECK-NEXT: f16x8.lt $push[[R:[0-9]+]]=, $0, $1{{$}}
128+
; CHECK-NEXT: return $pop[[R]]{{$}}
129+
define <8 x i1> @compare_olt_v8f16 (<8 x half> %x, <8 x half> %y) {
130+
%res = fcmp olt <8 x half> %x, %y
131+
ret <8 x i1> %res
132+
}
133+
134+
; CHECK-LABEL: compare_ogt_v8f16:
135+
; CHECK-NEXT: .functype compare_ogt_v8f16 (v128, v128) -> (v128){{$}}
136+
; CHECK-NEXT: f16x8.gt $push[[R:[0-9]+]]=, $0, $1{{$}}
137+
; CHECK-NEXT: return $pop[[R]]{{$}}
138+
define <8 x i1> @compare_ogt_v8f16 (<8 x half> %x, <8 x half> %y) {
139+
%res = fcmp ogt <8 x half> %x, %y
140+
ret <8 x i1> %res
141+
}
142+
143+
; CHECK-LABEL: compare_ole_v8f16:
144+
; CHECK-NEXT: .functype compare_ole_v8f16 (v128, v128) -> (v128){{$}}
145+
; CHECK-NEXT: f16x8.le $push[[R:[0-9]+]]=, $0, $1{{$}}
146+
; CHECK-NEXT: return $pop[[R]]{{$}}
147+
define <8 x i1> @compare_ole_v8f16 (<8 x half> %x, <8 x half> %y) {
148+
%res = fcmp ole <8 x half> %x, %y
149+
ret <8 x i1> %res
150+
}
151+
152+
; CHECK-LABEL: compare_oge_v8f16:
153+
; CHECK-NEXT: .functype compare_oge_v8f16 (v128, v128) -> (v128){{$}}
154+
; CHECK-NEXT: f16x8.ge $push[[R:[0-9]+]]=, $0, $1{{$}}
155+
; CHECK-NEXT: return $pop[[R]]{{$}}
156+
define <8 x i1> @compare_oge_v8f16 (<8 x half> %x, <8 x half> %y) {
157+
%res = fcmp oge <8 x half> %x, %y
158+
ret <8 x i1> %res
159+
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,4 +875,22 @@ main:
875875
# CHECK: f16x8.pmax # encoding: [0xfd,0xbb,0x02]
876876
f16x8.pmax
877877

878+
# CHECK: f16x8.eq # encoding: [0xfd,0xc0,0x02]
879+
f16x8.eq
880+
881+
# CHECK: f16x8.ne # encoding: [0xfd,0xc1,0x02]
882+
f16x8.ne
883+
884+
# CHECK: f16x8.lt # encoding: [0xfd,0xc2,0x02]
885+
f16x8.lt
886+
887+
# CHECK: f16x8.gt # encoding: [0xfd,0xc3,0x02]
888+
f16x8.gt
889+
890+
# CHECK: f16x8.le # encoding: [0xfd,0xc4,0x02]
891+
f16x8.le
892+
893+
# CHECK: f16x8.ge # encoding: [0xfd,0xc5,0x02]
894+
f16x8.ge
895+
878896
end_function

0 commit comments

Comments
 (0)