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

Enable !LJ_GC64 interpreter on PPC64. #140

Open
wants to merge 9 commits into
base: v2.1
Choose a base branch
from

Conversation

mwkmwkmwk
Copy link

This patchset gets the existing ppc interpreter working on powerpc64-linux (with no JIT and no FFI). My end goal is to get the interpreter+FFI+JIT working on powerpc64le-linux, and this is the first patchset in the series (the next patches will enable little-endian support, ELFv2 ABI, then do the same for FFI and JIT).

What do you think?

@mwkmwkmwk
Copy link
Author

Rebased on top of current v2.1. Ping.

@gut
Copy link

gut commented Apr 11, 2016

@Koriakin : Hi, did you check the #54 ? That implementation also has a functional FFI (JIT is not yet possible due to LJ_GC64 issue).

@edelsohn
Copy link

@gut #54 is the wrong approach in the short-term and we really would like to pursue the path that @Koriakin is proposes with his patches to enable the !LJ_GC64 interpreter and JIT on PPC64. Any help reviewing and merging the patches would be greatly appreciated!

@mwkmwkmwk
Copy link
Author

Rebased again. Ping?

This also adds a bit of plumbing to recognize ELF v2 ABI (which is NYI).
Since P64 no longer implies TOC, make TOC (and TOCENV) an independent define
passed to DynAsm from lj_arch.h.
The ABI mandates using CR save space in the caller's frame - we cannot use
the slot in our own frame, since some function we call could overwrite it.
@rrosatti
Copy link

rrosatti commented Aug 8, 2017

Hi, what's the status for this pull request?
I created a patch from this PR and it is already in debian/experimental: https://anonscm.debian.org/cgit/pkg-lua/luajit.git/tree/debian/patches/0004-Add-ppc64-support-based-on-koriakin-GitHub-patchset.patch?h=master-experimental
But, the best way to get this into stable is luajit release a version that includes the patch.

@gut
Copy link

gut commented Aug 30, 2017

Note: PR has conflicting files

@LuaJIT LuaJIT deleted a comment Jan 16, 2018
@clnperez
Copy link

clnperez commented Feb 6, 2018

Any hope of resurrecting this @Koriakin? I see you rebased in 2016 and never heard back on that. :/

@menantea
Copy link

Hi there, I am interesting to have this @Koriakin work integrated on luajit, could someone look at it ?
Thanks

@mwkmwkmwk
Copy link
Author

For what it's worth, I can cook up a new rebased version, but it doesn't seem to be a good use of resources if it's just going to end up being ignored (again). So, is there any hope of getting some comments on this patchset / getting it merged?

@elliottslaughter
Copy link

@Koriakin Sorry no one from the official team has been responding to you, and thank so much for putting in the time to do this.

As a user who really wants to use this, would you mind keeping it up-to-date anyway? I for one intend to use this, and based on the other responses it sounds like there are others too. Even in its current forked state, it's definitely useful to have this. The Summit supercomputer is coming up soon, which is Power9 based, so at least in the HPC community we're going to be stuck with this architecture for a while.

@edelsohn
Copy link

@elliottslaughter This issue was opened as a financial bounty. It's unfair to Marcin to request that he maintain the branch with no progress. If Summit and the HPC community wants LuaJIT for PPC64LE Linux, they should hire Marcin to maintain the fork or include a forked version in the deliverables for the Summit contract.

There are a few use cases (including users of nginx), but it doesn't make sense if the LuaJIT community won't respond. I think that users of LuaJIT should switch to another language with a more responsive and productive community.

|.endmacro
|
|->vm_exit_handler:
|.if JIT
| addi sp, sp, -(16+32*8+32*4)
| stmw r2, 16+32*8+2*4(sp)
| addi sp, TMP0, sp, -(EXIT_OFFSET+32*8+32*PSIZE)

Choose a reason for hiding this comment

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

FWIW, Debian is using the changes from this PR and the powerpc build fails because this addi instruction is incorrect:

