golang / golang/go

proposal: all: add GOLOONG64 environment variable

Open
#80,930 7 comments 2 reactions 0 assignees View on GitHub
arch-loong64 Proposal
Dominant language
Go
Stars
139k
Forks
19.9k
PR merge metrics
PR metrics pending

Description

Currently, the LoongArch ISA has evolved into two iterations (V1.0 and V1.1), introducing new instructions, some of which are beneficial to Go. For instance, V1.1 introduces the following:
- SC.Q instruction.
- LLACQ.W, SCREL.W, LLACQ.D, and SCREL.D instructions.
- AMCAS.B, AMCAS.H, AMCAS.W, AMCAS.D, AMCAS_DB.B, AMCAS_DB.H, AMCAS_DB.W, AMCAS_DB.D, AMSWAP.B, and AMSWAP.H instructions.
- AMADD.B, AMADD.H, AMSWAP_DB.B, AMSWAP_DB.H, AMADD_DB.B, and AMADD_DB.H instructions.
- Functional definitions for certain non-zero hint values of the dbar instruction.
- New evaluation methods for determining whether 32-bit integer division instructions on 64-bit machines are affected by the upper 32 bits of the source operand registers.
...

These instructions are currently used after runtime capability checks. Although these branches are highly predictable and the code blocks are minuscule, the CPU cycles they consume still add up significantly under high-frequency usage.

Therefore, this change proposes a new loong64-specific environment variable, GOLOONG64. The compiler and assembly functions can utilize this variable to determine which extensions are safe to use without relying on runtime checks, thereby potentiality improving performance and reducing binary size.

An initial version has been implemented, and the atomic operation logic has been refactored accordingly. Benchmarks conducted using the sweet/CockroachDB suite on a Loongson-3C6000/S machine demonstrate a promising performance gain.
Benchmarks/sweet/CockroachDB:

```
GOARCH: loong64
CPU: Loongson-3C6000/S @ 2200.00MHz
GOOS: linux

| old.results | new.results |
| sec/op | sec/op vs base |
CockroachDBkv0/nodes=1-16 495.0µ ± 5% 463.6µ ± 1% -6.35% (p=0.002 n=6)
CockroachDBkv50/nodes=1-16 527.2µ ± 2% 508.3µ ± 1% -3.59% (p=0.002 n=6)
CockroachDBkv95/nodes=1-16 567.7µ ± 4% 535.0µ ± 1% -5.77% (p=0.002 n=6)
CockroachDBkv0/nodes=3-16 489.3µ ± 1% 463.7µ ± 2% -5.24% (p=0.002 n=6)
CockroachDBkv50/nodes=3-16 530.2µ ± 1% 504.5µ ± 2% -4.84% (p=0.002 n=6)
CockroachDBkv95/nodes=3-16 563.6µ ± 1% 535.8µ ± 2% -4.93% (p=0.002 n=6)
geomean 528.0µ 500.9µ -5.12%
```

- Suggested values for GOLOONG64:

| GOLOONG64 Value | buildcfg.GOLOONG64 | Build Tags | optional | Key new facilities / instructions |
| :--- | :---: | :--- |:--- |:--- |
| v1.0 | 10 | loong64.v1.0 | ,lsx and ,lasx | - |
| v1.1 | 11 | loong64.v1.1 | ,lsx and ,lasx | (List of V1.1 instructions above) |

- _lsx: Loongson SIMD Extension (128-bit vector extension)_
- _lasx: Loongson Advanced SIMD Extension (256-bit vector extension)_

Contributor guide

Open the contributing guide

Research direction

No files or tests are named. Start by locating the existing runtime capability checks and atomic-operation logic referenced in the proposal, then trace how compiler and assembly settings are selected. Done means GOLOONG64 supports v1.0 and v1.1, exposes the stated buildcfg and build tags, and lets the relevant code use safe extensions without repeated runtime checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend, compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.