News for hackers. Stuff that matters.
Re:Show HN: Accelerating SHA256 by 100x in Golang on ARM by theparanoid on Wednesday July 27, 2016 @05:02PM (#12176496)
The amount of assembly in the Go ecosystem is crazy, ~1% of the standard library is assembly. There are better ways.
Re:Show HN: Accelerating SHA256 by 100x in Golang on ARM by giovannibajo1 on Wednesday July 27, 2016 @05:17PM (#12176572)
Most of it is written to take advantage of special hardware instructions in CPUs. If you take OpenSSL (a C library), it's got many assembly code paths as well.

I'm not sure why this should be a problem, it just shows attention to performance in my opinion.

Re:Show HN: Accelerating SHA256 by 100x in Golang on ARM by pcwalton on Wednesday July 27, 2016 @10:53PM (#12178046)
Opaque assembly blocks that the compiler doesn't understand the effects of are actually suboptimal for performance.
Re:Show HN: Accelerating SHA256 by 100x in Golang on ARM by Cthulhu_ on Thursday July 28, 2016 @05:42AM (#12179293)
Only if the compiler is aware of and can translate code into e.g. ARM-specific sha instructions. If not, then the developer is still smarter than the compiler and should use assembly to use those specific instructions.
Re:Show HN: Accelerating SHA256 by 100x in Golang on ARM by dlsniper on Thursday July 28, 2016 @01:11AM (#12178430)
Is this a general thing or a Go specific one? This generic statement seems to be false given how many optimizations that actually need assembly exist in Go and not only.
Re:Show HN: Accelerating SHA256 by 100x in Golang on ARM by pjmlp on Thursday July 28, 2016 @08:20AM (#12179722)
It is a general thing and quite common.

Either you keep adding intrisics to the compiler, or outsource it to an external Assembler.

Even managed languages have bytecode Assemblers available.

Re:Show HN: Accelerating SHA256 by 100x in Golang on ARM by drchickensalad on Thursday July 28, 2016 @12:23AM (#12178306)
Generally yes, specialized no.
Re:Show HN: Accelerating SHA256 by 100x in Golang on ARM by shinigami on Thursday July 28, 2016 @09:44AM (#12180120)
Rarely true for low level crypto code.
Re:Show HN: Accelerating SHA256 by 100x in Golang on ARM by sgmansfield on Wednesday July 27, 2016 @07:23PM (#12177262)
Do you have a source for the 1% number?

Also I'd like to know what you would consider an appropriate amount of assembly code.

Re:Show HN: Accelerating SHA256 by 100x in Golang on ARM by bradleyjg on Wednesday July 27, 2016 @05:19PM (#12176583)
What's the alternative in this case?
Re:Show HN: Accelerating SHA256 by 100x in Golang on ARM by white-flame on Wednesday July 27, 2016 @05:44PM (#12176738)
From a bird's eye view, adjust the compiler until it outputs the assembly you would have written. Hopefully this is done in such a way that such adjustments can be cross-beneficial across platforms, and can be easily created.
Re:Show HN: Accelerating SHA256 by 100x in Golang on ARM by giovannibajo1 on Wednesday July 27, 2016 @05:57PM (#12176817)
That's wishful thinking. GCC isn't able to do that with C language, a 20 years old compiler with a 40 years language. How would a compiler know that you can use a SHA2 instruction? Yes, there are intrinsics but then what about specialized vectorized instructions which don't match any primitive types or operations in the language (like, you can't express "add with carry" in C or Go)? And how can you explain a compiler that there is no data dependency in memory access between different buffers? Yes it might be able to prove it by itself in some cases, but history has shown that things like autovectorization are too fragile and can't be relied upon.

Optimized C libraries like compressors or security have assembly implementations as well. I'm not sure why using assembler should be considered a signal of a defect rather than a proof of optimization. There's really nothing wrong in using assembly to write a bytes.Index version optimized for AVX2.

Re:Show HN: Accelerating SHA256 by 100x in Golang on ARM by DannyBee on Wednesday July 27, 2016 @07:43PM (#12177359)
"That's wishful thinking. GCC isn't able to do that with C language, a 20 years old compiler with a 40 years language. How would a compiler know that you can use a SHA2 instruction?"

Well, actually, they could, it's just not worth pattern matching because it occurs so infrequently.

"but history has shown that things like autovectorization are too fragile and can't be relied upon."

Errr, i'd say the opposite. History has shown that good autovectorizing compilers can come pretty damn close to whatever you want.

Usually the only issue is that they may insert too many runtime checks, and that's easily solvable.

Re:Show HN: Accelerating SHA256 by 100x in Golang on ARM by giovannibajo1 on Thursday July 28, 2016 @09:09AM (#12179927)
Can you show me an opensource library implementing performance-sensitive computations in any field (graphics, numerics, crypto, etc.) which relies on autovectorization to obtain the performance characteristics that clients rely upon?

The large majority of performance-sensitive libraries I know of rely on carefully written native code (C, C++), with a mixture of assembly and/or intrinsics. This, to me, is a failure to concretize autovectorization from textbooks into an industry-accepted solution.

Re:Show HN: Accelerating SHA256 by 100x in Golang on ARM by pcwalton on Wednesday July 27, 2016 @10:51PM (#12178037)
> How would a compiler know that you can use a SHA2 instruction?

Intrinsics.

There's basically zero benefit to coding this stuff in assembly. Many standard libraries prefer intrinsics, because there's basically zero benefit to writing this stuff in assembly and many drawbacks from an optimization perspective.