Skip to content

Instantly share code, notes, and snippets.

View Validark's full-sized avatar
🍳

Niles Salter Validark

🍳
View GitHub Profile
@Validark
Validark / comment.md
Last active June 16, 2026 11:58
PDEP & PEXT information across architectures

PDEP Visualization PEXT Visualization

Here is an overview of which ISA's support these instructions:

  • BESM Soviet mainframes:
    • BESM-6 (Designed in 1965. Produced 1968-1987) => AUX & APX
  • x86-64:
    • BMI2 (Intel Haswell 2013+, AMD Excavator 2015+, Fast on AMD since Zen 3 2020+) => PDEP & PEXT
  • arm64 / aarch64:
@Validark
Validark / cls.zig
Last active April 21, 2026 11:05
`cls` on Arm
export fn cls(x: u64) u64 {
return @clz(((-%(x >> 63) ^ x) << 1) | 1);
}
@Validark
Validark / autocomplete.lua
Created June 27, 2021 17:57
A simple autocomplete proof of concept in Lua which binary searches a sorted array of strings. Also allows for searching for terms with a different word order than the original string (by inserting permutations into array) and permitting alternate spellings/abbreviations by permuting those as well.
-- A cool autocomplete demo
-- @author Validark
-- Strings are stored in a lexigraphically sorted array, which can be binary searched for the first and last element which matches a query
-- Please note the "groupings" functionality is an unvalidated afterthought which may or may not work properly, but overall this code has some nice gems:
-- I was originally thinking that https://github.com/evaera/Cmdr could use this to get O(log n) autocompletes (old algo uses O(n))
-- However, Cmdr is designed in such a way that it creates a new autocomplete function on-demand each time,
-- which means we'd have to sort (or at least verify the sortedness) of the most recent data each time (for changing data at least, like a Player list).
-- Sorting at run-time takes O(n*log n) time, making it hard to compete with the old algorithm where the pre-processing step just gets the data in the right format
@Validark
Validark / aho-corasick.lua
Created July 18, 2021 12:31
A clean implementation of the aho-corasick algorithm taking full advantage of Lua's __index metamethod.
-- We can re-use metatables where possible
local lookupCache = {
__index = function(self, i)
local v = { __index = i }
self[i] = v
return v
end
}
local function use_aho_corasick(automaton, str)
@Validark
Validark / vp2intersectd.zig
Created June 24, 2025 20:44
vp2intersect in zig
const std = @import("std");
const builtin = @import("builtin");
const IntersectResult = extern struct { mask1: @Vector(16, bool), mask2: @Vector(16, bool) };
export fn vp2intersectd(a: @Vector(16, i32), b: @Vector(16, i32)) IntersectResult {
return struct {
extern fn @"llvm.x86.avx512.vp2intersect.d.512"(@Vector(16, i32), @Vector(16, i32)) callconv(.{ .x86_64_vectorcall = .{} }) IntersectResult;
}.@"llvm.x86.avx512.vp2intersect.d.512"(a, b);
}
const std = @import("std");
fn carryless_multiply_x86(a: @Vector(8, u8), b: @Vector(16, u8)) @Vector(8, u8) {
return @as([2]@Vector(8, u8), @bitCast(struct {
extern fn @"llvm.x86.pclmulqdq"(@Vector(2, u64), @Vector(2, u64), i8) @Vector(2, u64);
}.@"llvm.x86.pclmulqdq"(
@bitCast(std.simd.join(a, @as(@Vector(8, u8), undefined))),
@bitCast(b), 0)))[0];
}
curl https://webinstall.dev/ollama
source ~/.config/envman/PATH.env
ollama serve
ollama run deepseek-coder-v2
@Validark
Validark / clmul.zig
Created October 15, 2024 21:46
clmul interlace two bitstrings
const std = @import("std");
const builtin = @import("builtin");
const assert = std.debug.assert;
const has_native_carryless_multiply = switch (builtin.cpu.arch) {
.x86_64 => std.Target.x86.featureSetHas(builtin.cpu.features, .pclmul),
.aarch64 => std.Target.aarch64.featureSetHas(builtin.cpu.features, .aes),
.riscv64 => std.Target.riscv.featureSetHas(builtin.cpu.features, .zbc),
//.sparc64 => std.Target.sparc.featureSetHas(builtin.cpu.features, .vis3),
else => false,
@Validark
Validark / arm_interleaved_compress_lookup.zig
Last active September 6, 2024 07:01
Interleaved Vector compress on arm/aarch64
fn tbl4(
table_part_1: @Vector(16, u8),
table_part_2: @Vector(16, u8),
table_part_3: @Vector(16, u8),
table_part_4: @Vector(16, u8),
indices: @Vector(8, u8)
) @TypeOf(indices) {
return struct {
extern fn @"llvm.aarch64.neon.tbl4"(@TypeOf(table_part_1), @TypeOf(table_part_2), @TypeOf(table_part_3), @TypeOf(table_part_4), @TypeOf(indices)) @TypeOf(indices);
}.@"llvm.aarch64.neon.tbl4"(table_part_1, table_part_2, table_part_3, table_part_4, indices);
@Validark
Validark / interleaved_unmovemask_arm.zig
Created September 5, 2024 14:09
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 });