Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions zigux/tests/phase1_hweight_bench_replay.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const std = @import("std");
const hweight = @import("hweight");

const iterations_hweight = 100_000;

const HweightReplay = struct {
checksum: u64,
first_counts: [4]u32,
last_count: u32,
};

fn runHweightReplay() HweightReplay {
var checksum: u64 = 0;
var first_counts: [4]u32 = undefined;
var last_count: u32 = 0;
var idx: usize = 0;
while (idx < iterations_hweight) : (idx += 1) {
const value: u32 = @truncate(0xf0f0_a5a5 ^ @as(u32, @intCast(idx)));
const count = hweight.swHweight32(value);
checksum +%= count;
if (idx < first_counts.len) {
first_counts[idx] = count;
}
if (idx + 1 == iterations_hweight) {
last_count = count;
}
}
return .{
.checksum = checksum,
.first_counts = first_counts,
.last_count = last_count,
};
}

test "phase1 hweight bench replay keeps the rolling popcount witness explicit" {
const replay = runHweightReplay();
try std.testing.expectEqual([4]u32{ 16, 15, 17, 16 }, replay.first_counts);
try std.testing.expectEqual(@as(u32, 16), replay.last_count);
try std.testing.expectEqual(@as(u64, 1_648_432), replay.checksum);
}

test "phase1 hweight bench replay matches the parked bench checksum packet" {
var checksum: u64 = 0;
var idx: usize = 0;
while (idx < iterations_hweight) : (idx += 1) {
const value: u32 = @truncate(0xf0f0_a5a5 ^ @as(u32, @intCast(idx)));
checksum +%= hweight.swHweight32(value);
}
try std.testing.expectEqual(@as(u64, 1_648_432), checksum);
}
39 changes: 39 additions & 0 deletions zigux/tests/phase1_hweight_bench_replay_build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const std = @import("std");

pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const root_module = b.createModule(.{
.root_source_file = b.path("phase1_hweight_bench_replay.zig"),
.target = target,
.optimize = optimize,
});
const hweight_module = b.createModule(.{
.root_source_file = b.path("../../tools/lib/hweight.zig"),
.target = target,
.optimize = optimize,
});

root_module.addImport("hweight", hweight_module);

const replay_tests = b.addTest(.{
.name = "phase1-hweight-bench-replay",
.root_module = root_module,
});
const run_replay = b.addRunArtifact(replay_tests);

const replay_step = b.step(
"phase1-hweight-bench-replay",
"Run the focused Phase 1 hweight bench replay from zigux/tests",
);
replay_step.dependOn(&run_replay.step);

const test_step = b.step(
"test",
"Run the focused Phase 1 hweight bench replay from zigux/tests",
);
test_step.dependOn(&run_replay.step);

b.default_step.dependOn(test_step);
}
Loading