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

Support more arguments to tail calls by passing them through the domain state #10595

Merged
merged 8 commits into from
Sep 9, 2021

Commits on Sep 9, 2021

  1. 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.
    xavierleroy committed Sep 9, 2021
    Configuration menu
    Copy the full SHA
    57c3ae5 View commit details
    Browse the repository at this point in the history
  2. Define size_domainstate_args as 64 * size_int

    Works both in 32 and 64 bits.
    xavierleroy committed Sep 9, 2021
    Configuration menu
    Copy the full SHA
    3499c4d View commit details
    Browse the repository at this point in the history
  3. Power: fix return calling convention

    Integer registers 0 to 15 are now available for returning results,
    not 0 to 7 as before.
    xavierleroy committed Sep 9, 2021
    Configuration menu
    Copy the full SHA
    5803b54 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    201c9aa View commit details
    Browse the repository at this point in the history
  5. Bow to check-typo

    xavierleroy committed Sep 9, 2021
    Configuration menu
    Copy the full SHA
    e94a514 View commit details
    Browse the repository at this point in the history
  6. More tests for tailcalls

    - Test tail calls to other functions, not just to self
    - Test up to 32 arguments.
    xavierleroy committed Sep 9, 2021
    Configuration menu
    Copy the full SHA
    18e1355 View commit details
    Browse the repository at this point in the history
  7. Changes for ocaml#10595

    xavierleroy committed Sep 9, 2021
    Configuration menu
    Copy the full SHA
    bf4c5f7 View commit details
    Browse the repository at this point in the history
  8. Bow to check-typo

    xavierleroy committed Sep 9, 2021
    Configuration menu
    Copy the full SHA
    f37834a View commit details
    Browse the repository at this point in the history