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

Provide __jmpb_ssp intrinsic #5576

Merged
merged 15 commits into from
Feb 23, 2024
Merged

Provide __jmpb_ssp intrinsic #5576

merged 15 commits into from
Feb 23, 2024

Conversation

vaivaswatha
Copy link
Contributor

@vaivaswatha vaivaswatha commented Feb 8, 2024

The new intrinsic __jmpb_ssp(offset: u64) jumps backwards, from the current value of $ssp, by a provided byte offset.

This intrinsic is necessary for dynamically loading and executing a contract.

Here's an example contract (taken from https://github.com/FuelLabs/ldc-testing) for dynamically loading another contract and transferring control to it. The "loadable" contract is the one used in the link above.

// to be compiled in release mode
contract;

abi MyContract {
    fn test_function(code_id: ContractId);
}

impl MyContract for Contract {
    fn test_function(code_id_p: ContractId) {
        let length = asm(code_id, length, word, ssp_saved) {
            // Allocate 32 bytes on the heap (we can't use the stack)
            addi word zero i32;
            aloc word;

            lw code_id fp i74;
           
            // Log the ContractID for debugging
            logd zero zero code_id word;

            // Load the entire contract with LDC
            csiz length code_id;
            // Save the old ssp
            move ssp_saved ssp;
            ldc code_id zero length;
            // return the ssp difference, to feed __jmpb_ssp.
            // This need not always be equal to `length` as `ldc` pads the `length`.
            sub length ssp ssp_saved;
            length: u64
        };
        __jmpb_ssp(length)
    }
}

The intrinsic generates code to do the following:

  1. Subract offset from $ssp.
  2. Subtract $is since $jmp adds it back.
  3. Divide by 4 since Jmp multiplies by 4
  4. Jump to the computed value.

Closes #5563

@vaivaswatha vaivaswatha changed the title Support for a __jmp_to_ssp intrinsic Support for a __jmp_to_ssp intrinsic Feb 8, 2024
@vaivaswatha vaivaswatha changed the title Support for a __jmp_to_ssp intrinsic Support for __jmp_to_ssp intrinsic Feb 8, 2024
@vaivaswatha vaivaswatha self-assigned this Feb 8, 2024
Copy link

Benchmark for 7b5c465

Click to view benchmark
Test Base PR %
code_action 5.3±0.13ms 5.3±0.01ms 0.00%
code_lens 341.5±46.47ns 331.7±7.64ns -2.87%
compile 2.9±0.02s 3.0±0.04s +3.45%
completion 4.8±0.03ms 4.9±0.09ms +2.08%
did_change_with_caching 2.8±0.02s 2.9±0.03s +3.57%
document_symbol 956.4±16.42µs 961.2±23.18µs +0.50%
format 90.6±1.38ms 90.1±1.42ms -0.55%
goto_definition 357.5±2.54µs 360.9±3.59µs +0.95%
highlight 9.0±0.16ms 9.1±0.17ms +1.11%
hover 537.8±5.28µs 543.8±12.62µs +1.12%
idents_at_position 123.5±0.47µs 123.8±1.06µs +0.24%
inlay_hints 665.0±22.23µs 678.8±8.46µs +2.08%
on_enter 501.8±15.14ns 493.7±20.82ns -1.61%
parent_decl_at_position 3.7±0.01ms 3.7±0.05ms 0.00%
prepare_rename 360.5±6.40µs 365.8±3.24µs +1.47%
rename 9.4±0.19ms 9.5±0.16ms +1.06%
semantic_tokens 1005.3±35.29µs 1046.0±15.94µs +4.05%
token_at_position 352.4±5.93µs 364.6±2.26µs +3.46%
tokens_at_position 3.7±0.03ms 3.7±0.03ms 0.00%
tokens_for_file 415.3±3.32µs 416.4±5.07µs +0.26%
traverse 38.5±0.77ms 37.8±0.60ms -1.82%

@vaivaswatha vaivaswatha changed the title Support for __jmp_to_ssp intrinsic Provide __jmpb_ssp intrinsic Feb 16, 2024
Copy link

Benchmark for 08c10ee

