If I wanted to see, for example, if this cache was stack deferred by the compiler in cases where the items length was less than 8, before the cache is actually used later on
How would I go about building a test case? I tried to make this example but its a little confusing using godbolt
https://godbolt.org/z/WMxhq5rob
const std = @import("std");
pub fn sorted(items: []u8) []u8 {
std.sort.block(u8, items, {}, std.sort.asc(u8));
return items[0..];
}
pub fn main() !void {
// Get current time in milliseconds as runtime value
const timestamp = std.time.milliTimestamp();
// Convert timestamp to 4 bytes
var items: [4]u8 = undefined;
items[0] = @truncate(@as(u64, @bitCast(timestamp)) >> 0);
items[1] = @truncate(@as(u64, @bitCast(timestamp)) >> 8);
items[2] = @truncate(@as(u64, @bitCast(timestamp)) >> 16);
items[3] = @truncate(@as(u64, @bitCast(timestamp)) >> 24);
std.debug.print("Before sorting: ", .{});
for (items) |item| {
std.debug.print("{d} ", .{item});
}
std.debug.print("\n", .{});
std.debug.print("After sorting: ", .{});
for (sorted(items[0..])) |item| {
std.debug.print("{d} ", .{item});
}
std.debug.print("\n", .{});
}
const std = @import("std");
pub fn sorted(items: []u8) []u8 {
std.sort.block(u8, items, {}, std.sort.asc(u8));
return items[0..];
}
pub fn main() !void {
// Get current time in milliseconds as runtime value
const timestamp = std.time.milliTimestamp();
// Convert timestamp to 4 bytes
var items: [4]u8 = undefined;
it...