Skip to content

Instantly share code, notes, and snippets.

@Validark
Created September 5, 2024 14:09
Show Gist options
  • Save Validark/9da0bacb229901da3a1ef9ce7ddba52d to your computer and use it in GitHub Desktop.
Save Validark/9da0bacb229901da3a1ef9ce7ddba52d to your computer and use it in GitHub Desktop.
interleaved unmovemask arm
const std = @import("std");
fn cmtst(a: anytype, comptime b: @TypeOf(a)) @TypeOf(a) {
return @select(u8, (a & b) != @as(@TypeOf(a), @splat(0)), @as(@TypeOf(a), @splat(0xff)), @as(@TypeOf(a), @splat(0)));
}
fn unmovemask(x: u64) @Vector(64, u8) {
const vec = @as(@Vector(8, u8), @bitCast(x));
const interlaced_vec = std.simd.interlace(.{ vec, vec });
return std.simd.join(
std.simd.join(cmtst(interlaced_vec, @bitCast(@as(@Vector(8, u16), @splat(@as(u16, @bitCast([2]u8{ 1 << 0, 1 << 4 })))))),
cmtst(interlaced_vec, @bitCast(@as(@Vector(8, u16), @splat(@as(u16, @bitCast([2]u8{ 1 << 1, 1 << 5 }))))))),
std.simd.join(cmtst(interlaced_vec, @bitCast(@as(@Vector(8, u16), @splat(@as(u16, @bitCast([2]u8{ 1 << 2, 1 << 6 })))))),
cmtst(interlaced_vec, @bitCast(@as(@Vector(8, u16), @splat(@as(u16, @bitCast([2]u8{ 1 << 3, 1 << 7 })))))))
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment