tiny.simd.Phast
Defined in tiny.simd.
API (6)
Actions
Public operations.
Fields and members
Public fields and members.
Source
Source: lib/simd/src/phast/family.zig:94
zig
pub const Phast = struct { data: Data, hash: hash_mod.Triple32, const Self = @This(); pub fn init(data: Data) PhastError!Self { if (data.isEmpty()) return error.BuildFailed; const num_buckets = data.config.numBuckets(); const slice_length = data.config.placement.sliceLength(); if (data.config.num_slots > std.math.maxInt(u32) or num_buckets > std.math.maxInt(u32) or !std.math.isPowerOfTwo(num_buckets) or data.seeds.words.len != data.config.seedWordsLen() or data.config.placement.num_slice_offsets == 0 or !std.math.isPowerOfTwo(slice_length) or slice_length > data.config.num_slots or data.config.placement.num_slice_offsets != data.config.num_slots - slice_length + 1) { return error.InvalidData; } return .{ .data = data, .hash = hash_mod.Triple32.initKey(data.config.hash_key), }; } pub fn index(self: Self, key: u32) u32 { const hash = self.hash.hash(key); const seed = self.data.seeds.get(hash & self.data.config.bucket_mask); return positionFromHashAndSeed(self.data.config.placement, hash, seed); } pub fn twoVec( self: Self, comptime D: type, first_keys: D.Vector, second_keys: D.Vector, ) VectorPair(D) { requireTag(D); var first_hashes = first_keys; var second_hashes = second_keys; self.hash.twoVec(D, &first_hashes, &second_hashes); var first_seeds: D.Vector = undefined; var second_seeds: D.Vector = undefined; inline for (0..D.lane_count) |lane| { first_seeds[lane] = self.data.seeds.get( first_hashes[lane] & self.data.config.bucket_mask, ); second_seeds[lane] = self.data.seeds.get( second_hashes[lane] & self.data.config.bucket_mask, ); } return positionPairFromHashesAndSeeds( self.data.config.placement, D, first_hashes, second_hashes, first_seeds, second_seeds, ); } pub fn indexBatch( self: Self, comptime D: type, keys: []const u32, indices: []u32, ) PhastError!void { requireTag(D); if (indices.len != keys.len) return error.PlanMismatch; var offset: usize = 0; while (offset + 2 * D.lane_count <= keys.len) : (offset += 2 * D.lane_count) { const first: D.Vector = keys[offset..][0..D.lane_count].*; const second: D.Vector = keys[offset + D.lane_count ..][0..D.lane_count].*; const result = self.twoVec(D, first, second); const first_indices: [D.lane_count]u32 = result.first; const second_indices: [D.lane_count]u32 = result.second; @memcpy(indices[offset..][0..D.lane_count], &first_indices); @memcpy(indices[offset + D.lane_count ..][0..D.lane_count], &second_indices); } for (keys[offset..], indices[offset..]) |key, *output| output.* = self.index(key); }};Source: lib/simd/src/root.zig:581
zig
pub const Phast = phast.Phast;Also reachable as
Audit
| Definitions | 5 |
|---|---|
| Public names | 10 |
| Members | 2 |
| Version | 26.7.0 |
| Revision | daab053ee433 |