From 330db487ac5260da4f8ecbcb35e4fe46ab840140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Sat, 19 Feb 2022 22:12:49 +0200 Subject: [PATCH] add roundUp assertion --- src/padding.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/padding.zig b/src/padding.zig index 66ff91e..df8017c 100644 --- a/src/padding.zig +++ b/src/padding.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const assert = std.debug.assert; // rounds up a u12 to the nearest factor of 4 and returns the difference // (padding) @@ -8,6 +9,7 @@ pub fn roundUpPadding(comptime T: type, comptime nbits: u8, n: T) T { // rounds up a u12 to the nearest factor of 4. pub fn roundUp(comptime T: type, comptime nbits: u8, n: T) T { + comptime assert(nbits < @bitSizeOf(T)); const factor = comptime (1 << nbits) - 1; return ((n + factor) & ~@as(T, factor)); }