x86_64: fix C abi of incomplete sse register

This commit is contained in:
Jacob Young 2024-05-01 23:39:59 -04:00 committed by Andrew Kelley
parent e9efed9ed1
commit 08cecc1c7e
3 changed files with 79 additions and 21 deletions

View File

@ -285,17 +285,16 @@ pub fn classifySystemV(ty: Type, zcu: *Zcu, target: std.Target, ctx: Context) [8
// "If one of the classes is MEMORY, the whole argument is passed in memory" // "If one of the classes is MEMORY, the whole argument is passed in memory"
// "If X87UP is not preceded by X87, the whole argument is passed in memory." // "If X87UP is not preceded by X87, the whole argument is passed in memory."
var found_sseup = false; for (result, 0..) |class, i| switch (class) {
for (result, 0..) |item, i| switch (item) {
.memory => return memory_class, .memory => return memory_class,
.x87up => if (i == 0 or result[i - 1] != .x87) return memory_class, .x87up => if (i == 0 or result[i - 1] != .x87) return memory_class,
.sseup => found_sseup = true,
else => continue, else => continue,
}; };
// "If the size of the aggregate exceeds two eightbytes and the first eight- // "If the size of the aggregate exceeds two eightbytes and the first eight-
// byte isnt SSE or any other eightbyte isnt SSEUP, the whole argument // byte isnt SSE or any other eightbyte isnt SSEUP, the whole argument
// is passed in memory." // is passed in memory."
if (ty_size > 16 and (result[0] != .sse or !found_sseup)) return memory_class; if (ty_size > 16 and (result[0] != .sse or
std.mem.indexOfNone(Class, result[1..], &.{ .sseup, .none }) != null)) return memory_class;
// "If SSEUP is not preceded by SSE or SSEUP, it is converted to SSE." // "If SSEUP is not preceded by SSE or SSEUP, it is converted to SSE."
for (&result, 0..) |*item, i| { for (&result, 0..) |*item, i| {

View File

@ -5478,17 +5478,35 @@ f80_extra_struct c_f80_extra_struct(f80_extra_struct a) {
#endif #endif
#ifndef ZIG_NO_F128 #ifndef ZIG_NO_F128
__float128 zig_f128(__float128 a);
__float128 c_f128(__float128 a) { __float128 c_f128(__float128 a) {
assert_or_panic((double)a == 12.34); assert_or_panic((double)a == 12.34);
assert_or_panic(zig_f128(12) == 34);
return 56.78; return 56.78;
} }
typedef struct { typedef struct {
__float128 a; __float128 a;
} f128_struct; } f128_struct;
f128_struct zig_f128_struct(f128_struct a);
f128_struct c_f128_struct(f128_struct a) { f128_struct c_f128_struct(f128_struct a) {
assert_or_panic((double)a.a == 12.34); assert_or_panic((double)a.a == 12.34);
f128_struct b = zig_f128_struct((f128_struct){12345});
assert_or_panic(b.a == 98765);
return (f128_struct){56.78}; return (f128_struct){56.78};
} }
typedef struct {
__float128 a, b;
} f128_f128_struct;
f128_f128_struct zig_f128_f128_struct(f128_f128_struct a);
f128_f128_struct c_f128_f128_struct(f128_f128_struct a) {
assert_or_panic((double)a.a == 12.34);
assert_or_panic((double)a.b == 87.65);
f128_f128_struct b = zig_f128_f128_struct((f128_f128_struct){13, 57});
assert_or_panic((double)b.a == 24);
assert_or_panic((double)b.b == 68);
return (f128_f128_struct){56.78, 43.21};
}
#endif #endif
void __attribute__((stdcall)) stdcall_scalars(char a, short b, int c, float d, double e) { void __attribute__((stdcall)) stdcall_scalars(char a, short b, int c, float d, double e) {

View File

@ -136,7 +136,7 @@ export fn zig_f64(x: f64) void {
expect(x == 56.78) catch @panic("test failure: zig_f64"); expect(x == 56.78) catch @panic("test failure: zig_f64");
} }
export fn zig_longdouble(x: c_longdouble) void { export fn zig_longdouble(x: c_longdouble) void {
if (!builtin.cpu.arch.isWasm()) return; // waiting for #1481 if (!builtin.target.isWasm()) return; // waiting for #1481
expect(x == 12.34) catch @panic("test failure: zig_longdouble"); expect(x == 12.34) catch @panic("test failure: zig_longdouble");
} }
@ -1671,7 +1671,7 @@ test "bool simd vector" {
} }
{ {
if (builtin.target.cpu.arch != .wasm32) c_vector_256_bool(.{ if (!builtin.target.isWasm()) c_vector_256_bool(.{
false, false,
true, true,
true, true,
@ -2189,7 +2189,7 @@ test "bool simd vector" {
try expect(vec[255] == false); try expect(vec[255] == false);
} }
{ {
if (builtin.target.cpu.arch != .wasm32) c_vector_512_bool(.{ if (!builtin.target.isWasm()) c_vector_512_bool(.{
true, true,
true, true,
true, true,
@ -5614,23 +5614,64 @@ test "f80 extra struct" {
try expect(a.b == 24); try expect(a.b == 24);
} }
extern fn c_f128(f128) f128; comptime {
test "f128 bare" { skip: {
if (!have_f128) return error.SkipZigTest; if (builtin.target.isWasm()) break :skip;
const a = c_f128(12.34); _ = struct {
try expect(@as(f64, @floatCast(a)) == 56.78); export fn zig_f128(x: f128) f128 {
} expect(x == 12) catch @panic("test failure");
return 34;
}
extern fn c_f128(f128) f128;
test "f128 bare" {
if (!have_f128) return error.SkipZigTest;
const f128_struct = extern struct { const a = c_f128(12.34);
a: f128, try expect(@as(f64, @floatCast(a)) == 56.78);
}; }
extern fn c_f128_struct(f128_struct) f128_struct;
test "f128 struct" {
if (!have_f128) return error.SkipZigTest;
const a = c_f128_struct(.{ .a = 12.34 }); const f128_struct = extern struct {
try expect(@as(f64, @floatCast(a.a)) == 56.78); a: f128,
};
export fn zig_f128_struct(a: f128_struct) f128_struct {
expect(a.a == 12345) catch @panic("test failure");
return .{ .a = 98765 };
}
extern fn c_f128_struct(f128_struct) f128_struct;
test "f128 struct" {
if (!have_f128) return error.SkipZigTest;
const a = c_f128_struct(.{ .a = 12.34 });
try expect(@as(f64, @floatCast(a.a)) == 56.78);
const b = c_f128_f128_struct(.{ .a = 12.34, .b = 87.65 });
try expect(@as(f64, @floatCast(b.a)) == 56.78);
try expect(@as(f64, @floatCast(b.b)) == 43.21);
}
const f128_f128_struct = extern struct {
a: f128,
b: f128,
};
export fn zig_f128_f128_struct(a: f128_f128_struct) f128_f128_struct {
expect(a.a == 13) catch @panic("test failure");
expect(a.b == 57) catch @panic("test failure");
return .{ .a = 24, .b = 68 };
}
extern fn c_f128_f128_struct(f128_f128_struct) f128_f128_struct;
test "f128 f128 struct" {
if (!have_f128) return error.SkipZigTest;
const a = c_f128_struct(.{ .a = 12.34 });
try expect(@as(f64, @floatCast(a.a)) == 56.78);
const b = c_f128_f128_struct(.{ .a = 12.34, .b = 87.65 });
try expect(@as(f64, @floatCast(b.a)) == 56.78);
try expect(@as(f64, @floatCast(b.b)) == 43.21);
}
};
}
} }
// The stdcall attribute on C functions is ignored when compiled on non-x86 // The stdcall attribute on C functions is ignored when compiled on non-x86