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

Neat, but I don't quite get it. How do I pass values between Go code and assembly? The format of this site is a little strange: it looks like an example Go snippet, followed by what I assume is the equivalent assembly code--but where is the connection? Or, is the point simply to teach us Go devs assembly?

Also, when is an appropriate time to use assembly in a Go program? After the failed trig experiment blog post that was featured here last week, the benefits aren't very clear to me.

EDIT: ok, I see it now. The empty function declaration. What an odd syntax. I get the tutorial now, but still wondering about the benefits.



Author of the failed trig experiment here.

After looking at the comments from people more knowledgeable than me, I realized that it had failed mostly because the assembly that I wrote was pretty bad. You have to know assembly language pretty well to beat the compiler.

I have been spending more time with this. And I understand my faults a bit better now. There are a lot of places which can be improved. And I have sent a CL to add some commands to the Go assembler (so that I don't have to write the ugly hex codes :P)

I plan to revisit the code once the CL is merged. And see how it goes.

To answer your question - You might get benefits if:

* You really understand what the compiler is doing.

* You know the current shortcomings of the Go assembler and the latest amd64 instruction set.

* You know assembly language well enough to write custom code for your problem and beat the compiler.

From what I have seen - the Go assembler attempts to generate binary code which supports old amd64 processors too. As a result of which you cannot take advantage of the latest instructions which come as part of AVX2 extensions. If you are doing high performance math stuff and know the AVX2 instruction set like the back of your hand, then you are sure to reap benefits.

Cheers.


Like in any programs to get better optimisation / performance on very specific functions.


Not sure if you saw the blog post I referenced that was trending here last week. These types of optimizations often turn out to be underwhelming.


Not true at all, there are 20-50x speedups for some of the functions that have been optimized into Go assembly. Specific cryptography routines for which CPUs have dedicated instructions. Those are the kinds of places where you'd use it. If you want to write assembly because you think you can generate better code than the compiler, you probably can, but it also almost certainly will be underwhelming as you say. It's only really worth it when you're using instructions the compiler won't emit, like specialized crypto, math, bit counting instructions, or SIMD instructions.




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

Search: