feature. See also
. The project being documented here (as the example) is the Zig library itself.
Builder.fp128ConstAssumeCapacity
fn fp128ConstAssumeCapacity(self: *Builder, val: f128) Constant
File
Code
fn fp128ConstAssumeCapacity(self: *Builder, val: f128) Constant {
const Adapter = struct {
builder: *const Builder,
pub fn hash(_: @This(), key: f128) u32 {
return @truncate(std.hash.Wyhash.hash(
comptime std.hash.int(@backingInt(Constant.Tag.fp128)),
std.mem.asBytes(&key),
));
}
pub fn eql(ctx: @This(), lhs_key: f128, _: void, rhs_index: usize) bool {
if (ctx.builder.constant_items.items(.tag)[rhs_index] != .fp128) return false;
const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
const rhs_extra = ctx.builder.constantExtraData(Constant.Fp128, rhs_data);
return @as(u128, @bitCast(lhs_key)) == @as(u128, rhs_extra.hi_hi) << 96 |
@as(u128, rhs_extra.hi_lo) << 64 | @as(u128, rhs_extra.lo_hi) << 32 | rhs_extra.lo_lo;
}
};
const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });
if (!gop.found_existing) {
gop.key_ptr.* = {};
gop.value_ptr.* = {};
self.constant_items.appendAssumeCapacity(.{
.tag = .fp128,
.data = self.addConstantExtraAssumeCapacity(Constant.Fp128{
.lo_lo = @truncate(@as(u128, @bitCast(val))),
.lo_hi = @truncate(@as(u128, @bitCast(val)) >> 32),
.hi_lo = @truncate(@as(u128, @bitCast(val)) >> 64),
.hi_hi = @intCast(@as(u128, @bitCast(val)) >> 96),
}),
});
}
return @fromBackingInt(@intCast(gop.index));
}