zig icon indicating copy to clipboard operation
zig copied to clipboard

loongarch: Scaffold self-hosted LoongArch backend

Open xtexx opened this issue 6 months ago • 12 comments

This PR adds a self-hosted LoongArch64 backend.

The backend currently implements only a few features.

Test runner is working, but due to the very limited number of passing behavior tests, the backend is not added to the test target list.

Although it is foreseeable that I will not have much time to work on this backend in the coming one year due to my study, I will try to keep the backend working and expand its features.

xtexx avatar Jun 14 '25 10:06 xtexx

No, it also generates encoders for LA32(S/R). Thank you for looking into this PR. I will rename this file next weekend as soon as I am available.

xtexx avatar Jun 15 '25 09:06 xtexx

cc @jacobly0 to review the general structure of the new backend.

alexrp avatar Jun 16 '25 05:06 alexrp

You might want to git mv src/arch/loongarch64 src/codegen/loongarch now to avoid annoying conflicts when somebody else does it later.

jacobly0 avatar Jun 16 '25 12:06 jacobly0

I had just force-pushed to rebase onto master, moving src/arch/loongarch64 to src/arch/loongarch, adding basic support for LA32.

xtexx avatar Jun 20 '25 13:06 xtexx

RISC-V CI failures seem related.

alexrp avatar Jun 24 '25 13:06 alexrp

They should be addressed once rebased onto https://github.com/ziglang/zig/pull/24180

xtexx avatar Jun 25 '25 23:06 xtexx

Needs a rebase (due to writergate?).

alexrp avatar Jul 11 '25 03:07 alexrp

FYI, we're in the process of purchasing a Loongson 3C6000/S machine for CI, so merging this will probably have to wait until we have that up and running.

alexrp avatar Aug 03 '25 09:08 alexrp

We have a machine now:

$ lscpu
Architecture:                loongarch64
  CPU op-mode(s):            32-bit, 64-bit
  Address sizes:             48 bits physical, 48 bits virtual
  Byte Order:                Little Endian
CPU(s):                      32
  On-line CPU(s) list:       0-31
Model name:                  Loongson-3C6000
  CPU family:                Loongson-64bit
  Model:                     0x10
  Thread(s) per core:        1
  Core(s) per socket:        32
  Socket(s):                 1
  BogoMIPS:                  4400,00
  Flags:                     cpucfg lam ual fpu lsx lasx crc32 complex crypto lspw lvz lbt_x86 lbt_arm lbt_mips
Caches (sum of all):
  L1d:                       2 MiB (32 instances)
  L1i:                       2 MiB (32 instances)
  L2:                        8 MiB (32 instances)
  L3:                        32 MiB (1 instance)
NUMA:
  NUMA node(s):              1
  NUMA node0 CPU(s):         0-31
Vulnerabilities:
  Gather data sampling:      Not affected
  Ghostwrite:                Not affected
  Indirect target selection: Not affected
  Itlb multihit:             Not affected
  L1tf:                      Not affected
  Mds:                       Not affected
  Meltdown:                  Not affected
  Mmio stale data:           Not affected
  Old microcode:             Not affected
  Reg file data sampling:    Not affected
  Retbleed:                  Not affected
  Spec rstack overflow:      Not affected
  Spec store bypass:         Not affected
  Spectre v1:                Not affected
  Spectre v2:                Not affected
  Srbds:                     Not affected
  Tsa:                       Not affected
  Tsx async abort:           Not affected
  Vmscape:                   Not affected
$ lsmem
RANGE                                  SIZE  STATE REMOVABLE BLOCK
0x0000000000000000-0x000000001fffffff  512M online       yes     0
0x0000000080000000-0x000000207fffffff  128G online       yes 4-259

Memory block size:                512M
Total online memory:             128,5G
Total offline memory:               0B

Still some infra stuff to do on our end to get it hooked up to CI, but just wanted to let you know that things are coming along.

alexrp avatar Sep 16 '25 09:09 alexrp

Yeah! On my side I am going to rewrite this PR (while it may take another some months).

xtexx avatar Sep 20 '25 05:09 xtexx

I'm assuming most people have noticed by now, but just for the record, the LoongArch CI machine is running over on Codeberg: https://codeberg.org/ziglang/zig/actions/runs/107/jobs/2/attempt/1

So you'll want to open this PR over there when you get back to it.

alexrp avatar Oct 25 '25 23:10 alexrp

Thanks for the hint. I am currently working on the rewrite of this PR which will still take some time to finish.

xtexx avatar Oct 29 '25 07:10 xtexx