Click to view benchmark
Test Base PR %
code_action 5.3±0.11ms 5.3±0.14ms 0.00%
code_lens 294.7±12.59ns 291.8±8.78ns -0.98%
compile 3.0±0.06s 3.0±0.09s 0.00%
completion 5.0±0.19ms 4.9±0.13ms -2.00%
did_change_with_caching 2.9±0.07s 2.9±0.11s 0.00%
document_symbol 1013.5±36.07µs 1046.9±7.81µs +3.30%
format 89.3±0.66ms 90.0±0.88ms +0.78%
goto_definition 371.0±7.73µs 352.1±8.76µs -5.09%
highlight 9.1±0.23ms 9.1±0.30ms 0.00%
hover 549.8±8.79µs 535.3±7.21µs -2.64%
idents_at_position 124.3±1.23µs 122.6±1.21µs -1.37%
inlay_hints 661.6±20.93µs 659.0±19.66µs -0.39%
on_enter 500.1±18.30ns 512.3±13.33ns +2.44%
parent_decl_at_position 3.9±0.22ms 3.6±0.04ms -7.69%
prepare_rename 366.0±8.07µs 355.0±5.39µs -3.01%
rename 9.4±0.19ms 9.2±0.16ms -2.13%
semantic_tokens 1072.4±25.41µs 1037.6±22.58µs -3.25%
token_at_position 369.3±2.38µs 419.7±4.48µs +13.65%
tokens_at_position 3.9±0.28ms 3.8±0.24ms -2.56%
tokens_for_file 422.3±5.17µs 410.5±3.52µs -2.79%
traverse 38.4±1.24ms 38.0±0.35ms -1.04%

Copy link

Benchmark for 56950c8

Click to view benchmark
Test Base PR %
code_action 6.1±0.08ms 5.2±0.11ms -14.75%
code_lens 301.4±7.67ns 291.7±16.32ns -3.22%
compile 3.0±0.03s 3.0±0.03s 0.00%
completion 4.7±0.11ms 4.7±0.12ms 0.00%
did_change_with_caching 2.9±0.03s 2.9±0.04s 0.00%
document_symbol 962.9±29.01µs 978.1±28.99µs +1.58%
format 91.3±1.15ms 89.6±1.30ms -1.86%
goto_definition 365.9±5.77µs 361.8±6.76µs -1.12%
highlight 8.8±0.03ms 8.8±0.25ms 0.00%
hover 534.9±7.09µs 542.4±6.52µs +1.40%
idents_at_position 121.4±0.49µs 121.2±0.66µs -0.16%
inlay_hints 683.8±16.53µs 659.8±11.67µs -3.51%
on_enter 481.2±7.32ns 506.9±23.11ns +5.34%
parent_decl_at_position 3.6±0.03ms 3.6±0.12ms 0.00%
prepare_rename 358.7±4.74µs 366.4±4.10µs +2.15%
rename 9.3±0.07ms 9.2±0.16ms -1.08%
semantic_tokens 1049.2±15.34µs 1054.6±12.53µs +0.51%
token_at_position 356.6±2.69µs 356.1±2.31µs -0.14%
tokens_at_position 3.6±0.04ms 3.6±0.04ms 0.00%
tokens_for_file 408.1±2.46µs 408.3±3.33µs +0.05%
traverse 37.7±0.50ms 38.3±1.18ms +1.59%

@vaivaswatha vaivaswatha marked this pull request as ready for review February 16, 2024 07:18
Copy link
Contributor

@IGI-111 IGI-111 left a comment

Choose a reason for hiding this comment

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

We're missing a documentation mention in book/src/reference/compiler_intrinsics.md but otherwise LGTM

@vaivaswatha vaivaswatha enabled auto-merge (squash) February 18, 2024 04:04
Copy link

Benchmark for f437271

