Skip to content(if available)orjump to list(if available)

How to store Go pointers from assembly

jasonthorsness

Go assembler is such a strange inclusion - I guess the idea is it lets you do low-level routines without requiring CGO?

foobiekr

Sometimes you need assembly. There's nothing shocking here other than Go doing this well when it's a gap for most languages.

Thaxll

It's heavily used where you need performance, for example crypto.

https://go.dev/wiki/AssemblyPolicy

https://github.com/golang/go/tree/master/src/crypto/internal...

nasretdinov

My understanding is that for crypto specifically it constant-time algorithms matter due to security implications, and those are only available when you use specific branchless assembly instructions, so it's not just performance

foobiekr

Just to pick nits, the important thing is basically no secret-dependent { branches, loop bounds checks, memory accesses }. This is a lot more complex than simple "constant time."

charcircuit

CPUs do not guarantee that branchless instructions always take the same amount of time.

nu11ptr

That is my understanding. It lets you bypass CGo overhead, but I'd be lying if I said I fully understood it.

cyberax

Remember that Go actually compiles the code to machine code directly, so it needs to have an assembler for its compiler. And if you have it, then why not make it available?

pjmlp

Not really, having an Assembler around has been quite common in compiled languages, before the rise of scripting languages in the 2000's.

For all my complaints about Go's design, that is certainly one that I appreciate.