Skip to content

Commit 76c89a3

Browse files
authored
Merge pull request #12071 from topolarity/windows-abi-change
compiler_rt: Update Windows ABI for float<->int conversion routines
2 parents f3333a5 + 2b52154 commit 76c89a3

30 files changed

+334
-207
lines changed

lib/compiler_rt/common.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ pub const want_aeabi = switch (builtin.abi) {
1717
};
1818
pub const want_ppc_abi = builtin.cpu.arch.isPPC() or builtin.cpu.arch.isPPC64();
1919

20+
// Libcalls that involve u128 on Windows x86-64 are expected by LLVM to use the
21+
// calling convention of @Vector(2, u64), rather than what's standard.
22+
pub const want_windows_v2u64_abi = builtin.os.tag == .windows and builtin.cpu.arch == .x86_64;
23+
2024
/// This governs whether to use these symbol names for f16/f32 conversions
2125
/// rather than the standard names:
2226
/// * __gnu_f2h_ieee

lib/compiler_rt/fixdfti.zig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1+
const builtin = @import("builtin");
12
const common = @import("./common.zig");
23
const floatToInt = @import("./float_to_int.zig").floatToInt;
34

45
pub const panic = common.panic;
56

67
comptime {
7-
@export(__fixdfti, .{ .name = "__fixdfti", .linkage = common.linkage });
8+
if (common.want_windows_v2u64_abi) {
9+
@export(__fixdfti_windows_x86_64, .{ .name = "__fixdfti", .linkage = common.linkage });
10+
} else {
11+
@export(__fixdfti, .{ .name = "__fixdfti", .linkage = common.linkage });
12+
}
813
}
914

1015
pub fn __fixdfti(a: f64) callconv(.C) i128 {
1116
return floatToInt(i128, a);
1217
}
18+
19+
const v2u64 = @Vector(2, u64);
20+
21+
fn __fixdfti_windows_x86_64(a: f64) callconv(.C) v2u64 {
22+
return @bitCast(v2u64, floatToInt(i128, a));
23+
}

lib/compiler_rt/fixhfti.zig

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1+
const builtin = @import("builtin");
12
const common = @import("./common.zig");
23
const floatToInt = @import("./float_to_int.zig").floatToInt;
34

45
pub const panic = common.panic;
56

67
comptime {
7-
@export(__fixhfti, .{ .name = "__fixhfti", .linkage = common.linkage });
8+
if (common.want_windows_v2u64_abi) {
9+
@export(__fixhfti_windows_x86_64, .{ .name = "__fixhfti", .linkage = common.linkage });
10+
} else {
11+
@export(__fixhfti, .{ .name = "__fixhfti", .linkage = common.linkage });
12+
}
813
}
914