Click to view benchmark
Test Base PR %
code_action 5.4±0.06ms 5.3±0.09ms -1.85%
code_lens 290.4±9.05ns 298.9±7.53ns +2.93%
compile 3.0±0.03s 3.0±0.03s 0.00%
completion 4.9±0.06ms 5.0±0.10ms +2.04%
did_change_with_caching 2.8±0.03s 2.9±0.03s +3.57%
document_symbol 969.6±26.70µs 952.3±17.51µs -1.78%
format 89.3±1.36ms 89.6±1.14ms +0.34%
goto_definition 367.9±5.67µs 354.1±8.18µs -3.75%
highlight 9.2±0.14ms 9.1±0.09ms -1.09%
hover 540.3±9.60µs 531.0±7.91µs -1.72%
idents_at_position 123.7±0.37µs 121.9±1.93µs -1.46%
inlay_hints 686.9±24.53µs 672.5±15.32µs -2.10%
on_enter 490.0±15.17ns 481.0±9.02ns -1.84%
parent_decl_at_position 3.8±0.02ms 3.7±0.01ms -2.63%
prepare_rename 361.4±4.80µs 359.6±7.10µs -0.50%
rename 9.5±0.19ms 9.5±0.09ms 0.00%
semantic_tokens 1059.3±7.90µs 1063.1±38.32µs +0.36%
token_at_position 360.9±2.70µs 360.6±3.00µs -0.08%
tokens_at_position 3.8±0.04ms 3.7±0.02ms -2.63%
tokens_for_file 415.2±3.59µs 412.2±5.81µs -0.72%
traverse 37.0±0.82ms 37.1±0.48ms +0.27%

Copy link

Benchmark for 3d8ff36

Click to view benchmark
Test Base PR %
code_action 5.6±0.22ms 5.4±0.17ms -3.57%
code_lens 292.3±10.49ns 296.2±5.81ns +1.33%
compile 3.1±0.04s 3.1±0.07s 0.00%
completion 5.0±0.15ms 5.0±0.16ms 0.00%
did_change_with_caching 2.9±0.05s 3.0±0.04s +3.45%
document_symbol 1078.7±44.03µs 966.0±21.49µs -10.45%
format 90.4±2.08ms 90.4±1.11ms 0.00%
goto_definition 368.4±3.88µs 358.2±10.23µs -2.77%
highlight 9.3±0.36ms 9.3±0.14ms 0.00%
hover 544.1±6.96µs 546.9±7.26µs +0.51%
idents_at_position 122.9±0.32µs 123.2±1.11µs +0.24%
inlay_hints 684.0±25.91µs 671.2±11.97µs -1.87%
on_enter 491.8±14.66ns 477.0±5.75ns -3.01%
parent_decl_at_position 3.8±0.05ms 3.8±0.09ms 0.00%
prepare_rename 384.9±7.62µs 357.5±6.46µs -7.12%
rename 9.7±0.22ms 10.1±0.21ms +4.12%
semantic_tokens 1060.3±32.32µs 1049.1±18.62µs -1.06%
token_at_position 356.1±1.81µs 356.6±3.94µs +0.14%
tokens_at_position 3.8±0.04ms 3.9±0.11ms +2.63%
tokens_for_file 406.7±2.09µs 412.9±3.62µs +1.52%
traverse 38.3±0.84ms 38.4±1.15ms +0.26%

IGI-111
IGI-111 previously approved these changes Feb 18, 2024
@IGI-111 IGI-111 requested a review from a team February 18, 2024 16:49
Copy link

Benchmark for d45c860

Click to view benchmark
Test Base PR %
code_action 5.1±0.07ms 5.4±0.32ms +5.88%
code_lens 285.4±6.56ns 332.7±9.52ns +16.57%
compile 3.0±0.03s 3.0±0.03s 0.00%
completion 4.7±0.09ms 4.9±0.02ms +4.26%
did_change_with_caching 2.8±0.02s 2.9±0.02s +3.57%
document_symbol 958.6±11.49µs 950.4±17.92µs -0.86%
format 74.9±0.58ms 74.2±2.67ms -0.93%
goto_definition 363.4±9.19µs 378.6±8.25µs +4.18%
highlight 8.8±0.20ms 9.1±0.22ms +3.41%
hover 534.8±9.63µs 544.3±11.18µs +1.78%
idents_at_position 121.6±0.29µs 122.1±1.18µs +0.41%
inlay_hints 664.7±21.57µs 671.1±23.49µs +0.96%
on_enter 485.7±4.34ns 511.8±13.61ns +5.37%
parent_decl_at_position 3.6±0.06ms 3.7±0.03ms +2.78%
prepare_rename 357.7±7.49µs 367.0±6.87µs +2.60%
rename 9.2±0.70ms 9.5±0.19ms +3.26%
semantic_tokens 1043.1±20.26µs 1051.2±14.54µs +0.78%
token_at_position 358.1±3.92µs 363.3±3.27µs +1.45%
tokens_at_position 3.6±0.04ms 3.7±0.04ms +2.78%
tokens_for_file 411.6±4.37µs 408.9±10.42µs -0.66%
traverse 38.4±1.43ms 37.6±0.54ms -2.08%

