Skip to content

Commit c8d2f5f

Browse files
committed
compiler_rt: Update Windows ABI for float<->int conversion routines
Starting with LLVM 14, the Libcalls to these functions are now lowered using a Vec(2, u64) instead of the standard ABI for i128 integers, so our compiler-rt implementation needs to be updated to expose the same ABI on Windows.
1 parent b88151e commit c8d2f5f

21 files changed

+305
-39
lines changed

lib/compiler_rt/fixdfti.zig

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1+
const builtin = @import("builtin");
2+
const arch = builtin.cpu.arch;
13
const common = @import("./common.zig");
24
const floatToInt = @import("./float_to_int.zig").floatToInt;
35

46
pub const panic = common.panic;
57

68
comptime {
7-
@export(__fixdfti, .{ .name = "__fixdfti", .linkage = common.linkage });
9+
const fixdfti_fn = if (builtin.os.tag == .windows and arch == .x86_64) b: {
10+
// The "ti" functions must use Vector(2, u64) return types to adhere to the ABI
11+
// that LLVM expects compiler-rt to have.
12+
break :b __fixdfti_windows_x86_64;
13+
} else __fixdfti;
14+
15+
@export(fixdfti_fn, .{ .name = "__fixdfti", .linkage = common.linkage });
816
}
917

1018
pub fn __fixdfti(a: f64) callconv(.C) i128 {
1119
return floatToInt(i128, a);
1220
}
21+
22+
const v128 = @import("std").meta.Vector(2, u64);
23+
24+
fn __fixdfti_windows_x86_64(a: f64) callconv(.C) v128 {
25+
return @bitCast(v128, floatToInt(i128, a));
26+
}

lib/compiler_rt/fixhfti.zig

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

46
pub const panic = common.panic;
57

68
comptime {
7-
@export(__fixhfti, .{ .name = "__fixhfti", .linkage = common.linkage });
9+
const fixhfti_fn = if (builtin.os.tag == .windows and arch == .x86_64) b: {
10+
// The "ti" functions must use Vector(2, u64) return types to adhere to the ABI
11+
// that LLVM expects compiler-rt to have.
12+
break :b __fixhfti_windows_x86_64;
13+
} else __fixhfti;
14+
15+
@export(fixhfti_fn, .{ .name = "__fixhfti", .linkage = common.linkage });
816
}
917

