Help us shape the future of Go! Take the 2026 Go Developer Survey

arm64

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package arm64 encodes the subset of A64 instructions the JIT emits.

Methods append one instruction each. Branches take labels, which are resolved by Code. Encodings follow the Arm Architecture Reference Manual; asm_test.go checks them against the system assembler.

Index

Constants

This section is empty.

Variables

View Source
var ErrTestRange = errors.New("arm64: test branch out of range")

ErrTestRange is Code's error for a Tbz or Tbnz farther than ±32 KB from its label, which LongTests allows.

Functions

This section is empty.

Types

type Asm

type Asm struct {

	// LongTests makes Tbz and Tbnz reach any label, as two instructions:
	// the opposite test, skipping an unconditional branch to the label.
	// Without it they reach ±32 KB, and Code reports ErrTestRange for one
	// that does not.
	LongTests bool
	// contains filtered or unexported fields
}

Asm accumulates instructions.

func (*Asm) Add

func (a *Asm) Add(rd, rn, rm Reg)

Add computes rd = rn + rm.

func (*Asm) AddImm

func (a *Asm) AddImm(rd, rn Reg, imm uint32)

AddImm computes rd = rn + imm, for imm in [0, 4095].

func (*Asm) AddShifted

func (a *Asm) AddShifted(rd, rn, rm Reg, shift uint32)

AddShifted computes rd = rn + rm<<shift.

func (*Asm) And

func (a *Asm) And(rd, rn, rm Reg)

And, Orr and Eor compute rd = rn & rm, rn | rm and rn ^ rm.

func (*Asm) Asr

func (a *Asm) Asr(rd, rn Reg, shift uint32)

Asr shifts rn right, signed, by shift into rd.

func (*Asm) B

func (a *Asm) B(l Label)

B branches to l.

func (*Asm) BCond

func (a *Asm) BCond(c Cond, l Label)

BCond branches to l when c holds.

func (*Asm) Bind

func (a *Asm) Bind(l Label)

Bind binds l to the next instruction.

func (*Asm) Br

func (a *Asm) Br(rn Reg)

Br branches to the address in rn.

func (*Asm) Cbnz

func (a *Asm) Cbnz(rt Reg, l Label)

Cbnz branches to l when rt is not zero.

func (*Asm) Cbz

func (a *Asm) Cbz(rt Reg, l Label)

Cbz branches to l when rt is zero.

func (*Asm) Cmp

func (a *Asm) Cmp(rn, rm Reg)

Cmp compares rn with rm.

func (*Asm) CmpImm

func (a *Asm) CmpImm(rn Reg, imm uint32)

CmpImm compares rn with imm.

func (*Asm) Code

func (a *Asm) Code() ([]byte, error)

Code resolves branches and returns the machine code.

func (*Asm) Csel

func (a *Asm) Csel(rd, rn, rm Reg, c Cond)

Csel computes rd = rn if c holds, else rm.

func (*Asm) Eor

func (a *Asm) Eor(rd, rn, rm Reg)

func (*Asm) Fabs

func (a *Asm) Fabs(fd, fn FReg)

Fabs computes fd = |fn|.

func (*Asm) Fadd

func (a *Asm) Fadd(fd, fn, fm FReg)

Fadd computes fd = fn + fm.

func (*Asm) Fcmp

func (a *Asm) Fcmp(fn, fm FReg)

Fcmp compares fn with fm. After it, MI means less, LS less or equal, GT greater and GE greater or equal, all false when either is NaN; EQ is equal and NE is not equal or unordered.

func (*Asm) FcvtDS

func (a *Asm) FcvtDS(fd, fn FReg)

func (*Asm) FcvtSD

func (a *Asm) FcvtSD(fd, fn FReg)

FcvtSD converts the float32 in fn to a double in fd; FcvtDS rounds the double in fn to a float32 in fd.

func (*Asm) Fcvtzs

func (a *Asm) Fcvtzs(rd Reg, fn FReg)

