-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Wasm/JS BigInt support #10860
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
Wasm/JS BigInt support #10860
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
bd47668
start somwehre
kripken 396d128
fixes
kripken 6c732ce
[ci skip]
kripken bd0d715
Avoid Xn notation
kripken 3b5e7c6
test
kripken f6a8dd9
fix
kripken 2724dbf
fix
kripken d740fc1
finish
kripken 3253cf2
fix
kripken d0f594e
more
kripken 96e0a32
more testing
kripken 8f0f5a4
test passing
kripken 54444d5
best [ci skip]
kripken d066009
fix mistake [ci skip]
kripken 94ede9f
fix text [ci skip]
kripken ed0aa7a
Merge remote-tracking branch 'origin/master' into bigint
kripken 1ff48aa
fastcomp
kripken 4e6e3d2
Merge remote-tracking branch 'origin/master' into bigint
kripken e67fa09
Merge remote-tracking branch 'origin/master' into bigint
kripken f8d831d
fix invokes + test
kripken 6422d23
i64_t
kripken de5cec5
get_func_ptr
kripken 081fcde
whitespace
kripken 26148b5
simpler
kripken 23a8be3
nicer
kripken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1390,7 +1390,9 @@ var SyscallsLibrary = { | |
FS.utime(path, atime, mtime); | ||
return 0; | ||
}, | ||
__sys_fallocate: function(fd, mode, off_low, off_high, len_low, len_high) { | ||
__sys_fallocate: function(fd, mode, {{{ defineI64Param('off') }}}, {{{ defineI64Param('len') }}}) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't tell whether this is gross or not. |
||
{{{ receiveI64ParamAsI32s('off') }}} | ||
{{{ receiveI64ParamAsI32s('len') }}} | ||
var stream = SYSCALLS.getStreamFromFD(fd) | ||
var offset = SYSCALLS.get64(off_low, off_high); | ||
var len = SYSCALLS.get64(len_low, len_high); | ||
|
@@ -1522,7 +1524,8 @@ var SyscallsLibrary = { | |
return 0; | ||
}, | ||
fd_seek__sig: 'iiiiii', | ||
fd_seek: function(fd, offset_low, offset_high, whence, newOffset) { | ||
fd_seek: function(fd, {{{ defineI64Param('offset') }}}, whence, newOffset) { | ||
{{{ receiveI64ParamAsI32s('offset') }}} | ||
var stream = SYSCALLS.getStreamFromFD(fd); | ||
var HIGH_OFFSET = 0x100000000; // 2^32 | ||
// use an unsigned operator on low and shift high by 32-bits | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
#include <emscripten.h> | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
|
||
int64_t big = 0x12345678aabbccddL; | ||
|
||
__attribute__((noinline)) | ||
int64_t foobar(int64_t x, int y) { | ||
x += EM_ASM_INT({ | ||
return 0; // prevents llvm from seeing the final value | ||
}); | ||
if (x == 1337) { | ||
throw 1; // looks like we might throw | ||
} | ||
return x + y; // use the int parameter too, to show they are all handled | ||
} | ||
|
||
int main() { | ||
int64_t x; | ||
try { | ||
puts("try"); | ||
x = foobar(big, 1); | ||
} catch(int) { | ||
puts("caught"); | ||
} | ||
printf("ok: 0x%llx.\n", x); | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
try | ||
ok: 0x12345678aabbccde. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// This code represents a simple native JavaScript binding to a test C function | ||
// that returns a 64 bit long. Notice that the least significant 32 bits are | ||
// returned in the normal return value, but the most significant 32 bits are | ||
// returned via the accessor method Runtime.getTempRet0() | ||
|
||
var Module = { | ||
'noExitRuntime' : true | ||
}; | ||
|
||
Module['runtest'] = function() { | ||
// Use eval to create BigInt, as no support for Xn notation yet in JS | ||
// optimizer. | ||
var bigint = _test_return64(eval('0xaabbccdd11223344n')); | ||
var low = Number(bigint & BigInt(0xffffffff)); | ||
var high = Number(bigint >> BigInt(32)); | ||
console.log("low = " + low); | ||
console.log("high = " + high); | ||
|
||
var ptr = _get_func_ptr(); | ||
bigint = dynCall_jj(ptr, eval('0xabcdef1912345678n')); | ||
low = Number(bigint & BigInt(0xffffffff)); | ||
high = Number(bigint >> BigInt(32)); | ||
console.log("low = " + low); | ||
console.log("high = " + high); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is legalization only dealing with the i64 issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We used to legalize f32s to doubles for JS too, but it turned out that was not necessary. So it is just i64s now, yes.