Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Generalise i8x16.any_true so as to support vectorised C strlen, strcmp, strstr, et al. #169

Closed
@julian-seward1

Description

@julian-seward1

(w/ apologies in advance if in fact this has already been considered, and I missed it)

It would be nice if the MVP could support basic vectorised operations for C-style strings, in particular strlen and strcmp. The spec already contains one of the key building blocks, i8x16.eq, which makes it possible to find bytes that are "interesting" (string-end zeroes, or non-equal bytes in strcmp).

But it appears to lack the other key operation, which is to find the index of the lowest (or highest, depending on endianness) zero byte lane in a v128. This is necessary at least for strlen.

i8x16.any_true is almost good enough, except it isn't. Because it doesn't produce the actual index, which is necessary to correctly calculate a string length.

Could i8x16.any_true be generalised to, or replaced by, i8x16.highest_true (and also lowest_true if necessary for the opposite endian'd case?) These would produce the index of the lowest or highest zero byte-lane.

At least on Intel, this can be efficiently implemented by using PMOVMSKB followed by an integer-ALU count-leading zeroes operation, or their older equivalents, BSF/BSR. I would be surprised if ARM didn't offer some equivalent mechanism.

Adding the 16-bit-lane equivalents (PMOVMSKW .. does that exist?) would make it possible to handle wchar versions of strlen/strcmp.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions