Skip to content

cl(feat):llgo.asm implement tinygo.Asm#1217

Merged
xushiwei merged 2 commits intogoplus:mainfrom
luoliwoshang:llgo/asm
Aug 19, 2025
Merged

cl(feat):llgo.asm implement tinygo.Asm#1217
xushiwei merged 2 commits intogoplus:mainfrom
luoliwoshang:llgo/asm

Conversation

@luoliwoshang
Copy link
Member

@luoliwoshang luoliwoshang commented Aug 17, 2025

Resolved #1216
Implements llgo.asm compiler directive for inline assembly, following the existing LLGo instruction pattern.

Usage

//go:linkname asm llgo.asm
func asm(instruction string)

func main() {
    asm("nop")
}

https://llvm.org/docs/LangRef.html#inline-assembler-expressions

Inline assembler expressions may only be used as the callee operand of a call or an invoke instruction.

This explains why inline assembly appears as call void asm sideeffect "nop", ""() in LLVM IR. This is not an actual function call, but rather the structured syntax required by LLVM IR to represent inline assembly code within its type-safe intermediate representation.

test:asm test with `nop`
func main() {
start := time.Now()
for i := 0; i < 100000; i++ {
asm("nop")
Copy link
Member Author

Choose a reason for hiding this comment

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

NOTE:single asm call seems hardly to make a directive function verification

cl/import.go Outdated
llgoCgoCheckPointer = llgoCgoBase + 0x6
llgoCgoCgocall = llgoCgoBase + 0x7

llgoAsmBase = llgoInstrBase + 0x40
Copy link
Member

Choose a reason for hiding this comment

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

asm don't have many instructions, so we don't need llgoAsmBase.

Copy link
Member Author

Choose a reason for hiding this comment

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

got it, we can determine whether the instruction corresponds to a complex or simple implementation based on the number of parameters.
remove llgoAsmBase at afee2be

@luoliwoshang luoliwoshang changed the title cl(feat):llgo.Asm cl(feat):llgo.asm Aug 17, 2025
@luoliwoshang luoliwoshang changed the title cl(feat):llgo.asm cl(feat):llgo.asm implement tinygo.Asm Aug 18, 2025
@xushiwei xushiwei merged commit c5b4452 into goplus:main Aug 19, 2025
32 checks passed
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.

cl(feat): llgo.asm implement tinygo.Asm

2 participants