Last night I was working on something and needed strlen, I wrote the following, but I am curious if someone knows of a better way. For example would it be worth unrolling offset 1,2,3? Is there a different op code I can use that would be better?
(func $strlen (param $s i32) (result i32)
(local $head i32)
(set_local $head (get_local $s))
(loop $done $loop
(br_if $done (i32.eq (i32.const 0) (i32.load8_u offset=0 (get_local $head))))
(set_local $head (i32.add (get_local $head) (i32.const 1)))
(return (i32.sub (get_local $head) (get_local $s)))