Skip to content

Commit ea7593b

Browse files
authored
[Fuzzer] Compare V8 variants (#7469)
Relaxed SIMD prevents comparisons between VMs, but v8-liftoff can be compared to v8-turboshaft for example, as it is the same VM in another mode. To do this, replace the `can_compare_to_others` with a function that considers a specific other VM.
1 parent d0d970c commit ea7593b

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

scripts/fuzz_opt.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ def can_run(self, wasm):
807807
def can_compare_to_self(self):
808808
return True
809809

810-
def can_compare_to_others(self):
810+
def can_compare_to_other(self, other):
811811
return True
812812

813813
class D8:
@@ -828,12 +828,15 @@ def can_compare_to_self(self):
828828
# can compare to themselves after opts in that case.
829829
return not NANS
830830

831-
def can_compare_to_others(self):
831+
def can_compare_to_other(self, other):
832+
# Relaxed SIMD allows different behavior between VMs, so only
833+
# allow comparisons to other d8 variants if it is enabled.
834+
if not all_disallowed(['relaxed-simd']) and not other.name.startswith('d8'):
835+
return False
836+
832837
# If not legalized, the JS will fail immediately, so no point to
833-
# compare to others. Relaxed SIMD allows different behavior
834-
# between VMs (in principle we could compare to other D8
835-
# variants, though TODO).
836-
return self.can_compare_to_self() and LEGALIZE and all_disallowed(['relaxed-simd'])
838+
# compare to others.
839+
return self.can_compare_to_self() and LEGALIZE
837840

838841
class D8Liftoff(D8):
839842
name = 'd8_liftoff'
@@ -887,7 +890,7 @@ def can_compare_to_self(self):
887890
# expects, but that's not quite what C has
888891
return not NANS
889892

890-
def can_compare_to_others(self):
893+
def can_compare_to_other(self, other):
891894
# C won't trap on OOB, and NaNs can differ from wasm VMs
892895
return not OOB and not NANS
893896

@@ -934,7 +937,7 @@ def can_run(self, wasm):
934937
return super(Wasm2C2Wasm, self).can_run(wasm) and self.has_emcc and \
935938
os.path.getsize(wasm) <= INPUT_SIZE_MEAN
936939

937-
def can_compare_to_others(self):
940+
def can_compare_to_other(self, other):
938941
# NaNs can differ from wasm VMs
939942
return not NANS
940943

@@ -962,10 +965,12 @@ def run_vms(self, wasm):
962965
ignored_before = ignored_vm_runs
963966

964967
# vm_results will map vms to their results
968+
relevant_vms = []
965969
vm_results = {}
966970
for vm in self.vms:
967971
if vm.can_run(wasm):
968972
print(f'[CompareVMs] running {vm.name}')
973+
relevant_vms.append(vm)
969974
vm_results[vm] = fix_output(vm.run(wasm))
970975

971976
# If the binaryen interpreter hit a host limitation then do not
@@ -986,13 +991,13 @@ def run_vms(self, wasm):
986991
return vm_results
987992

988993
# compare between the vms on this specific input
989-
first_vm = None
990-
for vm in vm_results.keys():
991-
if vm.can_compare_to_others():
992-
if first_vm is None:
993-
first_vm = vm
994-
else:
995-
compare_between_vms(vm_results[first_vm], vm_results[vm], 'CompareVMs between VMs: ' + first_vm.name + ' and ' + vm.name)
994+
num_vms = len(relevant_vms)
995+
for i in range(0, num_vms):
996+
for j in range(i + 1, num_vms):
997+
vm1 = relevant_vms[i]
998+
vm2 = relevant_vms[j]
999+
if vm1.can_compare_to_other(vm2) and vm2.can_compare_to_other(vm1):
1000+
compare_between_vms(vm_results[vm1], vm_results[vm2], 'CompareVMs between VMs: ' + vm1.name + ' and ' + vm2.name)
9961001

9971002
return vm_results
9981003

0 commit comments

Comments
 (0)