mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
x86_64: implement fallback for pcmpeqq
This commit is contained in:
parent
c4b93555b0
commit
b9c4400776
36
src/Type.zig
36
src/Type.zig
@ -962,7 +962,6 @@ pub fn abiAlignmentInner(
|
||||
) SemaError!AbiAlignmentInner {
|
||||
const pt = strat.pt(zcu, tid);
|
||||
const target = zcu.getTarget();
|
||||
const use_llvm = zcu.comp.config.use_llvm;
|
||||
const ip = &zcu.intern_pool;
|
||||
|
||||
switch (ty.toIntern()) {
|
||||
@ -970,7 +969,7 @@ pub fn abiAlignmentInner(
|
||||
else => switch (ip.indexToKey(ty.toIntern())) {
|
||||
.int_type => |int_type| {
|
||||
if (int_type.bits == 0) return .{ .scalar = .@"1" };
|
||||
return .{ .scalar = intAbiAlignment(int_type.bits, target, use_llvm) };
|
||||
return .{ .scalar = intAbiAlignment(int_type.bits, target) };
|
||||
},
|
||||
.ptr_type, .anyframe_type => {
|
||||
return .{ .scalar = ptrAbiAlignment(target) };
|
||||
@ -1023,7 +1022,7 @@ pub fn abiAlignmentInner(
|
||||
.error_set_type, .inferred_error_set_type => {
|
||||
const bits = zcu.errorSetBits();
|
||||
if (bits == 0) return .{ .scalar = .@"1" };
|
||||
return .{ .scalar = intAbiAlignment(bits, target, use_llvm) };
|
||||
return .{ .scalar = intAbiAlignment(bits, target) };
|
||||
},
|
||||
|
||||
// represents machine code; not a pointer
|
||||
@ -1036,7 +1035,7 @@ pub fn abiAlignmentInner(
|
||||
|
||||
.usize,
|
||||
.isize,
|
||||
=> return .{ .scalar = intAbiAlignment(target.ptrBitWidth(), target, use_llvm) },
|
||||
=> return .{ .scalar = intAbiAlignment(target.ptrBitWidth(), target) },
|
||||
|
||||
.c_char => return .{ .scalar = cTypeAlign(target, .char) },
|
||||
.c_short => return .{ .scalar = cTypeAlign(target, .short) },
|
||||
@ -1067,7 +1066,7 @@ pub fn abiAlignmentInner(
|
||||
.anyerror, .adhoc_inferred_error_set => {
|
||||
const bits = zcu.errorSetBits();
|
||||
if (bits == 0) return .{ .scalar = .@"1" };
|
||||
return .{ .scalar = intAbiAlignment(bits, target, use_llvm) };
|
||||
return .{ .scalar = intAbiAlignment(bits, target) };
|
||||
},
|
||||
|
||||
.void,
|
||||
@ -1291,7 +1290,6 @@ pub fn abiSizeInner(
|
||||
tid: strat.Tid(),
|
||||
) SemaError!AbiSizeInner {
|
||||
const target = zcu.getTarget();
|
||||
const use_llvm = zcu.comp.config.use_llvm;
|
||||
const ip = &zcu.intern_pool;
|
||||
|
||||
switch (ty.toIntern()) {
|
||||
@ -1300,7 +1298,7 @@ pub fn abiSizeInner(
|
||||
else => switch (ip.indexToKey(ty.toIntern())) {
|
||||
.int_type => |int_type| {
|
||||
if (int_type.bits == 0) return .{ .scalar = 0 };
|
||||
return .{ .scalar = intAbiSize(int_type.bits, target, use_llvm) };
|
||||
return .{ .scalar = intAbiSize(int_type.bits, target) };
|
||||
},
|
||||
.ptr_type => |ptr_type| switch (ptr_type.flags.size) {
|
||||
.slice => return .{ .scalar = @divExact(target.ptrBitWidth(), 8) * 2 },
|
||||
@ -1362,7 +1360,7 @@ pub fn abiSizeInner(
|
||||
.error_set_type, .inferred_error_set_type => {
|
||||
const bits = zcu.errorSetBits();
|
||||
if (bits == 0) return .{ .scalar = 0 };
|
||||
return .{ .scalar = intAbiSize(bits, target, use_llvm) };
|
||||
return .{ .scalar = intAbiSize(bits, target) };
|
||||
},
|
||||
|
||||
.error_union_type => |error_union_type| {
|
||||
@ -1455,7 +1453,7 @@ pub fn abiSizeInner(
|
||||
.anyerror, .adhoc_inferred_error_set => {
|
||||
const bits = zcu.errorSetBits();
|
||||
if (bits == 0) return .{ .scalar = 0 };
|
||||
return .{ .scalar = intAbiSize(bits, target, use_llvm) };
|
||||
return .{ .scalar = intAbiSize(bits, target) };
|
||||
},
|
||||
|
||||
.noreturn => unreachable,
|
||||
@ -1609,11 +1607,11 @@ pub fn ptrAbiAlignment(target: Target) Alignment {
|
||||
return Alignment.fromNonzeroByteUnits(@divExact(target.ptrBitWidth(), 8));
|
||||
}
|
||||
|
||||
pub fn intAbiSize(bits: u16, target: Target, use_llvm: bool) u64 {
|
||||
return intAbiAlignment(bits, target, use_llvm).forward(@as(u16, @intCast((@as(u17, bits) + 7) / 8)));
|
||||
pub fn intAbiSize(bits: u16, target: Target) u64 {
|
||||
return intAbiAlignment(bits, target).forward(@as(u16, @intCast((@as(u17, bits) + 7) / 8)));
|
||||
}
|
||||
|
||||
pub fn intAbiAlignment(bits: u16, target: Target, use_llvm: bool) Alignment {
|
||||
pub fn intAbiAlignment(bits: u16, target: Target) Alignment {
|
||||
return switch (target.cpu.arch) {
|
||||
.x86 => switch (bits) {
|
||||
0 => .none,
|
||||
@ -1632,19 +1630,16 @@ pub fn intAbiAlignment(bits: u16, target: Target, use_llvm: bool) Alignment {
|
||||
9...16 => .@"2",
|
||||
17...32 => .@"4",
|
||||
33...64 => .@"8",
|
||||
else => switch (target_util.zigBackend(target, use_llvm)) {
|
||||
.stage2_x86_64 => .@"8",
|
||||
else => .@"16",
|
||||
},
|
||||
else => .@"16",
|
||||
},
|
||||
else => return Alignment.fromByteUnits(@min(
|
||||
std.math.ceilPowerOfTwoPromote(u16, @as(u16, @intCast((@as(u17, bits) + 7) / 8))),
|
||||
maxIntAlignment(target, use_llvm),
|
||||
maxIntAlignment(target),
|
||||
)),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn maxIntAlignment(target: std.Target, use_llvm: bool) u16 {
|
||||
pub fn maxIntAlignment(target: std.Target) u16 {
|
||||
return switch (target.cpu.arch) {
|
||||
.avr => 1,
|
||||
.msp430 => 2,
|
||||
@ -1685,10 +1680,7 @@ pub fn maxIntAlignment(target: std.Target, use_llvm: bool) u16 {
|
||||
else => 8,
|
||||
},
|
||||
|
||||
.x86_64 => switch (target_util.zigBackend(target, use_llvm)) {
|
||||
.stage2_x86_64 => 8,
|
||||
else => 16,
|
||||
},
|
||||
.x86_64 => 16,
|
||||
|
||||
// Even LLVMABIAlignmentOfType(i128) agrees on these targets.
|
||||
.x86,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -677,11 +677,11 @@ pub const Instruction = struct {
|
||||
else => unreachable,
|
||||
},
|
||||
.frame => if (@TypeOf(encoder).options.allow_frame_locs) {
|
||||
try encoder.modRm_indirectDisp32(operand_enc, undefined);
|
||||
try encoder.modRm_indirectDisp32(operand_enc, 0);
|
||||
try encoder.disp32(undefined);
|
||||
} else return error.CannotEncode,
|
||||
.reloc => if (@TypeOf(encoder).options.allow_symbols) {
|
||||
try encoder.modRm_indirectDisp32(operand_enc, undefined);
|
||||
try encoder.modRm_indirectDisp32(operand_enc, 0);
|
||||
try encoder.disp32(undefined);
|
||||
} else return error.CannotEncode,
|
||||
},
|
||||
|
||||
@ -1312,10 +1312,10 @@ pub const Pool = struct {
|
||||
},
|
||||
else => {
|
||||
const target = &mod.resolved_target.result;
|
||||
const abi_align = Type.intAbiAlignment(int_info.bits, target.*, false);
|
||||
const abi_align = Type.intAbiAlignment(int_info.bits, target.*);
|
||||
const abi_align_bytes = abi_align.toByteUnits().?;
|
||||
const array_ctype = try pool.getArray(allocator, .{
|
||||
.len = @divExact(Type.intAbiSize(int_info.bits, target.*, false), abi_align_bytes),
|
||||
.len = @divExact(Type.intAbiSize(int_info.bits, target.*), abi_align_bytes),
|
||||
.elem_ctype = try pool.fromIntInfo(allocator, .{
|
||||
.signedness = .unsigned,
|
||||
.bits = @intCast(abi_align_bytes * 8),
|
||||
@ -1429,7 +1429,7 @@ pub const Pool = struct {
|
||||
.name = .{ .index = .len },
|
||||
.ctype = CType.usize,
|
||||
.alignas = AlignAs.fromAbiAlignment(
|
||||
Type.intAbiAlignment(target.ptrBitWidth(), target.*, false),
|
||||
Type.intAbiAlignment(target.ptrBitWidth(), target.*),
|
||||
),
|
||||
},
|
||||
};
|
||||
@ -1524,7 +1524,7 @@ pub const Pool = struct {
|
||||
.name = .{ .index = .len },
|
||||
.ctype = CType.usize,
|
||||
.alignas = AlignAs.fromAbiAlignment(
|
||||
Type.intAbiAlignment(target.ptrBitWidth(), target.*, false),
|
||||
Type.intAbiAlignment(target.ptrBitWidth(), target.*),
|
||||
),
|
||||
},
|
||||
};
|
||||
@ -1644,7 +1644,7 @@ pub const Pool = struct {
|
||||
.name = .{ .index = .@"error" },
|
||||
.ctype = error_set_ctype,
|
||||
.alignas = AlignAs.fromAbiAlignment(
|
||||
Type.intAbiAlignment(error_set_bits, target.*, false),
|
||||
Type.intAbiAlignment(error_set_bits, target.*),
|
||||
),
|
||||
},
|
||||
.{
|
||||
|
||||
@ -581,7 +581,7 @@ const DataLayoutBuilder = struct {
|
||||
switch (kind) {
|
||||
.integer => {
|
||||
if (self.target.ptrBitWidth() <= 16 and size >= 128) return;
|
||||
abi = @min(abi, Type.maxIntAlignment(self.target, true) * 8);
|
||||
abi = @min(abi, Type.maxIntAlignment(self.target) * 8);
|
||||
switch (self.target.cpu.arch) {
|
||||
.aarch64,
|
||||
.aarch64_be,
|
||||
|
||||
@ -396,7 +396,7 @@ fn abiDefines(self: *C, target: std.Target) !std.ArrayList(u8) {
|
||||
else => {},
|
||||
}
|
||||
try writer.print("#define ZIG_TARGET_MAX_INT_ALIGNMENT {d}\n", .{
|
||||
Type.maxIntAlignment(target, false),
|
||||
Type.maxIntAlignment(target),
|
||||
});
|
||||
return defines;
|
||||
}
|
||||
|
||||
@ -144,31 +144,17 @@ test "alignment and size of structs with 128-bit fields" {
|
||||
},
|
||||
},
|
||||
|
||||
.x86_64 => switch (builtin.zig_backend) {
|
||||
.stage2_x86_64 => .{
|
||||
.a_align = 8,
|
||||
.a_size = 16,
|
||||
.x86_64 => .{
|
||||
.a_align = 16,
|
||||
.a_size = 16,
|
||||
|
||||
.b_align = 16,
|
||||
.b_size = 32,
|
||||
.b_align = 16,
|
||||
.b_size = 32,
|
||||
|
||||
.u128_align = 8,
|
||||
.u128_size = 16,
|
||||
.u129_align = 8,
|
||||
.u129_size = 24,
|
||||
},
|
||||
else => .{
|
||||
.a_align = 16,
|
||||
.a_size = 16,
|
||||
|
||||
.b_align = 16,
|
||||
.b_size = 32,
|
||||
|
||||
.u128_align = 16,
|
||||
.u128_size = 16,
|
||||
.u129_align = 16,
|
||||
.u129_size = 32,
|
||||
},
|
||||
.u128_align = 16,
|
||||
.u128_size = 16,
|
||||
.u129_align = 16,
|
||||
.u129_size = 32,
|
||||
},
|
||||
|
||||
.x86,
|
||||
|
||||
@ -31,7 +31,37 @@ fn testBinary(comptime op: anytype) !void {
|
||||
try testType(u32, 0x80d7a2c6, 0xbff6a402);
|
||||
try testType(u64, 0x71138bc6b4a38898, 0x1bc4043de9438c7b);
|
||||
try testType(u128, 0xe05fc132ef2cd8affee00a907f0a851f, 0x29f912a72cfc6a7c6973426a9636da9a);
|
||||
try testType(
|
||||
u256,
|
||||
0xb7935f5c2f3b1ae7a422c0a7c446884294b7d5370bada307d2fe5a4c4284a999,
|
||||
0x310e6e196ba4f143b8d285ca6addf7f3bb3344224aff221b27607a31e148be08,
|
||||
);
|
||||
try testType(
|
||||
u512,
|
||||
0xe5b1fedca3c77db765e517aabd05ffc524a3a8aff1784bbf67c45b894447ede32b65b9940e78173c591e56e078932d465f235aece7ad47b7f229df7ba8f12295,
|
||||
0x8b4bb7c2969e3b121cc1082c442f8b4330f0a50058438fed56447175bb10178607ecfe425cb54dacc25ef26810f3e04681de1844f1aa8d029aca75d658634806,
|
||||
);
|
||||
|
||||
try testType(@Vector(1, u8), .{
|
||||
0x1f,
|
||||
}, .{
|
||||
0x06,
|
||||
});
|
||||
try testType(@Vector(2, u8), .{
|
||||
0x80, 0x63,
|
||||
}, .{
|
||||
0xe4, 0x28,
|
||||
});
|
||||
try testType(@Vector(4, u8), .{
|
||||
0x83, 0x9e, 0x1e, 0xc1,
|
||||
}, .{
|
||||
0xf0, 0x5c, 0x46, 0x85,
|
||||
});
|
||||
try testType(@Vector(8, u8), .{
|
||||
0x1e, 0x4d, 0x9d, 0x2a, 0x4c, 0x74, 0x0a, 0x83,
|
||||
}, .{
|
||||
0x28, 0x60, 0xa9, 0xb5, 0xd9, 0xa6, 0xf1, 0xb6,
|
||||
});
|
||||
try testType(@Vector(16, u8), .{
|
||||
0xea, 0x80, 0xbb, 0xe8, 0x74, 0x81, 0xc8, 0x66, 0x7b, 0x41, 0x90, 0xcb, 0x30, 0x70, 0x4b, 0x0f,
|
||||
}, .{
|
||||
@ -75,6 +105,21 @@ fn testBinary(comptime op: anytype) !void {
|
||||
0x56, 0x4f, 0xf1, 0xaa, 0x0a, 0x0f, 0xdb, 0x1b, 0xc8, 0x45, 0x9b, 0x12, 0xb4, 0x1a, 0xe4, 0xa3,
|
||||
});
|
||||
|
||||
try testType(@Vector(1, u16), .{
|
||||
0x9d6f,
|
||||
}, .{
|
||||
0x44b1,
|
||||
});
|
||||
try testType(@Vector(2, u16), .{
|
||||
0xa0fa, 0xc365,
|
||||
}, .{
|
||||
0xe736, 0xc394,
|
||||
});
|
||||
try testType(@Vector(4, u16), .{
|
||||
0x9608, 0xa558, 0x161b, 0x206f,
|
||||
}, .{
|
||||
0x3088, 0xf25c, 0x7837, 0x9b3f,
|
||||
});
|
||||
try testType(@Vector(8, u16), .{
|
||||
0xcf61, 0xb121, 0x3cf1, 0x3e9f, 0x43a7, 0x8d69, 0x96f5, 0xc11e,
|
||||
}, .{
|
||||
@ -118,6 +163,16 @@ fn testBinary(comptime op: anytype) !void {
|
||||
0x2c02, 0xff5b, 0x19ca, 0xbbf5, 0x870e, 0xc9ca, 0x47bb, 0xcfcc,
|
||||
});
|
||||
|
||||
try testType(@Vector(1, u32), .{
|
||||
0x1d0d9cc4,
|
||||
}, .{
|
||||
0xce2d0ab6,
|
||||
});
|
||||
try testType(@Vector(2, u32), .{
|
||||
0x5ab78c03, 0xd21bb513,
|
||||
}, .{
|
||||
0x8a6664eb, 0x79eac37d,
|
||||
});
|
||||
try testType(@Vector(4, u32), .{
|
||||
0x234d576e, 0x4151cc9c, 0x39f558e4, 0xba935a32,
|
||||
}, .{
|
||||
@ -161,9 +216,11 @@ fn testBinary(comptime op: anytype) !void {
|
||||
0xf080e943, 0xc8718d14, 0x3f920382, 0x18d101b5,
|
||||
});
|
||||
|
||||
// TODO: implement fallback for pcmpeqq
|
||||
if (!comptime @import("std").Target.x86.featureSetHas(@import("builtin").cpu.features, .sse4_1)) return;
|
||||
|
||||
try testType(@Vector(1, u64), .{
|
||||
0x333f593bf9d08546,
|
||||
}, .{
|
||||
0x6918bd767e730778,
|
||||
});
|
||||
try testType(@Vector(2, u64), .{
|
||||
0x4cd89a317b03d430, 0x28998f61842f63a9,
|
||||
}, .{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user