authorgravatar for justin.b.alexander1@gmail.comvegecode <justin.b.alexander1@gmail.com> 2019-03-22 22:47:38-05:00
committergravatar for justin.b.alexander1@gmail.comvegecode <justin.b.alexander1@gmail.com> 2019-03-31 15:54:02-05:00
log38c2093500dcb7dac7cce6bbe08abe92767f24ba
treee60175c0ff898e793dc93215e695cc16c71d837f
parent310f91fb4fd61346a3d24c86f854a9af46b815bf

Add __aeabi_{f,d}{add,sub} and __{add,sub}{s,d}f3 to compiler-rt


2 files changed, 35 insertions(+), 6 deletions(-)

std/special/compiler_rt.zig+9
......@@ -21,7 +21,11 @@ comptime {
2121
2222 @export("__unordtf2", @import("compiler_rt/comparetf2.zig").__unordtf2, linkage);
2323
24 @export("__addsf3", @import("compiler_rt/addXf3.zig").__addsf3, linkage);
25 @export("__adddf3", @import("compiler_rt/addXf3.zig").__adddf3, linkage);
2426 @export("__addtf3", @import("compiler_rt/addXf3.zig").__addtf3, linkage);
27 @export("__subsf3", @import("compiler_rt/addXf3.zig").__subsf3, linkage);
28 @export("__subdf3", @import("compiler_rt/addXf3.zig").__subdf3, linkage);
2529 @export("__subtf3", @import("compiler_rt/addXf3.zig").__subtf3, linkage);
2630
2731 @export("__mulsf3", @import("compiler_rt/mulXf3.zig").__mulsf3, linkage);
......@@ -102,6 +106,11 @@ comptime {
102106 @export("__aeabi_memcmp", __aeabi_memcmp, linkage);
103107 @export("__aeabi_memcmp4", __aeabi_memcmp, linkage);
104108 @export("__aeabi_memcmp8", __aeabi_memcmp, linkage);
109
110 @export("__aeabi_fadd", @import("compiler_rt/addXf3.zig").__addsf3, linkage);
111 @export("__aeabi_dadd", @import("compiler_rt/addXf3.zig").__adddf3, linkage);
112 @export("__aeabi_fsub", @import("compiler_rt/addXf3.zig").__subsf3, linkage);
113 @export("__aeabi_dsub", @import("compiler_rt/addXf3.zig").__subdf3, linkage);
105114 }
106115 if (builtin.os == builtin.Os.windows) {
107116 switch (builtin.arch) {
std/special/compiler_rt/addXf3.zig+26-6
......@@ -6,10 +6,28 @@ const std = @import("std");
66const builtin = @import("builtin");
77const compiler_rt = @import("../compiler_rt.zig");
88
9pub extern fn __addsf3(a: f32, b: f32) f32 {
10 return addXf3(f32, a, b);
11}
12
13pub extern fn __adddf3(a: f64, b: f64) f64 {
14 return addXf3(f64, a, b);
15}
16
917pub extern fn __addtf3(a: f128, b: f128) f128 {
1018 return addXf3(f128, a, b);
1119}
1220
21pub extern fn __subsf3(a: f32, b: f32) f32 {
22 const neg_b = @bitCast(f32, @bitCast(u32, b) ^ (u32(1) << 31));
23 return addXf3(f32, a, neg_b);
24}
25
26pub extern fn __subdf3(a: f64, b: f64) f64 {
27 const neg_b = @bitCast(f64, @bitCast(u64, b) ^ (u64(1) << 63));
28 return addXf3(f64, a, neg_b);
29}
30
1331pub extern fn __subtf3(a: f128, b: f128) f128 {
1432 const neg_b = @bitCast(f128, @bitCast(u128, b) ^ (u128(1) << 127));
1533 return addXf3(f128, a, neg_b);
......@@ -17,16 +35,18 @@ pub extern fn __subtf3(a: f128, b: f128) f128 {
1735
1836inline fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
1937 const Z = @IntType(false, T.bit_count);
38 const S = @IntType(false, T.bit_count - @clz(Z(T.bit_count) - 1));
2039 const significandBits = std.math.floatMantissaBits(T);
2140 const implicitBit = Z(1) << significandBits;
2241
2342 const shift = @clz(significand.*) - @clz(implicitBit);
24 significand.* <<= @intCast(u7, shift);
43 significand.* <<= @intCast(S, shift);
2544 return 1 - shift;
2645}
2746
2847inline fn addXf3(comptime T: type, a: T, b: T) T {
2948 const Z = @IntType(false, T.bit_count);
49 const S = @IntType(false, T.bit_count - @clz(Z(T.bit_count) - 1));
3050
3151 const typeWidth = T.bit_count;
3252 const significandBits = std.math.floatMantissaBits(T);
......@@ -126,8 +146,8 @@ inline fn addXf3(comptime T: type, a: T, b: T) T {
126146 const @"align" = @intCast(Z, aExponent - bExponent);
127147 if (@"align" != 0) {
128148 if (@"align" < typeWidth) {
129 const sticky = if (bSignificand << @intCast(u7, typeWidth - @"align") != 0) Z(1) else 0;
130 bSignificand = (bSignificand >> @truncate(u7, @"align")) | sticky;
149 const sticky = if (bSignificand << @intCast(S, typeWidth - @"align") != 0) Z(1) else 0;
150 bSignificand = (bSignificand >> @truncate(S, @"align")) | sticky;
131151 } else {
132152 bSignificand = 1; // sticky; b is known to be non-zero.
133153 }
......@@ -141,7 +161,7 @@ inline fn addXf3(comptime T: type, a: T, b: T) T {
141161 // and adjust the exponent:
142162 if (aSignificand < implicitBit << 3) {
143163 const shift = @intCast(i32, @clz(aSignificand)) - @intCast(i32, @clz(implicitBit << 3));
144 aSignificand <<= @intCast(u7, shift);
164 aSignificand <<= @intCast(S, shift);
145165 aExponent -= shift;
146166 }
147167 } else { // addition
......@@ -163,8 +183,8 @@ inline fn addXf3(comptime T: type, a: T, b: T) T {
163183 // Result is denormal before rounding; the exponent is zero and we
164184 // need to shift the significand.
165185 const shift = @intCast(Z, 1 - aExponent);
166 const sticky = if (aSignificand << @intCast(u7, typeWidth - shift) != 0) Z(1) else 0;
167 aSignificand = aSignificand >> @intCast(u7, shift | sticky);
186 const sticky = if (aSignificand << @intCast(S, typeWidth - shift) != 0) Z(1) else 0;
187 aSignificand = aSignificand >> @intCast(S, shift | sticky);
168188 aExponent = 0;
169189 }
170190