←back to thread

Show HN: Go Plan9 Memo

(pehringer.info)
302 points pehringer | 3 comments | | HN request time: 0.002s | source

A quick dive into the Plan9 assembly I picked up while developing my SIMD package for Go, and how it led to a 450% performance boost in calculations.
Show context
saclark11 ◴[] No.41880371[source]
> Overall, pretty weird stuff. I am not sure why the Go team went down this route. Maybe it simplifies the compiler by having this bespoke assembly format?

Rob Pike spoke on the design of Go's assembler at a talk in 2016 [1][2]. I think it basically came down to the observation that most assembly language is roughly the same, so why not build a common assembly language that "lets you talk to the machine at the lowest level and yet not have to learn a new syntax." It also enables them to automatically generate a working assembler given an instruction manual PDF for a new architecture as input.

[1]: https://www.youtube.com/watch?v=KINIAgRpkDA [2]: https://go.dev/talks/2016/asm.slide#1

replies(4): >>41880468 #>>41881654 #>>41884035 #>>41886094 #
alphazard ◴[] No.41880468[source]
And it worked. Go established cross-compilation as table-stakes for new programming languages, at a time when very few were doing it well, if at all.
replies(5): >>41880634 #>>41880798 #>>41883225 #>>41883804 #>>41884968 #
cloudfudge ◴[] No.41880798[source]
Yes, this is a great leap forward in my opinion. I had to do a project at a previous job where I wrote an agent that ran on x86, MIPS and ARM, and doing it in Go was a no-brainer. The other teams who had a bunch of C code that was a nightmare to cross-compile were so jealous they eventually moved a lot of things to Go.

I've been doing this for 35 years and cross compiling anything nontrivial was always a toolchain nightmare. Discovering a world where all I had to do was set GOARCH=mips64 (and possibly GOOS=darwin if I wanted mac binaries) before invoking the compiler is so magical I was extremely skeptical when I first read about it.

replies(4): >>41881898 #>>41882917 #>>41883141 #>>41886387 #
dsv3099i ◴[] No.41883141[source]
mips64!? That's a blast from the past. It must be some kind of legacy hw that's getting current software updates in some kind of really niche use case. Or academia. :)

Like previous you, I have to admit I'm skeptical but would be happy to be wrong.

replies(3): >>41883230 #>>41883246 #>>41883355 #
cloudfudge ◴[] No.41883246{3}[source]
> mips64 .. must be some kind of legacy hw that's getting current software updates

Hundreds of thousands of linux-based smartnic cards, actually. Fun stuff. Those particular ones were EOLd and have been replaced with ARM but the MIPS based ones will live on in the datacenters until they die, I'm sure.

> Like previous you, I have to admit I'm skeptical but would be happy to be wrong

Seriously, you are going to be delighted to be wrong. On your linux machine, go write a go program and write "GOOS=darwin GOARCH=arm64 go build ..." and you will have yourself an ARM mac binary. Or for going the other way, use GOOS=linux GOARCH=amd64. It really is that simple.

replies(1): >>41885834 #
ncruces ◴[] No.41885834{4}[source]
It gets even more amazing than that. Look at this bit from my GitHub Actions: https://github.com/ncruces/go-sqlite3/blob/fefee692dbfad39f6...

I install QEMU (I have the same setup locally), then it's one line each to run unit tests for: Linux 386, arm64, riscv64, ppc64le and s390x.

With QEMU installed, all you have to do is:

    GOARCH=bla go test ./...
replies(1): >>41888442 #
1. cryptofistMonk ◴[] No.41888442{5}[source]
Wait is go test automatically running it under QEMU or what's going on here?
replies(1): >>41888505 #
2. cryptofistMonk ◴[] No.41888505[source]
Ah I found this https://ctrl-c.us/posts/test-goarch I guess it's qemu-user-binfmt registering the alternate bin formats to automatically run under QEMU, that's pretty neat
replies(1): >>41888755 #
3. ncruces ◴[] No.41888755[source]
Yep.

The Go build system runs under your current architecture, cross-compiling tests to your target architecture.

Then, the Go test runner also runs under your current architecture, orchestrating running your cross compiled test binaries.

Since you registered to run cross-compiled binaries under QEMU, those test binaries magically run through QEMU.

The Go test runner collects test results, and reports back to you.

The first run might be slowish, as the Go compiler needs to cross compile the standard library and all your dependencies to your target platform. But once that's done and cached, and if your tests are fast, the edit-test cycle becomes pretty quick.