authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-01-20 10:29:24+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-28 11:45:04-07:00
log4411f9c019f8f41baeacd39be01af9f961df4e4e
tree1e811c386b03682fbe32f7ce61214d6fb3027073
parentf8b204bb189125e85a7f14f08c4bab60a462e76e

add behavior tests for f80


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

src/stage1/softfloat.hpp+1-1
......@@ -57,7 +57,7 @@ static inline bool zig_f128_isNaN(float128_t *aPtr) {
5757}
5858
5959static inline bool zig_extF80_isNaN(extFloat80_t *aPtr) {
60 return aPtr->signExp & 0x7FFF && aPtr->signif;
60 return (aPtr->signExp & 0x7FFF) == 0x7FFF && aPtr->signif & UINT64_C(0x7FFFFFFFFFFFFFFF);
6161}
6262
6363#endif
test/behavior/floatop_stage1.zig+81
......@@ -4,6 +4,7 @@ const math = std.math;
44const pi = std.math.pi;
55const e = std.math.e;
66const Vector = std.meta.Vector;
7const has_f80_rt = @import("builtin").cpu.arch == .x86_64;
78
89const epsilon = 0.000001;
910
......@@ -27,6 +28,10 @@ fn testSqrt() !void {
2728 var a: f64 = 25;
2829 try expect(@sqrt(a) == 5);
2930 }
31 if (has_f80_rt) {
32 var a: f80 = 25;
33 try expect(@sqrt(a) == 5);
34 }
3035 {
3136 const a: comptime_float = 25.0;
3237 try expect(@sqrt(a) == 5.0);
......@@ -86,6 +91,10 @@ fn testSin() !void {
8691 var a: f64 = 0;
8792 try expect(@sin(a) == 0);
8893 }
94 // {
95 // var a: f80 = 0;
96 // try expect(@sin(a) == 0);
97 // }
8998 {
9099 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
91100 var result = @sin(v);
......@@ -116,6 +125,10 @@ fn testCos() !void {
116125 var a: f64 = 0;
117126 try expect(@cos(a) == 1);
118127 }
128 // {
129 // var a: f80 = 0;
130 // try expect(@cos(a) == 1);
131 // }
119132 {
120133 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
121134 var result = @cos(v);
......@@ -146,6 +159,10 @@ fn testExp() !void {
146159 var a: f64 = 0;
147160 try expect(@exp(a) == 1);
148161 }
162 // {
163 // var a: f80 = 0;
164 // try expect(@exp(a) == 1);
165 // }
149166 {
150167 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
151168 var result = @exp(v);
......@@ -176,6 +193,10 @@ fn testExp2() !void {
176193 var a: f64 = 2;
177194 try expect(@exp2(a) == 4);
178195 }
196 // {
197 // var a: f80 = 2;
198 // try expect(@exp2(a) == 4);
199 // }
179200 {
180201 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
181202 var result = @exp2(v);
......@@ -208,6 +229,10 @@ fn testLog() !void {
208229 var a: f64 = e;
209230 try expect(@log(a) == 1 or @log(a) == @bitCast(f64, @as(u64, 0x3ff0000000000000)));
210231 }
232 // {
233 // var a: f80 = e;
234 // try expect(@log(a) == 1);
235 // }
211236 {
212237 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
213238 var result = @log(v);
......@@ -238,6 +263,10 @@ fn testLog2() !void {
238263 var a: f64 = 4;
239264 try expect(@log2(a) == 2);
240265 }
266 // {
267 // var a: f80 = 4;
268 // try expect(@log2(a) == 2);
269 // }
241270 {
242271 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
243272 var result = @log2(v);
......@@ -268,6 +297,10 @@ fn testLog10() !void {
268297 var a: f64 = 1000;
269298 try expect(@log10(a) == 3);
270299 }
300 // {
301 // var a: f80 = 1000;
302 // try expect(@log10(a) == 3);
303 // }
271304 {
272305 var v: Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
273306 var result = @log10(v);
......@@ -304,6 +337,12 @@ fn testFabs() !void {
304337 try expect(@fabs(a) == 2.5);
305338 try expect(@fabs(b) == 2.5);
306339 }
340 // {
341 // var a: f80 = -2.5;
342 // var b: f80 = 2.5;
343 // try expect(@fabs(a) == 2.5);
344 // try expect(@fabs(b) == 2.5);
345 // }
307346 {
308347 var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
309348 var result = @fabs(v);
......@@ -334,6 +373,10 @@ fn testFloor() !void {
334373 var a: f64 = 3.5;
335374 try expect(@floor(a) == 3);
336375 }
376 // {
377 // var a: f80 = 3.5;
378 // try expect(@floor(a) == 3);
379 // }
337380 {
338381 var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
339382 var result = @floor(v);
......@@ -364,6 +407,10 @@ fn testCeil() !void {
364407 var a: f64 = 3.5;
365408 try expect(@ceil(a) == 4);
366409 }
410 // {
411 // var a: f80 = 3.5;
412 // try expect(@ceil(a) == 4);
413 // }
367414 {
368415 var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
369416 var result = @ceil(v);
......@@ -394,6 +441,10 @@ fn testTrunc() !void {
394441 var a: f64 = -3.5;
395442 try expect(@trunc(a) == -3);
396443 }
444 // {
445 // var a: f80 = -3.5;
446 // try expect(@trunc(a) == -3);
447 // }
397448 {
398449 var v: Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
399450 var result = @trunc(v);
......@@ -403,3 +454,33 @@ fn testTrunc() !void {
403454 try expect(math.approxEqAbs(f32, @trunc(@as(f32, -0.4)), result[3], epsilon));
404455 }
405456}
457
458test "floating point comparisons" {
459 if (has_f80_rt) try testFloatComparisons();
460 comptime try testFloatComparisons();
461}
462
463fn testFloatComparisons() !void {
464 inline for ([_]type{ f16, f32, f64, f80, f128 }) |ty| {
465 // No decimal part
466 {
467 const x: ty = 1.0;
468 try expect(x == 1);
469 try expect(x != 0);
470 try expect(x > 0);
471 try expect(x < 2);
472 try expect(x >= 1);
473 try expect(x <= 1);
474 }
475 // Non-zero decimal part
476 {
477 const x: ty = 1.5;
478 try expect(x != 1);
479 try expect(x != 2);
480 try expect(x > 1);
481 try expect(x < 2);
482 try expect(x >= 1);
483 try expect(x <= 2);
484 }
485 }
486}
test/behavior/math_stage1.zig+19
......@@ -5,6 +5,7 @@ const expectEqualSlices = std.testing.expectEqualSlices;
55const maxInt = std.math.maxInt;
66const minInt = std.math.minInt;
77const mem = std.mem;
8const has_f80_rt = @import("builtin").cpu.arch == .x86_64;
89
910test "allow signed integer division/remainder when values are comptime known and positive or exact" {
1011 try expect(5 / 3 == 1);
......@@ -194,6 +195,8 @@ fn testSqrt(comptime T: type, x: T) !void {
194195test "@fabs" {
195196 try testFabs(f128, 12.0);
196197 comptime try testFabs(f128, 12.0);
198 if (has_f80_rt) try testFabs(f80, 12.0);
199 // comptime try testFabs(f80, 12.0);
197200 try testFabs(f64, 12.0);
198201 comptime try testFabs(f64, 12.0);
199202 try testFabs(f32, 12.0);
......@@ -217,6 +220,8 @@ test "@floor" {
217220 // FIXME: Generates a floorl function call
218221 // testFloor(f128, 12.0);
219222 comptime try testFloor(f128, 12.0);
223 // try testFloor(f80, 12.0);
224 comptime try testFloor(f80, 12.0);
220225 try testFloor(f64, 12.0);
221226 comptime try testFloor(f64, 12.0);
222227 try testFloor(f32, 12.0);
......@@ -240,6 +245,8 @@ test "@ceil" {
240245 // FIXME: Generates a ceill function call
241246 //testCeil(f128, 12.0);
242247 comptime try testCeil(f128, 12.0);
248 // try testCeil(f80, 12.0);
249 comptime try testCeil(f80, 12.0);
243250 try testCeil(f64, 12.0);
244251 comptime try testCeil(f64, 12.0);
245252 try testCeil(f32, 12.0);
......@@ -263,6 +270,14 @@ test "@trunc" {
263270 // FIXME: Generates a truncl function call
264271 //testTrunc(f128, 12.0);
265272 comptime try testTrunc(f128, 12.0);
273 // try testTrunc(f80, 12.0);
274 // comptime try testTrunc(f80, 12.0);
275 comptime {
276 const x: f80 = 12.0;
277 const y = x + 0.8;
278 const z = @trunc(y);
279 try expectEqual(x, z);
280 }
266281 try testTrunc(f64, 12.0);
267282 comptime try testTrunc(f64, 12.0);
268283 try testTrunc(f32, 12.0);
......@@ -294,6 +309,8 @@ test "@round" {
294309 // FIXME: Generates a roundl function call
295310 //testRound(f128, 12.0);
296311 comptime try testRound(f128, 12.0);
312 // try testRound(f80, 12.0);
313 comptime try testRound(f80, 12.0);
297314 try testRound(f64, 12.0);
298315 comptime try testRound(f64, 12.0);
299316 try testRound(f32, 12.0);
......@@ -333,10 +350,12 @@ test "NaN comparison" {
333350 try testNanEqNan(f32);
334351 try testNanEqNan(f64);
335352 try testNanEqNan(f128);
353 if (has_f80_rt) try testNanEqNan(f80);
336354 comptime try testNanEqNan(f16);
337355 comptime try testNanEqNan(f32);
338356 comptime try testNanEqNan(f64);
339357 comptime try testNanEqNan(f128);
358 // comptime try testNanEqNan(f80);
340359}
341360
342361fn testNanEqNan(comptime F: type) !void {
test/behavior/muladd.zig+6
......@@ -25,6 +25,12 @@ fn testMulAdd() !void {
2525 var c: f64 = 6.25;
2626 try expect(@mulAdd(f64, a, b, c) == 20);
2727 }
28 // {
29 // var a: f16 = 5.5;
30 // var b: f80 = 2.5;
31 // var c: f80 = 6.25;
32 // try expect(@mulAdd(f80, a, b, c) == 20);
33 // }
2834 if (builtin.os.tag == .macos and builtin.cpu.arch == .aarch64) {
2935 // https://github.com/ziglang/zig/issues/9900
3036 return error.SkipZigTest;
test/behavior/type_stage1.zig+2-1
......@@ -13,8 +13,9 @@ test "Type.Float" {
1313 try testing.expect(f16 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 16 } }));
1414 try testing.expect(f32 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 32 } }));
1515 try testing.expect(f64 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 64 } }));
16 try testing.expect(f80 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 80 } }));
1617 try testing.expect(f128 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 128 } }));
17 try testTypes(&[_]type{ f16, f32, f64, f128 });
18 try testTypes(&[_]type{ f16, f32, f64, f80, f128 });
1819}
1920
2021test "Type.Array" {
test/behavior/widening.zig+5
......@@ -2,6 +2,7 @@ const std = @import("std");
22const expect = std.testing.expect;
33const mem = std.mem;
44const builtin = @import("builtin");
5const has_f80_rt = @import("builtin").cpu.arch == .x86_64;
56
67test "integer widening" {
78 var a: u8 = 250;
......@@ -27,6 +28,10 @@ test "float widening" {
2728 try expect(a == b);
2829 try expect(b == c);
2930 try expect(c == d);
31 if (has_f80_rt) {
32 var e: f80 = c;
33 try expect(c == e);
34 }
3035}
3136
3237test "float widening f16 to f128" {