make[4]: Entering directory '/<<PKGBUILDDIR>>/src'
HOSTCC    host/minilua.o
HOSTLINK  host/minilua
DYNASM    host/buildvm_arch.h
vm_ppc.dasc:2777: error: wrong number of parameters for `addi':
  |  addi sp, TMP0, sp, -(EXIT_OFFSET+32*8+32*PSIZE)
vm_ppc.dasc:*: info: 1 error in input file -- no output file generated.
make[4]: *** [Makefile:648: host/buildvm_arch.h] Error 1

Copy link

Choose a reason for hiding this comment

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

Ah, I missed that you already notified the author about this issue.

siddhesh pushed a commit to moonjit/moonjit that referenced this pull request Jun 12, 2019
 Create a patch for PPC64 support based on
LuaJIT#140.
https://bugzilla.redhat.com/show_bug.cgi?id=1591701
 This patch has been rebased to match FPU support

Author: Guy Menanteau <menantea@fr.ibm.com>

Signed-Off-By: Marcin Kościelnicki <koriakin@0x04.net
Signed-Off-By: Siddhesh Poyarekar <siddhesh@gotplt.org>
@glaubitz
Copy link

glaubitz commented Aug 2, 2019

Has this been PR tested on 32-bit PowerPC (big-endian)?

I see that ever since Debian has imported this patch to the luajit package to add support for ppc64el, the package fails to build from source:

Building LuaJIT 2.1.0-beta3
make -C src amalg
make[3]: Entering directory '/«PKGBUILDDIR»/src'
+--------------------------------------------------------------------------+
| WARNING: Compiling the amalgamation needs a lot of virtual memory        |
| (around 300 MB with GCC 4.x)! If you don't have enough physical memory   |
| your machine will start swapping to disk and the compile will not finish |
| within a reasonable amount of time.                                      |
| So either compile on a bigger machine or use the non-amalgamated build.  |
+--------------------------------------------------------------------------+
make all "LJCORE_O=ljamalg.o"
make[4]: Entering directory '/«PKGBUILDDIR»/src'
HOSTCC    host/minilua.o
HOSTLINK  host/minilua
DYNASM    host/buildvm_arch.h
vm_ppc.dasc:2777: error: wrong number of parameters for `addi':
  |  addi sp, TMP0, sp, -(EXIT_OFFSET+32*8+32*PSIZE)
vm_ppc.dasc:*: info: 1 error in input file -- no output file generated.
Makefile:647: recipe for target 'host/buildvm_arch.h' failed
make[4]: *** [host/buildvm_arch.h] Error 1
make[4]: Leaving directory '/«PKGBUILDDIR»/src'
Makefile:612: recipe for target 'amalg' failed
make[3]: *** [amalg] Error 2
make[3]: Leaving directory '/«PKGBUILDDIR»/src'
Makefile:158: recipe for target 'amalg' failed
make[2]: *** [amalg] Error 2

Could this be fixed before the merge? As far as I know, 32-bit PowerPC is still officially supported and we're still building packages for this target in both Debian and openSUSE (I happen to be developer for both).

Full log in: https://buildd.debian.org/status/fetch.php?pkg=luajit&arch=powerpc&ver=2.1.0%7Ebeta3-2&stamp=1502015864&raw=0

@clnperez
Copy link

clnperez commented Aug 7, 2019

@siddhesh if you still need a test system, you can also get one from http://openpower.ic.unicamp.br/minicloud/ . Feel free to use me [clnperez - at - us - dot - ibm - dot -com] as a reference when requesting. This will get you a linux VM you can use, since this is an open source project.

Do you have a fork for luajit2 already?

@glaubitz
Copy link

glaubitz commented Aug 7, 2019

@clnperez Does the minicloud have BE systems as this bug affects 32-bit big-endian?

@clnperez
Copy link

clnperez commented Aug 7, 2019

@glaubitz it does not. Sorry, I had read that but forgotten when I made that update. Thanks for the reminder.

@siddhesh
Copy link

siddhesh commented Aug 8, 2019

Sorry, got busy in $dayjob.

