Commit 132d9636 authored by Milad Fa's avatar Milad Fa Committed by V8 LUCI CQ

s390: [wasm][liftoff] Detect NaNs for fuzzing

Port e6961df2

Original Commit Message:

    Instrument floating-point operations to set a flag if the result is NaN.

R=martyn.capewell@arm.com, joransiu@ca.ibm.com, junyan@redhat.com, midawson@redhat.com
BUG=
LOG=N

Change-Id: I6f3fe550bf30f85bbb3fa9437d676896e876fd30
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3137418Reviewed-by: 's avatarJunliang Yan <junyan@redhat.com>
Commit-Queue: Milad Fa <mfarazma@redhat.com>
Cr-Commit-Position: refs/heads/main@{#76645}
parent ecefa2a4
......@@ -4374,20 +4374,35 @@ EVALUATE(VFMAX) {
#undef CASE
template <class S, class D, class Operation>
void VectorFPCompare(Simulator* sim, int dst, int src1, int src2,
void VectorFPCompare(Simulator* sim, int dst, int src1, int src2, int m6,
Operation op) {
static_assert(sizeof(S) == sizeof(D),
"Expect input type size == output type size");
bool some_zero = false;
bool all_zero = true;
FOR_EACH_LANE(i, D) {
S src1_val = sim->get_simd_register_by_lane<S>(src1, i);
S src2_val = sim->get_simd_register_by_lane<S>(src2, i);
D value = op(src1_val, src2_val);
sim->set_simd_register_by_lane<D>(dst, i, value);
if (value) {
all_zero = false;
} else {
some_zero = true;
}
}
// TODO(miladfarca) implement other conditions.
if (m6) {
if (all_zero) {
sim->condition_reg_ = CC_OF;
} else if (some_zero) {
sim->condition_reg_ = 0x04;
}
}
}
#define VECTOR_FP_COMPARE_FOR_TYPE(S, D, op) \
VectorFPCompare<S, D>(this, r1, r2, r3, \
#define VECTOR_FP_COMPARE_FOR_TYPE(S, D, op) \
VectorFPCompare<S, D>(this, r1, r2, r3, m6, \
[](S a, S b) { return (a op b) ? -1 : 0; });
#define VECTOR_FP_COMPARE(op) \
......@@ -4421,7 +4436,6 @@ void VectorFPCompare(Simulator* sim, int dst, int src1, int src2,
EVALUATE(VFCE) {
DCHECK_OPCODE(VFCE);
DECODE_VRR_C_INSTRUCTION(r1, r2, r3, m6, m5, m4);
USE(m6);
VECTOR_FP_COMPARE(==)
return length;
}
......
......@@ -3041,14 +3041,40 @@ void LiftoffAssembler::MaybeOSR() {}
void LiftoffAssembler::emit_set_if_nan(Register dst, DoubleRegister src,
ValueKind kind) {
UNIMPLEMENTED();
Label return_nan, done;
if (kind == kF32) {
cebr(src, src);
bunordered(&return_nan);
} else {
DCHECK_EQ(kind, kF64);
cdbr(src, src);
bunordered(&return_nan);
}
b(&done);
bind(&return_nan);
StoreF32LE(src, MemOperand(dst), r0);
bind(&done);
}
void LiftoffAssembler::emit_s128_set_if_nan(Register dst, LiftoffRegister src,
Register tmp_gp,
LiftoffRegister tmp_s128,
ValueKind lane_kind) {
UNIMPLEMENTED();
Label return_nan, done;
if (lane_kind == kF32) {
vfce(tmp_s128.fp(), src.fp(), src.fp(), Condition(1), Condition(0),
Condition(2));
b(Condition(0x5), &return_nan); // If any or all are NaN.
} else {
DCHECK_EQ(lane_kind, kF64);
vfce(tmp_s128.fp(), src.fp(), src.fp(), Condition(1), Condition(0),
Condition(3));
b(Condition(0x5), &return_nan);
}
b(&done);
bind(&return_nan);
StoreF32LE(src.fp(), MemOperand(dst), r0);
bind(&done);
}
void LiftoffStackSlots::Construct(int param_slots) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment