diff options
| author | dweiller <4678790+dweiller@users.noreply.github.com> | 2025-01-23 00:13:23 +1100 |
|---|---|---|
| committer | dweiller <4678790+dweiller@users.noreply.github.com> | 2025-04-26 13:34:16 +1000 |
| commit | 898ca824585e78306bb0137dbae1fbf859b762b6 (patch) | |
| tree | 49934715689d33a7544b56e229e42b0d2e2063ef /src/codegen/llvm.zig | |
| parent | b9f440620d969204e8196ae6c226f939eb194d5e (diff) | |
| download | zig-898ca824585e78306bb0137dbae1fbf859b762b6.tar.gz zig-898ca824585e78306bb0137dbae1fbf859b762b6.zip | |
compiler: add @memmove builtin
Diffstat (limited to 'src/codegen/llvm.zig')
| -rw-r--r-- | src/codegen/llvm.zig | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 3e389ed9c5..c0d16d5ab2 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -4941,6 +4941,7 @@ pub const FuncGen = struct { .memset => try self.airMemset(inst, false), .memset_safe => try self.airMemset(inst, true), .memcpy => try self.airMemcpy(inst), + .memmove => try self.airMemmove(inst), .set_union_tag => try self.airSetUnionTag(inst), .get_union_tag => try self.airGetUnionTag(inst), .clz => try self.airClzCtz(inst, .ctlz), @@ -9927,6 +9928,32 @@ pub const FuncGen = struct { return .none; } + fn airMemmove(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { + const o = self.ng.object; + const pt = o.pt; + const zcu = pt.zcu; + const bin_op = self.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; + const dest_slice = try self.resolveInst(bin_op.lhs); + const dest_ptr_ty = self.typeOf(bin_op.lhs); + const src_slice = try self.resolveInst(bin_op.rhs); + const src_ptr_ty = self.typeOf(bin_op.rhs); + const src_ptr = try self.sliceOrArrayPtr(src_slice, src_ptr_ty); + const len = try self.sliceOrArrayLenInBytes(dest_slice, dest_ptr_ty); + const dest_ptr = try self.sliceOrArrayPtr(dest_slice, dest_ptr_ty); + const access_kind: Builder.MemoryAccessKind = if (src_ptr_ty.isVolatilePtr(zcu) or + dest_ptr_ty.isVolatilePtr(zcu)) .@"volatile" else .normal; + + _ = try self.wip.callMemMove( + dest_ptr, + dest_ptr_ty.ptrAlignment(zcu).toLlvm(), + src_ptr, + src_ptr_ty.ptrAlignment(zcu).toLlvm(), + len, + access_kind, + ); + return .none; + } + fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { const o = self.ng.object; const pt = o.pt; |
