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 {...@@ -21,7 +21,11 @@ comptime {
2121
22 @export("__unordtf2", @import("compiler_rt/comparetf2.zig").__unordtf2, linkage);22 @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);
24 @export("__addtf3", @import("compiler_rt/addXf3.zig").__addtf3, linkage);26 @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);
25 @export("__subtf3", @import("compiler_rt/addXf3.zig").__subtf3, linkage);29 @export("__subtf3", @import("compiler_rt/addXf3.zig").__subtf3, linkage);
2630
27 @export("__mulsf3", @import("compiler_rt/mulXf3.zig").__mulsf3, linkage);31 @export("__mulsf3", @import("compiler_rt/mulXf3.zig").__mulsf3, linkage);
...@@ -102,6 +106,11 @@ comptime {...@@ -102,6 +106,11 @@ comptime {
102 @export("__aeabi_memcmp", __aeabi_memcmp, linkage);106 @export("__aeabi_memcmp", __aeabi_memcmp, linkage);
103 @export("__aeabi_memcmp4", __aeabi_memcmp, linkage);107 @export("__aeabi_memcmp4", __aeabi_memcmp, linkage);
104 @export("__aeabi_memcmp8", __aeabi_memcmp, linkage);108 @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);
105 }114 }
106 if (builtin.os == builtin.Os.windows) {115 if (builtin.os == builtin.Os.windows) {
107 switch (builtin.arch) {116 switch (builtin.arch) {
std/special/compiler_rt/addXf3.zig+26-6
...@@ -6,10 +6,28 @@ const std = @import("std");...@@ -6,10 +6,28 @@ const std = @import("std");
6const builtin = @import("builtin");6const builtin = @import("builtin");
7const compiler_rt = @import("../compiler_rt.zig");7const 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
9pub extern fn __addtf3(a: f128, b: f128) f128 {17pub extern fn __addtf3(a: f128, b: f128) f128 {
10 return addXf3(f128, a, b);18 return addXf3(f128, a, b);
11}19}
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
13pub extern fn __subtf3(a: f128, b: f128) f128 {31pub extern fn __subtf3(a: f128, b: f128) f128 {
14 const neg_b = @bitCast(f128, @bitCast(u128, b) ^ (u128(1) << 127));32 const neg_b = @bitCast(f128, @bitCast(u128, b) ^ (u128(1) << 127));
15 return addXf3(f128, a, neg_b);33 return addXf3(f128, a, neg_b);
...@@ -17,16 +35,18 @@ pub extern fn __subtf3(a: f128, b: f128) f128 {...@@ -17,16 +35,18 @@ pub extern fn __subtf3(a: f128, b: f128) f128 {
1735
18inline fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {36inline fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
19 const Z = @IntType(false, T.bit_count);37 const Z = @IntType(false, T.bit_count);
38 const S = @IntType(false, T.bit_count - @clz(Z(T.bit_count) - 1));
20 const significandBits = std.math.floatMantissaBits(T);39 const significandBits = std.math.floatMantissaBits(T);
21 const implicitBit = Z(1) << significandBits;40 const implicitBit = Z(1) << significandBits;
2241
23 const shift = @clz(significand.*) - @clz(implicitBit);42 const shift = @clz(significand.*) - @clz(implicitBit);
24 significand.* <<= @intCast(u7, shift);43 significand.* <<= @intCast(S, shift);
25 return 1 - shift;44 return 1 - shift;
26}45}
2746
28inline fn addXf3(comptime T: type, a: T, b: T) T {47inline fn addXf3(comptime T: type, a: T, b: T) T {
29 const Z = @IntType(false, T.bit_count);48 const Z = @IntType(false, T.bit_count);
49 const S = @IntType(false, T.bit_count - @clz(Z(T.bit_count) - 1));
3050
31 const typeWidth = T.bit_count;51 const typeWidth = T.bit_count;
32 const significandBits = std.math.floatMantissaBits(T);52 const significandBits = std.math.floatMantissaBits(T);
...@@ -126,8 +146,8 @@ inline fn addXf3(comptime T: type, a: T, b: T) T {...@@ -126,8 +146,8 @@ inline fn addXf3(comptime T: type, a: T, b: T) T {
126 const @"align" = @intCast(Z, aExponent - bExponent);146 const @"align" = @intCast(Z, aExponent - bExponent);
127 if (@"align" != 0) {147 if (@"align" != 0) {
128 if (@"align" < typeWidth) {148 if (@"align" < typeWidth) {
129 const sticky = if (bSignificand << @intCast(u7, typeWidth - @"align") != 0) Z(1) else 0;149 const sticky = if (bSignificand << @intCast(S, typeWidth - @"align") != 0) Z(1) else 0;
130 bSignificand = (bSignificand >> @truncate(u7, @"align")) | sticky;150 bSignificand = (bSignificand >> @truncate(S, @"align")) | sticky;
131 } else {151 } else {
132 bSignificand = 1; // sticky; b is known to be non-zero.152 bSignificand = 1; // sticky; b is known to be non-zero.
133 }153 }
...@@ -141,7 +161,7 @@ inline fn addXf3(comptime T: type, a: T, b: T) T {...@@ -141,7 +161,7 @@ inline fn addXf3(comptime T: type, a: T, b: T) T {
141 // and adjust the exponent:161 // and adjust the exponent:
142 if (aSignificand < implicitBit << 3) {162 if (aSignificand < implicitBit << 3) {
143 const shift = @intCast(i32, @clz(aSignificand)) - @intCast(i32, @clz(implicitBit << 3));163 const shift = @intCast(i32, @clz(aSignificand)) - @intCast(i32, @clz(implicitBit << 3));
144 aSignificand <<= @intCast(u7, shift);164 aSignificand <<= @intCast(S, shift);
145 aExponent -= shift;165 aExponent -= shift;
146 }166 }
147 } else { // addition167 } else { // addition
...@@ -163,8 +183,8 @@ inline fn addXf3(comptime T: type, a: T, b: T) T {...@@ -163,8 +183,8 @@ inline fn addXf3(comptime T: type, a: T, b: T) T {
163 // Result is denormal before rounding; the exponent is zero and we183 // Result is denormal before rounding; the exponent is zero and we
164 // need to shift the significand.184 // need to shift the significand.
165 const shift = @intCast(Z, 1 - aExponent);185 const shift = @intCast(Z, 1 - aExponent);
166 const sticky = if (aSignificand << @intCast(u7, typeWidth - shift) != 0) Z(1) else 0;186 const sticky = if (aSignificand << @intCast(S, typeWidth - shift) != 0) Z(1) else 0;
167 aSignificand = aSignificand >> @intCast(u7, shift | sticky);187 aSignificand = aSignificand >> @intCast(S, shift | sticky);
168 aExponent = 0;188 aExponent = 0;
169 }189 }
170190