From 2e1265f384fc37d9e071be0819389c37c30c3d7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Gr=C3=A9goire?= Date: Mon, 7 Sep 2026 19:43:40 -0400 Subject: [PATCH] ke/ipl: avoid too many @intFromEnum --- src/kern/ipl.zig | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/kern/ipl.zig b/src/kern/ipl.zig index 72e1e10..dd94fc5 100644 --- a/src/kern/ipl.zig +++ b/src/kern/ipl.zig @@ -17,6 +17,10 @@ pub const Ipl = enum(u8) { pub fn get_max_software() Ipl { return .Dispatch; } + + pub fn value(self: Ipl) u8 { + return @intFromEnum(self); + } }; const PerCpu = struct { @@ -52,7 +56,7 @@ pub fn raise(new: Ipl) Ipl { ); } - if (@intFromEnum(new) > @intFromEnum(Ipl.get_max_software())) { + if (new.value() > Ipl.get_max_software().value()) { // Moving between hardware levels is rare. @branchHint(.unlikely); kep.impl.set_hardware_ipl(new); @@ -74,14 +78,14 @@ pub fn lower(new: Ipl) void { ); } - if (@intFromEnum(new) <= @intFromEnum(Ipl.get_max_software()) and - @intFromEnum(old) > @intFromEnum(Ipl.get_max_software())) + if (new.value() <= Ipl.get_max_software().value() and + old.value() > Ipl.get_max_software().value()) { @branchHint(.unlikely); kep.impl.set_hardware_ipl(.Passive); } - if (@intFromEnum(new) < @intFromEnum(Ipl.Dispatch) and + if (new.value() < Ipl.Dispatch.value() and is_softint_pending(.Dispatch)) { // Dispatch DPCs if necessary. @@ -105,18 +109,18 @@ pub fn set_hardware(new: Ipl) Ipl { /// Mark a software interrupt of IPL `ipl` on `cpu` as pending. pub fn set_softint_pending(cpu: u32, ipl: Ipl) void { - std.debug.assert(@intFromEnum(ipl) <= @intFromEnum(Ipl.Dispatch)); + std.debug.assert(ipl.value() <= Ipl.Dispatch.value()); _ = percpu.remote(cpu).pending_softints.bitSet( - @intCast(@intFromEnum(ipl)), + @intCast(ipl.value()), .monotonic, ); } /// Mark a software interrupt of IPL `ipl` on `cpu` as handled. pub fn clear_softint_pending(cpu: u32, ipl: Ipl) void { - std.debug.assert(@intFromEnum(ipl) <= @intFromEnum(Ipl.Dispatch)); + std.debug.assert(ipl.value() <= Ipl.Dispatch.value()); _ = percpu.remote(cpu).pending_softints.bitReset( - @intCast(@intFromEnum(ipl)), + @intCast(ipl.value()), .monotonic, ); } @@ -124,8 +128,8 @@ pub fn clear_softint_pending(cpu: u32, ipl: Ipl) void { /// Check whether a software interrupt of IPL `ipl` /// is pending on the current CPU. pub fn is_softint_pending(ipl: Ipl) bool { - std.debug.assert(@intFromEnum(ipl) <= @intFromEnum(Ipl.Dispatch)); - const shift: u3 = @intCast(@intFromEnum(ipl)); + std.debug.assert(ipl.value() <= Ipl.Dispatch.value()); + const shift: u3 = @intCast(ipl.value()); const bit: u8 = @as(u8, 1) << shift; return percpu.local().pending_softints.load(.monotonic) & bit != 0; }