@IGI-111 IGI-111 requested review from a team and dmihal February 21, 2024 03:57
Copy link

Benchmark for 92db795

Click to view benchmark
Test Base PR %
code_action 5.2±0.14ms 5.4±0.16ms +3.85%
code_lens 288.3±7.36ns 287.1±9.95ns -0.42%
compile 3.0±0.04s 3.0±0.04s 0.00%
completion 4.7±0.16ms 4.8±0.09ms +2.13%
did_change_with_caching 2.9±0.02s 2.9±0.09s 0.00%
document_symbol 956.6±15.91µs 959.2±21.14µs +0.27%
format 74.5±1.26ms 74.3±1.02ms -0.27%
goto_definition 360.1±6.61µs 364.5±8.47µs +1.22%
highlight 8.8±0.14ms 9.1±0.20ms +3.41%
hover 537.5±12.15µs 540.2±11.41µs +0.50%
idents_at_position 122.9±0.45µs 121.6±0.39µs -1.06%
inlay_hints 658.6±22.60µs 677.2±39.97µs +2.82%
on_enter 499.2±61.12ns 506.5±17.00ns +1.46%
parent_decl_at_position 3.6±0.03ms 3.7±0.03ms +2.78%
prepare_rename 359.4±4.29µs 368.7±5.71µs +2.59%
rename 9.1±0.14ms 9.5±0.23ms +4.40%
semantic_tokens 1030.8±16.45µs 1045.5±18.20µs +1.43%
token_at_position 354.5±3.33µs 360.2±2.56µs +1.61%
tokens_at_position 3.6±0.09ms 3.7±0.05ms +2.78%
tokens_for_file 489.9±1.76µs 413.3±6.15µs -15.64%
traverse 38.3±1.29ms 38.6±0.73ms +0.78%

Copy link

Benchmark for 3e48be9

Click to view benchmark
Test Base PR %
code_action 5.1±0.09ms 5.7±0.17ms +11.76%
code_lens 335.1±11.00ns 291.6±9.21ns -12.98%
compile 3.1±0.03s 3.2±0.05s +3.23%
completion 4.7±0.10ms 5.4±0.39ms +14.89%
did_change_with_caching 2.9±0.03s 2.9±0.10s 0.00%
document_symbol 968.4±24.68µs 979.9±20.94µs +1.19%
format 73.7±1.13ms 74.2±1.09ms +0.68%
goto_definition 367.1±11.10µs 373.9±10.25µs +1.85%
highlight 8.8±0.18ms 9.2±0.22ms +4.55%
hover 537.6±7.13µs 542.6±9.20µs +0.93%
idents_at_position 123.9±0.75µs 123.7±0.72µs -0.16%
inlay_hints 660.4±11.68µs 665.9±13.82µs +0.83%
on_enter 479.6±6.93ns 505.8±16.65ns +5.46%
parent_decl_at_position 3.6±0.19ms 3.7±0.17ms +2.78%
prepare_rename 361.4±5.45µs 369.3±3.42µs +2.19%
rename 9.3±0.23ms 9.9±0.30ms +6.45%
semantic_tokens 1050.1±25.79µs 1071.8±24.65µs +2.07%
token_at_position 360.2±5.81µs 358.7±2.96µs -0.42%
tokens_at_position 3.6±0.03ms 3.6±0.06ms 0.00%
tokens_for_file 417.3±4.16µs 412.4±8.55µs -1.17%
traverse 39.7±0.83ms 38.8±0.44ms -2.27%

@vaivaswatha vaivaswatha merged commit a8fd24f into master Feb 23, 2024
39 checks passed
@vaivaswatha vaivaswatha deleted the vaivaswatha/jmp_to_ssp branch February 23, 2024 21:53
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.

Instrinsic jump to $ssp
3 participants