10-
fn __fixhfti(a: f16) callconv(.C) i128 {
15+
pub fn __fixhfti(a: f16) callconv(.C) i128 {
1116
return floatToInt(i128, a);
1217
}
18+
19+
const v2u64 = @Vector(2, u64);
20+
21+
fn __fixhfti_windows_x86_64(a: f16) callconv(.C) v2u64 {
22+
return @bitCast(v2u64, floatToInt(i128, a));
23+
}

lib/compiler_rt/fixsfti.zig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1+
const builtin = @import("builtin");
12
const common = @import("./common.zig");
23
const floatToInt = @import("./float_to_int.zig").floatToInt;
34

45
pub const panic = common.panic;
56

67
comptime {
7-
@export(__fixsfti, .{ .name = "__fixsfti", .linkage = common.linkage });
8+
if (common.want_windows_v2u64_abi) {
9+
@export(__fixsfti_windows_x86_64, .{ .name = "__fixsfti", .linkage = common.linkage });
10+
} else {
11+
@export(__fixsfti, .{ .name = "__fixsfti", .linkage = common.linkage });
12+
}
813
}
914

1015
pub fn __fixsfti(a: f32) callconv(.C) i128 {
1116
return floatToInt(i128, a);
1217
}
18+
19+
const v2u64 = @Vector(2, u64);
20+
21+
fn __fixsfti_windows_x86_64(a: f32) callconv(.C) v2u64 {
22+
return @bitCast(v2u64, floatToInt(i128, a));
23+
}

lib/compiler_rt/fixtfti.zig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1+
const builtin = @import("builtin");
12
const common = @import("./common.zig");
23
const floatToInt = @import("./float_to_int.zig").floatToInt;
34

45
pub const panic = common.panic;
56

67
comptime {
7-
@export(__fixtfti, .{ .name = "__fixtfti", .linkage = common.linkage });
8+
if (common.want_windows_v2u64_abi) {
9+
@export(__fixtfti_windows_x86_64, .{ .name = "__fixtfti", .linkage = common.linkage });
10+
} else {
11+
@export(__fixtfti, .{ .name = "__fixtfti", .linkage = common.linkage });
12+
}
813
}
914

1015
pub fn __fixtfti(a: f128) callconv(.C) i128 {
1116
return floatToInt(i128, a);
1217
}
18+
19+
const v2u64 = @Vector(2, u64);
20+
21+
fn __fixtfti_windows_x86_64(a: f128) callconv(.C) v2u64 {
22+
return @bitCast(v2u64, floatToInt(i128, a));
23+
}

lib/compiler_rt/fixunsdfti.zig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1+
const builtin = @import("builtin");
12
const common = @import("./common.zig");
23
const floatToInt = @import("./float_to_int.zig").floatToInt;
34

45
pub const panic = common.panic;
56

67
comptime {
7-
@export(__fixunsdfti, .{ .name = "__fixunsdfti", .linkage = common.linkage });
8+
if (common.want_windows_v2u64_abi) {
9+
@export(__fixunsdfti_windows_x86_64, .{ .name = "__fixunsdfti", .linkage = common.linkage });
10+
} else {
11+
@export(__fixunsdfti, .{ .name = "__fixunsdfti", .linkage = common.linkage });
12+
}
813
}
914

1015
pub fn __fixunsdfti(a: f64) callconv(.C) u128 {
1116
return floatToInt(u128, a);
1217
}
18+
19+
const v2u64 = @Vector(2, u64);
20+
21+
fn __fixunsdfti_windows_x86_64(a: f64) callconv(.C) v2u64 {
22+
return @bitCast(v2u64, floatToInt(u128, a));
23+
}

lib/compiler_rt/fixunshfti.zig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1+
const builtin = @import("builtin");
12
const common = @import("./common.zig");
23
const floatToInt = @import("./float_to_int.zig").floatToInt;
34

45
pub const panic = common.panic;
56

67
comptime {
7-
@export(__fixunshfti, .{ .name = "__fixunshfti", .linkage = common.linkage });
8+
if (common.want_windows_v2u64_abi) {
9+
@export(__fixunshfti_windows_x86_64, .{ .name = "__fixunshfti", .linkage = common.linkage });
10+
} else {
11+
@export(__fixunshfti, .{ .name = "__fixunshfti", .linkage = common.linkage });
12+
}
813
}
914

1015
pub fn __fixunshfti(a: f16) callconv(.C) u128 {
1116
return floatToInt(u128, a);
1217
}
18+
19+
const v2u64 = @import("std").meta.Vector(2, u64);
20+
21+
fn __fixunshfti_windows_x86_64(a: f16) callconv(.C) v2u64 {
22+
return @bitCast(v2u64, floatToInt(u128, a));
23+
}

lib/compiler_rt/fixunssfti.zig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1+
const builtin = @import("builtin");
12
const common = @import("./common.zig");
23
const floatToInt = @import("./float_to_int.zig").floatToInt;
34

45
pub const panic = common.panic;
56

67
comptime {
7-
@export(__fixunssfti, .{ .name = "__fixunssfti", .linkage = common.linkage });
8+
if (common.want_windows_v2u64_abi) {
9+
@export(__fixunssfti_windows_x86_64, .{ .name = "__fixunssfti", .linkage = common.linkage });
10+
} else {
11+
@export(__fixunssfti, .{ .name = "__fixunssfti", .linkage = common.linkage });
12+
}
813
}
914

1015
pub fn __fixunssfti(a: f32) callconv(.C) u128 {
1116
return floatToInt(u128, a);
1217
}
18+
19+
const v2u64 = @Vector(2, u64);
20+
21+
fn __fixunssfti_windows_x86_64(a: f32) callconv(.C) v2u64 {
22+
return @bitCast(v2u64, floatToInt(u128, a));
23+
}

lib/compiler_rt/fixunstfti.zig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1+
const builtin = @import("builtin");
12
const common = @import("./common.zig");
23
const floatToInt = @import("./float_to_int.zig").floatToInt;
34

45
pub const panic = common.panic;
56

67
comptime {
7-
@export(__fixunstfti, .{ .name = "__fixunstfti", .linkage = common.linkage });
8+
if (common.want_windows_v2u64_abi) {
9+
@export(__fixunstfti_windows_x86_64, .{ .name = "__fixunstfti", .linkage = common.linkage });
10+
} else {
11+
@export(__fixunstfti, .{ .name = "__fixunstfti", .linkage = common.linkage });
12+
}
813
}
914

1015
pub fn __fixunstfti(a: f128) callconv(.C) u128 {
1116
return floatToInt(u128, a);
1217
}
18+
19+
const v2u64 = @Vector(2, u64);
20+
21+
fn __fixunstfti_windows_x86_64(a: f128) callconv(.C) v2u64 {
22+
return @bitCast(v2u64, floatToInt(u128, a));
23+
}

lib/compiler_rt/fixunsxfti.zig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1+
const builtin = @import("builtin");
12
const common = @import("./common.zig");
23
const floatToInt = @import("./float_to_int.zig").floatToInt;
34

45
pub const panic = common.panic;
56

67
comptime {
7-
@export(__fixunsxfti, .{ .name = "__fixunsxfti", .linkage = common.linkage });
8+
if (common.want_windows_v2u64_abi) {
9+
@export(__fixunsxfti_windows_x86_64, .{ .name = "__fixunsxfti", .linkage = common.linkage });
10+
} else {
11+
@export(__fixunsxfti, .{ .name = "__fixunsxfti", .linkage = common.linkage });
12+
}
813
}
914

1015
pub fn __fixunsxfti(a: f80) callconv(.C) u128 {
1116
return floatToInt(u128, a);
1217
}
18+
19+
const v2u64 = @Vector(2, u64);
20+
21+
fn __fixunsxfti_windows_x86_64(a: f80) callconv(.C) v2u64 {
22+
return @bitCast(v2u64, floatToInt(u128, a));
23+
}

0 commit comments

Comments
 (0)