@siddhesh You can register for the gcc compile farm (https://gcc.gnu.org/wiki/CompileFarm) and use one of the POWER machines available there.

Last time I checked there weren't any ppc64 BE machines online. I checked again and indeed the one listed BE machine is offline.

If they don't have a usable machine there, please send me an email with my github username at debian dot org and we'll sort out access to a Debian POWER machine for you.

Thanks, I'll send you my pubkey.

Btw, how much effort would it be to add basic support for SPARC64?

It will be significant given the current architecture. It might be easier (about a month or so) to get a port without JIT.

@siddhesh
Copy link

siddhesh commented Aug 8, 2019

Do you have a fork for luajit2 already?

The luajit2 project is responsive, so my fork of luajit2 is basically just to post PRs. The only hurdle for the luajit2 fork being a proper replacement to this project is that it has a few openresty-specific language extensions that should go behind an optional flag. I'm working on that (and getting the ports I put in my fork, including this one) and hopefully by the end of it Debian should be able to simply replace luajit with luajit2 to get more regular updates; I intend to do the same for Fedora.

@siddhesh
Copy link

I've pushed the following fixes into master of my fork to fix this, thankfully it wasn't as bad as I thought it would be and the bugs mostly seem to be minor oversights:

moonjit@4121ead
moonjit@1b12bef
moonjit@f135acc
moonjit@4c83e55
moonjit@84240a6

@glaubitz
Copy link

@siddhesh Awesome, thanks a lot!

@seth-priya
Copy link

@siddhesh I am also interested in luajit for PPC64(LE), do you have an insight as to how much work (if any) remains on that front? and if there is anything I can help with?

I assume that you are planning to get the support for this into luajit2 ultimately?

@siddhesh
Copy link

Hi @seth-priya, there is still work to be done; incidentally someone just noticed that the JIT is not enabled for ppc64le[1]. You could work on fixing up the JIT compiler to emit correct code for ppc64le.

And yes, I do intend to get all of this stuff into luajit2.

[1] https://www.freelists.org/post/luajit/Luajit-build-for-ppc64le

@seth-priya
Copy link

Thanks @siddhesh, based on what you have seen while working on this, do you have a feel of how much effort might be involved in fixing the JIT compiler for ppc64le?

@seth-priya
Copy link

One more thing, I was able to build the code both from https://github.com/siddhesh/LuaJIT and integrating the Power patch (locally) to https://github.com/openresty/luajit2, there is one test case failure when I run the test suite at https://github.com/openresty/luajit2-test-suite (on both branches), as below

Not sure if I missed something, but I am checking further (this is on ppc64le / RHEL 7.6)
/usr/local/bin/luajit-2.1.0-beta3: math_special.lua:44: got: "+1 +0 nan nan +1 +1 nan nan nan"
expected: "+1 +1 +1 +1 +1 +1 +1 +1 +1"
stack traceback:
[C]: in function 'error'
math_special.lua:25: in function 'check'
math_special.lua:44: in main chunk
[C]: at 0x10005940
Failed test when running /usr/local/bin/luajit-2.1.0-beta3 math_special.lua 1: 256
1 tests failed.

@siddhesh
Copy link

That test is categorised as unportable in https://github.com/LuaJIT/LuaJIT-test-cleanup and I believe the luajit2 testsuite is based on an old version of this. I haven't looked at it closely, but there may be issues with the test itself. It's worth some investigation.

Please make a new issue/PR to discuss this though, since it seems like a distinct issue. An issue on my fork would be great but if you prefer using this fork it's fine too since I'm watching issues here too. I only cannot pull PRs from here and change issue/PR state, just like everyone else :)

@seth-priya
Copy link

@siddhesh sure, can't see an issues tab on https://github.com/siddhesh/LuaJIT though, looks like something you may need to enable explicitly for the fork? thanks!

@siddhesh
Copy link

Ahh, thanks for pointing out, I have enabled issues now.

@seth-priya
Copy link

@siddhesh I created an issue moonjit#2, and noted the observations there.

On your earlier comment,
_Hi @seth-priya, there is still work to be done; incidentally someone just noticed that the JIT is not enabled for ppc64le[1]. You could work on fixing up the JIT compiler to emit correct code for ppc64le.

And yes, I do intend to get all of this stuff into luajit2.

[1] https://www.freelists.org/post/luajit/Luajit-build-for-ppc64le_

since the JIT support may take a while to implement and is not necessarily required for all use cases, do you think we can move ahead with the current changes for Power and get them into luajit2? similar to what we already have for Z?

@seth-priya
Copy link

@siddhesh now that the test failure for ppc64le is resolved, any thoughts on the above comments? Can we push forward with the upstreaming of the Power changes (without JIT support)? There is an increasing number of open source packages that depend on openresty, currently the build for openresty fails on Power because luajit2 fails to build, having these changes up-stream would help cross the first hurdle … thoughts?

@siddhesh
Copy link

There you go @seth-priya:

openresty/luajit2#77

siddhesh pushed a commit to moonjit/moonjit that referenced this pull request Nov 23, 2019
 Create a patch for PPC64 support based on
LuaJIT#140.
https://bugzilla.redhat.com/show_bug.cgi?id=1591701
 This patch has been rebased to match FPU support

Author: Guy Menanteau <menantea@fr.ibm.com>

Signed-Off-By: Marcin Kościelnicki <koriakin@0x04.net
Signed-Off-By: Siddhesh Poyarekar <siddhesh@gotplt.org>
siddhesh pushed a commit to moonjit/moonjit that referenced this pull request Nov 23, 2019
 Create a patch for PPC64 support based on
LuaJIT#140.
https://bugzilla.redhat.com/show_bug.cgi?id=1591701
 This patch has been rebased to match FPU support

Author: Guy Menanteau <menantea@fr.ibm.com>

Signed-Off-By: Marcin Kościelnicki <koriakin@0x04.net
Signed-Off-By: Siddhesh Poyarekar <siddhesh@gotplt.org>
siddhesh pushed a commit to moonjit/moonjit that referenced this pull request Nov 23, 2019
 Create a patch for PPC64 support based on
