Skip to content

Allow using bitwise operators on boolean vectors #23259

Closed
@nikneym

Description

@nikneym

@reduce allows doing bitwise operations on boolean vectors, like this:

const a: @Vector(16, u8) = @splat('a');
const b: @Vector(16, u8) = @splat('b');

// false
@reduce(.Or, a == b);

However, following is not allowed:

// Vector full of dots.
const dot: @Vector(16, u8) = @splat('.');
// Vector full of spaces.
const space: @Vector(16, u8) = @splat(' ');
// Chunk we want to do search on.
const chunk: @Vector(16, u8) = "quick brown fox.".*;

// Find the occurrences of either dot or space.
const result = (chunk == dot) | (chunk == space);
error: invalid operands to binary bitwise expression: 'vector' and 'vector'

This works if the boolean vectors are casted to integer vectors with @intFromBool:

const result = @intFromBool(chunk == dot) | @intFromBool(chunk == space);

I believe allowing the earlier would be more convenient.

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