10-
fn __fixhfti(a: f16) callconv(.C) i128 {
18+
pub fn __fixhfti(a: f16) callconv(.C) i128 {
1119
return floatToInt(i128, a);
1220
}
21+
22+
const v128 = @import("std").meta.Vector(2, u64);
23+
24+
fn __fixhfti_windows_x86_64(a: f16) callconv(.C) v128 {
25+
return @bitCast(v128, floatToInt(i128, a));
26+
}

lib/compiler_rt/fixsfti.zig

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1+
const builtin = @import("builtin");
2+
const arch = builtin.cpu.arch;
13
const common = @import("./common.zig");
24
const floatToInt = @import("./float_to_int.zig").floatToInt;
35

46
pub const panic = common.panic;
57

68
comptime {
7-
@export(__fixsfti, .{ .name = "__fixsfti", .linkage = common.linkage });
9+
const fixsfti_fn = if (builtin.os.tag == .windows and arch == .x86_64) b: {
10+
// The "ti" functions must use Vector(2, u64) return types to adhere to the ABI
11+
// that LLVM expects compiler-rt to have.
12+
break :b __fixsfti_windows_x86_64;
13+
} else __fixsfti;
14+
15+
@export(fixsfti_fn, .{ .name = "__fixsfti", .linkage = common.linkage });
816
}
917

1018
pub fn __fixsfti(a: f32) callconv(.C) i128 {
1119
return floatToInt(i128, a);
1220
}
21+
22+
const v128 = @import("std").meta.Vector(2, u64);
23+
24+
fn __fixsfti_windows_x86_64(a: f32) callconv(.C) v128 {
25+
return @bitCast(v128, floatToInt(i128, a));
26+
}

lib/compiler_rt/fixtfti.zig

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1+
const builtin = @import("builtin");
2+
const arch = builtin.cpu.arch;
13
const common = @import("./common.zig");
24
const floatToInt = @import("./float_to_int.zig").floatToInt;
35

46
pub const panic = common.panic;
57

68
comptime {
7-
@export(__fixtfti, .{ .name = "__fixtfti", .linkage = common.linkage });
9+
const fixtfti_fn = if (builtin.os.tag == .windows and arch == .x86_64) b: {
10+
// The "ti" functions must use Vector(2, u64) return types to adhere to the ABI
11+
// that LLVM expects compiler-rt to have.
12+
break :b __fixtfti_windows_x86_64;
13+
} else __fixtfti;
14+
15+
@export(fixtfti_fn, .{ .name = "__fixtfti", .linkage = common.linkage });
816
}
917

1018
pub fn __fixtfti(a: f128) callconv(.C) i128 {
1119
return floatToInt(i128, a);
1220
}
21+
22+
const v128 = @import("std").meta.Vector(2, u64);
23+
24+
fn __fixtfti_windows_x86_64(a: f128) callconv(.C) v128 {
25+
return @bitCast(v128, floatToInt(i128, a));
26+
}

lib/compiler_rt/fixunsdfti.zig

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1+
const builtin = @import("builtin");
2+
const arch = builtin.cpu.arch;
13
const common = @import("./common.zig");
24
const floatToInt = @import("./float_to_int.zig").floatToInt;
35

46
pub const panic = common.panic;
57

68
comptime {
7-
@export(__fixunsdfti, .{ .name = "__fixunsdfti", .linkage = common.linkage });
9+
const fixunsdfti_fn = if (builtin.os.tag == .windows and arch == .x86_64) b: {
10+
// The "ti" functions must use Vector(2, u64) return types to adhere to the ABI
11+
// that LLVM expects compiler-rt to have.
12+
break :b __fixunsdfti_windows_x86_64;
13+
} else __fixunsdfti;
14+
15+
@export(fixunsdfti_fn, .{ .name = "__fixunsdfti", .linkage = common.linkage });
816
}
917

1018
pub fn __fixunsdfti(a: f64) callconv(.C) u128 {
1119
return floatToInt(u128, a);
1220
}
21+
22+
const v128 = @import("std").meta.Vector(2, u64);
23+
24+
fn __fixunsdfti_windows_x86_64(a: f64) callconv(.C) v128 {
25+
return @bitCast(v128, floatToInt(u128, a));
26+
}

lib/compiler_rt/fixunshfti.zig

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1+
const builtin = @import("builtin");
2+
const arch = builtin.cpu.arch;
13
const common = @import("./common.zig");
24
const floatToInt = @import("./float_to_int.zig").floatToInt;
35

46
pub const panic = common.panic;
57

68
comptime {
7-
@export(__fixunshfti, .{ .name = "__fixunshfti", .linkage = common.linkage });
9+
const fixunshfti_fn = if (builtin.os.tag == .windows and arch == .x86_64) b: {
10+
// The "ti" functions must use Vector(2, u64) return types to adhere to the ABI
11+
// that LLVM expects compiler-rt to have.
12+
break :b __fixunshfti_windows_x86_64;
13+
} else __fixunshfti;
14+
15+
@export(fixunshfti_fn, .{ .name = "__fixunshfti", .linkage = common.linkage });
816
}
917

1018
pub fn __fixunshfti(a: f16) callconv(.C) u128 {
1119
return floatToInt(u128, a);
1220
}
21+
22+
const v128 = @import("std").meta.Vector(2, u64);
23+
24+
fn __fixunshfti_windows_x86_64(a: f16) callconv(.C) v128 {
25+
return @bitCast(v128, floatToInt(u128, a));
26+
}

lib/compiler_rt/fixunssfti.zig

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1+
const builtin = @import("builtin");
2+
const arch = builtin.cpu.arch;
13
const common = @import("./common.zig");
24
const floatToInt = @import("./float_to_int.zig").floatToInt;
35

46
pub const panic = common.panic;
57

68
comptime {
7-
@export(__fixunssfti, .{ .name = "__fixunssfti", .linkage = common.linkage });
9+
const fixunssfti_fn = if (builtin.os.tag == .windows and arch == .x86_64) b: {
10+
// The "ti" functions must use Vector(2, u64) return types to adhere to the ABI
11+
// that LLVM expects compiler-rt to have.
12+
break :b __fixunssfti_windows_x86_64;
13+
} else __fixunssfti;
14+
15+
@export(fixunssfti_fn, .{ .name = "__fixunssfti", .linkage = common.linkage });
816
}
917

1018
pub fn __fixunssfti(a: f32) callconv(.C) u128 {
1119
return floatToInt(u128, a);
1220
}
21+
22+
const v128 = @import("std").meta.Vector(2, u64);
23+
24+
fn __fixunssfti_windows_x86_64(a: f32) callconv(.C) v128 {
25+
return @bitCast(v128, floatToInt(u128, a));
26+
}

lib/compiler_rt/fixunstfti.zig

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1+
const builtin = @import("builtin");
2+
const arch = builtin.cpu.arch;
13
const common = @import("./common.zig");
24
const floatToInt = @import("./float_to_int.zig").floatToInt;
35

46
pub const panic = common.panic;
57

68
comptime {
7-
@export(__fixunstfti, .{ .name = "__fixunstfti", .linkage = common.linkage });
9+
const fixunstfti_fn = if (builtin.os.tag == .windows and arch == .x86_64) b: {
10+
// The "ti" functions must use Vector(2, u64) return types to adhere to the ABI
11+
// that LLVM expects compiler-rt to have.
12+
break :b __fixunstfti_windows_x86_64;
13+
} else __fixunstfti;
14+
15+
@export(fixunstfti_fn, .{ .name = "__fixunstfti", .linkage = common.linkage });
816
}
917

1018
pub fn __fixunstfti(a: f128) callconv(.C) u128 {
1119
return floatToInt(u128, a);
1220
}
21+
22+
const v128 = @import("std").meta.Vector(2, u64);
23+
24+
fn __fixunstfti_windows_x86_64(a: f128) callconv(.C) v128 {
25+
return @bitCast(v128, floatToInt(u128, a));
26+
}

lib/compiler_rt/fixunsxfti.zig

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1+
const builtin = @import("builtin");
2+
const arch = builtin.cpu.arch;
13
const common = @import("./common.zig");
24
const floatToInt = @import("./float_to_int.zig").floatToInt;
35

46
pub const panic = common.panic;
57

68
comptime {
7-
@export(__fixunsxfti, .{ .name = "__fixunsxfti", .linkage = common.linkage });
9+
const fixunsxfti_fn = if (builtin.os.tag == .windows and arch == .x86_64) b: {
10+
// The "ti" functions must use Vector(2, u64) return types to adhere to the ABI
11+
// that LLVM expects compiler-rt to have.
12+
break :b __fixunsxfti_windows_x86_64;
13+
} else __fixunsxfti;
14+
15+
@export(fixunsxfti_fn, .{ .name = "__fixunsxfti", .linkage = common.linkage });
816
}
917

1018
pub fn __fixunsxfti(a: f80) callconv(.C) u128 {
1119
return floatToInt(u128, a);
1220
}
21+
22+
const v128 = @import("std").meta.Vector(2, u64);
23+
24+
fn __fixunsxfti_windows_x86_64(a: f80) callconv(.C) v128 {
25+
return @bitCast(v128, floatToInt(u128, a));
26+
}

lib/compiler_rt/fixxfti.zig

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

46
pub const panic = common.panic;
57

68
comptime {
7-
@export(__fixxfti, .{ .name = "__fixxfti", .linkage = common.linkage });
9+
const fixxfti_fn = if (builtin.os.tag == .windows and arch == .x86_64) b: {
10+
// The "ti" functions must use Vector(2, u64) return types to adhere to the ABI
11+
// that LLVM expects compiler-rt to have.
12+
break :b __fixxfti_windows_x86_64;
13+
} else __fixxfti;
14+
15+
@export(fixxfti_fn, .{ .name = "__fixxfti", .linkage = common.linkage });
816
}
917

10-
fn __fixxfti(a: f80) callconv(.C) i128 {
18+
pub fn __fixxfti(a: f80) callconv(.C) i128 {
1119
return floatToInt(i128, a);
1220
}
21+
22+
const v128 = @import("std").meta.Vector(2, u64);
23+
24+
fn __fixxfti_windows_x86_64(a: f80) callconv(.C) v128 {
25+
return @bitCast(v128, floatToInt(i128, a));
26+
}

0 commit comments

Comments
 (0)