From b5edd9ad5727201d86a683107c5540e62aa30734 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 11 Feb 2024 06:41:41 +0530 Subject: [PATCH] Dont precalculate mask in loop body No need since we dont shift. Avoids the extra mask instructions for the not found case. --- tools/simdstring/generate.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/simdstring/generate.go b/tools/simdstring/generate.go index d820181e3..b23c3804e 100644 --- a/tools/simdstring/generate.go +++ b/tools/simdstring/generate.go @@ -1368,7 +1368,7 @@ func (s *State) index_func(f *Function, test_bytes func(bytes_to_test, test_ans f.MaskForCountDestructive(test_ans, mask) f.Comment("We need to shift out the possible extra bytes at the start of the string caused by the unaligned read") f.ShiftMaskRightDestructive(mask, extra_bytes) - f.JumpIfNonZero(mask, "byte_found") + f.JumpIfNonZero(mask, "byte_found_in_mask") }() f.Comment("Now loop over aligned blocks") @@ -1383,12 +1383,13 @@ func (s *State) index_func(f *Function, test_bytes func(bytes_to_test, test_ans f.Label("loop_body") f.LoadPointerAligned(pos, bytes_to_test) test_bytes(bytes_to_test, test_ans) - f.MaskForCountDestructive(test_ans, mask) - f.JumpIfNonZero(mask, "byte_found") + f.JumpIfNonZero(test_ans, "byte_found_in_vec") f.JumpTo("loop_start") + f.Label("byte_found_in_vec") + f.MaskForCountDestructive(test_ans, mask) f.Comment("Get the result from", mask, "and return it") - f.Label("byte_found") + f.Label("byte_found_in_mask") f.CountLeadingZeroBytesInMask(mask, mask) f.AddToSelf(mask, pos) f.JumpIfLessThan(mask, limit, "result_in_bounds")