authorgravatar for paul.verigo@gmail.comPavel Verigo <paul.verigo@gmail.com> 2026-07-06 12:52:19+02:00
committergravatar for paul.verigo@gmail.comPavel Verigo <paul.verigo@gmail.com> 2026-07-06 20:49:09+02:00
logefcaf6a72d19c6105b235e45dc79f70023d84ffc
tree26e239f5a047627b23b6bcf70baba7812f980463
parent73f6d498fc83763054f62677f3a67871d3825136

lib: use @divCeil


20 files changed, 28 insertions(+), 40 deletions(-)

lib/compiler/Maker/WebServer.zig+1-1
......@@ -163,7 +163,7 @@ pub fn updateConfiguration(ws: *WebServer, maker: *Maker) !void {
163163 assert(idx == step_names_trailing.len);
164164 }
165165
166 const step_status_bits = try gpa.alloc(u8, std.math.divCeil(usize, all_steps.len, 4) catch unreachable);
166 const step_status_bits = try gpa.alloc(u8, @divCeil(all_steps.len, 4));
167167 errdefer gpa.free(step_status_bits);
168168 @memset(step_status_bits, 0);
169169
lib/compiler_rt/limb64.zig+1-2
......@@ -3,7 +3,6 @@ const testing = std.testing;
33const assert = std.debug.assert;
44const maxInt = std.math.maxInt;
55const minInt = std.math.minInt;
6const divCeil = std.math.divCeil;
76
87const builtin = @import("builtin");
98const compiler_rt = @import("../compiler_rt.zig");
......@@ -26,7 +25,7 @@ inline fn limbSet(limbs: []u64, i: usize, value: u64) void {
2625}
2726
2827fn usedLimbCount(bits: u16) u16 {
29 return divCeil(u16, bits, 64) catch unreachable;
28 return @divCeil(bits, 64);
3029}
3130
3231fn limbCount(bits: u16) u16 {
lib/compiler_rt/udivmodei4.zig+1-1
......@@ -8,7 +8,7 @@ const shl = std.math.shl;
88const compiler_rt = @import("../compiler_rt.zig");
99const symbol = @import("../compiler_rt.zig").symbol;
1010
11const max_limbs = std.math.divCeil(usize, 65535, 32) catch unreachable; // max supported type is u65535
11const max_limbs = @divCeil(65535, 32); // max supported type is u65535
1212
1313comptime {
1414 symbol(&__udivei4, "__udivei4");
lib/fuzzer.zig+1-1
......@@ -52,7 +52,7 @@ var fuzzer: Fuzzer = undefined;
5252var current_test_name: ?[]const u8 = null;
5353
5454fn bitsetUsizes(elems: usize) usize {
55 return math.divCeil(usize, elems, @bitSizeOf(usize)) catch unreachable;
55 return @divCeil(elems, @bitSizeOf(usize));
5656}
5757
5858const Executable = struct {
lib/std/Random.zig+1-1
......@@ -126,7 +126,7 @@ pub fn enumValueWithIndex(r: Random, comptime EnumType: type, comptime Index: ty
126126pub fn int(r: Random, comptime T: type) T {
127127 const bits = @typeInfo(T).int.bits;
128128 const UnsignedT = @Int(.unsigned, bits);
129 const ceil_bytes = comptime std.math.divCeil(u16, bits, 8) catch unreachable;
129 const ceil_bytes = @divCeil(bits, 8);
130130 const ByteAlignedT = @Int(.unsigned, ceil_bytes * 8);
131131
132132 var rand_bytes: [ceil_bytes]u8 = undefined;
lib/std/Target.zig+1-1
......@@ -1252,7 +1252,7 @@ pub const Cpu = struct {
12521252 ints: [usize_count]usize,
12531253
12541254 pub const needed_bit_count = 347;
1255 pub const byte_count = (needed_bit_count + 7) / 8;
1255 pub const byte_count = @divCeil(needed_bit_count, 8);
12561256 pub const usize_count = (byte_count + (@sizeOf(usize) - 1)) / @sizeOf(usize);
12571257 pub const Index = std.math.Log2Int(@Int(.unsigned, usize_count * @bitSizeOf(usize)));
12581258 pub const ShiftInt = std.math.Log2Int(usize);
lib/std/crypto/aes_gcm.zig+2-2
......@@ -39,7 +39,7 @@ fn AesGcm(comptime Aes: anytype) type {
3939 mem.writeInt(u32, j[nonce_length..][0..4], 1, .big);
4040 aes.encrypt(&t, &j);
4141
42 const block_count = (math.divCeil(usize, ad.len, Ghash.block_length) catch unreachable) + (math.divCeil(usize, c.len, Ghash.block_length) catch unreachable) + 1;
42 const block_count = @divCeil(ad.len, Ghash.block_length) + @divCeil(c.len, Ghash.block_length) + 1;
4343 var mac = Ghash.initForBlockCount(&h, block_count);
4444 mac.update(ad);
4545 mac.pad();
......@@ -81,7 +81,7 @@ fn AesGcm(comptime Aes: anytype) type {
8181 mem.writeInt(u32, j[nonce_length..][0..4], 1, .big);
8282 aes.encrypt(&t, &j);
8383
84 const block_count = (math.divCeil(usize, ad.len, Ghash.block_length) catch unreachable) + (math.divCeil(usize, c.len, Ghash.block_length) catch unreachable) + 1;
84 const block_count = @divCeil(ad.len, Ghash.block_length) + @divCeil(c.len, Ghash.block_length) + 1;
8585 var mac = Ghash.initForBlockCount(&h, block_count);
8686 mac.update(ad);
8787 mac.pad();
lib/std/crypto/ascon.zig+1-1
......@@ -198,7 +198,7 @@ pub fn State(comptime endian: std.builtin.Endian) type {
198198 ///
199199 /// Note: Clears complete words that contain the specified byte range
200200 pub fn clear(self: *Self, from: usize, to: usize) void {
201 @memset(self.st[from / 8 .. (to + 7) / 8], 0);
201 @memset(self.st[from / 8 .. @divCeil(to, 8)], 0);
202202 }
203203
204204 /// Clear the entire state, disabling compiler optimizations.
lib/std/crypto/ff.zig+3-3
......@@ -61,14 +61,14 @@ pub fn Uint(comptime max_bits: comptime_int) type {
6161
6262 return struct {
6363 const Self = @This();
64 const max_limbs_count = math.divCeil(usize, max_bits, t_bits) catch unreachable;
64 const max_limbs_count = @divCeil(max_bits, t_bits);
6565
6666 limbs_buffer: [max_limbs_count]Limb,
6767 /// The number of active limbs.
6868 limbs_len: usize,
6969
7070 /// Number of bytes required to serialize an integer.
71 pub const encoded_bytes = math.divCeil(usize, max_bits, 8) catch unreachable;
71 pub const encoded_bytes = @divCeil(max_bits, 8);
7272
7373 /// Constant slice of active limbs.
7474 fn limbsConst(self: *const Self) []const Limb {
......@@ -847,7 +847,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type {
847847 }
848848 var e_normalized = Fe{ .v = e.v.normalize() };
849849 var buf_: [Fe.encoded_bytes]u8 = undefined;
850 var buf = buf_[0 .. math.divCeil(usize, e_normalized.v.limbs_len * t_bits, 8) catch unreachable];
850 var buf = buf_[0..@divCeil(e_normalized.v.limbs_len * t_bits, 8)];
851851 e_normalized.toBytes(buf, .little) catch unreachable;
852852 const leading = @clz(e_normalized.v.limbsConst()[e_normalized.v.limbs_len - carry_bits]);
853853 buf = buf[0 .. buf.len - leading / 8];
lib/std/crypto/pbkdf2.zig+1-1
......@@ -74,7 +74,7 @@ pub fn pbkdf2(dk: []u8, password: []const u8, salt: []const u8, rounds: u32, com
7474 // block
7575 //
7676
77 const blocks_count = @as(u32, @intCast(std.math.divCeil(usize, dk_len, h_len) catch unreachable));
77 const blocks_count: u32 = @intCast(@divCeil(dk_len, h_len));
7878 var r = dk_len % h_len;
7979 if (r == 0) {
8080 r = h_len;
lib/std/crypto/sha2.zig+1-1
......@@ -474,7 +474,7 @@ fn Sha2x64(comptime iv: Iv64, digest_bits: comptime_int) type {
474474 return struct {
475475 const Self = @This();
476476 pub const block_length = 128;
477 pub const digest_length = std.math.divCeil(comptime_int, digest_bits, 8) catch unreachable;
477 pub const digest_length = @divCeil(digest_bits, 8);
478478 pub const Options = struct {};
479479
480480 s: Iv64,
lib/std/crypto/sha3.zig+2-2
......@@ -58,7 +58,7 @@ pub fn Keccak(comptime f: u11, comptime output_bits: u11, comptime default_delim
5858 st: State,
5959
6060 /// The output length, in bytes.
61 pub const digest_length = std.math.divCeil(comptime_int, output_bits, 8) catch unreachable;
61 pub const digest_length: comptime_int = @divCeil(output_bits, 8);
6262 /// The block length, or rate, in bytes.
6363 pub const block_length = State.rate;
6464 /// The delimiter can be overwritten in the options.
......@@ -464,7 +464,7 @@ pub const NistLengthEncoding = enum {
464464 /// Encode a length according to NIST SP 800-185.
465465 pub fn encode(comptime encoding: NistLengthEncoding, len: usize) Length {
466466 const len_bits = @bitSizeOf(@TypeOf(len)) - @clz(len) + 3;
467 const len_bytes = std.math.divCeil(usize, len_bits, 8) catch unreachable;
467 const len_bytes = @divCeil(len_bits, 8);
468468
469469 var res = Length{ .len = len_bytes + 1 };
470470 if (encoding == .right) {
lib/std/debug.zig+1-1
......@@ -349,7 +349,7 @@ pub fn dumpHexFallible(t: Io.Terminal, bytes: []const u8) !void {
349349 var chunks = mem.window(u8, bytes, 16, 16);
350350 while (chunks.next()) |window| {
351351 // 1. Print the address.
352 const address = (@intFromPtr(bytes.ptr) + 0x10 * (std.math.divCeil(usize, chunks.index orelse bytes.len, 16) catch unreachable)) - 0x10;
352 const address = (@intFromPtr(bytes.ptr) + 0x10 * @divCeil(chunks.index orelse bytes.len, 16) - 0x10);
353353 try t.setColor(.dim);
354354 // We print the address in lowercase and the bytes in uppercase hexadecimal to distinguish them more.
355355 // Also, make sure all lines are aligned by padding the address.
lib/std/enums.zig+1-1
......@@ -1391,7 +1391,7 @@ test "EnumIndexer non-exhaustive" {
13911391 const max_index: comptime_int = std.math.maxInt(RangedType);
13921392 const number_zero_tag_index: usize = switch (@typeInfo(BackingInt).int.signedness) {
13931393 .unsigned => 0,
1394 .signed => std.math.divCeil(comptime_int, max_index, 2) catch unreachable,
1394 .signed => @divCeil(max_index, 2),
13951395 };
13961396
13971397 try testing.expectEqual(E, Indexer.Key);
lib/std/hash/auto_hash.zig+1-1
......@@ -99,7 +99,7 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void {
9999 } else {
100100 // Take only the part containing the key value, the remaining
101101 // bytes are undefined and must not be hashed!
102 const byte_size = comptime std.math.divCeil(comptime_int, @bitSizeOf(Key), 8) catch unreachable;
102 const byte_size = @divCeil(@bitSizeOf(Key), 8);
103103 @call(.always_inline, Hasher.update, .{ hasher, std.mem.asBytes(&key)[0..byte_size] });
104104 }
105105 },
lib/std/math.zig+3-14
......@@ -922,21 +922,10 @@ fn testDivFloor() !void {
922922pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {
923923 @setRuntimeSafety(false);
924924 if (denominator == 0) return error.DivisionByZero;
925 const info = @typeInfo(T);
926 switch (info) {
927 .comptime_float, .float => return @ceil(numerator / denominator),
928 .comptime_int, .int => {
929 if (numerator < 0 and denominator < 0) {
930 if (info == .int and numerator == minInt(T) and denominator == -1)
931 return error.Overflow;
932 return @divFloor(numerator + 1, denominator) + 1;
933 }
934 if (numerator > 0 and denominator > 0)
935 return @divFloor(numerator - 1, denominator) + 1;
936 return @divTrunc(numerator, denominator);
937 },
938 else => @compileError("divCeil unsupported on " ++ @typeName(T)),
925 if (@typeInfo(T) == .int and numerator == minInt(T) and denominator == -1) {
926 return error.Overflow;
939927 }
928 return @divCeil(numerator, denominator);
940929}
941930
942931test divCeil {
lib/std/math/big/int.zig+1-1
......@@ -122,7 +122,7 @@ pub fn calcNonZeroTwosCompLimbCount(bit_count: usize) usize {
122122/// Special cases `bit_count == 0` to return 1. Zero-bit integers can only store the value zero
123123/// and this big integer implementation stores zero using one limb.
124124pub fn calcTwosCompLimbCount(bit_count: usize) usize {
125 return @max(std.math.divCeil(usize, bit_count, @bitSizeOf(Limb)) catch unreachable, 1);
125 return @max(@divCeil(bit_count, @bitSizeOf(Limb)), 1);
126126}
127127
128128/// a + b * c + *carry, sets carry to the overflow bits
lib/std/mem.zig+3-3
......@@ -1937,7 +1937,7 @@ fn readPackedIntLittle(comptime T: type, bytes: []const u8, bit_offset: usize) T
19371937 const bit_count = @as(usize, @bitSizeOf(T));
19381938 const bit_shift = @as(u3, @intCast(bit_offset % 8));
19391939
1940 const load_size = (bit_count + 7) / 8;
1940 const load_size = @divCeil(bit_count, 8);
19411941 const load_tail_bits = @as(u3, @intCast((load_size * 8) - bit_count));
19421942 const LoadInt = @Int(.unsigned, load_size * 8);
19431943
......@@ -1964,9 +1964,9 @@ fn readPackedIntBig(comptime T: type, bytes: []const u8, bit_offset: usize) T {
19641964
19651965 const bit_count = @as(usize, @bitSizeOf(T));
19661966 const bit_shift = @as(u3, @intCast(bit_offset % 8));
1967 const byte_count = (@as(usize, bit_shift) + bit_count + 7) / 8;
1967 const byte_count = @divCeil(@as(usize, bit_shift) + bit_count, 8);
19681968
1969 const load_size = (bit_count + 7) / 8;
1969 const load_size = @divCeil(bit_count, 8);
19701970 const load_tail_bits = @as(u3, @intCast((load_size * 8) - bit_count));
19711971 const LoadInt = @Int(.unsigned, load_size * 8);
19721972
lib/std/zig/AstGen.zig+1-1
......@@ -4896,7 +4896,7 @@ fn structDeclInner(
48964896 const field_default_body_lens = try scratch.addOptionalSlice(scan_result.any_field_values, scan_result.fields_len);
48974897 const field_comptime_bits = try scratch.addOptionalSlice(
48984898 scan_result.any_comptime_fields,
4899 std.math.divCeil(u32, scan_result.fields_len, 32) catch unreachable,
4899 @divCeil(scan_result.fields_len, 32),
49004900 );
49014901 if (field_comptime_bits) |bits| @memset(bits.get(astgen), 0);
49024902
lib/std/zig/Zir.zig+1-1
......@@ -5279,7 +5279,7 @@ pub fn getStructDecl(zir: *const Zir, struct_decl: Inst.Index) UnwrappedStructDe
52795279 break :lens @ptrCast(lens);
52805280 } else null;
52815281 const field_comptime_bits: ?[]const u32 = if (small.any_comptime_fields) bits: {
5282 const bits_len = std.math.divCeil(u32, fields_len, 32) catch unreachable;
5282 const bits_len = @divCeil(fields_len, 32);
52835283 const bits = zir.extra[extra_index..][0..bits_len];
52845284 extra_index += bits_len;
52855285 break :bits bits;