LuaJIT#140.
https://bugzilla.redhat.com/show_bug.cgi?id=1591701
 This patch has been rebased to match FPU support

Author: Guy Menanteau <menantea@fr.ibm.com>

Signed-Off-By: Marcin Kościelnicki <koriakin@0x04.net
Signed-Off-By: Siddhesh Poyarekar <siddhesh@gotplt.org>
siddhesh pushed a commit to openresty/luajit2 that referenced this pull request May 3, 2020
 Create a patch for PPC64 support based on
LuaJIT/LuaJIT#140.
https://bugzilla.redhat.com/show_bug.cgi?id=1591701
 This patch has been rebased to match FPU support

Author: Guy Menanteau <menantea@fr.ibm.com>

Signed-Off-By: Marcin Kościelnicki <koriakin@0x04.net
Signed-Off-By: Siddhesh Poyarekar <siddhesh@gotplt.org>

[ppc] Fix access beyond list in ipairs

The load into TMP2 was incorrectly put into ENDIAN_LE, which made the
subsequent check invalid.

[ppc] Fix typo

[ppc]  Load BASEP4 as much as possible

BASEP4 doesn't seem to get initialized all the time, especially when
BASE is updated because of which programs can crash at random on
ppc32.  Err on the conservative side and set BASEP4 every time BASE_LO
(or BASE_HI for LE) are accessed.

This eventually needs to be tuned optimally.

[ppc] Revert LE code for assert

[ppc] Fix off by one in assert

It ended up reading the first argument twice.

Fix BC_POW on ppc64le
@mcepl
Copy link

mcepl commented Mar 23, 2022

@mwkmwkmwk Could I ask for the annual (or even less) rebase of this patch on the top of the current LuaJIT, please? There seems to be some live in LuaJIT now, so perhaps we can finally try to persuade @MikePall that it could be a good idea to merge. However, it certainly won't be easy if this PR still has conflict.

@elliottslaughter
Copy link

@mcepl For what it's worth, I've been using https://github.com/moonjit/moonjit successfully on PPC64le. It has patches that (to the best of my knowledge) are only on that fork, and is the only fork I've been able to use successfully on PPC64le. The maintainer stepped back a while ago, so it's technically unmaintained, but the code still works, and LuaJIT (unlike PUC Lua) actually maintains backwards compatibility, so feature-wise it's not falling behind. Not a great situation but hopefully survivable until at least the end of the current hardware cycle.

If someone did want to look at this, it would definitely be important to make sure this fork (or whichever one we move forward with) is up to date with all the relevant patches.

@mcepl
Copy link

mcepl commented Mar 24, 2022

@elliottslaughter I know about moonjit. I am the lead maintainer of Lua packages for openSUSE, a Linux distribution. We have package for moonjit available, but it is not available for normal users, because it is difficult to keep two LuaJIT interpreters side-by-side (yes, it is possible to somehow make it more configurable and have only one switched on as the LuaJIT interpreter for the distribution, but it is too much work than I can provide; patches welcome!).

Yes, we can live without PPC64 support for some time (a long time), but I would much prefer if the efforts could be harmonized into one project.

@barracuda156
Copy link

@mwkmwkmwk

  1. I hope this will not break ppc what exists now? We need it working on Big-endian targets, including 32-bit Darwin. (64-bit is broken, I believe.)
  2. Adding support for ppc64 should be Bi-endian.

@@ -245,7 +241,7 @@ void emit_asm(BuildCtx *ctx)
int i, rel;

fprintf(ctx->fp, "\t.file \"buildvm_%s.dasc\"\n", ctx->dasm_arch);
#if LJ_ARCH_PPC64
#if LJ_ARCH_PPC_ELFV2

Choose a reason for hiding this comment

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

Is this specifically ELF-only?

@@ -86,10 +86,23 @@ typedef union FPRArg {
#elif LJ_TARGET_PPC

#define CCALL_NARG_GPR 8
#if LJ_ARCH_BITS == 64
#define CCALL_NARG_FPR 13

Choose a reason for hiding this comment

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

Is this is a number of arguments to be passed in FPR, it should be 14, AFAIK, and not restricted to ppc64: 32-bit ppc also has 14 FPRs available:

The registers that can be used to pass arguments to called functions are the general-purpose registers GPR3 through GPR10, the floating-point registers FPR1 through FPR13, and the vector registers V2 through V13 (see "Register Preservation" (page 23) for details).
http://personal.denison.edu/~bressoud/cs281-s07/MacOSXLowLevelABI.pdf

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