Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Jun 19, 2024

As reported in #13249, the fixed use of %a5 in the bytecode interpreter conflicts with its internal usage as a GOT base by Glibc, and given the scarce number of available registers on this platform, it is probably better to trust the compiler to perform register assignment here.

@ghost ghost mentioned this pull request Jun 19, 2024
@gasche
Copy link
Member

gasche commented Jun 19, 2024

This PR appears to fix a bug that would let Debian testing progress further, and in this sense it is good.

On the other hand I am not sure about the idea of removing the register assignment because there are too few registers. Even when there are few, quite probably the PC, SP and ACCU registers of the VM are those you really want to have in machine registers. Has this calculus changed in OCaml 5 rather than OCaml 4? Could you suggest other registers to reserve instead? (Do we even have a reliable way to do a performance comparison of the two approaches?)

@ghost
Copy link
Author

ghost commented Jun 19, 2024

This PR appears to fix a bug that would let Debian testing progress further, and in this sense it is good.

On the other hand I am not sure about the idea of removing the register assignment because there are too few registers. Even when there are few, quite probably the PC, SP and ACCU registers of the VM are those you really want to have in machine registers. Has this calculus changed in OCaml 5 rather than OCaml 4? Could you suggest other registers to reserve instead? (Do we even have a reliable way to do a performance comparison of the two approaches?)

This has not changed from OCaml 4 and I expect OCaml 4 to fail the same way - at least when the interpreter needs to invoke a libc function which accesses global data (and thus will perform %a5-related loads).

On m68k, register allocation is painful, because although there are 16 general-purpose registers, they are not all equal, only %a0-%a7 can be used for addressing (e.g. for register-related memory loads and stores), and only %d0-%d7 can be used for data computation. Also, %a7 is the stack pointer and %a6 the frame pointer. Now that %a5 is also reserved as the GOT pointer, this leaves only five address registers; at this point I think it is better to trust the compiler register allocation among these five registers, rather than force two of them to be fixed and only three left.

It might be worth trying to keep fixed allocations but use %a3 instead of %a5 for PC_REG and compare execution times against the "no fixed assignment" version suggested in this PR, though.

@gasche
Copy link
Member

gasche commented Jun 19, 2024

I would be more at ease with the minimal/conservative change (using a3 instead of a5) first. We could wait for a performance test (which probably is never going to come because few people care about this architecture) to remove the assignments altogether.

@ghost
Copy link
Author

ghost commented Jun 19, 2024

I would be more at ease with the minimal/conservative change (using a3 instead of a5) first. We could wait for a performance test (which probably is never going to come because few people care about this architecture) to remove the assignments altogether.

How about this new version?

@ghost ghost changed the title [bytecode runtime] Remove fixed register assignments on m68k [bytecode runtime] Rework fixed register assignments on m68k Jun 19, 2024
@gasche
Copy link
Member

gasche commented Jun 19, 2024

I feel happy with this new version -- as in, I don't have the expertise to ensure that this is right, but my risk assessment is that this is very probably fine if you say it is, so we could go ahead.

What are the benefits of keeping a5 on non-linux systems, instead of switching to a3 uniformly, which seems simpler?

@glondu if you have an easy way to check that this patch works just as well as disabling the register assignment, I would be interested in a confirmation. But I am thinking of approving&merging it anyway.

@ghost
Copy link
Author

ghost commented Jun 19, 2024

What are the benefits of keeping a5 on non-linux systems, instead of switching to a3 uniformly, which seems simpler?

I don't know. If someone is willing to dig into history, the rationale behind the choice of the existing assignment might provide useful information (as in: "we tried various combinations and this one turns out to be better because...") but I'm not sure there are traces of it.

Copy link
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

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

Hm. I don't understand enough about the domain to see why a5->a3 would make a difference, but I don't want to insist and I am happy to approve the PR as-is.

@gasche
Copy link
Member

gasche commented Jun 19, 2024

I looked at the git history, the m68k register assignment was chosen in 1996 by @xavierleroy and never changed since: 9a374eb.

@ghost
Copy link
Author

ghost commented Jun 19, 2024

Yet this proves there were still Sun3 running in INRIA in 1996! At least in Rocquencourt - INRIA Sophia-Antipolis was already full SPARC (and Linux) at that time. 😀

@glondu
Copy link
Contributor

glondu commented Jun 20, 2024

@glondu if you have an easy way to check that this patch works just as well as disabling the register assignment, I would be interested in a confirmation. But I am thinking of approving&merging it anyway.

I've just uploaded to experimental a new version of the package, with the current state of this PR + disabling runtime_events on armel. Results should appear in a few hours there: https://buildd.debian.org/status/package.php?p=ocaml&suite=experimental

Copy link
Contributor

@xavierleroy xavierleroy left a comment

Choose a reason for hiding this comment

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

So there's still one M68k machine compiling Debian packages... (I doubt anyone uses those packages, esp. the OCaml ones, but that's the way it is). Proposed simplification below.

@xavierleroy
Copy link
Contributor

Yet this proves there were still Sun3 running in INRIA in 1996! At least in Rocquencourt

I probably restarted an old Sun 3/60 that was lying around just to do this M68k port. In retrospect, I should not have.

The use of %a5 conflicts with its internal usage as a GOT base by Glibc,
so shift assignments one register down.
@gasche gasche merged commit 5b32e48 into ocaml:trunk Jun 20, 2024
@ghost ghost deleted the m68k_is_not_dead branch June 20, 2024 13:59
glondu pushed a commit to glondu/ocaml that referenced this pull request Jun 28, 2024
The use of %a5 conflicts with its internal usage as a GOT base by Glibc,
so shift assignments one register down.

Origin: ocaml#13252
raspbian-autopush pushed a commit to raspbian-packages/ocaml that referenced this pull request Aug 20, 2024
The use of %a5 conflicts with its internal usage as a GOT base by Glibc,
so shift assignments one register down.

Origin: ocaml/ocaml#13252

Gbp-Pq: Name 0009-Rework-fixed-register-assignments-on-m68k.patch
raspbian-autopush pushed a commit to raspbian-packages/ocaml that referenced this pull request Aug 20, 2024
The use of %a5 conflicts with its internal usage as a GOT base by Glibc,
so shift assignments one register down.

Origin: ocaml/ocaml#13252

Gbp-Pq: Name 0009-Rework-fixed-register-assignments-on-m68k.patch
raspbian-autopush pushed a commit to raspbian-packages/ocaml that referenced this pull request Sep 5, 2024
The use of %a5 conflicts with its internal usage as a GOT base by Glibc,
so shift assignments one register down.

Origin: ocaml/ocaml#13252

Gbp-Pq: Name 0009-Rework-fixed-register-assignments-on-m68k.patch
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.

4 participants