authorgravatar for motiejus@jakstys.ltMotiejus Jakštys <motiejus@jakstys.lt> 2023-06-09 16:02:18-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-17 12:49:13-07:00
logd41111d7ef531f6f55a19c56205d6d2f1134c224
tree14d7b7764a64fa2d4d274c0726a1a587484c4999
parent5baa05664e6dac0f473c8411f6e9d8e0f62555a9

mem: rename align*Generic to mem.align*

Anecdote 1: The generic version is way more popular than the non-generic one in Zig codebase: git grep -w alignForward | wc -l 56 git grep -w alignForwardGeneric | wc -l 149 git grep -w alignBackward | wc -l 6 git grep -w alignBackwardGeneric | wc -l 15 Anecdote 2: In my project (turbonss) that does much arithmetic and alignment I exclusively use the Generic functions. Anecdote 3: we used only the Generic versions in the Macho Man's linker workshop.

39 files changed, 223 insertions(+), 232 deletions(-)

lib/std/Thread.zig+4-4
......@@ -931,18 +931,18 @@ const LinuxThreadImpl = struct {
931931 guard_offset = bytes;
932932
933933 bytes += @max(page_size, config.stack_size);
934 bytes = std.mem.alignForward(bytes, page_size);
934 bytes = std.mem.alignForward(usize, bytes, page_size);
935935 stack_offset = bytes;
936936
937 bytes = std.mem.alignForward(bytes, linux.tls.tls_image.alloc_align);
937 bytes = std.mem.alignForward(usize, bytes, linux.tls.tls_image.alloc_align);
938938 tls_offset = bytes;
939939 bytes += linux.tls.tls_image.alloc_size;
940940
941 bytes = std.mem.alignForward(bytes, @alignOf(Instance));
941 bytes = std.mem.alignForward(usize, bytes, @alignOf(Instance));
942942 instance_offset = bytes;
943943 bytes += @sizeOf(Instance);
944944
945 bytes = std.mem.alignForward(bytes, page_size);
945 bytes = std.mem.alignForward(usize, bytes, page_size);
946946 break :blk bytes;
947947 };
948948
lib/std/dynamic_library.zig+2-2
......@@ -124,7 +124,7 @@ pub const ElfDynLib = struct {
124124 // corresponding to the actual LOAD sections.
125125 const file_bytes = try os.mmap(
126126 null,
127 mem.alignForward(size, mem.page_size),
127 mem.alignForward(usize, size, mem.page_size),
128128 os.PROT.READ,
129129 os.MAP.PRIVATE,
130130 fd,
......@@ -187,7 +187,7 @@ pub const ElfDynLib = struct {
187187 // extra nonsense mapped before/after the VirtAddr,MemSiz
188188 const aligned_addr = (base + ph.p_vaddr) & ~(@as(usize, mem.page_size) - 1);
189189 const extra_bytes = (base + ph.p_vaddr) - aligned_addr;
190 const extended_memsz = mem.alignForward(ph.p_memsz + extra_bytes, mem.page_size);
190 const extended_memsz = mem.alignForward(usize, ph.p_memsz + extra_bytes, mem.page_size);
191191 const ptr = @intToPtr([*]align(mem.page_size) u8, aligned_addr);
192192 const prot = elfToMmapProt(ph.p_flags);
193193 if ((ph.p_flags & elf.PF_W) == 0) {
lib/std/hash_map.zig+6-6
......@@ -1545,13 +1545,13 @@ pub fn HashMapUnmanaged(
15451545 const meta_size = @sizeOf(Header) + new_capacity * @sizeOf(Metadata);
15461546 comptime assert(@alignOf(Metadata) == 1);
15471547
1548 const keys_start = std.mem.alignForward(meta_size, key_align);
1548 const keys_start = std.mem.alignForward(usize, meta_size, key_align);
15491549 const keys_end = keys_start + new_capacity * @sizeOf(K);
15501550
1551 const vals_start = std.mem.alignForward(keys_end, val_align);
1551 const vals_start = std.mem.alignForward(usize, keys_end, val_align);
15521552 const vals_end = vals_start + new_capacity * @sizeOf(V);
15531553
1554 const total_size = std.mem.alignForward(vals_end, max_align);
1554 const total_size = std.mem.alignForward(usize, vals_end, max_align);
15551555
15561556 const slice = try allocator.alignedAlloc(u8, max_align, total_size);
15571557 const ptr = @ptrToInt(slice.ptr);
......@@ -1581,13 +1581,13 @@ pub fn HashMapUnmanaged(
15811581 const meta_size = @sizeOf(Header) + cap * @sizeOf(Metadata);
15821582 comptime assert(@alignOf(Metadata) == 1);
15831583
1584 const keys_start = std.mem.alignForward(meta_size, key_align);
1584 const keys_start = std.mem.alignForward(usize, meta_size, key_align);
15851585 const keys_end = keys_start + cap * @sizeOf(K);
15861586
1587 const vals_start = std.mem.alignForward(keys_end, val_align);
1587 const vals_start = std.mem.alignForward(usize, keys_end, val_align);
15881588 const vals_end = vals_start + cap * @sizeOf(V);
15891589
1590 const total_size = std.mem.alignForward(vals_end, max_align);
1590 const total_size = std.mem.alignForward(usize, vals_end, max_align);
15911591
15921592 const slice = @intToPtr([*]align(max_align) u8, @ptrToInt(self.header()))[0..total_size];
15931593 allocator.free(slice);
lib/std/heap.zig+4-4
......@@ -83,7 +83,7 @@ const CAllocator = struct {
8383 // the aligned address.
8484 var unaligned_ptr = @ptrCast([*]u8, c.malloc(len + alignment - 1 + @sizeOf(usize)) orelse return null);
8585 const unaligned_addr = @ptrToInt(unaligned_ptr);
86 const aligned_addr = mem.alignForward(unaligned_addr + @sizeOf(usize), alignment);
86 const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), alignment);
8787 var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr);
8888 getHeader(aligned_ptr).* = unaligned_ptr;
8989
......@@ -249,7 +249,7 @@ pub const wasm_allocator = Allocator{
249249/// Verifies that the adjusted length will still map to the full length
250250pub fn alignPageAllocLen(full_len: usize, len: usize) usize {
251251 const aligned_len = mem.alignAllocLen(full_len, len);
252 assert(mem.alignForward(aligned_len, mem.page_size) == full_len);
252 assert(mem.alignForward(usize, aligned_len, mem.page_size) == full_len);
253253 return aligned_len;
254254}
255255
......@@ -307,7 +307,7 @@ pub const HeapAllocator = switch (builtin.os.tag) {
307307 };
308308 const ptr = os.windows.kernel32.HeapAlloc(heap_handle, 0, amt) orelse return null;
309309 const root_addr = @ptrToInt(ptr);
310 const aligned_addr = mem.alignForward(root_addr, ptr_align);
310 const aligned_addr = mem.alignForward(usize, root_addr, ptr_align);
311311 const buf = @intToPtr([*]u8, aligned_addr)[0..n];
312312 getRecordPtr(buf).* = root_addr;
313313 return buf.ptr;
......@@ -840,7 +840,7 @@ pub fn testAllocatorAlignedShrink(base_allocator: mem.Allocator) !void {
840840 // which is 16 pages, hence the 32. This test may require to increase
841841 // the size of the allocations feeding the `allocator` parameter if they
842842 // fail, because of this high over-alignment we want to have.
843 while (@ptrToInt(slice.ptr) == mem.alignForward(@ptrToInt(slice.ptr), mem.page_size * 32)) {
843 while (@ptrToInt(slice.ptr) == mem.alignForward(usize, @ptrToInt(slice.ptr), mem.page_size * 32)) {
844844 try stuff_to_free.append(slice);
845845 slice = try allocator.alignedAlloc(u8, 16, alloc_size);
846846 }
lib/std/heap/PageAllocator.zig+6-6
......@@ -17,7 +17,7 @@ fn alloc(_: *anyopaque, n: usize, log2_align: u8, ra: usize) ?[*]u8 {
1717 _ = log2_align;
1818 assert(n > 0);
1919 if (n > maxInt(usize) - (mem.page_size - 1)) return null;
20 const aligned_len = mem.alignForward(n, mem.page_size);
20 const aligned_len = mem.alignForward(usize, n, mem.page_size);
2121
2222 if (builtin.os.tag == .windows) {
2323 const w = os.windows;
......@@ -54,14 +54,14 @@ fn resize(
5454) bool {
5555 _ = log2_buf_align;
5656 _ = return_address;
57 const new_size_aligned = mem.alignForward(new_size, mem.page_size);
57 const new_size_aligned = mem.alignForward(usize, new_size, mem.page_size);
5858
5959 if (builtin.os.tag == .windows) {
6060 const w = os.windows;
6161 if (new_size <= buf_unaligned.len) {
6262 const base_addr = @ptrToInt(buf_unaligned.ptr);
6363 const old_addr_end = base_addr + buf_unaligned.len;
64 const new_addr_end = mem.alignForward(base_addr + new_size, mem.page_size);
64 const new_addr_end = mem.alignForward(usize, base_addr + new_size, mem.page_size);
6565 if (old_addr_end > new_addr_end) {
6666 // For shrinking that is not releasing, we will only
6767 // decommit the pages not needed anymore.
......@@ -73,14 +73,14 @@ fn resize(
7373 }
7474 return true;
7575 }
76 const old_size_aligned = mem.alignForward(buf_unaligned.len, mem.page_size);
76 const old_size_aligned = mem.alignForward(usize, buf_unaligned.len, mem.page_size);
7777 if (new_size_aligned <= old_size_aligned) {
7878 return true;
7979 }
8080 return false;
8181 }
8282
83 const buf_aligned_len = mem.alignForward(buf_unaligned.len, mem.page_size);
83 const buf_aligned_len = mem.alignForward(usize, buf_unaligned.len, mem.page_size);
8484 if (new_size_aligned == buf_aligned_len)
8585 return true;
8686
......@@ -103,7 +103,7 @@ fn free(_: *anyopaque, slice: []u8, log2_buf_align: u8, return_address: usize) v
103103 if (builtin.os.tag == .windows) {
104104 os.windows.VirtualFree(slice.ptr, 0, os.windows.MEM_RELEASE);
105105 } else {
106 const buf_aligned_len = mem.alignForward(slice.len, mem.page_size);
106 const buf_aligned_len = mem.alignForward(usize, slice.len, mem.page_size);
107107 const ptr = @alignCast(mem.page_size, slice.ptr);
108108 os.munmap(ptr[0..buf_aligned_len]);
109109 }
lib/std/heap/WasmPageAllocator.zig+3-3
......@@ -100,7 +100,7 @@ fn extendedOffset() usize {
100100}
101101
102102fn nPages(memsize: usize) usize {
103 return mem.alignForward(memsize, mem.page_size) / mem.page_size;
103 return mem.alignForward(usize, memsize, mem.page_size) / mem.page_size;
104104}
105105
106106fn alloc(ctx: *anyopaque, len: usize, log2_align: u8, ra: usize) ?[*]u8 {
......@@ -170,7 +170,7 @@ fn resize(
170170 _ = ctx;
171171 _ = log2_buf_align;
172172 _ = return_address;
173 const aligned_len = mem.alignForward(buf.len, mem.page_size);
173 const aligned_len = mem.alignForward(usize, buf.len, mem.page_size);
174174 if (new_len > aligned_len) return false;
175175 const current_n = nPages(aligned_len);
176176 const new_n = nPages(new_len);
......@@ -190,7 +190,7 @@ fn free(
190190 _ = ctx;
191191 _ = log2_buf_align;
192192 _ = return_address;
193 const aligned_len = mem.alignForward(buf.len, mem.page_size);
193 const aligned_len = mem.alignForward(usize, buf.len, mem.page_size);
194194 const current_n = nPages(aligned_len);
195195 const base = nPages(@ptrToInt(buf.ptr));
196196 freePages(base, base + current_n);
lib/std/heap/arena_allocator.zig+1-1
......@@ -186,7 +186,7 @@ pub const ArenaAllocator = struct {
186186 const cur_alloc_buf = @ptrCast([*]u8, cur_node)[0..cur_node.data];
187187 const cur_buf = cur_alloc_buf[@sizeOf(BufNode)..];
188188 const addr = @ptrToInt(cur_buf.ptr) + self.state.end_index;
189 const adjusted_addr = mem.alignForward(addr, ptr_align);
189 const adjusted_addr = mem.alignForward(usize, addr, ptr_align);
190190 const adjusted_index = self.state.end_index + (adjusted_addr - addr);
191191 const new_end_index = adjusted_index + n;
192192
lib/std/heap/general_purpose_allocator.zig+1
......@@ -309,6 +309,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
309309
310310 fn bucketStackFramesStart(size_class: usize) usize {
311311 return mem.alignForward(
312 usize,
312313 @sizeOf(BucketHeader) + usedBitsCount(size_class),
313314 @alignOf(usize),
314315 );
lib/std/mem.zig+23-33
......@@ -4213,23 +4213,17 @@ test "sliceAsBytes preserves pointer attributes" {
42134213/// Round an address up to the next (or current) aligned address.
42144214/// The alignment must be a power of 2 and greater than 0.
42154215/// Asserts that rounding up the address does not cause integer overflow.
4216pub fn alignForward(addr: usize, alignment: usize) usize {
4217 return alignForwardGeneric(usize, addr, alignment);
4216pub fn alignForward(comptime T: type, addr: T, alignment: T) T {
4217 assert(isValidAlignGeneric(T, alignment));
4218 return alignBackward(T, addr + (alignment - 1), alignment);
42184219}
42194220
42204221pub fn alignForwardLog2(addr: usize, log2_alignment: u8) usize {
42214222 const alignment = @as(usize, 1) << @intCast(math.Log2Int(usize), log2_alignment);
4222 return alignForward(addr, alignment);
4223 return alignForward(usize, addr, alignment);
42234224}
42244225
4225/// Round an address up to the next (or current) aligned address.
4226/// The alignment must be a power of 2 and greater than 0.
4227/// Asserts that rounding up the address does not cause integer overflow.
4228pub fn alignForwardGeneric(comptime T: type, addr: T, alignment: T) T {
4229 assert(alignment > 0);
4230 assert(std.math.isPowerOfTwo(alignment));
4231 return alignBackwardGeneric(T, addr + (alignment - 1), alignment);
4232}
4226pub const alignForwardGeneric = @compileError("renamed to alignForward");
42334227
42344228/// Force an evaluation of the expression; this tries to prevent
42354229/// the compiler from optimizing the computation away even if the
......@@ -4322,38 +4316,32 @@ test "doNotOptimizeAway" {
43224316}
43234317
43244318test "alignForward" {
4325 try testing.expect(alignForward(1, 1) == 1);
4326 try testing.expect(alignForward(2, 1) == 2);
4327 try testing.expect(alignForward(1, 2) == 2);
4328 try testing.expect(alignForward(2, 2) == 2);
4329 try testing.expect(alignForward(3, 2) == 4);
4330 try testing.expect(alignForward(4, 2) == 4);
4331 try testing.expect(alignForward(7, 8) == 8);
4332 try testing.expect(alignForward(8, 8) == 8);
4333 try testing.expect(alignForward(9, 8) == 16);
4334 try testing.expect(alignForward(15, 8) == 16);
4335 try testing.expect(alignForward(16, 8) == 16);
4336 try testing.expect(alignForward(17, 8) == 24);
4319 try testing.expect(alignForward(usize, 1, 1) == 1);
4320 try testing.expect(alignForward(usize, 2, 1) == 2);
4321 try testing.expect(alignForward(usize, 1, 2) == 2);
4322 try testing.expect(alignForward(usize, 2, 2) == 2);
4323 try testing.expect(alignForward(usize, 3, 2) == 4);
4324 try testing.expect(alignForward(usize, 4, 2) == 4);
4325 try testing.expect(alignForward(usize, 7, 8) == 8);
4326 try testing.expect(alignForward(usize, 8, 8) == 8);
4327 try testing.expect(alignForward(usize, 9, 8) == 16);
4328 try testing.expect(alignForward(usize, 15, 8) == 16);
4329 try testing.expect(alignForward(usize, 16, 8) == 16);
4330 try testing.expect(alignForward(usize, 17, 8) == 24);
43374331}
43384332
43394333/// Round an address down to the previous (or current) aligned address.
43404334/// Unlike `alignBackward`, `alignment` can be any positive number, not just a power of 2.
43414335pub fn alignBackwardAnyAlign(i: usize, alignment: usize) usize {
43424336 if (isValidAlign(alignment))
4343 return alignBackward(i, alignment);
4337 return alignBackward(usize, i, alignment);
43444338 assert(alignment != 0);
43454339 return i - @mod(i, alignment);
43464340}
43474341
43484342/// Round an address down to the previous (or current) aligned address.
43494343/// The alignment must be a power of 2 and greater than 0.
4350pub fn alignBackward(addr: usize, alignment: usize) usize {
4351 return alignBackwardGeneric(usize, addr, alignment);
4352}
4353
4354/// Round an address down to the previous (or current) aligned address.
4355/// The alignment must be a power of 2 and greater than 0.
4356pub fn alignBackwardGeneric(comptime T: type, addr: T, alignment: T) T {
4344pub fn alignBackward(comptime T: type, addr: T, alignment: T) T {
43574345 assert(isValidAlignGeneric(T, alignment));
43584346 // 000010000 // example alignment
43594347 // 000001111 // subtract 1
......@@ -4361,6 +4349,8 @@ pub fn alignBackwardGeneric(comptime T: type, addr: T, alignment: T) T {
43614349 return addr & ~(alignment - 1);
43624350}
43634351
4352pub const alignBackwardGeneric = @compileError("renamed to alignBackward");
4353
43644354/// Returns whether `alignment` is a valid alignment, meaning it is
43654355/// a positive power of 2.
43664356pub fn isValidAlign(alignment: usize) bool {
......@@ -4391,7 +4381,7 @@ pub fn isAligned(addr: usize, alignment: usize) bool {
43914381}
43924382
43934383pub fn isAlignedGeneric(comptime T: type, addr: T, alignment: T) bool {
4394 return alignBackwardGeneric(T, addr, alignment) == addr;
4384 return alignBackward(T, addr, alignment) == addr;
43954385}
43964386
43974387test "isAligned" {
......@@ -4439,7 +4429,7 @@ pub fn alignInBytes(bytes: []u8, comptime new_alignment: usize) ?[]align(new_ali
44394429 const begin_address = @ptrToInt(bytes.ptr);
44404430 const end_address = begin_address + bytes.len;
44414431
4442 const begin_address_aligned = mem.alignForward(begin_address, new_alignment);
4432 const begin_address_aligned = mem.alignForward(usize, begin_address, new_alignment);
44434433 const new_length = std.math.sub(usize, end_address, begin_address_aligned) catch |e| switch (e) {
44444434 error.Overflow => return null,
44454435 };
lib/std/mem/Allocator.zig+2-2
......@@ -208,7 +208,7 @@ pub fn allocAdvancedWithRetAddr(
208208 comptime assert(a <= mem.page_size);
209209
210210 if (n == 0) {
211 const ptr = comptime std.mem.alignBackward(math.maxInt(usize), a);
211 const ptr = comptime std.mem.alignBackward(usize, math.maxInt(usize), a);
212212 return @intToPtr([*]align(a) T, ptr)[0..0];
213213 }
214214
......@@ -267,7 +267,7 @@ pub fn reallocAdvanced(
267267 }
268268 if (new_n == 0) {
269269 self.free(old_mem);
270 const ptr = comptime std.mem.alignBackward(math.maxInt(usize), Slice.alignment);
270 const ptr = comptime std.mem.alignBackward(usize, math.maxInt(usize), Slice.alignment);
271271 return @intToPtr([*]align(Slice.alignment) T, ptr)[0..0];
272272 }
273273
lib/std/meta/trailer_flags.zig+3-3
......@@ -105,9 +105,9 @@ pub fn TrailerFlags(comptime Fields: type) type {
105105 const active = (self.bits & (1 << i)) != 0;
106106 if (i == @enumToInt(field)) {
107107 assert(active);
108 return mem.alignForwardGeneric(usize, off, @alignOf(field_info.type));
108 return mem.alignForward(usize, off, @alignOf(field_info.type));
109109 } else if (active) {
110 off = mem.alignForwardGeneric(usize, off, @alignOf(field_info.type));
110 off = mem.alignForward(usize, off, @alignOf(field_info.type));
111111 off += @sizeOf(field_info.type);
112112 }
113113 }
......@@ -123,7 +123,7 @@ pub fn TrailerFlags(comptime Fields: type) type {
123123 if (@sizeOf(field.type) == 0)
124124 continue;
125125 if ((self.bits & (1 << i)) != 0) {
126 off = mem.alignForwardGeneric(usize, off, @alignOf(field.type));
126 off = mem.alignForward(usize, off, @alignOf(field.type));
127127 off += @sizeOf(field.type);
128128 }
129129 }
lib/std/os/linux/tls.zig+4-4
......@@ -233,7 +233,7 @@ fn initTLS(phdrs: []elf.Phdr) void {
233233 l += tls_align_factor - delta;
234234 l += @sizeOf(CustomData);
235235 tcb_offset = l;
236 l += mem.alignForward(tls_tcb_size, tls_align_factor);
236 l += mem.alignForward(usize, tls_tcb_size, tls_align_factor);
237237 data_offset = l;
238238 l += tls_data_alloc_size;
239239 break :blk l;
......@@ -241,14 +241,14 @@ fn initTLS(phdrs: []elf.Phdr) void {
241241 .VariantII => blk: {
242242 var l: usize = 0;
243243 data_offset = l;
244 l += mem.alignForward(tls_data_alloc_size, tls_align_factor);
244 l += mem.alignForward(usize, tls_data_alloc_size, tls_align_factor);
245245 // The thread pointer is aligned to p_align
246246 tcb_offset = l;
247247 l += tls_tcb_size;
248248 // The CustomData structure is right after the TCB with no padding
249249 // in between so it can be easily found
250250 l += @sizeOf(CustomData);
251 l = mem.alignForward(l, @alignOf(DTV));
251 l = mem.alignForward(usize, l, @alignOf(DTV));
252252 dtv_offset = l;
253253 l += @sizeOf(DTV);
254254 break :blk l;
......@@ -329,7 +329,7 @@ pub fn initStaticTLS(phdrs: []elf.Phdr) void {
329329
330330 // Make sure the slice is correctly aligned.
331331 const begin_addr = @ptrToInt(alloc_tls_area.ptr);
332 const begin_aligned_addr = mem.alignForward(begin_addr, tls_image.alloc_align);
332 const begin_aligned_addr = mem.alignForward(usize, begin_addr, tls_image.alloc_align);
333333 const start = begin_aligned_addr - begin_addr;
334334 break :blk alloc_tls_area[start .. start + tls_image.alloc_size];
335335 };
lib/std/os/uefi/pool_allocator.zig+2-2
......@@ -24,7 +24,7 @@ const UefiPoolAllocator = struct {
2424
2525 const ptr_align = @as(usize, 1) << @intCast(Allocator.Log2Align, log2_ptr_align);
2626
27 const metadata_len = mem.alignForward(@sizeOf(usize), ptr_align);
27 const metadata_len = mem.alignForward(usize, @sizeOf(usize), ptr_align);
2828
2929 const full_len = metadata_len + len;
3030
......@@ -32,7 +32,7 @@ const UefiPoolAllocator = struct {
3232 if (uefi.system_table.boot_services.?.allocatePool(uefi.efi_pool_memory_type, full_len, &unaligned_ptr) != .Success) return null;
3333
3434 const unaligned_addr = @ptrToInt(unaligned_ptr);
35 const aligned_addr = mem.alignForward(unaligned_addr + @sizeOf(usize), ptr_align);
35 const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), ptr_align);
3636
3737 var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr);
3838 getHeader(aligned_ptr).* = unaligned_ptr;
lib/std/tar.zig+1-1
......@@ -116,7 +116,7 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
116116 const header: Header = .{ .bytes = buffer[start..][0..512] };
117117 start += 512;
118118 const file_size = try header.fileSize();
119 const rounded_file_size = std.mem.alignForwardGeneric(u64, file_size, 512);
119 const rounded_file_size = std.mem.alignForward(u64, file_size, 512);
120120 const pad_len = @intCast(usize, rounded_file_size - file_size);
121121 const unstripped_file_name = try header.fullFileName(&file_name_buffer);
122122 switch (header.fileType()) {
lib/std/target.zig+1-1
......@@ -1944,7 +1944,7 @@ pub const Target = struct {
19441944 16 => 2,
19451945 32 => 4,
19461946 64 => 8,
1947 80 => @intCast(u16, mem.alignForward(10, c_type_alignment(t, .longdouble))),
1947 80 => @intCast(u16, mem.alignForward(usize, 10, c_type_alignment(t, .longdouble))),
19481948 128 => 16,
19491949 else => unreachable,
19501950 },
lib/std/testing.zig+1-1
......@@ -305,7 +305,7 @@ pub fn expectEqualSlices(comptime T: type, expected: []const T, actual: []const
305305 var window_start: usize = 0;
306306 if (@max(actual.len, expected.len) > max_window_size) {
307307 const alignment = if (T == u8) 16 else 2;
308 window_start = std.mem.alignBackward(diff_index - @min(diff_index, alignment), alignment);
308 window_start = std.mem.alignBackward(usize, diff_index - @min(diff_index, alignment), alignment);
309309 }
310310 const expected_window = expected[window_start..@min(expected.len, window_start + max_window_size)];
311311 const expected_truncated = window_start + expected_window.len < expected.len;
src/Module.zig+5-5
......@@ -1293,7 +1293,7 @@ pub const Union = struct {
12931293 payload_align = @max(payload_align, 1);
12941294 if (!have_tag or !u.tag_ty.hasRuntimeBits(mod)) {
12951295 return .{
1296 .abi_size = std.mem.alignForwardGeneric(u64, payload_size, payload_align),
1296 .abi_size = std.mem.alignForward(u64, payload_size, payload_align),
12971297 .abi_align = payload_align,
12981298 .most_aligned_field = most_aligned_field,
12991299 .most_aligned_field_size = most_aligned_field_size,
......@@ -1314,18 +1314,18 @@ pub const Union = struct {
13141314 if (tag_align >= payload_align) {
13151315 // {Tag, Payload}
13161316 size += tag_size;
1317 size = std.mem.alignForwardGeneric(u64, size, payload_align);
1317 size = std.mem.alignForward(u64, size, payload_align);
13181318 size += payload_size;
13191319 const prev_size = size;
1320 size = std.mem.alignForwardGeneric(u64, size, tag_align);
1320 size = std.mem.alignForward(u64, size, tag_align);
13211321 padding = @intCast(u32, size - prev_size);
13221322 } else {
13231323 // {Payload, Tag}
13241324 size += payload_size;
1325 size = std.mem.alignForwardGeneric(u64, size, tag_align);
1325 size = std.mem.alignForward(u64, size, tag_align);
13261326 size += tag_size;
13271327 const prev_size = size;
1328 size = std.mem.alignForwardGeneric(u64, size, payload_align);
1328 size = std.mem.alignForward(u64, size, payload_align);
13291329 padding = @intCast(u32, size - prev_size);
13301330 }
13311331 return .{
src/arch/aarch64/CodeGen.zig+3-3
......@@ -566,7 +566,7 @@ fn gen(self: *Self) !void {
566566
567567 // Backpatch stack offset
568568 const total_stack_size = self.max_end_stack + self.saved_regs_stack_space;
569 const aligned_total_stack_end = mem.alignForwardGeneric(u32, total_stack_size, self.stack_align);
569 const aligned_total_stack_end = mem.alignForward(u32, total_stack_size, self.stack_align);
570570 const stack_size = aligned_total_stack_end - self.saved_regs_stack_space;
571571 self.max_end_stack = stack_size;
572572 if (math.cast(u12, stack_size)) |size| {
......@@ -1011,7 +1011,7 @@ fn allocMem(
10111011 std.math.ceilPowerOfTwoAssert(u32, abi_size);
10121012
10131013 // TODO find a free slot instead of always appending
1014 const offset = mem.alignForwardGeneric(u32, self.next_stack_offset, adjusted_align) + abi_size;
1014 const offset = mem.alignForward(u32, self.next_stack_offset, adjusted_align) + abi_size;
10151015 self.next_stack_offset = offset;
10161016 self.max_end_stack = @max(self.max_end_stack, self.next_stack_offset);
10171017
......@@ -6328,7 +6328,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
63286328 const param_size = @intCast(u32, ty.toType().abiSize(mod));
63296329 const param_alignment = ty.toType().abiAlignment(mod);
63306330
6331 stack_offset = std.mem.alignForwardGeneric(u32, stack_offset, param_alignment);
6331 stack_offset = std.mem.alignForward(u32, stack_offset, param_alignment);
63326332 result.args[i] = .{ .stack_argument_offset = stack_offset };
63336333 stack_offset += param_size;
63346334 } else {
src/arch/arm/CodeGen.zig+5-5
......@@ -560,7 +560,7 @@ fn gen(self: *Self) !void {
560560
561561 // Backpatch stack offset
562562 const total_stack_size = self.max_end_stack + self.saved_regs_stack_space;
563 const aligned_total_stack_end = mem.alignForwardGeneric(u32, total_stack_size, self.stack_align);
563 const aligned_total_stack_end = mem.alignForward(u32, total_stack_size, self.stack_align);
564564 const stack_size = aligned_total_stack_end - self.saved_regs_stack_space;
565565 self.max_end_stack = stack_size;
566566 self.mir_instructions.set(sub_reloc, .{
......@@ -991,7 +991,7 @@ fn allocMem(
991991 assert(abi_align > 0);
992992
993993 // TODO find a free slot instead of always appending
994 const offset = mem.alignForwardGeneric(u32, self.next_stack_offset, abi_align) + abi_size;
994 const offset = mem.alignForward(u32, self.next_stack_offset, abi_align) + abi_size;
995995 self.next_stack_offset = offset;
996996 self.max_end_stack = @max(self.max_end_stack, self.next_stack_offset);
997997
......@@ -6214,7 +6214,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62146214
62156215 for (fn_info.param_types, 0..) |ty, i| {
62166216 if (ty.toType().abiAlignment(mod) == 8)
6217 ncrn = std.mem.alignForwardGeneric(usize, ncrn, 2);
6217 ncrn = std.mem.alignForward(usize, ncrn, 2);
62186218
62196219 const param_size = @intCast(u32, ty.toType().abiSize(mod));
62206220 if (std.math.divCeil(u32, param_size, 4) catch unreachable <= 4 - ncrn) {
......@@ -6229,7 +6229,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62296229 } else {
62306230 ncrn = 4;
62316231 if (ty.toType().abiAlignment(mod) == 8)
6232 nsaa = std.mem.alignForwardGeneric(u32, nsaa, 8);
6232 nsaa = std.mem.alignForward(u32, nsaa, 8);
62336233
62346234 result.args[i] = .{ .stack_argument_offset = nsaa };
62356235 nsaa += param_size;
......@@ -6267,7 +6267,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62676267 const param_size = @intCast(u32, ty.toType().abiSize(mod));
62686268 const param_alignment = ty.toType().abiAlignment(mod);
62696269
6270 stack_offset = std.mem.alignForwardGeneric(u32, stack_offset, param_alignment);
6270 stack_offset = std.mem.alignForward(u32, stack_offset, param_alignment);
62716271 result.args[i] = .{ .stack_argument_offset = stack_offset };
62726272 stack_offset += param_size;
62736273 } else {
src/arch/arm/abi.zig+1-1
......@@ -13,7 +13,7 @@ pub const Class = union(enum) {
1313 i64_array: u8,
1414
1515 fn arrSize(total_size: u64, arr_size: u64) Class {
16 const count = @intCast(u8, std.mem.alignForwardGeneric(u64, total_size, arr_size) / arr_size);
16 const count = @intCast(u8, std.mem.alignForward(u64, total_size, arr_size) / arr_size);
1717 if (arr_size == 32) {
1818 return .{ .i32_array = count };
1919 } else {
src/arch/riscv64/CodeGen.zig+1-1
......@@ -792,7 +792,7 @@ fn allocMem(self: *Self, inst: Air.Inst.Index, abi_size: u32, abi_align: u32) !u
792792 if (abi_align > self.stack_align)
793793 self.stack_align = abi_align;
794794 // TODO find a free slot instead of always appending
795 const offset = mem.alignForwardGeneric(u32, self.next_stack_offset, abi_align);
795 const offset = mem.alignForward(u32, self.next_stack_offset, abi_align);
796796 self.next_stack_offset = offset + abi_size;
797797 if (self.next_stack_offset > self.max_end_stack)
798798 self.max_end_stack = self.next_stack_offset;
src/arch/sparc64/CodeGen.zig+2-2
......@@ -423,7 +423,7 @@ fn gen(self: *Self) !void {
423423
424424 // Backpatch stack offset
425425 const total_stack_size = self.max_end_stack + abi.stack_reserved_area;
426 const stack_size = mem.alignForwardGeneric(u32, total_stack_size, self.stack_align);
426 const stack_size = mem.alignForward(u32, total_stack_size, self.stack_align);
427427 if (math.cast(i13, stack_size)) |size| {
428428 self.mir_instructions.set(save_inst, .{
429429 .tag = .save,
......@@ -2781,7 +2781,7 @@ fn allocMem(self: *Self, inst: Air.Inst.Index, abi_size: u32, abi_align: u32) !u
27812781 if (abi_align > self.stack_align)
27822782 self.stack_align = abi_align;
27832783 // TODO find a free slot instead of always appending
2784 const offset = mem.alignForwardGeneric(u32, self.next_stack_offset, abi_align) + abi_size;
2784 const offset = mem.alignForward(u32, self.next_stack_offset, abi_align) + abi_size;
27852785 self.next_stack_offset = offset;
27862786 if (self.next_stack_offset > self.max_end_stack)
27872787 self.max_end_stack = self.next_stack_offset;
src/arch/wasm/CodeGen.zig+4-4
......@@ -1286,7 +1286,7 @@ fn genFunc(func: *CodeGen) InnerError!void {
12861286 // store stack pointer so we can restore it when we return from the function
12871287 try prologue.append(.{ .tag = .local_tee, .data = .{ .label = func.initial_stack_value.local.value } });
12881288 // get the total stack size
1289 const aligned_stack = std.mem.alignForwardGeneric(u32, func.stack_size, func.stack_alignment);
1289 const aligned_stack = std.mem.alignForward(u32, func.stack_size, func.stack_alignment);
12901290 try prologue.append(.{ .tag = .i32_const, .data = .{ .imm32 = @intCast(i32, aligned_stack) } });
12911291 // substract it from the current stack pointer
12921292 try prologue.append(.{ .tag = .i32_sub, .data = .{ .tag = {} } });
......@@ -1531,7 +1531,7 @@ fn allocStack(func: *CodeGen, ty: Type) !WValue {
15311531 func.stack_alignment = abi_align;
15321532 }
15331533
1534 const offset = std.mem.alignForwardGeneric(u32, func.stack_size, abi_align);
1534 const offset = std.mem.alignForward(u32, func.stack_size, abi_align);
15351535 defer func.stack_size = offset + abi_size;
15361536
15371537 return WValue{ .stack_offset = .{ .value = offset, .references = 1 } };
......@@ -1564,7 +1564,7 @@ fn allocStackPtr(func: *CodeGen, inst: Air.Inst.Index) !WValue {
15641564 func.stack_alignment = abi_alignment;
15651565 }
15661566
1567 const offset = std.mem.alignForwardGeneric(u32, func.stack_size, abi_alignment);
1567 const offset = std.mem.alignForward(u32, func.stack_size, abi_alignment);
15681568 defer func.stack_size = offset + abi_size;
15691569
15701570 return WValue{ .stack_offset = .{ .value = offset, .references = 1 } };
......@@ -2975,7 +2975,7 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue
29752975 if (layout.payload_align > layout.tag_align) break :blk 0;
29762976
29772977 // tag is stored first so calculate offset from where payload starts
2978 break :blk @intCast(u32, std.mem.alignForwardGeneric(u64, layout.tag_size, layout.tag_align));
2978 break :blk @intCast(u32, std.mem.alignForward(u64, layout.tag_size, layout.tag_align));
29792979 },
29802980 },
29812981 .Pointer => switch (parent_ty.ptrSize(mod)) {
src/arch/x86_64/CodeGen.zig+5-5
......@@ -2150,7 +2150,7 @@ fn setFrameLoc(
21502150 const frame_i = @enumToInt(frame_index);
21512151 if (aligned) {
21522152 const alignment = @as(i32, 1) << self.frame_allocs.items(.abi_align)[frame_i];
2153 offset.* = mem.alignForwardGeneric(i32, offset.*, alignment);
2153 offset.* = mem.alignForward(i32, offset.*, alignment);
21542154 }
21552155 self.frame_locs.set(frame_i, .{ .base = base, .disp = offset.* });
21562156 offset.* += self.frame_allocs.items(.abi_size)[frame_i];
......@@ -2207,7 +2207,7 @@ fn computeFrameLayout(self: *Self) !FrameLayout {
22072207 self.setFrameLoc(.stack_frame, .rsp, &rsp_offset, true);
22082208 for (stack_frame_order) |frame_index| self.setFrameLoc(frame_index, .rsp, &rsp_offset, true);
22092209 rsp_offset += stack_frame_align_offset;
2210 rsp_offset = mem.alignForwardGeneric(i32, rsp_offset, @as(i32, 1) << needed_align);
2210 rsp_offset = mem.alignForward(i32, rsp_offset, @as(i32, 1) << needed_align);
22112211 rsp_offset -= stack_frame_align_offset;
22122212 frame_size[@enumToInt(FrameIndex.call_frame)] =
22132213 @intCast(u31, rsp_offset - frame_offset[@enumToInt(FrameIndex.stack_frame)]);
......@@ -11807,7 +11807,7 @@ fn resolveCallingConventionValues(
1180711807 const param_size = @intCast(u31, ty.abiSize(mod));
1180811808 const param_align = @intCast(u31, ty.abiAlignment(mod));
1180911809 result.stack_byte_count =
11810 mem.alignForwardGeneric(u31, result.stack_byte_count, param_align);
11810 mem.alignForward(u31, result.stack_byte_count, param_align);
1181111811 arg.* = .{ .load_frame = .{
1181211812 .index = stack_frame_base,
1181311813 .off = result.stack_byte_count,
......@@ -11847,7 +11847,7 @@ fn resolveCallingConventionValues(
1184711847 const param_size = @intCast(u31, ty.abiSize(mod));
1184811848 const param_align = @intCast(u31, ty.abiAlignment(mod));
1184911849 result.stack_byte_count =
11850 mem.alignForwardGeneric(u31, result.stack_byte_count, param_align);
11850 mem.alignForward(u31, result.stack_byte_count, param_align);
1185111851 arg.* = .{ .load_frame = .{
1185211852 .index = stack_frame_base,
1185311853 .off = result.stack_byte_count,
......@@ -11858,7 +11858,7 @@ fn resolveCallingConventionValues(
1185811858 else => return self.fail("TODO implement function parameters and return values for {} on x86_64", .{cc}),
1185911859 }
1186011860
11861 result.stack_byte_count = mem.alignForwardGeneric(u31, result.stack_byte_count, result.stack_align);
11861 result.stack_byte_count = mem.alignForward(u31, result.stack_byte_count, result.stack_align);
1186211862 return result;
1186311863}
1186411864
src/codegen.zig+4-4
......@@ -290,7 +290,7 @@ pub fn generateSymbol(
290290 .fail => |em| return .{ .fail = em },
291291 }
292292 const unpadded_end = code.items.len - begin;
293 const padded_end = mem.alignForwardGeneric(u64, unpadded_end, abi_align);
293 const padded_end = mem.alignForward(u64, unpadded_end, abi_align);
294294 const padding = math.cast(usize, padded_end - unpadded_end) orelse return error.Overflow;
295295
296296 if (padding > 0) {
......@@ -303,7 +303,7 @@ pub fn generateSymbol(
303303 const begin = code.items.len;
304304 try code.writer().writeInt(u16, err_val, endian);
305305 const unpadded_end = code.items.len - begin;
306 const padded_end = mem.alignForwardGeneric(u64, unpadded_end, abi_align);
306 const padded_end = mem.alignForward(u64, unpadded_end, abi_align);
307307 const padding = math.cast(usize, padded_end - unpadded_end) orelse return error.Overflow;
308308
309309 if (padding > 0) {
......@@ -1020,7 +1020,7 @@ pub fn errUnionPayloadOffset(payload_ty: Type, mod: *Module) u64 {
10201020 if (payload_align >= error_align or !payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
10211021 return 0;
10221022 } else {
1023 return mem.alignForwardGeneric(u64, Type.anyerror.abiSize(mod), payload_align);
1023 return mem.alignForward(u64, Type.anyerror.abiSize(mod), payload_align);
10241024 }
10251025}
10261026
......@@ -1029,7 +1029,7 @@ pub fn errUnionErrorOffset(payload_ty: Type, mod: *Module) u64 {
10291029 const payload_align = payload_ty.abiAlignment(mod);
10301030 const error_align = Type.anyerror.abiAlignment(mod);
10311031 if (payload_align >= error_align and payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
1032 return mem.alignForwardGeneric(u64, payload_ty.abiSize(mod), error_align);
1032 return mem.alignForward(u64, payload_ty.abiSize(mod), error_align);
10331033 } else {
10341034 return 0;
10351035 }
src/codegen/llvm.zig+22-22
......@@ -1633,7 +1633,7 @@ pub const Object = struct {
16331633
16341634 var offset: u64 = 0;
16351635 offset += ptr_size;
1636 offset = std.mem.alignForwardGeneric(u64, offset, len_align);
1636 offset = std.mem.alignForward(u64, offset, len_align);
16371637 const len_offset = offset;
16381638
16391639 const fields: [2]*llvm.DIType = .{
......@@ -1801,7 +1801,7 @@ pub const Object = struct {
18011801
18021802 var offset: u64 = 0;
18031803 offset += payload_size;
1804 offset = std.mem.alignForwardGeneric(u64, offset, non_null_align);
1804 offset = std.mem.alignForward(u64, offset, non_null_align);
18051805 const non_null_offset = offset;
18061806
18071807 const fields: [2]*llvm.DIType = .{
......@@ -1888,12 +1888,12 @@ pub const Object = struct {
18881888 error_index = 0;
18891889 payload_index = 1;
18901890 error_offset = 0;
1891 payload_offset = std.mem.alignForwardGeneric(u64, error_size, payload_align);
1891 payload_offset = std.mem.alignForward(u64, error_size, payload_align);
18921892 } else {
18931893 payload_index = 0;
18941894 error_index = 1;
18951895 payload_offset = 0;
1896 error_offset = std.mem.alignForwardGeneric(u64, payload_size, error_align);
1896 error_offset = std.mem.alignForward(u64, payload_size, error_align);
18971897 }
18981898
18991899 var fields: [2]*llvm.DIType = undefined;
......@@ -1995,7 +1995,7 @@ pub const Object = struct {
19951995
19961996 const field_size = field_ty.toType().abiSize(mod);
19971997 const field_align = field_ty.toType().abiAlignment(mod);
1998 const field_offset = std.mem.alignForwardGeneric(u64, offset, field_align);
1998 const field_offset = std.mem.alignForward(u64, offset, field_align);
19991999 offset = field_offset + field_size;
20002000
20012001 const field_name = if (tuple.names.len != 0)
......@@ -2086,7 +2086,7 @@ pub const Object = struct {
20862086 const field = field_and_index.field;
20872087 const field_size = field.ty.abiSize(mod);
20882088 const field_align = field.alignment(mod, layout);
2089 const field_offset = std.mem.alignForwardGeneric(u64, offset, field_align);
2089 const field_offset = std.mem.alignForward(u64, offset, field_align);
20902090 offset = field_offset + field_size;
20912091
20922092 const field_name = mod.intern_pool.stringToSlice(fields.keys()[field_and_index.index]);
......@@ -2242,10 +2242,10 @@ pub const Object = struct {
22422242 var payload_offset: u64 = undefined;
22432243 if (layout.tag_align >= layout.payload_align) {
22442244 tag_offset = 0;
2245 payload_offset = std.mem.alignForwardGeneric(u64, layout.tag_size, layout.payload_align);
2245 payload_offset = std.mem.alignForward(u64, layout.tag_size, layout.payload_align);
22462246 } else {
22472247 payload_offset = 0;
2248 tag_offset = std.mem.alignForwardGeneric(u64, layout.payload_size, layout.tag_align);
2248 tag_offset = std.mem.alignForward(u64, layout.payload_size, layout.tag_align);
22492249 }
22502250
22512251 const tag_di = dib.createMemberType(
......@@ -2861,9 +2861,9 @@ pub const DeclGen = struct {
28612861 fields_buf[0] = llvm_error_type;
28622862 fields_buf[1] = llvm_payload_type;
28632863 const payload_end =
2864 std.mem.alignForwardGeneric(u64, error_size, payload_align) +
2864 std.mem.alignForward(u64, error_size, payload_align) +
28652865 payload_size;
2866 const abi_size = std.mem.alignForwardGeneric(u64, payload_end, error_align);
2866 const abi_size = std.mem.alignForward(u64, payload_end, error_align);
28672867 const padding = @intCast(c_uint, abi_size - payload_end);
28682868 if (padding == 0) {
28692869 return dg.context.structType(&fields_buf, 2, .False);
......@@ -2874,9 +2874,9 @@ pub const DeclGen = struct {
28742874 fields_buf[0] = llvm_payload_type;
28752875 fields_buf[1] = llvm_error_type;
28762876 const error_end =
2877 std.mem.alignForwardGeneric(u64, payload_size, error_align) +
2877 std.mem.alignForward(u64, payload_size, error_align) +
28782878 error_size;
2879 const abi_size = std.mem.alignForwardGeneric(u64, error_end, payload_align);
2879 const abi_size = std.mem.alignForward(u64, error_end, payload_align);
28802880 const padding = @intCast(c_uint, abi_size - error_end);
28812881 if (padding == 0) {
28822882 return dg.context.structType(&fields_buf, 2, .False);
......@@ -2910,7 +2910,7 @@ pub const DeclGen = struct {
29102910 const field_align = field_ty.toType().abiAlignment(mod);
29112911 big_align = @max(big_align, field_align);
29122912 const prev_offset = offset;
2913 offset = std.mem.alignForwardGeneric(u64, offset, field_align);
2913 offset = std.mem.alignForward(u64, offset, field_align);
29142914
29152915 const padding_len = offset - prev_offset;
29162916 if (padding_len > 0) {
......@@ -2924,7 +2924,7 @@ pub const DeclGen = struct {
29242924 }
29252925 {
29262926 const prev_offset = offset;
2927 offset = std.mem.alignForwardGeneric(u64, offset, big_align);
2927 offset = std.mem.alignForward(u64, offset, big_align);
29282928 const padding_len = offset - prev_offset;
29292929 if (padding_len > 0) {
29302930 const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len));
......@@ -2979,7 +2979,7 @@ pub const DeclGen = struct {
29792979 field_align < field_ty_align;
29802980 big_align = @max(big_align, field_align);
29812981 const prev_offset = offset;
2982 offset = std.mem.alignForwardGeneric(u64, offset, field_align);
2982 offset = std.mem.alignForward(u64, offset, field_align);
29832983
29842984 const padding_len = offset - prev_offset;
29852985 if (padding_len > 0) {
......@@ -2993,7 +2993,7 @@ pub const DeclGen = struct {
29932993 }
29942994 {
29952995 const prev_offset = offset;
2996 offset = std.mem.alignForwardGeneric(u64, offset, big_align);
2996 offset = std.mem.alignForward(u64, offset, big_align);
29972997 const padding_len = offset - prev_offset;
29982998 if (padding_len > 0) {
29992999 const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len));
......@@ -3552,7 +3552,7 @@ pub const DeclGen = struct {
35523552 const field_align = field_ty.toType().abiAlignment(mod);
35533553 big_align = @max(big_align, field_align);
35543554 const prev_offset = offset;
3555 offset = std.mem.alignForwardGeneric(u64, offset, field_align);
3555 offset = std.mem.alignForward(u64, offset, field_align);
35563556
35573557 const padding_len = offset - prev_offset;
35583558 if (padding_len > 0) {
......@@ -3575,7 +3575,7 @@ pub const DeclGen = struct {
35753575 }
35763576 {
35773577 const prev_offset = offset;
3578 offset = std.mem.alignForwardGeneric(u64, offset, big_align);
3578 offset = std.mem.alignForward(u64, offset, big_align);
35793579 const padding_len = offset - prev_offset;
35803580 if (padding_len > 0) {
35813581 const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len));
......@@ -3650,7 +3650,7 @@ pub const DeclGen = struct {
36503650 const field_align = field.alignment(mod, struct_obj.layout);
36513651 big_align = @max(big_align, field_align);
36523652 const prev_offset = offset;
3653 offset = std.mem.alignForwardGeneric(u64, offset, field_align);
3653 offset = std.mem.alignForward(u64, offset, field_align);
36543654
36553655 const padding_len = offset - prev_offset;
36563656 if (padding_len > 0) {
......@@ -3673,7 +3673,7 @@ pub const DeclGen = struct {
36733673 }
36743674 {
36753675 const prev_offset = offset;
3676 offset = std.mem.alignForwardGeneric(u64, offset, big_align);
3676 offset = std.mem.alignForward(u64, offset, big_align);
36773677 const padding_len = offset - prev_offset;
36783678 if (padding_len > 0) {
36793679 const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len));
......@@ -10274,7 +10274,7 @@ fn llvmField(ty: Type, field_index: usize, mod: *Module) ?LlvmField {
1027410274 const field_align = field_ty.toType().abiAlignment(mod);
1027510275 big_align = @max(big_align, field_align);
1027610276 const prev_offset = offset;
10277 offset = std.mem.alignForwardGeneric(u64, offset, field_align);
10277 offset = std.mem.alignForward(u64, offset, field_align);
1027810278
1027910279 const padding_len = offset - prev_offset;
1028010280 if (padding_len > 0) {
......@@ -10308,7 +10308,7 @@ fn llvmField(ty: Type, field_index: usize, mod: *Module) ?LlvmField {
1030810308 const field_align = field.alignment(mod, layout);
1030910309 big_align = @max(big_align, field_align);
1031010310 const prev_offset = offset;
10311 offset = std.mem.alignForwardGeneric(u64, offset, field_align);
10311 offset = std.mem.alignForward(u64, offset, field_align);
1031210312
1031310313 const padding_len = offset - prev_offset;
1031410314 if (padding_len > 0) {
src/codegen/spirv.zig+2-2
......@@ -472,12 +472,12 @@ pub const DeclGen = struct {
472472 try self.initializers.append(result_id);
473473
474474 self.partial_word.len = 0;
475 self.size = std.mem.alignForwardGeneric(u32, self.size, @sizeOf(Word));
475 self.size = std.mem.alignForward(u32, self.size, @sizeOf(Word));
476476 }
477477
478478 /// Fill the buffer with undefined values until the size is aligned to `align`.
479479 fn fillToAlign(self: *@This(), alignment: u32) !void {
480 const target_size = std.mem.alignForwardGeneric(u32, self.size, alignment);
480 const target_size = std.mem.alignForward(u32, self.size, alignment);
481481 try self.addUndef(target_size - self.size);
482482 }
483483
src/link/Coff.zig+15-15
......@@ -437,10 +437,10 @@ fn allocateSection(self: *Coff, name: []const u8, size: u32, flags: coff.Section
437437 const vaddr = blk: {
438438 if (index == 0) break :blk self.page_size;
439439 const prev_header = self.sections.items(.header)[index - 1];
440 break :blk mem.alignForwardGeneric(u32, prev_header.virtual_address + prev_header.virtual_size, self.page_size);
440 break :blk mem.alignForward(u32, prev_header.virtual_address + prev_header.virtual_size, self.page_size);
441441 };
442442 // We commit more memory than needed upfront so that we don't have to reallocate too soon.
443 const memsz = mem.alignForwardGeneric(u32, size, self.page_size) * 100;
443 const memsz = mem.alignForward(u32, size, self.page_size) * 100;
444444 log.debug("found {s} free space 0x{x} to 0x{x} (0x{x} - 0x{x})", .{
445445 name,
446446 off,
......@@ -505,8 +505,8 @@ fn growSection(self: *Coff, sect_id: u32, needed_size: u32) !void {
505505fn growSectionVirtualMemory(self: *Coff, sect_id: u32, needed_size: u32) !void {
506506 const header = &self.sections.items(.header)[sect_id];
507507 const increased_size = padToIdeal(needed_size);
508 const old_aligned_end = header.virtual_address + mem.alignForwardGeneric(u32, header.virtual_size, self.page_size);
509 const new_aligned_end = header.virtual_address + mem.alignForwardGeneric(u32, increased_size, self.page_size);
508 const old_aligned_end = header.virtual_address + mem.alignForward(u32, header.virtual_size, self.page_size);
509 const new_aligned_end = header.virtual_address + mem.alignForward(u32, increased_size, self.page_size);
510510 const diff = new_aligned_end - old_aligned_end;
511511 log.debug("growing {s} in virtual memory by {x}", .{ self.getSectionName(header), diff });
512512
......@@ -567,7 +567,7 @@ fn allocateAtom(self: *Coff, atom_index: Atom.Index, new_atom_size: u32, alignme
567567 const ideal_capacity_end_vaddr = math.add(u32, sym.value, ideal_capacity) catch ideal_capacity;
568568 const capacity_end_vaddr = sym.value + capacity;
569569 const new_start_vaddr_unaligned = capacity_end_vaddr - new_atom_ideal_capacity;
570 const new_start_vaddr = mem.alignBackwardGeneric(u32, new_start_vaddr_unaligned, alignment);
570 const new_start_vaddr = mem.alignBackward(u32, new_start_vaddr_unaligned, alignment);
571571 if (new_start_vaddr < ideal_capacity_end_vaddr) {
572572 // Additional bookkeeping here to notice if this free list node
573573 // should be deleted because the atom that it points to has grown to take up
......@@ -596,11 +596,11 @@ fn allocateAtom(self: *Coff, atom_index: Atom.Index, new_atom_size: u32, alignme
596596 const last_symbol = last.getSymbol(self);
597597 const ideal_capacity = if (header.isCode()) padToIdeal(last.size) else last.size;
598598 const ideal_capacity_end_vaddr = last_symbol.value + ideal_capacity;
599 const new_start_vaddr = mem.alignForwardGeneric(u32, ideal_capacity_end_vaddr, alignment);
599 const new_start_vaddr = mem.alignForward(u32, ideal_capacity_end_vaddr, alignment);
600600 atom_placement = last_index;
601601 break :blk new_start_vaddr;
602602 } else {
603 break :blk mem.alignForwardGeneric(u32, header.virtual_address, alignment);
603 break :blk mem.alignForward(u32, header.virtual_address, alignment);
604604 }
605605 };
606606
......@@ -722,7 +722,7 @@ pub fn createAtom(self: *Coff) !Atom.Index {
722722fn growAtom(self: *Coff, atom_index: Atom.Index, new_atom_size: u32, alignment: u32) !u32 {
723723 const atom = self.getAtom(atom_index);
724724 const sym = atom.getSymbol(self);
725 const align_ok = mem.alignBackwardGeneric(u32, sym.value, alignment) == sym.value;
725 const align_ok = mem.alignBackward(u32, sym.value, alignment) == sym.value;
726726 const need_realloc = !align_ok or new_atom_size > atom.capacity(self);
727727 if (!need_realloc) return sym.value;
728728 return self.allocateAtom(atom_index, new_atom_size, alignment);
......@@ -1798,7 +1798,7 @@ fn writeBaseRelocations(self: *Coff) !void {
17981798
17991799 for (offsets.items) |offset| {
18001800 const rva = sym.value + offset;
1801 const page = mem.alignBackwardGeneric(u32, rva, self.page_size);
1801 const page = mem.alignBackward(u32, rva, self.page_size);
18021802 const gop = try page_table.getOrPut(page);
18031803 if (!gop.found_existing) {
18041804 gop.value_ptr.* = std.ArrayList(coff.BaseRelocation).init(gpa);
......@@ -1819,7 +1819,7 @@ fn writeBaseRelocations(self: *Coff) !void {
18191819 if (sym.section_number == .UNDEFINED) continue;
18201820
18211821 const rva = @intCast(u32, header.virtual_address + index * self.ptr_width.size());
1822 const page = mem.alignBackwardGeneric(u32, rva, self.page_size);
1822 const page = mem.alignBackward(u32, rva, self.page_size);
18231823 const gop = try page_table.getOrPut(page);
18241824 if (!gop.found_existing) {
18251825 gop.value_ptr.* = std.ArrayList(coff.BaseRelocation).init(gpa);
......@@ -1907,7 +1907,7 @@ fn writeImportTables(self: *Coff) !void {
19071907 lookup_table_size += @intCast(u32, itable.entries.items.len + 1) * @sizeOf(coff.ImportLookupEntry64.ByName);
19081908 for (itable.entries.items) |entry| {
19091909 const sym_name = self.getSymbolName(entry);
1910 names_table_size += 2 + mem.alignForwardGeneric(u32, @intCast(u32, sym_name.len + 1), 2);
1910 names_table_size += 2 + mem.alignForward(u32, @intCast(u32, sym_name.len + 1), 2);
19111911 }
19121912 dll_names_size += @intCast(u32, lib_name.len + ext.len + 1);
19131913 }
......@@ -2102,7 +2102,7 @@ fn writeHeader(self: *Coff) !void {
21022102 };
21032103 const subsystem: coff.Subsystem = .WINDOWS_CUI;
21042104 const size_of_image: u32 = self.getSizeOfImage();
2105 const size_of_headers: u32 = mem.alignForwardGeneric(u32, self.getSizeOfHeaders(), default_file_alignment);
2105 const size_of_headers: u32 = mem.alignForward(u32, self.getSizeOfHeaders(), default_file_alignment);
21062106 const image_base = self.getImageBase();
21072107
21082108 const base_of_code = self.sections.get(self.text_section_index.?).header.virtual_address;
......@@ -2247,7 +2247,7 @@ fn allocatedSize(self: *Coff, start: u32) u32 {
22472247fn findFreeSpace(self: *Coff, object_size: u32, min_alignment: u32) u32 {
22482248 var start: u32 = 0;
22492249 while (self.detectAllocCollision(start, object_size)) |item_end| {
2250 start = mem.alignForwardGeneric(u32, item_end, min_alignment);
2250 start = mem.alignForward(u32, item_end, min_alignment);
22512251 }
22522252 return start;
22532253}
......@@ -2294,9 +2294,9 @@ inline fn getSectionHeadersOffset(self: Coff) u32 {
22942294}
22952295
22962296inline fn getSizeOfImage(self: Coff) u32 {
2297 var image_size: u32 = mem.alignForwardGeneric(u32, self.getSizeOfHeaders(), self.page_size);
2297 var image_size: u32 = mem.alignForward(u32, self.getSizeOfHeaders(), self.page_size);
22982298 for (self.sections.items(.header)) |header| {
2299 image_size += mem.alignForwardGeneric(u32, header.virtual_size, self.page_size);
2299 image_size += mem.alignForward(u32, header.virtual_size, self.page_size);
23002300 }
23012301 return image_size;
23022302}
src/link/Dwarf.zig+1-1
......@@ -2152,7 +2152,7 @@ pub fn writeDbgAranges(self: *Dwarf, addr: u64, size: u64) !void {
21522152 di_buf.appendAssumeCapacity(0); // segment_selector_size
21532153
21542154 const end_header_offset = di_buf.items.len;
2155 const begin_entries_offset = mem.alignForward(end_header_offset, ptr_width_bytes * 2);
2155 const begin_entries_offset = mem.alignForward(usize, end_header_offset, ptr_width_bytes * 2);
21562156 di_buf.appendNTimesAssumeCapacity(0, begin_entries_offset - end_header_offset);
21572157
21582158 // Currently only one compilation unit is supported, so the address range is simply
src/link/Elf.zig+5-5
......@@ -439,7 +439,7 @@ pub fn allocatedSize(self: *Elf, start: u64) u64 {
439439pub fn findFreeSpace(self: *Elf, object_size: u64, min_alignment: u32) u64 {
440440 var start: u64 = 0;
441441 while (self.detectAllocCollision(start, object_size)) |item_end| {
442 start = mem.alignForwardGeneric(u64, item_end, min_alignment);
442 start = mem.alignForward(u64, item_end, min_alignment);
443443 }
444444 return start;
445445}
......@@ -1173,7 +1173,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
11731173 phdr_table.p_offset = self.findFreeSpace(needed_size, @intCast(u32, phdr_table.p_align));
11741174 }
11751175
1176 phdr_table_load.p_offset = mem.alignBackwardGeneric(u64, phdr_table.p_offset, phdr_table_load.p_align);
1176 phdr_table_load.p_offset = mem.alignBackward(u64, phdr_table.p_offset, phdr_table_load.p_align);
11771177 const load_align_offset = phdr_table.p_offset - phdr_table_load.p_offset;
11781178 phdr_table_load.p_filesz = load_align_offset + needed_size;
11791179 phdr_table_load.p_memsz = load_align_offset + needed_size;
......@@ -2215,7 +2215,7 @@ fn shrinkAtom(self: *Elf, atom_index: Atom.Index, new_block_size: u64) void {
22152215fn growAtom(self: *Elf, atom_index: Atom.Index, new_block_size: u64, alignment: u64) !u64 {
22162216 const atom = self.getAtom(atom_index);
22172217 const sym = atom.getSymbol(self);
2218 const align_ok = mem.alignBackwardGeneric(u64, sym.st_value, alignment) == sym.st_value;
2218 const align_ok = mem.alignBackward(u64, sym.st_value, alignment) == sym.st_value;
22192219 const need_realloc = !align_ok or new_block_size > atom.capacity(self);
22202220 if (!need_realloc) return sym.st_value;
22212221 return self.allocateAtom(atom_index, new_block_size, alignment);
......@@ -2269,7 +2269,7 @@ fn allocateAtom(self: *Elf, atom_index: Atom.Index, new_block_size: u64, alignme
22692269 const ideal_capacity_end_vaddr = std.math.add(u64, big_atom_sym.st_value, ideal_capacity) catch ideal_capacity;
22702270 const capacity_end_vaddr = big_atom_sym.st_value + capacity;
22712271 const new_start_vaddr_unaligned = capacity_end_vaddr - new_atom_ideal_capacity;
2272 const new_start_vaddr = mem.alignBackwardGeneric(u64, new_start_vaddr_unaligned, alignment);
2272 const new_start_vaddr = mem.alignBackward(u64, new_start_vaddr_unaligned, alignment);
22732273 if (new_start_vaddr < ideal_capacity_end_vaddr) {
22742274 // Additional bookkeeping here to notice if this free list node
22752275 // should be deleted because the block that it points to has grown to take up
......@@ -2298,7 +2298,7 @@ fn allocateAtom(self: *Elf, atom_index: Atom.Index, new_block_size: u64, alignme
22982298 const last_sym = last.getSymbol(self);
22992299 const ideal_capacity = padToIdeal(last_sym.st_size);
23002300 const ideal_capacity_end_vaddr = last_sym.st_value + ideal_capacity;
2301 const new_start_vaddr = mem.alignForwardGeneric(u64, ideal_capacity_end_vaddr, alignment);
2301 const new_start_vaddr = mem.alignForward(u64, ideal_capacity_end_vaddr, alignment);
23022302 // Set up the metadata to be updated, after errors are no longer possible.
23032303 atom_placement = last_index;
23042304 break :blk new_start_vaddr;
src/link/MachO.zig+25-25
......@@ -1777,7 +1777,7 @@ fn shrinkAtom(self: *MachO, atom_index: Atom.Index, new_block_size: u64) void {
17771777fn growAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignment: u64) !u64 {
17781778 const atom = self.getAtom(atom_index);
17791779 const sym = atom.getSymbol(self);
1780 const align_ok = mem.alignBackwardGeneric(u64, sym.n_value, alignment) == sym.n_value;
1780 const align_ok = mem.alignBackward(u64, sym.n_value, alignment) == sym.n_value;
17811781 const need_realloc = !align_ok or new_atom_size > atom.capacity(self);
17821782 if (!need_realloc) return sym.n_value;
17831783 return self.allocateAtom(atom_index, new_atom_size, alignment);
......@@ -2598,7 +2598,7 @@ fn populateMissingMetadata(self: *MachO) !void {
25982598 // The first __TEXT segment is immovable and covers MachO header and load commands.
25992599 self.header_segment_cmd_index = @intCast(u8, self.segments.items.len);
26002600 const ideal_size = @max(self.base.options.headerpad_size orelse 0, default_headerpad_size);
2601 const needed_size = mem.alignForwardGeneric(u64, padToIdeal(ideal_size), self.page_size);
2601 const needed_size = mem.alignForward(u64, padToIdeal(ideal_size), self.page_size);
26022602
26032603 log.debug("found __TEXT segment (header-only) free space 0x{x} to 0x{x}", .{ 0, needed_size });
26042604
......@@ -2735,7 +2735,7 @@ fn populateMissingMetadata(self: *MachO) !void {
27352735
27362736fn calcPagezeroSize(self: *MachO) u64 {
27372737 const pagezero_vmsize = self.base.options.pagezero_size orelse default_pagezero_vmsize;
2738 const aligned_pagezero_vmsize = mem.alignBackwardGeneric(u64, pagezero_vmsize, self.page_size);
2738 const aligned_pagezero_vmsize = mem.alignBackward(u64, pagezero_vmsize, self.page_size);
27392739 if (self.base.options.output_mode == .Lib) return 0;
27402740 if (aligned_pagezero_vmsize == 0) return 0;
27412741 if (aligned_pagezero_vmsize != pagezero_vmsize) {
......@@ -2759,10 +2759,10 @@ fn allocateSection(self: *MachO, segname: []const u8, sectname: []const u8, opts
27592759 const section_id = @intCast(u8, self.sections.slice().len);
27602760 const vmaddr = blk: {
27612761 const prev_segment = self.segments.items[segment_id - 1];
2762 break :blk mem.alignForwardGeneric(u64, prev_segment.vmaddr + prev_segment.vmsize, self.page_size);
2762 break :blk mem.alignForward(u64, prev_segment.vmaddr + prev_segment.vmsize, self.page_size);
27632763 };
27642764 // We commit more memory than needed upfront so that we don't have to reallocate too soon.
2765 const vmsize = mem.alignForwardGeneric(u64, opts.size, self.page_size);
2765 const vmsize = mem.alignForward(u64, opts.size, self.page_size);
27662766 const off = self.findFreeSpace(opts.size, self.page_size);
27672767
27682768 log.debug("found {s},{s} free space 0x{x} to 0x{x} (0x{x} - 0x{x})", .{
......@@ -2790,8 +2790,8 @@ fn allocateSection(self: *MachO, segname: []const u8, sectname: []const u8, opts
27902790 var section = macho.section_64{
27912791 .sectname = makeStaticString(sectname),
27922792 .segname = makeStaticString(segname),
2793 .addr = mem.alignForwardGeneric(u64, vmaddr, opts.alignment),
2794 .offset = mem.alignForwardGeneric(u32, @intCast(u32, off), opts.alignment),
2793 .addr = mem.alignForward(u64, vmaddr, opts.alignment),
2794 .offset = mem.alignForward(u32, @intCast(u32, off), opts.alignment),
27952795 .size = opts.size,
27962796 .@"align" = math.log2(opts.alignment),
27972797 .flags = opts.flags,
......@@ -2846,8 +2846,8 @@ fn growSection(self: *MachO, sect_id: u8, needed_size: u64) !void {
28462846 }
28472847
28482848 header.size = needed_size;
2849 segment.filesize = mem.alignForwardGeneric(u64, needed_size, self.page_size);
2850 segment.vmsize = mem.alignForwardGeneric(u64, needed_size, self.page_size);
2849 segment.filesize = mem.alignForward(u64, needed_size, self.page_size);
2850 segment.vmsize = mem.alignForward(u64, needed_size, self.page_size);
28512851}
28522852
28532853fn growSectionVirtualMemory(self: *MachO, sect_id: u8, needed_size: u64) !void {
......@@ -2855,7 +2855,7 @@ fn growSectionVirtualMemory(self: *MachO, sect_id: u8, needed_size: u64) !void {
28552855 const segment = self.getSegmentPtr(sect_id);
28562856 const increased_size = padToIdeal(needed_size);
28572857 const old_aligned_end = segment.vmaddr + segment.vmsize;
2858 const new_aligned_end = segment.vmaddr + mem.alignForwardGeneric(u64, increased_size, self.page_size);
2858 const new_aligned_end = segment.vmaddr + mem.alignForward(u64, increased_size, self.page_size);
28592859 const diff = new_aligned_end - old_aligned_end;
28602860 log.debug("shifting every segment after {s},{s} in virtual memory by {x}", .{
28612861 header.segName(),
......@@ -2927,7 +2927,7 @@ fn allocateAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignm
29272927 const ideal_capacity_end_vaddr = math.add(u64, sym.n_value, ideal_capacity) catch ideal_capacity;
29282928 const capacity_end_vaddr = sym.n_value + capacity;
29292929 const new_start_vaddr_unaligned = capacity_end_vaddr - new_atom_ideal_capacity;
2930 const new_start_vaddr = mem.alignBackwardGeneric(u64, new_start_vaddr_unaligned, alignment);
2930 const new_start_vaddr = mem.alignBackward(u64, new_start_vaddr_unaligned, alignment);
29312931 if (new_start_vaddr < ideal_capacity_end_vaddr) {
29322932 // Additional bookkeeping here to notice if this free list node
29332933 // should be deleted because the atom that it points to has grown to take up
......@@ -2956,11 +2956,11 @@ fn allocateAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignm
29562956 const last_symbol = last.getSymbol(self);
29572957 const ideal_capacity = if (requires_padding) padToIdeal(last.size) else last.size;
29582958 const ideal_capacity_end_vaddr = last_symbol.n_value + ideal_capacity;
2959 const new_start_vaddr = mem.alignForwardGeneric(u64, ideal_capacity_end_vaddr, alignment);
2959 const new_start_vaddr = mem.alignForward(u64, ideal_capacity_end_vaddr, alignment);
29602960 atom_placement = last_index;
29612961 break :blk new_start_vaddr;
29622962 } else {
2963 break :blk mem.alignForwardGeneric(u64, segment.vmaddr, alignment);
2963 break :blk mem.alignForward(u64, segment.vmaddr, alignment);
29642964 }
29652965 };
29662966
......@@ -3034,17 +3034,17 @@ fn writeLinkeditSegmentData(self: *MachO) !void {
30343034 for (self.segments.items, 0..) |segment, id| {
30353035 if (self.linkedit_segment_cmd_index.? == @intCast(u8, id)) continue;
30363036 if (seg.vmaddr < segment.vmaddr + segment.vmsize) {
3037 seg.vmaddr = mem.alignForwardGeneric(u64, segment.vmaddr + segment.vmsize, self.page_size);
3037 seg.vmaddr = mem.alignForward(u64, segment.vmaddr + segment.vmsize, self.page_size);
30383038 }
30393039 if (seg.fileoff < segment.fileoff + segment.filesize) {
3040 seg.fileoff = mem.alignForwardGeneric(u64, segment.fileoff + segment.filesize, self.page_size);
3040 seg.fileoff = mem.alignForward(u64, segment.fileoff + segment.filesize, self.page_size);
30413041 }
30423042 }
30433043
30443044 try self.writeDyldInfoData();
30453045 try self.writeSymtabs();
30463046
3047 seg.vmsize = mem.alignForwardGeneric(u64, seg.filesize, self.page_size);
3047 seg.vmsize = mem.alignForward(u64, seg.filesize, self.page_size);
30483048}
30493049
30503050fn collectRebaseDataFromTableSection(self: *MachO, sect_id: u8, rebase: *Rebase, table: anytype) !void {
......@@ -3236,17 +3236,17 @@ fn writeDyldInfoData(self: *MachO) !void {
32363236 assert(mem.isAlignedGeneric(u64, link_seg.fileoff, @alignOf(u64)));
32373237 const rebase_off = link_seg.fileoff;
32383238 const rebase_size = rebase.size();
3239 const rebase_size_aligned = mem.alignForwardGeneric(u64, rebase_size, @alignOf(u64));
3239 const rebase_size_aligned = mem.alignForward(u64, rebase_size, @alignOf(u64));
32403240 log.debug("writing rebase info from 0x{x} to 0x{x}", .{ rebase_off, rebase_off + rebase_size_aligned });
32413241
32423242 const bind_off = rebase_off + rebase_size_aligned;
32433243 const bind_size = bind.size();
3244 const bind_size_aligned = mem.alignForwardGeneric(u64, bind_size, @alignOf(u64));
3244 const bind_size_aligned = mem.alignForward(u64, bind_size, @alignOf(u64));
32453245 log.debug("writing bind info from 0x{x} to 0x{x}", .{ bind_off, bind_off + bind_size_aligned });
32463246
32473247 const lazy_bind_off = bind_off + bind_size_aligned;
32483248 const lazy_bind_size = lazy_bind.size();
3249 const lazy_bind_size_aligned = mem.alignForwardGeneric(u64, lazy_bind_size, @alignOf(u64));
3249 const lazy_bind_size_aligned = mem.alignForward(u64, lazy_bind_size, @alignOf(u64));
32503250 log.debug("writing lazy bind info from 0x{x} to 0x{x}", .{
32513251 lazy_bind_off,
32523252 lazy_bind_off + lazy_bind_size_aligned,
......@@ -3254,7 +3254,7 @@ fn writeDyldInfoData(self: *MachO) !void {
32543254
32553255 const export_off = lazy_bind_off + lazy_bind_size_aligned;
32563256 const export_size = trie.size;
3257 const export_size_aligned = mem.alignForwardGeneric(u64, export_size, @alignOf(u64));
3257 const export_size_aligned = mem.alignForward(u64, export_size, @alignOf(u64));
32583258 log.debug("writing export trie from 0x{x} to 0x{x}", .{ export_off, export_off + export_size_aligned });
32593259
32603260 const needed_size = math.cast(usize, export_off + export_size_aligned - rebase_off) orelse
......@@ -3412,7 +3412,7 @@ fn writeStrtab(self: *MachO) !void {
34123412 const offset = seg.fileoff + seg.filesize;
34133413 assert(mem.isAlignedGeneric(u64, offset, @alignOf(u64)));
34143414 const needed_size = self.strtab.buffer.items.len;
3415 const needed_size_aligned = mem.alignForwardGeneric(u64, needed_size, @alignOf(u64));
3415 const needed_size_aligned = mem.alignForward(u64, needed_size, @alignOf(u64));
34163416 seg.filesize = offset + needed_size_aligned - seg.fileoff;
34173417
34183418 log.debug("writing string table from 0x{x} to 0x{x}", .{ offset, offset + needed_size_aligned });
......@@ -3447,7 +3447,7 @@ fn writeDysymtab(self: *MachO, ctx: SymtabCtx) !void {
34473447 const offset = seg.fileoff + seg.filesize;
34483448 assert(mem.isAlignedGeneric(u64, offset, @alignOf(u64)));
34493449 const needed_size = nindirectsyms * @sizeOf(u32);
3450 const needed_size_aligned = mem.alignForwardGeneric(u64, needed_size, @alignOf(u64));
3450 const needed_size_aligned = mem.alignForward(u64, needed_size, @alignOf(u64));
34513451 seg.filesize = offset + needed_size_aligned - seg.fileoff;
34523452
34533453 log.debug("writing indirect symbol table from 0x{x} to 0x{x}", .{ offset, offset + needed_size_aligned });
......@@ -3514,10 +3514,10 @@ fn writeCodeSignaturePadding(self: *MachO, code_sig: *CodeSignature) !void {
35143514 const seg = self.getLinkeditSegmentPtr();
35153515 // Code signature data has to be 16-bytes aligned for Apple tools to recognize the file
35163516 // https://github.com/opensource-apple/cctools/blob/fdb4825f303fd5c0751be524babd32958181b3ed/libstuff/checkout.c#L271
3517 const offset = mem.alignForwardGeneric(u64, seg.fileoff + seg.filesize, 16);
3517 const offset = mem.alignForward(u64, seg.fileoff + seg.filesize, 16);
35183518 const needed_size = code_sig.estimateSize(offset);
35193519 seg.filesize = offset + needed_size - seg.fileoff;
3520 seg.vmsize = mem.alignForwardGeneric(u64, seg.filesize, self.page_size);
3520 seg.vmsize = mem.alignForward(u64, seg.filesize, self.page_size);
35213521 log.debug("writing code signature padding from 0x{x} to 0x{x}", .{ offset, offset + needed_size });
35223522 // Pad out the space. We need to do this to calculate valid hashes for everything in the file
35233523 // except for code signature data.
......@@ -3630,7 +3630,7 @@ fn allocatedSize(self: *MachO, start: u64) u64 {
36303630fn findFreeSpace(self: *MachO, object_size: u64, min_alignment: u32) u64 {
36313631 var start: u64 = 0;
36323632 while (self.detectAllocCollision(start, object_size)) |item_end| {
3633 start = mem.alignForwardGeneric(u64, item_end, min_alignment);
3633 start = mem.alignForward(u64, item_end, min_alignment);
36343634 }
36353635 return start;
36363636}
src/link/MachO/CodeSignature.zig+4-4
......@@ -282,7 +282,7 @@ pub fn writeAdhocSignature(
282282 self.code_directory.inner.execSegFlags = if (opts.output_mode == .Exe) macho.CS_EXECSEG_MAIN_BINARY else 0;
283283 self.code_directory.inner.codeLimit = opts.file_size;
284284
285 const total_pages = @intCast(u32, mem.alignForward(opts.file_size, self.page_size) / self.page_size);
285 const total_pages = @intCast(u32, mem.alignForward(usize, opts.file_size, self.page_size) / self.page_size);
286286
287287 try self.code_directory.code_slots.ensureTotalCapacityPrecise(gpa, total_pages);
288288 self.code_directory.code_slots.items.len = total_pages;
......@@ -357,7 +357,7 @@ fn parallelHash(
357357) !void {
358358 var wg: WaitGroup = .{};
359359
360 const total_num_chunks = mem.alignForward(file_size, self.page_size) / self.page_size;
360 const total_num_chunks = mem.alignForward(usize, file_size, self.page_size) / self.page_size;
361361 assert(self.code_directory.code_slots.items.len >= total_num_chunks);
362362
363363 const buffer = try gpa.alloc(u8, self.page_size * total_num_chunks);
......@@ -421,7 +421,7 @@ pub fn size(self: CodeSignature) u32 {
421421pub fn estimateSize(self: CodeSignature, file_size: u64) u32 {
422422 var ssize: u64 = @sizeOf(macho.SuperBlob) + @sizeOf(macho.BlobIndex) + self.code_directory.size();
423423 // Approx code slots
424 const total_pages = mem.alignForwardGeneric(u64, file_size, self.page_size) / self.page_size;
424 const total_pages = mem.alignForward(u64, file_size, self.page_size) / self.page_size;
425425 ssize += total_pages * hash_size;
426426 var n_special_slots: u32 = 0;
427427 if (self.requirements) |req| {
......@@ -436,7 +436,7 @@ pub fn estimateSize(self: CodeSignature, file_size: u64) u32 {
436436 ssize += @sizeOf(macho.BlobIndex) + sig.size();
437437 }
438438 ssize += n_special_slots * hash_size;
439 return @intCast(u32, mem.alignForwardGeneric(u64, ssize, @sizeOf(u64)));
439 return @intCast(u32, mem.alignForward(u64, ssize, @sizeOf(u64)));
440440}
441441
442442pub fn clear(self: *CodeSignature, allocator: Allocator) void {
src/link/MachO/DebugSymbols.zig+9-9
......@@ -68,7 +68,7 @@ pub fn populateMissingMetadata(self: *DebugSymbols) !void {
6868
6969 const off = @intCast(u64, self.page_size);
7070 const ideal_size: u16 = 200 + 128 + 160 + 250;
71 const needed_size = mem.alignForwardGeneric(u64, padToIdeal(ideal_size), self.page_size);
71 const needed_size = mem.alignForward(u64, padToIdeal(ideal_size), self.page_size);
7272
7373 log.debug("found __DWARF segment free space 0x{x} to 0x{x}", .{ off, off + needed_size });
7474
......@@ -213,7 +213,7 @@ fn findFreeSpace(self: *DebugSymbols, object_size: u64, min_alignment: u64) u64
213213 const segment = self.getDwarfSegmentPtr();
214214 var offset: u64 = segment.fileoff;
215215 while (self.detectAllocCollision(offset, object_size)) |item_end| {
216 offset = mem.alignForwardGeneric(u64, item_end, min_alignment);
216 offset = mem.alignForward(u64, item_end, min_alignment);
217217 }
218218 return offset;
219219}
......@@ -355,18 +355,18 @@ fn finalizeDwarfSegment(self: *DebugSymbols, macho_file: *MachO) void {
355355 file_size = @max(file_size, header.offset + header.size);
356356 }
357357
358 const aligned_size = mem.alignForwardGeneric(u64, file_size, self.page_size);
358 const aligned_size = mem.alignForward(u64, file_size, self.page_size);
359359 dwarf_segment.vmaddr = base_vmaddr;
360360 dwarf_segment.filesize = aligned_size;
361361 dwarf_segment.vmsize = aligned_size;
362362
363363 const linkedit = self.getLinkeditSegmentPtr();
364 linkedit.vmaddr = mem.alignForwardGeneric(
364 linkedit.vmaddr = mem.alignForward(
365365 u64,
366366 dwarf_segment.vmaddr + aligned_size,
367367 self.page_size,
368368 );
369 linkedit.fileoff = mem.alignForwardGeneric(
369 linkedit.fileoff = mem.alignForward(
370370 u64,
371371 dwarf_segment.fileoff + aligned_size,
372372 self.page_size,
......@@ -458,7 +458,7 @@ fn writeLinkeditSegmentData(self: *DebugSymbols, macho_file: *MachO) !void {
458458 try self.writeStrtab();
459459
460460 const seg = &self.segments.items[self.linkedit_segment_cmd_index.?];
461 const aligned_size = mem.alignForwardGeneric(u64, seg.filesize, self.page_size);
461 const aligned_size = mem.alignForward(u64, seg.filesize, self.page_size);
462462 seg.vmsize = aligned_size;
463463}
464464
......@@ -497,7 +497,7 @@ fn writeSymtab(self: *DebugSymbols, macho_file: *MachO) !void {
497497 const nsyms = nlocals + nexports;
498498
499499 const seg = &self.segments.items[self.linkedit_segment_cmd_index.?];
500 const offset = mem.alignForwardGeneric(u64, seg.fileoff, @alignOf(macho.nlist_64));
500 const offset = mem.alignForward(u64, seg.fileoff, @alignOf(macho.nlist_64));
501501 const needed_size = nsyms * @sizeOf(macho.nlist_64);
502502 seg.filesize = offset + needed_size - seg.fileoff;
503503
......@@ -522,8 +522,8 @@ fn writeStrtab(self: *DebugSymbols) !void {
522522
523523 const seg = &self.segments.items[self.linkedit_segment_cmd_index.?];
524524 const symtab_size = @intCast(u32, self.symtab_cmd.nsyms * @sizeOf(macho.nlist_64));
525 const offset = mem.alignForwardGeneric(u64, self.symtab_cmd.symoff + symtab_size, @alignOf(u64));
526 const needed_size = mem.alignForwardGeneric(u64, self.strtab.buffer.items.len, @alignOf(u64));
525 const offset = mem.alignForward(u64, self.symtab_cmd.symoff + symtab_size, @alignOf(u64));
526 const needed_size = mem.alignForward(u64, self.strtab.buffer.items.len, @alignOf(u64));
527527
528528 seg.filesize = offset + needed_size - seg.fileoff;
529529 self.symtab_cmd.stroff = @intCast(u32, offset);
src/link/MachO/load_commands.zig+4-4
......@@ -17,7 +17,7 @@ pub const default_dyld_path: [*:0]const u8 = "/usr/lib/dyld";
1717fn calcInstallNameLen(cmd_size: u64, name: []const u8, assume_max_path_len: bool) u64 {
1818 const darwin_path_max = 1024;
1919 const name_len = if (assume_max_path_len) darwin_path_max else name.len + 1;
20 return mem.alignForwardGeneric(u64, cmd_size + name_len, @alignOf(u64));
20 return mem.alignForward(u64, cmd_size + name_len, @alignOf(u64));
2121}
2222
2323const CalcLCsSizeCtx = struct {
......@@ -149,7 +149,7 @@ pub fn calcNumOfLCs(lc_buffer: []const u8) u32 {
149149
150150pub fn writeDylinkerLC(lc_writer: anytype) !void {
151151 const name_len = mem.sliceTo(default_dyld_path, 0).len;
152 const cmdsize = @intCast(u32, mem.alignForwardGeneric(
152 const cmdsize = @intCast(u32, mem.alignForward(
153153 u64,
154154 @sizeOf(macho.dylinker_command) + name_len,
155155 @sizeOf(u64),
......@@ -176,7 +176,7 @@ const WriteDylibLCCtx = struct {
176176
177177fn writeDylibLC(ctx: WriteDylibLCCtx, lc_writer: anytype) !void {
178178 const name_len = ctx.name.len + 1;
179 const cmdsize = @intCast(u32, mem.alignForwardGeneric(
179 const cmdsize = @intCast(u32, mem.alignForward(
180180 u64,
181181 @sizeOf(macho.dylib_command) + name_len,
182182 @sizeOf(u64),
......@@ -253,7 +253,7 @@ pub fn writeRpathLCs(gpa: Allocator, options: *const link.Options, lc_writer: an
253253
254254 while (try it.next()) |rpath| {
255255 const rpath_len = rpath.len + 1;
256 const cmdsize = @intCast(u32, mem.alignForwardGeneric(
256 const cmdsize = @intCast(u32, mem.alignForward(
257257 u64,
258258 @sizeOf(macho.rpath_command) + rpath_len,
259259 @sizeOf(u64),
src/link/MachO/thunks.zig+3-3
......@@ -109,7 +109,7 @@ pub fn createThunks(zld: *Zld, sect_id: u8) !void {
109109
110110 while (true) {
111111 const atom = zld.getAtom(group_end);
112 offset = mem.alignForwardGeneric(u64, offset, try math.powi(u32, 2, atom.alignment));
112 offset = mem.alignForward(u64, offset, try math.powi(u32, 2, atom.alignment));
113113
114114 const sym = zld.getSymbolPtr(atom.getSymbolWithLoc());
115115 sym.n_value = offset;
......@@ -153,7 +153,7 @@ pub fn createThunks(zld: *Zld, sect_id: u8) !void {
153153 } else break;
154154 }
155155
156 offset = mem.alignForwardGeneric(u64, offset, Thunk.getAlignment());
156 offset = mem.alignForward(u64, offset, Thunk.getAlignment());
157157 allocateThunk(zld, thunk_index, offset, header);
158158 offset += zld.thunks.items[thunk_index].getSize();
159159
......@@ -193,7 +193,7 @@ fn allocateThunk(
193193 var offset = base_offset;
194194 while (true) {
195195 const atom = zld.getAtom(atom_index);
196 offset = mem.alignForwardGeneric(u64, offset, Thunk.getAlignment());
196 offset = mem.alignForward(u64, offset, Thunk.getAlignment());
197197
198198 const sym = zld.getSymbolPtr(atom.getSymbolWithLoc());
199199 sym.n_value = offset;
src/link/MachO/zld.zig+17-17
......@@ -1207,7 +1207,7 @@ pub const Zld = struct {
12071207
12081208 fn createSegments(self: *Zld) !void {
12091209 const pagezero_vmsize = self.options.pagezero_size orelse MachO.default_pagezero_vmsize;
1210 const aligned_pagezero_vmsize = mem.alignBackwardGeneric(u64, pagezero_vmsize, self.page_size);
1210 const aligned_pagezero_vmsize = mem.alignBackward(u64, pagezero_vmsize, self.page_size);
12111211 if (self.options.output_mode != .Lib and aligned_pagezero_vmsize > 0) {
12121212 if (aligned_pagezero_vmsize != pagezero_vmsize) {
12131213 log.warn("requested __PAGEZERO size (0x{x}) is not page aligned", .{pagezero_vmsize});
......@@ -1466,7 +1466,7 @@ pub const Zld = struct {
14661466 while (true) {
14671467 const atom = self.getAtom(atom_index);
14681468 const atom_alignment = try math.powi(u32, 2, atom.alignment);
1469 const atom_offset = mem.alignForwardGeneric(u64, header.size, atom_alignment);
1469 const atom_offset = mem.alignForward(u64, header.size, atom_alignment);
14701470 const padding = atom_offset - header.size;
14711471
14721472 const sym = self.getSymbolPtr(atom.getSymbolWithLoc());
......@@ -1534,7 +1534,7 @@ pub const Zld = struct {
15341534 const slice = self.sections.slice();
15351535 for (slice.items(.header)[indexes.start..indexes.end], 0..) |*header, sect_id| {
15361536 const alignment = try math.powi(u32, 2, header.@"align");
1537 const start_aligned = mem.alignForwardGeneric(u64, start, alignment);
1537 const start_aligned = mem.alignForward(u64, start, alignment);
15381538 const n_sect = @intCast(u8, indexes.start + sect_id + 1);
15391539
15401540 header.offset = if (header.isZerofill())
......@@ -1598,8 +1598,8 @@ pub const Zld = struct {
15981598 segment.vmsize = start;
15991599 }
16001600
1601 segment.filesize = mem.alignForwardGeneric(u64, segment.filesize, self.page_size);
1602 segment.vmsize = mem.alignForwardGeneric(u64, segment.vmsize, self.page_size);
1601 segment.filesize = mem.alignForward(u64, segment.filesize, self.page_size);
1602 segment.vmsize = mem.alignForward(u64, segment.vmsize, self.page_size);
16031603 }
16041604
16051605 const InitSectionOpts = struct {
......@@ -1709,7 +1709,7 @@ pub const Zld = struct {
17091709 try self.writeSymtabs();
17101710
17111711 const seg = self.getLinkeditSegmentPtr();
1712 seg.vmsize = mem.alignForwardGeneric(u64, seg.filesize, self.page_size);
1712 seg.vmsize = mem.alignForward(u64, seg.filesize, self.page_size);
17131713 }
17141714
17151715 fn collectRebaseDataFromContainer(
......@@ -2112,17 +2112,17 @@ pub const Zld = struct {
21122112 assert(mem.isAlignedGeneric(u64, link_seg.fileoff, @alignOf(u64)));
21132113 const rebase_off = link_seg.fileoff;
21142114 const rebase_size = rebase.size();
2115 const rebase_size_aligned = mem.alignForwardGeneric(u64, rebase_size, @alignOf(u64));
2115 const rebase_size_aligned = mem.alignForward(u64, rebase_size, @alignOf(u64));
21162116 log.debug("writing rebase info from 0x{x} to 0x{x}", .{ rebase_off, rebase_off + rebase_size_aligned });
21172117
21182118 const bind_off = rebase_off + rebase_size_aligned;
21192119 const bind_size = bind.size();
2120 const bind_size_aligned = mem.alignForwardGeneric(u64, bind_size, @alignOf(u64));
2120 const bind_size_aligned = mem.alignForward(u64, bind_size, @alignOf(u64));
21212121 log.debug("writing bind info from 0x{x} to 0x{x}", .{ bind_off, bind_off + bind_size_aligned });
21222122
21232123 const lazy_bind_off = bind_off + bind_size_aligned;
21242124 const lazy_bind_size = lazy_bind.size();
2125 const lazy_bind_size_aligned = mem.alignForwardGeneric(u64, lazy_bind_size, @alignOf(u64));
2125 const lazy_bind_size_aligned = mem.alignForward(u64, lazy_bind_size, @alignOf(u64));
21262126 log.debug("writing lazy bind info from 0x{x} to 0x{x}", .{
21272127 lazy_bind_off,
21282128 lazy_bind_off + lazy_bind_size_aligned,
......@@ -2130,7 +2130,7 @@ pub const Zld = struct {
21302130
21312131 const export_off = lazy_bind_off + lazy_bind_size_aligned;
21322132 const export_size = trie.size;
2133 const export_size_aligned = mem.alignForwardGeneric(u64, export_size, @alignOf(u64));
2133 const export_size_aligned = mem.alignForward(u64, export_size, @alignOf(u64));
21342134 log.debug("writing export trie from 0x{x} to 0x{x}", .{ export_off, export_off + export_size_aligned });
21352135
21362136 const needed_size = math.cast(usize, export_off + export_size_aligned - rebase_off) orelse
......@@ -2268,7 +2268,7 @@ pub const Zld = struct {
22682268 const offset = link_seg.fileoff + link_seg.filesize;
22692269 assert(mem.isAlignedGeneric(u64, offset, @alignOf(u64)));
22702270 const needed_size = buffer.items.len;
2271 const needed_size_aligned = mem.alignForwardGeneric(u64, needed_size, @alignOf(u64));
2271 const needed_size_aligned = mem.alignForward(u64, needed_size, @alignOf(u64));
22722272 const padding = math.cast(usize, needed_size_aligned - needed_size) orelse return error.Overflow;
22732273 if (padding > 0) {
22742274 try buffer.ensureUnusedCapacity(padding);
......@@ -2347,7 +2347,7 @@ pub const Zld = struct {
23472347 const offset = seg.fileoff + seg.filesize;
23482348 assert(mem.isAlignedGeneric(u64, offset, @alignOf(u64)));
23492349 const needed_size = out_dice.items.len * @sizeOf(macho.data_in_code_entry);
2350 const needed_size_aligned = mem.alignForwardGeneric(u64, needed_size, @alignOf(u64));
2350 const needed_size_aligned = mem.alignForward(u64, needed_size, @alignOf(u64));
23512351 seg.filesize = offset + needed_size_aligned - seg.fileoff;
23522352
23532353 const buffer = try self.gpa.alloc(u8, math.cast(usize, needed_size_aligned) orelse return error.Overflow);
......@@ -2480,7 +2480,7 @@ pub const Zld = struct {
24802480 const offset = seg.fileoff + seg.filesize;
24812481 assert(mem.isAlignedGeneric(u64, offset, @alignOf(u64)));
24822482 const needed_size = self.strtab.buffer.items.len;
2483 const needed_size_aligned = mem.alignForwardGeneric(u64, needed_size, @alignOf(u64));
2483 const needed_size_aligned = mem.alignForward(u64, needed_size, @alignOf(u64));
24842484 seg.filesize = offset + needed_size_aligned - seg.fileoff;
24852485
24862486 log.debug("writing string table from 0x{x} to 0x{x}", .{ offset, offset + needed_size_aligned });
......@@ -2515,7 +2515,7 @@ pub const Zld = struct {
25152515 const offset = seg.fileoff + seg.filesize;
25162516 assert(mem.isAlignedGeneric(u64, offset, @alignOf(u64)));
25172517 const needed_size = nindirectsyms * @sizeOf(u32);
2518 const needed_size_aligned = mem.alignForwardGeneric(u64, needed_size, @alignOf(u64));
2518 const needed_size_aligned = mem.alignForward(u64, needed_size, @alignOf(u64));
25192519 seg.filesize = offset + needed_size_aligned - seg.fileoff;
25202520
25212521 log.debug("writing indirect symbol table from 0x{x} to 0x{x}", .{ offset, offset + needed_size_aligned });
......@@ -2690,7 +2690,7 @@ pub const Zld = struct {
26902690
26912691 for (subsections[0..count]) |cut| {
26922692 const size = cut.end - cut.start;
2693 const num_chunks = mem.alignForward(size, chunk_size) / chunk_size;
2693 const num_chunks = mem.alignForward(usize, size, chunk_size) / chunk_size;
26942694
26952695 var i: usize = 0;
26962696 while (i < num_chunks) : (i += 1) {
......@@ -2725,10 +2725,10 @@ pub const Zld = struct {
27252725 const seg = self.getLinkeditSegmentPtr();
27262726 // Code signature data has to be 16-bytes aligned for Apple tools to recognize the file
27272727 // https://github.com/opensource-apple/cctools/blob/fdb4825f303fd5c0751be524babd32958181b3ed/libstuff/checkout.c#L271
2728 const offset = mem.alignForwardGeneric(u64, seg.fileoff + seg.filesize, 16);
2728 const offset = mem.alignForward(u64, seg.fileoff + seg.filesize, 16);
27292729 const needed_size = code_sig.estimateSize(offset);
27302730 seg.filesize = offset + needed_size - seg.fileoff;
2731 seg.vmsize = mem.alignForwardGeneric(u64, seg.filesize, self.page_size);
2731 seg.vmsize = mem.alignForward(u64, seg.filesize, self.page_size);
27322732 log.debug("writing code signature padding from 0x{x} to 0x{x}", .{ offset, offset + needed_size });
27332733 // Pad out the space. We need to do this to calculate valid hashes for everything in the file
27342734 // except for code signature data.
src/link/Wasm.zig+8-8
......@@ -2118,7 +2118,7 @@ fn allocateAtoms(wasm: *Wasm) !void {
21182118 }
21192119 }
21202120 }
2121 offset = std.mem.alignForwardGeneric(u32, offset, atom.alignment);
2121 offset = std.mem.alignForward(u32, offset, atom.alignment);
21222122 atom.offset = offset;
21232123 log.debug("Atom '{s}' allocated from 0x{x:0>8} to 0x{x:0>8} size={d}", .{
21242124 symbol_loc.getName(wasm),
......@@ -2129,7 +2129,7 @@ fn allocateAtoms(wasm: *Wasm) !void {
21292129 offset += atom.size;
21302130 atom_index = atom.prev orelse break;
21312131 }
2132 segment.size = std.mem.alignForwardGeneric(u32, offset, segment.alignment);
2132 segment.size = std.mem.alignForward(u32, offset, segment.alignment);
21332133 }
21342134}
21352135
......@@ -2731,7 +2731,7 @@ fn setupMemory(wasm: *Wasm) !void {
27312731 const is_obj = wasm.base.options.output_mode == .Obj;
27322732
27332733 if (place_stack_first and !is_obj) {
2734 memory_ptr = std.mem.alignForwardGeneric(u64, memory_ptr, stack_alignment);
2734 memory_ptr = std.mem.alignForward(u64, memory_ptr, stack_alignment);
27352735 memory_ptr += stack_size;
27362736 // We always put the stack pointer global at index 0
27372737 wasm.wasm_globals.items[0].init.i32_const = @bitCast(i32, @intCast(u32, memory_ptr));
......@@ -2741,7 +2741,7 @@ fn setupMemory(wasm: *Wasm) !void {
27412741 var data_seg_it = wasm.data_segments.iterator();
27422742 while (data_seg_it.next()) |entry| {
27432743 const segment = &wasm.segments.items[entry.value_ptr.*];
2744 memory_ptr = std.mem.alignForwardGeneric(u64, memory_ptr, segment.alignment);
2744 memory_ptr = std.mem.alignForward(u64, memory_ptr, segment.alignment);
27452745
27462746 // set TLS-related symbols
27472747 if (mem.eql(u8, entry.key_ptr.*, ".tdata")) {
......@@ -2779,7 +2779,7 @@ fn setupMemory(wasm: *Wasm) !void {
27792779 // create the memory init flag which is used by the init memory function
27802780 if (wasm.base.options.shared_memory and wasm.hasPassiveInitializationSegments()) {
27812781 // align to pointer size
2782 memory_ptr = mem.alignForwardGeneric(u64, memory_ptr, 4);
2782 memory_ptr = mem.alignForward(u64, memory_ptr, 4);
27832783 const loc = try wasm.createSyntheticSymbol("__wasm_init_memory_flag", .data);
27842784 const sym = loc.getSymbol(wasm);
27852785 sym.virtual_address = @intCast(u32, memory_ptr);
......@@ -2787,7 +2787,7 @@ fn setupMemory(wasm: *Wasm) !void {
27872787 }
27882788
27892789 if (!place_stack_first and !is_obj) {
2790 memory_ptr = std.mem.alignForwardGeneric(u64, memory_ptr, stack_alignment);
2790 memory_ptr = std.mem.alignForward(u64, memory_ptr, stack_alignment);
27912791 memory_ptr += stack_size;
27922792 wasm.wasm_globals.items[0].init.i32_const = @bitCast(i32, @intCast(u32, memory_ptr));
27932793 }
......@@ -2796,7 +2796,7 @@ fn setupMemory(wasm: *Wasm) !void {
27962796 // We must set its virtual address so it can be used in relocations.
27972797 if (wasm.findGlobalSymbol("__heap_base")) |loc| {
27982798 const symbol = loc.getSymbol(wasm);
2799 symbol.virtual_address = @intCast(u32, mem.alignForwardGeneric(u64, memory_ptr, heap_alignment));
2799 symbol.virtual_address = @intCast(u32, mem.alignForward(u64, memory_ptr, heap_alignment));
28002800 }
28012801
28022802 // Setup the max amount of pages
......@@ -2818,7 +2818,7 @@ fn setupMemory(wasm: *Wasm) !void {
28182818 }
28192819 memory_ptr = initial_memory;
28202820 }
2821 memory_ptr = mem.alignForwardGeneric(u64, memory_ptr, std.wasm.page_size);
2821 memory_ptr = mem.alignForward(u64, memory_ptr, std.wasm.page_size);
28222822 // In case we do not import memory, but define it ourselves,
28232823 // set the minimum amount of pages on the memory section.
28242824 wasm.memories.limits.min = @intCast(u32, memory_ptr / page_size);
src/objcopy.zig+3-3
......@@ -1024,7 +1024,7 @@ fn ElfFile(comptime is_64: bool) type {
10241024 dest.sh_size = @intCast(Elf_OffSize, data.len);
10251025
10261026 const addralign = if (src.sh_addralign == 0 or dest.sh_type == elf.SHT_NOBITS) 1 else src.sh_addralign;
1027 dest.sh_offset = std.mem.alignForwardGeneric(Elf_OffSize, eof_offset, addralign);
1027 dest.sh_offset = std.mem.alignForward(Elf_OffSize, eof_offset, addralign);
10281028 if (src.sh_offset != dest.sh_offset and section.segment != null and update.action != .empty and dest.sh_type != elf.SHT_NOTE) {
10291029 if (src.sh_offset > dest.sh_offset) {
10301030 dest.sh_offset = src.sh_offset; // add padding to avoid modifing the program segments
......@@ -1085,7 +1085,7 @@ fn ElfFile(comptime is_64: bool) type {
10851085 // add a ".gnu_debuglink" section
10861086 if (options.debuglink) |link| {
10871087 const payload = payload: {
1088 const crc_offset = std.mem.alignForward(link.name.len + 1, 4);
1088 const crc_offset = std.mem.alignForward(usize, link.name.len + 1, 4);
10891089 const buf = try allocator.alignedAlloc(u8, 4, crc_offset + 4);
10901090 @memcpy(buf[0..link.name.len], link.name);
10911091 @memset(buf[link.name.len..crc_offset], 0);
......@@ -1117,7 +1117,7 @@ fn ElfFile(comptime is_64: bool) type {
11171117
11181118 // write the section header at the tail
11191119 {
1120 const offset = std.mem.alignForwardGeneric(Elf_OffSize, eof_offset, @alignOf(Elf_Shdr));
1120 const offset = std.mem.alignForward(Elf_OffSize, eof_offset, @alignOf(Elf_Shdr));
11211121
11221122 const data = std.mem.sliceAsBytes(updated_section_header);
11231123 assert(data.len == @as(usize, updated_elf_header.e_shentsize) * new_shnum);
src/type.zig+11-11
......@@ -1339,7 +1339,7 @@ pub const Type = struct {
13391339 .storage = .{ .lazy_size = ty.toIntern() },
13401340 } })).toValue() },
13411341 };
1342 const result = std.mem.alignForwardGeneric(u32, total_bytes, alignment);
1342 const result = std.mem.alignForward(u32, total_bytes, alignment);
13431343 return AbiSizeAdvanced{ .scalar = result };
13441344 },
13451345
......@@ -1380,14 +1380,14 @@ pub const Type = struct {
13801380 var size: u64 = 0;
13811381 if (code_align > payload_align) {
13821382 size += code_size;
1383 size = std.mem.alignForwardGeneric(u64, size, payload_align);
1383 size = std.mem.alignForward(u64, size, payload_align);
13841384 size += payload_size;
1385 size = std.mem.alignForwardGeneric(u64, size, code_align);
1385 size = std.mem.alignForward(u64, size, code_align);
13861386 } else {
13871387 size += payload_size;
1388 size = std.mem.alignForwardGeneric(u64, size, code_align);
1388 size = std.mem.alignForward(u64, size, code_align);
13891389 size += code_size;
1390 size = std.mem.alignForwardGeneric(u64, size, payload_align);
1390 size = std.mem.alignForward(u64, size, payload_align);
13911391 }
13921392 return AbiSizeAdvanced{ .scalar = size };
13931393 },
......@@ -1595,7 +1595,7 @@ pub const Type = struct {
15951595
15961596 fn intAbiSize(bits: u16, target: Target) u64 {
15971597 const alignment = intAbiAlignment(bits, target);
1598 return std.mem.alignForwardGeneric(u64, @intCast(u16, (@as(u17, bits) + 7) / 8), alignment);
1598 return std.mem.alignForward(u64, @intCast(u16, (@as(u17, bits) + 7) / 8), alignment);
15991599 }
16001600
16011601 fn intAbiAlignment(bits: u16, target: Target) u32 {
......@@ -3194,7 +3194,7 @@ pub const Type = struct {
31943194
31953195 const field_align = field.alignment(mod, it.struct_obj.layout);
31963196 it.big_align = @max(it.big_align, field_align);
3197 const field_offset = std.mem.alignForwardGeneric(u64, it.offset, field_align);
3197 const field_offset = std.mem.alignForward(u64, it.offset, field_align);
31983198 it.offset = field_offset + field.ty.abiSize(mod);
31993199 return FieldOffset{ .field = i, .offset = field_offset };
32003200 }
......@@ -3223,7 +3223,7 @@ pub const Type = struct {
32233223 return field_offset.offset;
32243224 }
32253225
3226 return std.mem.alignForwardGeneric(u64, it.offset, @max(it.big_align, 1));
3226 return std.mem.alignForward(u64, it.offset, @max(it.big_align, 1));
32273227 },
32283228
32293229 .anon_struct_type => |tuple| {
......@@ -3239,11 +3239,11 @@ pub const Type = struct {
32393239
32403240 const field_align = field_ty.toType().abiAlignment(mod);
32413241 big_align = @max(big_align, field_align);
3242 offset = std.mem.alignForwardGeneric(u64, offset, field_align);
3242 offset = std.mem.alignForward(u64, offset, field_align);
32433243 if (i == index) return offset;
32443244 offset += field_ty.toType().abiSize(mod);
32453245 }
3246 offset = std.mem.alignForwardGeneric(u64, offset, @max(big_align, 1));
3246 offset = std.mem.alignForward(u64, offset, @max(big_align, 1));
32473247 return offset;
32483248 },
32493249
......@@ -3254,7 +3254,7 @@ pub const Type = struct {
32543254 const layout = union_obj.getLayout(mod, true);
32553255 if (layout.tag_align >= layout.payload_align) {
32563256 // {Tag, Payload}
3257 return std.mem.alignForwardGeneric(u64, layout.tag_size, layout.payload_align);
3257 return std.mem.alignForward(u64, layout.tag_size, layout.payload_align);
32583258 } else {
32593259 // {Payload, Tag}
32603260 return 0;