Skip to content

Add RISC-V 64 Support for LuaJIT v2.1#236

Open
IgnotaYun wants to merge 23 commits into
openresty:v2.1-agentzhfrom
IgnotaYun:v2.1-riscv64
Open

Add RISC-V 64 Support for LuaJIT v2.1#236
IgnotaYun wants to merge 23 commits into
openresty:v2.1-agentzhfrom
IgnotaYun:v2.1-riscv64

Conversation

@IgnotaYun

@IgnotaYun IgnotaYun commented Jun 27, 2024

Copy link
Copy Markdown

This set of patches adds support for RV64G LP64D on Linux, with full interpreter and JIT support.

Patch ported from PLCT LuaJIT, tested with LuaJIT/LuaJIT-test-cleanup.

See also upstream pr LuaJIT/LuaJIT#1267

@IgnotaYun

Copy link
Copy Markdown
Author

Oops, seems we have some issues with amd64 target……

@IgnotaYun

Copy link
Copy Markdown
Author

Oops, seems we have some issues with amd64 target……

Should have been fixed.

@IgnotaYun IgnotaYun force-pushed the v2.1-riscv64 branch 3 times, most recently from b2c6b14 to 74fe9b0 Compare July 3, 2024 14:09
@LocutusOfBorg LocutusOfBorg mentioned this pull request Nov 2, 2024
@mengzhuo

mengzhuo commented Nov 3, 2024

Copy link
Copy Markdown

Can we rerun Travis CI?
Alpine using this package for LuaJit2

@IgnotaYun

Copy link
Copy Markdown
Author

Can we rerun Travis CI?

Alpine using this package for LuaJit2

I'll do a patch refresh soon.

Btw, I'm considering dropping DynASM call pseudo in favor of "PLT inline" as it's more performant and less hacky.

@IgnotaYun

Copy link
Copy Markdown
Author

Can we rerun Travis CI? Alpine using this package for LuaJit2

Done, all passing.

@mengzhuo

mengzhuo commented Nov 8, 2024

Copy link
Copy Markdown

@zhuizhuhaomeng PTAL, thanks

@IgnotaYun IgnotaYun force-pushed the v2.1-riscv64 branch 3 times, most recently from cac9628 to 59e9671 Compare November 23, 2024 10:56
@yuzibo

yuzibo commented Nov 29, 2024

Copy link
Copy Markdown

Thanks for the work!

Debian luajit has supported riscv64 based on the patch. This fixed almost >30 build dependency issues. So far, there have been no reports of build failures or test failures.

@IgnotaYun IgnotaYun force-pushed the v2.1-riscv64 branch 5 times, most recently from 4e7448d to 887b468 Compare January 18, 2025 07:00
@IgnotaYun IgnotaYun force-pushed the v2.1-riscv64 branch 2 times, most recently from 3a2022a to ea214b2 Compare January 23, 2025 06:38
@BKPepe

BKPepe commented Oct 6, 2025

Copy link
Copy Markdown

@zhuizhuhaomeng Could you please take a look? 😇

@glaubitz

glaubitz commented Oct 7, 2025

Copy link
Copy Markdown

Is there a chance this can be reviewed?

@IgnotaYun

Copy link
Copy Markdown
Author

Is there a chance this can be reviewed?

Ultimately, it depends on upstream opinion (i.e., Mike).

I am currently employed full-time at PLCT Lab. As Mike focuses on version 3.0, we will ensure that a functional fork for version 2.1 is available.

@IgnotaYun

Copy link
Copy Markdown
Author

@andreas-schwab I've identified the bug and drafted a patch.
Please apply this patch for now, as merging upstream changes will take a bit longer.

Again, thanks for your report!

diff --git a/src/vm_riscv64.dasc b/src/vm_riscv64.dasc
index 8ba54b50..3e60f3cd 100644
--- a/src/vm_riscv64.dasc
+++ b/src/vm_riscv64.dasc
@@ -2876,8 +2876,10 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
     |  // Check if RA or RD is a cdata.
     |  xori TMP0, CARG3, LJ_TCDATA
     |  xori TMP1, CARG4, LJ_TCDATA
-    |  and TMP0, TMP0, TMP1
-    |  bxeqz TMP0, ->vmeta_equal_cd
+    |  seqz TMP0, TMP0
+    |  seqz TMP1, TMP1
+    |  or TMP0, TMP0, TMP1
+    |  bxnez TMP0, ->vmeta_equal_cd
     |.endif
     |  lui TMP3, (-(BCBIAS_J*4 >> 12)) & 0xfffff               // -BCBIAS_J*4
     |  decode_BC4b TMP2

@andreas-schwab

Copy link
Copy Markdown

Thanks, I can confirm that this fixes the problem.

@IgnotaYun IgnotaYun force-pushed the v2.1-riscv64 branch 2 times, most recently from f8b9fbb to 8f5c498 Compare June 16, 2026 09:12
@IgnotaYun

Copy link
Copy Markdown
Author

Bumped to LJRV 1ce02dd, based-off OpenResty LuaJIT v2.1-20260606.

bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Jun 17, 2026
https://build.opensuse.org/request/show/1359644
by user mcepl + anag_factory
- riscv64-support.patch: apply bugfix from
  openresty/luajit2/pull/236#issuecomment-4706366520
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.

7 participants