Skip to content
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

fix(ext/ffi): trampoline for fast calls #15139

Merged
merged 38 commits into from
Jul 12, 2022

Conversation

littledivy
Copy link
Member

@littledivy littledivy commented Jul 10, 2022

Pointed out by @aapoalas #15125 introduced a bug in FFI calls. The first parameter of a fast function must be a V8Value receiver. This patch implements a fix by patching symbol calls to ignore the receiver.

#[test]
fn test_gen_trampoline() {
assert_eq!(
codegen(vec![], NativeType::Void),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice! I like seeing tests with this.

ext/ffi/jit_trampoline.rs Outdated Show resolved Hide resolved
ext/ffi/lib.rs Outdated Show resolved Hide resolved
@aapoalas
Copy link
Collaborator

Oh yeah, regarding the u8 / u16 / i8 / i16 support, @phosra had a good note about return values:
#15122 (comment)

@ghost

This comment was marked as resolved.

@aapoalas
Copy link
Collaborator

If the first parameter is now the receiver, does this mean that C functions with empty parameters would now supported?

0-ary C functions were already supported. eg. Here're a few lines from benchmarks I ran on a PR of mine which changes nothing related to normal FFI calls:

benchmark                              time (avg)             (min … max)       p75       p99      p995
------------------------------------------------------------------------- -----------------------------
nop()                                3.56 ns/iter    (3.45 ns … 19.23 ns)    3.5 ns   4.37 ns   4.75 ns
add_u32()                            7.91 ns/iter    (7.17 ns … 18.92 ns)   7.64 ns  13.32 ns  15.29 ns
nop_u8()                             7.88 ns/iter     (7.4 ns … 34.05 ns)    7.4 ns  12.53 ns  16.59 ns

This just changes how those calls are called: Currently they're given an extra parameter that they do not expect but luckily also do not care about.

@ghost

This comment was marked as resolved.

@littledivy littledivy marked this pull request as ready for review July 11, 2022 06:00
ext/ffi/jit_trampoline.rs Outdated Show resolved Hide resolved
test_ffi/tests/test.js Outdated Show resolved Hide resolved
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

It would be very nice to have ext/ffi/README updated with an summary of how this works.

ext/ffi/tcc.rs Outdated Show resolved Hide resolved
ext/ffi/tcc.rs Outdated Show resolved Hide resolved
ext/ffi/lib.rs Show resolved Hide resolved
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

Please add an explanation of the process to ext/ffi/README

ry added a commit that referenced this pull request Jul 11, 2022
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

Why the third_party changes if windows is not supported?

@littledivy littledivy requested a review from ry July 11, 2022 18:38
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM - nice work Divy

TODO: remove tcc and directly write asm instead.

@littledivy littledivy merged commit 77d065e into denoland:main Jul 12, 2022
@littledivy littledivy deleted the ffi-trampoline branch March 24, 2024 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants