diff options
| author | John Schmidt <john.schmidt.h@gmail.com> | 2022-03-17 17:25:42 +0100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-03-17 18:00:48 -0700 |
| commit | adfcc8851b6bb47b085cfe2526f0797b1f414996 (patch) | |
| tree | ab8778be360da7a005e8de4d707b7bfc70e62635 /src/codegen | |
| parent | 7233a3324aaa5b3995606f24b2b961149219986b (diff) | |
| download | zig-adfcc8851b6bb47b085cfe2526f0797b1f414996.tar.gz zig-adfcc8851b6bb47b085cfe2526f0797b1f414996.zip | |
Implement `@byteSwap` for vectors
Make the behavior tests for this a little more primitive to exercise as
little extra functionality as possible.
Diffstat (limited to 'src/codegen')
| -rw-r--r-- | src/codegen/llvm.zig | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 481730452c..5a231ddc6e 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -6078,9 +6078,26 @@ pub const FuncGen = struct { if (bits % 16 == 8) { // If not an even byte-multiple, we need zero-extend + shift-left 1 byte // The truncated result at the end will be the correct bswap - operand_llvm_ty = self.context.intType(bits + 8); - const extended = self.builder.buildZExt(operand, operand_llvm_ty, ""); - operand = self.builder.buildShl(extended, operand_llvm_ty.constInt(8, .False), ""); + const scalar_llvm_ty = self.context.intType(bits + 8); + if (operand_ty.zigTypeTag() == .Vector) { + const vec_len = operand_ty.vectorLen(); + operand_llvm_ty = scalar_llvm_ty.vectorType(vec_len); + + const shifts = try self.gpa.alloc(*const llvm.Value, vec_len); + defer self.gpa.free(shifts); + + for (shifts) |*elem| { + elem.* = scalar_llvm_ty.constInt(8, .False); + } + const shift_vec = llvm.constVector(shifts.ptr, vec_len); + + const extended = self.builder.buildZExt(operand, operand_llvm_ty, ""); + operand = self.builder.buildShl(extended, shift_vec, ""); + } else { + const extended = self.builder.buildZExt(operand, scalar_llvm_ty, ""); + operand = self.builder.buildShl(extended, scalar_llvm_ty.constInt(8, .False), ""); + operand_llvm_ty = scalar_llvm_ty; + } bits = bits + 8; } |
