Checking if a value is comptime-known
Ziggit
Checking if a value is comptime-known
Is there a nicer way of writing this? inline fn isComptimeKnown(value: usize) bool { return @TypeOfT@aspeOf(@as([*]u8, @ptrFromInt(1))[0..value]) != []u8; } I use it to encode a comptime-known value as an immediate in inline assembly (an optimization LLVM intentionally cannot do): pub inline fn write(comptime name: []const u8, value: usize) void { if (isComptimeKnown(value) and value >> 12 == 0) { asm volatile (std.fmt.comptimePrint("csrwi {s}, {d}", .{ name, value })); ...
0 comments
No comments yet.