Fcvtzs converts fn to a signed integer in rd, rounding toward zero and saturating, as Go's int(f) does on arm64.

func (*Asm) Fcvtzu

func (a *Asm) Fcvtzu(rd Reg, fn FReg)

Fcvtzu converts fn to an unsigned integer in rd, rounding toward zero and saturating, as Go's uint64(f) does on arm64.

func (*Asm) Fdiv

func (a *Asm) Fdiv(fd, fn, fm FReg)

Fdiv computes fd = fn / fm.

func (*Asm) Fmadd

func (a *Asm) Fmadd(fd, fn, fm, fa FReg)

Fmadd computes fd = fa + fn*fm with a single rounding.

func (*Asm) Fmov

func (a *Asm) Fmov(fd, fn FReg)

Fmov copies fn to fd.

func (*Asm) FmovFromF

func (a *Asm) FmovFromF(rd Reg, fn FReg)

FmovFromF copies the bits of fn to rd.

func (*Asm) FmovToF

func (a *Asm) FmovToF(fd FReg, rn Reg)

FmovToF copies the bits of rn to fd.

func (*Asm) Fmsub

func (a *Asm) Fmsub(fd, fn, fm, fa FReg)

Fmsub computes fd = fa - fn*fm with a single rounding.

func (*Asm) Fmul

func (a *Asm) Fmul(fd, fn, fm FReg)

Fmul computes fd = fn * fm.

func (*Asm) Fneg

func (a *Asm) Fneg(fd, fn FReg)

Fneg computes fd = -fn.

func (*Asm) Frintm

func (a *Asm) Frintm(fd, fn FReg)

Frintm rounds fn toward minus infinity.

func (*Asm) Frintp

func (a *Asm) Frintp(fd, fn FReg)

Frintp rounds fn toward plus infinity.

func (*Asm) Fsqrt

func (a *Asm) Fsqrt(fd, fn FReg)

Fsqrt computes fd = sqrt(fn).

func (*Asm) Fsub

func (a *Asm) Fsub(fd, fn, fm FReg)

Fsub computes fd = fn - fm.

func (*Asm) Ldr

func (a *Asm) Ldr(rt, rn Reg, off uint32)

Ldr loads the 64-bit word at rn+off, where off is a multiple of 8 below 32768.

func (*Asm) LdrD

func (a *Asm) LdrD(ft FReg, rn Reg, off uint32)

LdrD loads the double at rn+off.

func (*Asm) LdrS

func (a *Asm) LdrS(ft FReg, rn Reg, off uint32)

LdrS loads the float32 at rn+off into the low bits of ft.

func (*Asm) LdrW

func (a *Asm) LdrW(rt, rn Reg, off uint32)

LdrW loads the 32-bit word at rn+off, zero-extended.

func (*Asm) Ldrb

func (a *Asm) Ldrb(rt, rn Reg, off uint32)

Ldrb loads the byte at rn+off into rt, zero-extended.

func (*Asm) Ldrsw

func (a *Asm) Ldrsw(rt, rn Reg, off uint32)

Ldrsw loads the 32-bit word at rn+off into rt, sign-extended.

func (*Asm) Len

func (a *Asm) Len() int

Len returns the number of instructions emitted so far.

func (*Asm) Lslv

func (a *Asm) Lslv(rd, rn, rm Reg)

Lslv and Lsrv shift rn left or right, logically, by rm mod 64.

func (*Asm) Lsr

func (a *Asm) Lsr(rd, rn Reg, shift uint32)

Lsr computes rd = rn >> shift, unsigned.

func (*Asm) Lsrv

func (a *Asm) Lsrv(rd, rn, rm Reg)

func (*Asm) Mov

func (a *Asm) Mov(rd, rm Reg)

Mov copies rm to rd.

func (*Asm) MovImm

func (a *Asm) MovImm(rd Reg, v uint64)

MovImm loads a 64-bit constant into rd with MOVZ and MOVK.

func (*Asm) Msub

func (a *Asm) Msub(rd, rn, rm, ra Reg)

