-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support more arguments to tail calls by passing them through the domain state #10595
Merged
Commits on Sep 9, 2021
-
Support more arguments to tail calls by passing them through the doma…
…in state In 2004, commit af9b98f, the calling conventions for the i386 port of ocamlopt were changed: the first 6 integer arguments go into registers, like before, but the next 16 arguments go into a global array `caml_extra_params`, instead of being passed on stack like before. The reason for this hack is that passing arguments in global memory does not preclude tail call optimization, unlike passing arguments on stack. Parameters passed via `caml_extra_params` are immediately copied on stack or in registers on function entry, before another function call, a GC, or a context switch can take place, so everything is safe in OCaml, and in Multicore OCaml as long as there is only one execution domain. This hack was justified by the paucity of registers provided by the i386 architecture. It was believed that other architectures provide enough registers for parameter passing that most if not all reasonable tail calls can be accommodated. Now it's 2021 and users want tail calls with more arguments than available registers on all the architectures we support. So, biting the bullet and swallowing some pride, this commit extends the 2004 i386 hack to all the architectures supported by OCaml. Once the registers available for passing function arguments are exhausted, the next 64 arguments are passed in a memory area that is part of the domain state. This argument passing is compatible with tail calls, so we get guaranteed tail calls up to 70 arguments (in the worst case). The domain state is used instead of a global array so that (1) this is compatible with Multicore OCaml and concurrent execution of multiple domains, and (2) we benefit from efficient addressing from the domain state register. For i386, we don't have a domain state register, and Multicore OCaml will support only one domain on this architecture, so we keep using a global `caml_extra_params` array; only, its size was increased to support 64 arguments.
Configuration menu - View commit details
-
Copy full SHA for 57c3ae5 - Browse repository at this point
Copy the full SHA 57c3ae5View commit details -
Define size_domainstate_args as 64 * size_int
Works both in 32 and 64 bits.
Configuration menu - View commit details
-
Copy full SHA for 3499c4d - Browse repository at this point
Copy the full SHA 3499c4dView commit details -
Power: fix return calling convention
Integer registers 0 to 15 are now available for returning results, not 0 to 7 as before.
Configuration menu - View commit details
-
Copy full SHA for 5803b54 - Browse repository at this point
Copy the full SHA 5803b54View commit details -
Configuration menu - View commit details
-
Copy full SHA for 201c9aa - Browse repository at this point
Copy the full SHA 201c9aaView commit details -
Configuration menu - View commit details
-
Copy full SHA for e94a514 - Browse repository at this point
Copy the full SHA e94a514View commit details -
- Test tail calls to other functions, not just to self - Test up to 32 arguments.
Configuration menu - View commit details
-
Copy full SHA for 18e1355 - Browse repository at this point
Copy the full SHA 18e1355View commit details -
Configuration menu - View commit details
-
Copy full SHA for bf4c5f7 - Browse repository at this point
Copy the full SHA bf4c5f7View commit details -
Configuration menu - View commit details
-
Copy full SHA for f37834a - Browse repository at this point
Copy the full SHA f37834aView commit details
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.