doNotOptimizeAway

This commit is contained in:
Jacob Sandlund
2025-09-06 14:55:21 -04:00
parent f86a3a9b50
commit c3994347c0
5 changed files with 30 additions and 42 deletions

View File

@@ -126,11 +126,7 @@ fn stepWcwidth(ptr: *anyopaque) Benchmark.Error!void {
const cp_, const consumed = d.next(c);
assert(consumed);
if (cp_) |cp| {
const width = wcwidth(cp);
// Write the width to the buffer to avoid it being compiled
// away
buf[0] = @intCast(width);
std.mem.doNotOptimizeAway(wcwidth(cp));
}
}
}
@@ -156,14 +152,10 @@ fn stepTable(ptr: *anyopaque) Benchmark.Error!void {
if (cp_) |cp| {
// This is the same trick we do in terminal.zig so we
// keep it here.
const width = if (cp <= 0xFF)
std.mem.doNotOptimizeAway(if (cp <= 0xFF)
1
else
table.get(@intCast(cp)).width;
// Write the width to the buffer to avoid it being compiled
// away
buf[0] = @intCast(width);
table.get(@intCast(cp)).width);
}
}
}
@@ -187,11 +179,7 @@ fn stepSimd(ptr: *anyopaque) Benchmark.Error!void {
const cp_, const consumed = d.next(c);
assert(consumed);
if (cp_) |cp| {
const width = simd.codepointWidth(cp);
// Write the width to the buffer to avoid it being compiled
// away
buf[0] = @intCast(width);
std.mem.doNotOptimizeAway(simd.codepointWidth(cp));
}
}
}
@@ -217,16 +205,12 @@ fn stepUucode(ptr: *anyopaque) Benchmark.Error!void {
if (cp_) |cp| {
// This is the same trick we do in terminal.zig so we
// keep it here.
const width = if (cp <= 0xFF)
std.mem.doNotOptimizeAway(if (cp <= 0xFF)
1
else
//uucode.getX(.width, @intCast(cp));
//uucode.getWidth(@intCast(cp));
uucode.getSpecial(@intCast(cp)).width;
// Write the width to the buffer to avoid it being compiled
// away
buf[0] = @intCast(width);
uucode.getSpecial(@intCast(cp)).width);
}
}
}