←back to thread

Show HN: Go Plan9 Memo

(pehringer.info)
302 points pehringer | 1 comments | | HN request time: 0s | 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 #
p_l ◴[] No.41880634[source]
Go essentially copied the design from Plan9 compilers, which it was originally based on. It's one of the many things it inherited from Plan9 environment.
replies(1): >>41880900 #
kjksf ◴[] No.41880900[source]
It's more "reused" because Plan9 compilers were designed / co-implemented by Pike / Thomson, 2 out of 3 original designers of Go.

For those interested, here's Thomson's paper about Plan9 C compilers: https://9p.io/sys/doc/compiler.html and https://doc.cat-v.org/bell_labs/new_c_compilers/

replies(1): >>41881241 #
derefr ◴[] No.41881241{3}[source]
I would love to see a deep dive on what features / architectural paradigms the Golang runtime shares with Plan9. Has anything like that been written?

One that always sticks out to me personally is the use in Go of the term "dial" instead of "connect" for network connection establishment. This is, AFAICT, another Pike+Thompson-ism, as it can be seen previously in the form of the Plan9 dial(3) syscall — https://9fans.github.io/plan9port/man/man3/dial.html .

---

A tangent: I have wondered before whether Pike and Thompson drafted the design for the language that would become Golang long before working at Google, initially to replace C specifically in the context of being the lingua-franca for systems programming on Plan 9. And that, therefore — at least in the designer's minds — Golang would have always had Plan9 as its secret "flagship target" that it should have a 1:1 zero-impedance abstraction mapping onto. Even if they never bothered to actually make a Plan9 Golang runtime.

You could test this hypothesis by implementing an actual Golang runtime for Plan9†, and then comparing it to the Golang runtimes for other OSes — if Plan9 were the "intended home" for Golang programs, then you'd expect the Golang runtime to be very "thin" on Plan9.

(To put that another way: imagine the Golang runtime as something like WINE — a virtualization layer that implements things that could be syscalls / OS library code, in the form of client-side runtime shim code. A "WINE implementation for Windows" would be an extremely thin shim, as every shim call would just point to a 1:1-API-matched piece of OS-provided code. My hypothesis here is that "Golang for Plan9" is the same kind of thing as "WINE for Windows.")

† I was saying this as a thought experiment, not thinking there would actually be a Plan9 implementation of the Golang runtime... but there is! (https://go.dev/wiki/Plan9) So someone can actually check this :)

replies(3): >>41881641 #>>41882050 #>>41882466 #
mbivert ◴[] No.41881641{4}[source]
> I would love to see a deep dive on what features / architectural paradigms the Golang runtime shares with Plan9. Has anything like that been written?

If it has, then it's most likely available on https://cat-v.org/. Even if it hasn't, cat-v.org is a great starting point.

Besides, close to your line of thought, and assuming you didn't knew about this already, Pike & al previously worked on Limbo[0], a "predecessor" of Go, used to wrote Inferno[1], a Plan9-like OS, which could be hosted on arbitrary OSes via a bespoke virtual machine called "Dis".

So there were indeed a few previous "drafts" for Go. I'd doubt that Go has been designed "for" Plan9 though.

[0]: https://en.wikipedia.org/wiki/Limbo_(programming_language)

[1]: https://en.wikipedia.org/wiki/Inferno_(operating_system)

replies(1): >>41882143 #
1. exitb ◴[] No.41882143{5}[source]
There’s also libthread[1] which implements concurrency model similar to goroutines (at least earlier, as they appear to be no longer just cooperatively scheduled?). That manual also mentions Alef and Newsqueak as influential predecessors.

[1] http://man.9front.org/2/thread