Msub computes rd = ra - rn*rm.

func (*Asm) Mul

func (a *Asm) Mul(rd, rn, rm Reg)

Mul computes rd = rn * rm, keeping the low 64 bits.

func (*Asm) Mvn

func (a *Asm) Mvn(rd, rm Reg)

Mvn computes rd = ^rm.

func (*Asm) Neg

func (a *Asm) Neg(rd, rm Reg)

Neg computes rd = -rm.

func (*Asm) NewLabel

func (a *Asm) NewLabel() Label

NewLabel returns an unbound label.

func (*Asm) Offset

func (a *Asm) Offset(l Label) int

Offset returns the byte offset of bound label l.

func (*Asm) Orr

func (a *Asm) Orr(rd, rn, rm Reg)

func (*Asm) Ret

func (a *Asm) Ret()

Ret returns through the link register.

func (*Asm) Scvtf

func (a *Asm) Scvtf(fd FReg, rn Reg)

Scvtf converts the signed integer in rn to a double in fd.

func (*Asm) Sdiv

func (a *Asm) Sdiv(rd, rn, rm Reg)

Sdiv and Udiv compute rd = rn / rm, signed and unsigned, rounding toward zero. Dividing by zero gives zero.

func (*Asm) Smulh

func (a *Asm) Smulh(rd, rn, rm Reg)

Smulh computes rd = the high 64 bits of the signed 128-bit rn * rm.

func (*Asm) Str

func (a *Asm) Str(rt, rn Reg, off uint32)

Str stores rt at rn+off, where off is a multiple of 8 below 32768.

func (*Asm) StrD

func (a *Asm) StrD(ft FReg, rn Reg, off uint32)

StrD stores the double ft at rn+off.

func (*Asm) StrS

func (a *Asm) StrS(ft FReg, rn Reg, off uint32)

StrS stores the float32 in the low bits of ft at rn+off.

func (*Asm) StrW

func (a *Asm) StrW(rt, rn Reg, off uint32)

StrW stores the low 32 bits of rt at rn+off.

func (*Asm) Strb

func (a *Asm) Strb(rt, rn Reg, off uint32)

Strb stores the low byte of rt at rn+off.

func (*Asm) Sub

func (a *Asm) Sub(rd, rn, rm Reg)

Sub computes rd = rn - rm.

func (*Asm) SubImm

func (a *Asm) SubImm(rd, rn Reg, imm uint32)

SubImm computes rd = rn - imm, for imm in [0, 4095].

func (*Asm) SubsImm

func (a *Asm) SubsImm(rd, rn Reg, imm uint32)

SubsImm computes rd = rn - imm and sets the flags.

func (*Asm) Tbnz

func (a *Asm) Tbnz(rt Reg, b uint32, l Label)

Tbnz branches to l when bit b of rt is one.

func (*Asm) Tbz

func (a *Asm) Tbz(rt Reg, b uint32, l Label)

Tbz branches to l when bit b of rt is zero.

func (*Asm) Ucvtf

func (a *Asm) Ucvtf(fd FReg, rn Reg)

Ucvtf converts the unsigned integer in rn to a double in fd.

func (*Asm) Udiv

func (a *Asm) Udiv(rd, rn, rm Reg)

type Cond

type Cond uint8

Cond is a condition code.

const (
	EQ Cond = 0
	NE Cond = 1
	HS Cond = 2
	LO Cond = 3
	MI Cond = 4
	PL Cond = 5
	VS Cond = 6
	VC Cond = 7
	HI Cond = 8
	LS Cond = 9
	GE Cond = 10
	LT Cond = 11
	GT Cond = 12
	LE Cond = 13
)

type FReg

type FReg uint8

FReg is a floating-point register, D0 to D31.

type Label

type Label int

Label marks a position in the code.

type Reg

type Reg uint8

Reg is a general-purpose register, X0 to X30. ZR is the zero register, and SP the stack pointer in the instructions that accept it.

const (
	ZR Reg = 31
	SP Reg = 31
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL