2021-12-29 21:09:00 +00:00
|
|
|
const std = @import("std");
|
|
|
|
|
2022-10-21 08:12:24 +00:00
|
|
|
pub fn sext(comptime bits: comptime_int, value: u32) u32 {
|
|
|
|
comptime std.debug.assert(bits <= 32);
|
|
|
|
const amount = 32 - bits;
|
2022-10-21 08:11:44 +00:00
|
|
|
|
2022-10-21 08:12:24 +00:00
|
|
|
return @bitCast(u32, @bitCast(i32, value << amount) >> amount);
|
2021-12-29 21:09:00 +00:00
|
|
|
}
|