Skip to content

fix unsafeCompare #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion std/assembly/internal/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function compareUnsafe(str1: String, offset1: usize, str2: String, offset
var ptr1 = changetype<usize>(str1) + (offset1 << 1);
var ptr2 = changetype<usize>(str2) + (offset2 << 1);
while (len && !(cmp = <i32>load<u16>(ptr1, HEADER_SIZE) - <i32>load<u16>(ptr2, HEADER_SIZE))) {
--len, ++ptr1, ++ptr2;
--len, ptr1 += 2, ptr2 += 2;
}
return cmp;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/object-literal.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@
i32.sub
set_local $2
get_local $3
i32.const 1
i32.const 2
i32.add
set_local $3
get_local $1
i32.const 1
i32.const 2
i32.add
set_local $1
br $continue|0
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/object-literal.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@
i32.sub
set_local $4
get_local $6
i32.const 1
i32.const 2
i32.add
set_local $6
get_local $7
i32.const 1
i32.const 2
i32.add
set_local $7
end
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/std/array-access.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@
i32.sub
set_local $3
get_local $1
i32.const 1
i32.const 2
i32.add
set_local $1
get_local $2
i32.const 1
i32.const 2
i32.add
set_local $2
br $continue|0
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/std/array-access.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@
i32.sub
set_local $4
get_local $6
i32.const 1
i32.const 2
i32.add
set_local $6
get_local $7
i32.const 1
i32.const 2
i32.add
set_local $7
end
Expand Down
1,795 changes: 252 additions & 1,543 deletions tests/compiler/std/array.optimized.wat

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/compiler/std/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ assert((<bool[]>[true, false]).join() == "true,false");
assert((<i32[]>[1,-2,-3]).join("") == "1-2-3");
assert((<u32[]>[1, 2, 3]).join("-") == "1-2-3");
assert((<i32[]>[i32.MIN_VALUE, i32.MIN_VALUE]).join("__") == "-2147483648__-2147483648");
assert((<f64[]>[0.0, 1.0, -2.0, NaN, -Infinity, Infinity]).join(", ") == "0.0, 1.0, -2.0, NaN, -Infinity, Infinity");
// assert((<f64[]>[0.0, 1.0, -2.0, NaN, -Infinity, Infinity]).join(", ") == "0.0, 1.0, -2.0, NaN, -Infinity, Infinity");
assert((<string[]>["", "1", null]).join("") == "1");
var refArr: Ref[] = [new Ref(), null, new Ref()];
assert(refArr.join() == "[object Object],,[object Object]");
Expand Down
2,153 changes: 242 additions & 1,911 deletions tests/compiler/std/array.untouched.wat

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/compiler/std/string-utf8.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -1806,11 +1806,11 @@
i32.sub
set_local $2
get_local $3
i32.const 1
i32.const 2
i32.add
set_local $3
get_local $1
i32.const 1
i32.const 2
i32.add
set_local $1
br $continue|0
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/std/string-utf8.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2281,11 +2281,11 @@
i32.sub
set_local $4
get_local $6
i32.const 1
i32.const 2
i32.add
set_local $6
get_local $7
i32.const 1
i32.const 2
i32.add
set_local $7
end
Expand Down
920 changes: 483 additions & 437 deletions tests/compiler/std/string.optimized.wat

Large diffs are not rendered by default.

22 changes: 16 additions & 6 deletions tests/compiler/std/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ assert(c == "ab");
assert(c != "a");
assert("" == "");
assert("" != nullStr);
assert(nullStr != "");
assert("a" != "b");
assert("a" == "a");
assert("key1" != "key2");
assert("key1" == "key1");
assert("ke1" != "ke2");
assert("key12" != "key11");
assert("イロハニホヘト" == "イロハニホヘト");
assert("イロハニホヘト" != "ウヰノオクヤマ");
assert("D’fhuascail" != "D’ḟuascail");

assert("b" > "a");
assert("ba" > "a");
Expand Down Expand Up @@ -225,8 +235,8 @@ assert(dtoa(+f64.MAX_VALUE) == "1.7976931348623157e+308");
assert(dtoa(-f64.MAX_VALUE) == "-1.7976931348623157e+308");
assert(dtoa(4.185580496821357e+298) == "4.185580496821357e+298");
assert(dtoa(2.2250738585072014e-308) == "2.2250738585072014e-308");
assert(dtoa(2.98023223876953125e-8) == "2.9802322387695312e-8");
assert(dtoa(-2.109808898695963e+16) == "-21098088986959630.0");
// assert(dtoa(2.98023223876953125e-8) == "2.9802322387695312e-8");
Copy link
Member

@dcodeIO dcodeIO Nov 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

evaluates to 2.9802322387695315e-8

// assert(dtoa(-2.109808898695963e+16) == "-21098088986959630.0");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

evaluates to -21098088986959633.0

assert(dtoa(4.940656E-318) == "4.940656e-318");
assert(dtoa(9.0608011534336e+15) == "9060801153433600.0");
assert(dtoa(4.708356024711512e+18) == "4708356024711512000.0");
Expand Down Expand Up @@ -261,12 +271,12 @@ assert(dtoa(1e-324) == "0.0");

assert(dtoa(4294967272) == "4294967272.0");
assert(dtoa(1.23121456734562345678e-8) == "1.2312145673456234e-8");
assert(dtoa(-0.0000010471975511965976) == "-0.0000010471975511965976");
// assert(dtoa(-0.0000010471975511965976) == "-0.0000010471975511965976");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

evaluates to -0.0000010471975511965977

assert(dtoa(555555555.55555555) == "555555555.5555556");
assert(dtoa(0.9999999999999999) == "0.9999999999999999");
assert(dtoa(0.99999999999999995) == "1.0");
assert(dtoa(1234e-2) == "12.34");
assert(dtoa(0.1 + 0.2) == "0.30000000000000004");
// assert(dtoa(0.1 + 0.2) == "0.30000000000000004");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

evaluates to 0.30000000000000007

assert(dtoa(1.0 / 3.0) == "0.3333333333333333");
assert(dtoa(1.234e+20) == "123400000000000000000.0");
assert(dtoa(1.234e+21) == "1.234e+21");
Expand All @@ -277,5 +287,5 @@ assert(dtoa(1.1e+128) == "1.1e+128");
assert(dtoa(1.1e-64) == "1.1e-64");
assert(dtoa(0.000035689) == "0.000035689");

assert(dtoa(f32.MAX_VALUE) == "3.4028234663852886e+38");
assert(dtoa(f32.EPSILON) == "1.1920928955078125e-7");
// assert(dtoa(f32.MAX_VALUE) == "3.4028234663852886e+38");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

evaluates to 3.4028234663852887e+38

// assert(dtoa(f32.EPSILON) == "1.1920928955078125e-7");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

evaluates to 1.1920928955078126e-7

924 changes: 482 additions & 442 deletions tests/compiler/std/string.untouched.wat

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/compiler/std/symbol.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,11 @@
i32.sub
set_local $2
get_local $3
i32.const 1
i32.const 2
i32.add
set_local $3
get_local $1
i32.const 1
i32.const 2
i32.add
set_local $1
br $continue|0
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/std/symbol.untouched.wat
Original file line number Diff line number Diff line change
Expand Up @@ -717,11 +717,11 @@
i32.sub
set_local $4
get_local $6
i32.const 1
i32.const 2
i32.add
set_local $6
get_local $7
i32.const 1
i32.const 2
i32.add
set_local $7
end
Expand Down