authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-02 13:37:24-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-11-02 13:37:24-05:00
log061ff11b2b8aca33fec0d5d381855d5bd3aa6ff9
tree43488e010c69f136e7d7a91535ad477ecafcc6fb
parentecdd6366052ec815466db0c64b2a5abe59267393
parentdc872a221d8301cfac4b9ead09196c5b18cf63b2
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #6927 from LemonBoy/mipsbe-std

Fixes for stdlib for mips BE targets

7 files changed, 77 insertions(+), 122 deletions(-)

lib/std/array_hash_map.zig-3
......@@ -930,9 +930,6 @@ test "basic hash map usage" {
930930}
931931
932932test "iterator hash map" {
933 // https://github.com/ziglang/zig/issues/5127
934 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
935
936933 var reset_map = AutoArrayHashMap(i32, i32).init(std.testing.allocator);
937934 defer reset_map.deinit();
938935
lib/std/io/test.zig-3
......@@ -140,9 +140,6 @@ test "File seek ops" {
140140}
141141
142142test "setEndPos" {
143 // https://github.com/ziglang/zig/issues/5127
144 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
145
146143 var tmp = tmpDir(.{});
147144 defer tmp.cleanup();
148145
lib/std/json.zig+11-13
......@@ -2125,7 +2125,11 @@ fn unescapeString(output: []u8, input: []const u8) !void {
21252125
21262126 const secondCodeUnit = std.fmt.parseInt(u16, input[inIndex + 8 .. inIndex + 12], 16) catch unreachable;
21272127
2128 if (std.unicode.utf16leToUtf8(output[outIndex..], &[2]u16{ firstCodeUnit, secondCodeUnit })) |byteCount| {
2128 const utf16le_seq = [2]u16{
2129 mem.littleToNative(u16, firstCodeUnit),
2130 mem.littleToNative(u16, secondCodeUnit),
2131 };
2132 if (std.unicode.utf16leToUtf8(output[outIndex..], &utf16le_seq)) |byteCount| {
21292133 outIndex += byteCount;
21302134 inIndex += 12;
21312135 } else |_| {
......@@ -2265,9 +2269,6 @@ test "integer after float has proper type" {
22652269}
22662270
22672271test "escaped characters" {
2268 // https://github.com/ziglang/zig/issues/5127
2269 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
2270
22712272 var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator);
22722273 defer arena_allocator.deinit();
22732274 const input =
......@@ -2300,9 +2301,6 @@ test "escaped characters" {
23002301}
23012302
23022303test "string copy option" {
2303 // https://github.com/ziglang/zig/issues/5127
2304 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
2305
23062304 const input =
23072305 \\{
23082306 \\ "noescape": "aą😂",
......@@ -2721,9 +2719,9 @@ test "stringify struct with indentation" {
27212719 \\}
27222720 ,
27232721 struct {
2724 foo: u32,
2725 bar: [3]u32,
2726 }{
2722 foo: u32,
2723 bar: [3]u32,
2724 }{
27272725 .foo = 42,
27282726 .bar = .{ 1, 2, 3 },
27292727 },
......@@ -2734,9 +2732,9 @@ test "stringify struct with indentation" {
27342732 try teststringify(
27352733 "{\n\t\"foo\":42,\n\t\"bar\":[\n\t\t1,\n\t\t2,\n\t\t3\n\t]\n}",
27362734 struct {
2737 foo: u32,
2738 bar: [3]u32,
2739 }{
2735 foo: u32,
2736 bar: [3]u32,
2737 }{
27402738 .foo = 42,
27412739 .bar = .{ 1, 2, 3 },
27422740 },
lib/std/json/test.zig-69
......@@ -337,18 +337,12 @@ test "y_string_1_2_3_bytes_UTF-8_sequences" {
337337}
338338
339339test "y_string_accepted_surrogate_pair" {
340 // https://github.com/ziglang/zig/issues/5127
341 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
342
343340 ok(
344341 \\["\uD801\udc37"]
345342 );
346343}
347344
348345test "y_string_accepted_surrogate_pairs" {
349 // https://github.com/ziglang/zig/issues/5127
350 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
351
352346 ok(
353347 \\["\ud83d\ude39\ud83d\udc8d"]
354348 );
......@@ -415,9 +409,6 @@ test "y_string_in_array_with_leading_space" {
415409}
416410
417411test "y_string_last_surrogates_1_and_2" {
418 // https://github.com/ziglang/zig/issues/5127
419 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
420
421412 ok(
422413 \\["\uDBFF\uDFFF"]
423414 );
......@@ -478,9 +469,6 @@ test "y_string_space" {
478469}
479470
480471test "y_string_surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF" {
481 // https://github.com/ziglang/zig/issues/5127
482 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
483
484472 ok(
485473 \\["\uD834\uDd1e"]
486474 );
......@@ -523,90 +511,60 @@ test "y_string_unescaped_char_delete" {
523511}
524512
525513test "y_string_unicode_2" {
526 // https://github.com/ziglang/zig/issues/5127
527 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
528
529514 ok(
530515 \\["⍂㈴⍂"]
531516 );
532517}
533518
534519test "y_string_unicodeEscapedBackslash" {
535 // https://github.com/ziglang/zig/issues/5127
536 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
537
538520 ok(
539521 \\["\u005C"]
540522 );
541523}
542524
543525test "y_string_unicode_escaped_double_quote" {
544 // https://github.com/ziglang/zig/issues/5127
545 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
546
547526 ok(
548527 \\["\u0022"]
549528 );
550529}
551530
552531test "y_string_unicode" {
553 // https://github.com/ziglang/zig/issues/5127
554 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
555
556532 ok(
557533 \\["\uA66D"]
558534 );
559535}
560536
561537test "y_string_unicode_U+10FFFE_nonchar" {
562 // https://github.com/ziglang/zig/issues/5127
563 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
564
565538 ok(
566539 \\["\uDBFF\uDFFE"]
567540 );
568541}
569542
570543test "y_string_unicode_U+1FFFE_nonchar" {
571 // https://github.com/ziglang/zig/issues/5127
572 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
573
574544 ok(
575545 \\["\uD83F\uDFFE"]
576546 );
577547}
578548
579549test "y_string_unicode_U+200B_ZERO_WIDTH_SPACE" {
580 // https://github.com/ziglang/zig/issues/5127
581 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
582
583550 ok(
584551 \\["\u200B"]
585552 );
586553}
587554
588555test "y_string_unicode_U+2064_invisible_plus" {
589 // https://github.com/ziglang/zig/issues/5127
590 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
591
592556 ok(
593557 \\["\u2064"]
594558 );
595559}
596560
597561test "y_string_unicode_U+FDD0_nonchar" {
598 // https://github.com/ziglang/zig/issues/5127
599 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
600
601562 ok(
602563 \\["\uFDD0"]
603564 );
604565}
605566
606567test "y_string_unicode_U+FFFE_nonchar" {
607 // https://github.com/ziglang/zig/issues/5127
608 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
609
610568 ok(
611569 \\["\uFFFE"]
612570 );
......@@ -1858,63 +1816,42 @@ test "i_object_key_lone_2nd_surrogate" {
18581816}
18591817
18601818test "i_string_1st_surrogate_but_2nd_missing" {
1861 // https://github.com/ziglang/zig/issues/5127
1862 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
1863
18641819 anyStreamingErrNonStreaming(
18651820 \\["\uDADA"]
18661821 );
18671822}
18681823
18691824test "i_string_1st_valid_surrogate_2nd_invalid" {
1870 // https://github.com/ziglang/zig/issues/5127
1871 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
1872
18731825 anyStreamingErrNonStreaming(
18741826 \\["\uD888\u1234"]
18751827 );
18761828}
18771829
18781830test "i_string_incomplete_surrogate_and_escape_valid" {
1879 // https://github.com/ziglang/zig/issues/5127
1880 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
1881
18821831 anyStreamingErrNonStreaming(
18831832 \\["\uD800\n"]
18841833 );
18851834}
18861835
18871836test "i_string_incomplete_surrogate_pair" {
1888 // https://github.com/ziglang/zig/issues/5127
1889 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
1890
18911837 anyStreamingErrNonStreaming(
18921838 \\["\uDd1ea"]
18931839 );
18941840}
18951841
18961842test "i_string_incomplete_surrogates_escape_valid" {
1897 // https://github.com/ziglang/zig/issues/5127
1898 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
1899
19001843 anyStreamingErrNonStreaming(
19011844 \\["\uD800\uD800\n"]
19021845 );
19031846}
19041847
19051848test "i_string_invalid_lonely_surrogate" {
1906 // https://github.com/ziglang/zig/issues/5127
1907 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
1908
19091849 anyStreamingErrNonStreaming(
19101850 \\["\ud800"]
19111851 );
19121852}
19131853
19141854test "i_string_invalid_surrogate" {
1915 // https://github.com/ziglang/zig/issues/5127
1916 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
1917
19181855 anyStreamingErrNonStreaming(
19191856 \\["\ud800abc"]
19201857 );
......@@ -1927,9 +1864,6 @@ test "i_string_invalid_utf-8" {
19271864}
19281865
19291866test "i_string_inverted_surrogates_U+1D11E" {
1930 // https://github.com/ziglang/zig/issues/5127
1931 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
1932
19331867 anyStreamingErrNonStreaming(
19341868 \\["\uDd1e\uD834"]
19351869 );
......@@ -1942,9 +1876,6 @@ test "i_string_iso_latin_1" {
19421876}
19431877
19441878test "i_string_lone_second_surrogate" {
1945 // https://github.com/ziglang/zig/issues/5127
1946 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
1947
19481879 anyStreamingErrNonStreaming(
19491880 \\["\uDFAA"]
19501881 );
lib/std/os/linux.zig+46-22
......@@ -48,13 +48,27 @@ pub fn getauxval(index: usize) usize {
4848 return 0;
4949}
5050
51// Some architectures require 64bit parameters for some syscalls to be passed in
52// even-aligned register pair
51// Some architectures (and some syscalls) require 64bit parameters to be passed
52// in a even-aligned register pair.
5353const require_aligned_register_pair = //
5454 std.Target.current.cpu.arch.isMIPS() or
5555 std.Target.current.cpu.arch.isARM() or
5656 std.Target.current.cpu.arch.isThumb();
5757
58// Split a 64bit value into a {LSB,MSB} pair.
59fn splitValue64(val: u64) [2]u32 {
60 switch (builtin.endian) {
61 .Little => return [2]u32{
62 @truncate(u32, val),
63 @truncate(u32, val >> 32),
64 },
65 .Big => return [2]u32{
66 @truncate(u32, val >> 32),
67 @truncate(u32, val),
68 },
69 }
70}
71
5872/// Get the errno from a syscall return value, or 0 for no error.
5973pub fn getErrno(r: usize) u12 {
6074 const signed_r = @bitCast(isize, r);
......@@ -263,24 +277,26 @@ pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
263277}
264278
265279pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize {
280 const offset_halves = splitValue64(offset);
266281 return syscall5(
267282 .preadv,
268283 @bitCast(usize, @as(isize, fd)),
269284 @ptrToInt(iov),
270285 count,
271 @truncate(usize, offset),
272 @truncate(usize, offset >> 32),
286 offset_halves[0],
287 offset_halves[1],
273288 );
274289}
275290
276291pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: kernel_rwf) usize {
292 const offset_halves = splitValue64(offset);
277293 return syscall6(
278294 .preadv2,
279295 @bitCast(usize, @as(isize, fd)),
280296 @ptrToInt(iov),
281297 count,
282 @truncate(usize, offset),
283 @truncate(usize, offset >> 32),
298 offset_halves[0],
299 offset_halves[1],
284300 flags,
285301 );
286302}
......@@ -294,24 +310,26 @@ pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize {
294310}
295311
296312pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize {
313 const offset_halves = splitValue64(offset);
297314 return syscall5(
298315 .pwritev,
299316 @bitCast(usize, @as(isize, fd)),
300317 @ptrToInt(iov),
301318 count,
302 @truncate(usize, offset),
303 @truncate(usize, offset >> 32),
319 offset_halves[0],
320 offset_halves[1],
304321 );
305322}
306323
307324pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, flags: kernel_rwf) usize {
325 const offset_halves = splitValue64(offset);
308326 return syscall6(
309327 .pwritev2,
310328 @bitCast(usize, @as(isize, fd)),
311329 @ptrToInt(iov),
312330 count,
313 @truncate(usize, offset),
314 @truncate(usize, offset >> 32),
331 offset_halves[0],
332 offset_halves[1],
315333 flags,
316334 );
317335}
......@@ -338,6 +356,7 @@ pub fn symlinkat(existing: [*:0]const u8, newfd: i32, newpath: [*:0]const u8) us
338356
339357pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize {
340358 if (@hasField(SYS, "pread64")) {
359 const offset_halves = splitValue64(offset);
341360 if (require_aligned_register_pair) {
342361 return syscall6(
343362 .pread64,
......@@ -345,8 +364,8 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize {
345364 @ptrToInt(buf),
346365 count,
347366 0,
348 @truncate(usize, offset),
349 @truncate(usize, offset >> 32),
367 offset_halves[0],
368 offset_halves[1],
350369 );
351370 } else {
352371 return syscall5(
......@@ -354,8 +373,8 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize {
354373 @bitCast(usize, @as(isize, fd)),
355374 @ptrToInt(buf),
356375 count,
357 @truncate(usize, offset),
358 @truncate(usize, offset >> 32),
376 offset_halves[0],
377 offset_halves[1],
359378 );
360379 }
361380 } else {
......@@ -401,20 +420,21 @@ pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
401420
402421pub fn ftruncate(fd: i32, length: u64) usize {
403422 if (@hasField(SYS, "ftruncate64")) {
423 const length_halves = splitValue64(length);
404424 if (require_aligned_register_pair) {
405425 return syscall4(
406426 .ftruncate64,
407427 @bitCast(usize, @as(isize, fd)),
408428 0,
409 @truncate(usize, length),
410 @truncate(usize, length >> 32),
429 length_halves[0],
430 length_halves[1],
411431 );
412432 } else {
413433 return syscall3(
414434 .ftruncate64,
415435 @bitCast(usize, @as(isize, fd)),
416 @truncate(usize, length),
417 @truncate(usize, length >> 32),
436 length_halves[0],
437 length_halves[1],
418438 );
419439 }
420440 } else {
......@@ -428,6 +448,8 @@ pub fn ftruncate(fd: i32, length: u64) usize {
428448
429449pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: u64) usize {
430450 if (@hasField(SYS, "pwrite64")) {
451 const offset_halves = splitValue64(offset);
452
431453 if (require_aligned_register_pair) {
432454 return syscall6(
433455 .pwrite64,
......@@ -435,8 +457,8 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: u64) usize {
435457 @ptrToInt(buf),
436458 count,
437459 0,
438 @truncate(usize, offset),
439 @truncate(usize, offset >> 32),
460 offset_halves[0],
461 offset_halves[1],
440462 );
441463 } else {
442464 return syscall5(
......@@ -444,8 +466,8 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: u64) usize {
444466 @bitCast(usize, @as(isize, fd)),
445467 @ptrToInt(buf),
446468 count,
447 @truncate(usize, offset),
448 @truncate(usize, offset >> 32),
469 offset_halves[0],
470 offset_halves[1],
449471 );
450472 }
451473 } else {
......@@ -540,6 +562,8 @@ pub fn close(fd: i32) usize {
540562
541563/// Can only be called on 32 bit systems. For 64 bit see `lseek`.
542564pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize {
565 // NOTE: The offset parameter splitting is independent from the target
566 // endianness.
543567 return syscall5(
544568 ._llseek,
545569 @bitCast(usize, @as(isize, fd)),
lib/std/unicode.zig+20-9
......@@ -706,41 +706,52 @@ fn calcUtf16LeLen(utf8: []const u8) usize {
706706}
707707
708708test "utf8ToUtf16LeStringLiteral" {
709 // https://github.com/ziglang/zig/issues/5127
710 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
711
712709 {
713 const bytes = [_:0]u16{0x41};
710 const bytes = [_:0]u16{
711 mem.nativeToLittle(u16, 0x41),
712 };
714713 const utf16 = utf8ToUtf16LeStringLiteral("A");
715714 testing.expectEqualSlices(u16, &bytes, utf16);
716715 testing.expect(utf16[1] == 0);
717716 }
718717 {
719 const bytes = [_:0]u16{ 0xD801, 0xDC37 };
718 const bytes = [_:0]u16{
719 mem.nativeToLittle(u16, 0xD801),
720 mem.nativeToLittle(u16, 0xDC37),
721 };
720722 const utf16 = utf8ToUtf16LeStringLiteral("𐐷");
721723 testing.expectEqualSlices(u16, &bytes, utf16);
722724 testing.expect(utf16[2] == 0);
723725 }
724726 {
725 const bytes = [_:0]u16{0x02FF};
727 const bytes = [_:0]u16{
728 mem.nativeToLittle(u16, 0x02FF),
729 };
726730 const utf16 = utf8ToUtf16LeStringLiteral("\u{02FF}");
727731 testing.expectEqualSlices(u16, &bytes, utf16);
728732 testing.expect(utf16[1] == 0);
729733 }
730734 {
731 const bytes = [_:0]u16{0x7FF};
735 const bytes = [_:0]u16{
736 mem.nativeToLittle(u16, 0x7FF),
737 };
732738 const utf16 = utf8ToUtf16LeStringLiteral("\u{7FF}");
733739 testing.expectEqualSlices(u16, &bytes, utf16);
734740 testing.expect(utf16[1] == 0);
735741 }
736742 {
737 const bytes = [_:0]u16{0x801};
743 const bytes = [_:0]u16{
744 mem.nativeToLittle(u16, 0x801),
745 };
738746 const utf16 = utf8ToUtf16LeStringLiteral("\u{801}");
739747 testing.expectEqualSlices(u16, &bytes, utf16);
740748 testing.expect(utf16[1] == 0);
741749 }
742750 {
743 const bytes = [_:0]u16{ 0xDBFF, 0xDFFF };
751 const bytes = [_:0]u16{
752 mem.nativeToLittle(u16, 0xDBFF),
753 mem.nativeToLittle(u16, 0xDFFF),
754 };
744755 const utf16 = utf8ToUtf16LeStringLiteral("\u{10FFFF}");
745756 testing.expectEqualSlices(u16, &bytes, utf16);
746757 testing.expect(utf16[2] == 0);
test/stage1/behavior/union.zig-3
......@@ -623,9 +623,6 @@ test "0-sized extern union definition" {
623623}
624624
625625test "union initializer generates padding only if needed" {
626 // https://github.com/ziglang/zig/issues/5127
627 if (std.Target.current.cpu.arch == .mips) return error.SkipZigTest;
628
629626 const U = union(enum) {
630627 A: u24,
631628 };