aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-03-17 18:04:46 -0700
committerGitHub <noreply@github.com>2022-03-17 18:04:46 -0700
commitff21cb42a0201501d0bb762c9e496997fbccfdf3 (patch)
tree045f08ea0530a9f1bdbecd7895d06469618a1a20 /src/codegen
parent7233a3324aaa5b3995606f24b2b961149219986b (diff)
parent4fa506063373b38bed842af53e6405dec7107534 (diff)
downloadzig-ff21cb42a0201501d0bb762c9e496997fbccfdf3.tar.gz
zig-ff21cb42a0201501d0bb762c9e496997fbccfdf3.zip
Merge pull request #11206 from schmee/vector-byteswap
Implement `@byteSwap` for vectors
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/llvm.zig23
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;
}