Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Lots of optimized code in Go's standard library has fast paths in assembly which is linked into the final binary on a platform by platform basis. I this sense, it's probably easier than C to drop into assembly. Granted, Go's memory model is not going to enforce a whole lot so you better know what you're doing at this point.


Eh? Go doesn't have any capability to include inline assembly,

> "There is no facility in the Go programming language to support in-line assembler language code, and there are no plans to do so" http://stackoverflow.com/questions/2951028/is-it-possible-to...

Of course the C parts of Go's standard library have optimized assembly - using C's capability to do.

So Go is not easier in any way for dropping into assembly - in fact it's much harder, you can't do it in the language, at best you might be lucky if Go's library does some stuff like that for you.


I didn't say inline. I said linked. It's pretty easy to add.


You said "easier than C". How is linking to assembly code from Go any easier than linking to assembly code from C?


Just go see how it's done. Look for example at how `math.Exp` is declared:

http://golang.org/src/pkg/math/exp.go?s=368:395#L4

You'll notice that 'exp' is defined below, using Go.

However, 'Exp' is also defined in Assembly. For example, amd64:

http://golang.org/src/pkg/math/exp_amd64.s

This is all compatible with the `go` tool. You just drop in your Assembly, run `go build`, and the appropriate Assembly version is chosen based on your target architecture (or the Go code is used as a fallback if no Assembly for the target architecture exists).

I don't have much experience with inlining Assembly in C, but this is pretty damn easy.


That is so awesome, I'm willing to bet they plan on inlining quite a few functions in the future too... which means drastic speedups.


Easy? Sure. Easier than C? Nope. Sounds like it has the equivalent of a few make rules written for you (which is nice, make is a mess, but not really an advantage for go-the-language per se), but you could do exactly the same thing in C - and you can also inline assembly in your C source file.


> Sounds like it has the equivalent of a few make rules written for you

No. It sounds like the `go` tool is aware of how to compile different pieces of code for different architectures.

> but you could do exactly the same thing in C - and you can also inline assembly in your C source file.

Why does this make C easier? Does C automatically choose the correct target architecture for every piece of Assembly you write?


>Why does this make C easier?

It gives you more options. It makes it more practical to interleave C and assembly at a very granular level, whereas it sounds like you can only do it at the function level or coarser in go.

>Does C automatically choose the correct target architecture for every piece of Assembly you write?

No. I won't deny that go has a good build system, but I'm more interested in the language.


> Why does this make C easier?

Inlining some assembly where you need it - interacting with C variables, etc. - is definitely the most convenient thing.

Of course, if you don't want that, you can just put the assembly code in a separate function, also very easy to do with C.


> I don't have much experience with inlining Assembly in C, but this is pretty damn easy.

It's about the same as C. If you want to see really easy, take a look at how LuaJIT does it (DynASM).


It allows multiple platforms to be implemented w/o a series of macros.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: