Hacker News

Top stories

Live mirror
30 storiesupdated just nowView source snapshot
  1. Human brain is two separate organs, Stanford Medicine-led research finds(stanford.edu ↗)
    44comments
  2. GPT-6 Astra Solves a WWI German Radio Cipher(prinzai.com ↗)
    21comments
  3. If math is more than proof, we need to better celebrate the rest of it(terrytao.wordpress.com ↗)
    18comments
  4. San Francisco Onion Futures Company(onionfutures.com ↗)
    59comments
  5. Android 17 is the first since 3.x to add new APIs without releasing to the AOSP(grapheneos.social ↗)
    383comments
  6. Typesafe-computer-use drives a Mac toward a goal for 1/50th of a cent per step(github.com/awlevin ↗)
    32comments
  7. Science Is Open Software(jepedersen.dk ↗)
    31comments
  8. SDCC – Small Device C Compiler(sourceforge.net ↗)
    16comments
  9. Cloudflare Quick Tunnels(cloudflare.com ↗)
    275comments
  10. Why building a Rust LSP is hard(rust-glancer.github.io ↗)
    28comments
  11. Saving another 100TB of RAM(cloudflare.com ↗)
    66comments
  12. You can run Git on object storage if you re-make packfiles(tigrisdata.com ↗)
    8comments
  13. How to Write with an LLM(sockpuppet.org ↗)
    320comments
  14. NASA-IBM Lunar Foundation open-Source Geospatial AI Model(usra.edu ↗)
    2comments
  15. Ctenophores: Wonders of Biology(quantamagazine.org ↗)
    4comments
  16. The first new cat species discovered in 100 years(nationalgeographic.com ↗)
    99comments
  17. How OpenAI Used Its Own LLMs to Design Its Jalapeño Chip(ieee.org ↗)
    81comments
  18. Goroutine Leak Profiles(go.dev ↗)
    2comments
  19. Veronese's Dogs(publicdomainreview.org ↗)
    discuss
  20. OpenJev(openjev.com ↗)
    258comments
  21. Show HN: Cactus Needle 3: 8-29MB automation models can match DeepSeek V4 Flash(cactuscompute.com ↗)
    88comments
  22. Photon-Emission-Guided Laser Fault Injection Enables RP2350 Secure Debug(ledger.com ↗)
    67comments
  23. Cache-to-Cache: Direct Semantic Communication Between LLMs (2025)(arxiv.org ↗)
    12comments
  24. How come AI-related posts get so many points on HN?
    6comments
  25. Minimal Phone 2(minimalcompany.com ↗)
    218comments
  26. The Farnese letter(simonklee.dk ↗)
    6comments
  27. Cyclomatic Complexity in C#(ndepend.com ↗)
    18comments
  28. Warez: The Infrastructure and Aesthetics of Piracy (2021)(archive.org ↗)
    54comments
  29. Inside ZCode: Silently uploading your Git history to the cloud(ferstar.org ↗)
    97comments
  30. Xcode 27.1 Beta Release Notes(developer.apple.com ↗)
    99comments

How to Use AVX512 in Golang

98 pointsby 3y agogorse.io
33 comments
3y agoHN ↗

For someone experts assembly, avo is a better tool to write assembly in hand.

3y agoHN ↗

Cgo is a real option here, or at least would be an interesting comparison. The function is likely called with large enough data to amortize the (few ns) overhead and it's certainly more maintainable.

Another option is GOAMD64=v3 / v4 which will enable AVX2 / AVX512 on the regular Go output, although the compiler does almost no autovectorization compared to gccgo/gollvm.

3y agoHN ↗

It is a pity that CGO isn't in the final benchmark. >_<

3y agoHN ↗

Granted I don't know what will happen between now and March 1st, but there are some inaccuracies in this article... is this a GPT product?

- Encoding Machine Code[0] Not sure what "Go assembly provides three instructions for representing binary machine code" is intended to mean, but go supports register moves/actions for Byte(1)/Word(2)/Long(4)/Quad(8)/Octo(16), both aligned and unaligned (depending on architecture/processor). The next section literally references a quad action (`movq`). Note O/Octo and DQ/Double Quad mean the same thing depending on instruction/arch (sigh)

- When you're using specialized features you have other commands for larger register features (eg in AVX512 on AMD64 asm:`MULPS`, goasm:`VMULPS`)

- Redirect Jump Instruction[1], what is the value of this conversion recommendation if this article is recommending an auto converter that should do this for you? Go-asm can support jumping to addresses (routine scoped), or labels.. labels can be in any case, perhaps goat requires only upper case?

- Generate Go Function Definitions[2].. err isn't this the value prop of goat[3], the point of this article, that this can be done for you? Why are `cznic`, and `cc` being introduced here?

- Function Calls[4] The "complete wrapper" won't compile (typos), I think it's supposed to be closer to [5] (in the repo)

- Function Calls[4] the "Note" makes no sense given the code is go only (missing go-asm paste?)

- The summary benchmark[6], demonstrates AVX2 (far more common) is often faster, and doesn't explain what was measured, nor on what architecture, whether it was aligned, whether any steps were taken to improve performance on the architecture. Based on the repo [7], there's no attempt at alignment, if you can't do AVX512, or AVX2, you can still do 64bit/quad operations rather than going straight to 8bit/byte ops.

- The assembly (.s) files seemingly produced by GOAT[8] are far from human readable go-asm files (the comments in the file could be go-asm source code), don't follow the convention of <file>_<arch>.s, and don't support all platforms that C/golang do (although ARM64 & AMD64 is a large market share)

[0]: https://gorse.io/posts/avx512-in-golang.html#encoding-machin... [1]: https://gorse.io/posts/avx512-in-golang.html#redirect-jump-i... [2]: https://gorse.io/posts/avx512-in-golang.html#generate-go-fun... [3]: https://github.com/gorse-io/gorse/tree/master/cmd/goat [4]: https://gorse.io/posts/avx512-in-golang.html#function-calls [5]: https://github.com/gorse-io/gorse/blob/master/base/floats/fl... [6]: https://gorse.io/posts/avx512-in-golang.html#summary [7]: https://github.com/gorse-io/gorse/tree/master/base/floats [8]: https://github.com/gorse-io/gorse/blob/master/base/floats/fl...

3y agoHN ↗

I am the author and I am really regret about this title. I think a better title should be "How to Use AVX512 in Golang via the C Compiler" :O

3y agoHN ↗

The graph at the end is not readable on the dark theme background. The labels are almost the same colour.

3y agoHN ↗

Another suggestion for the title: Go, not Golang.

3y agoHN ↗

If faced with a co-worker who uses 'Golang', try pronouncing it 'Gol-ang' at regular intervals, liable to annoy them sufficiently to persuade them to desist ...

3y agoHN ↗

They’ll more likely ask if your code is still compiling, since you have so much free time.

3y agoHN ↗

For that sort of problem I'd generally use C, so laugh in their face :-)

3y agoHN ↗

This is a hill I am also willing to die on.

Last time this annoyed me, I did a thorough look at the Go source code to figure out how accurate calling the language "Go" is. Basically, aside from the mailing lists and bug tracker URLs, "golang" only appears in one place; the ppc64 port contributed by IBM. Everywhere else in the code, it refers to itself as "Go".

3y agoHN ↗

"Go" matches to many things unrelated to the programming language. Golang is more likely to match specifically the programming language.

3y agoHN ↗

Similar to how many people back in the day used "csharp" instead of C# so search engines could actually find things.

3y agoHN ↗

It didn’t help that search engines would “helpfully” ignore the sharp symbol (octothorp) and show results for just “c”

3y agoHN ↗

Is discarding the primary communications channels for the project a valid decision? In addition, the main website of the project was "golang.org" for over a decade. That domain still redirects to the current homepage at go.dev.

3y agoHN ↗

Ruby is at ruby-lang.org but I've never heard anyone call it Rubylang. You can't always get the domain name (or Google Group) you want.

3y agoHN ↗

They're out there: https://github.com/topics/rubylang

I get that these people are not in your circle or whatever, but the term 'golang' appears nine times on Go's own case studies mood board: https://go.dev/solutions/#case-studies

Personally I suspect people more readily adopt 'golang' because all the mailing lists used it as the prefix, the domain was golang (as opposed to go-lang), the official subreddit is /r/golang, and the developers have such a habit of prefixing things with 'go' (as in GOPATH, goroutines, etc). I used to believe it was because there was another programming language with the same name, but I never did find examples of its use in the wild, so I'm no longer sure that affected anything.

3y agoHN ↗

March 1, 2023

What? Did a timetraveller write this?

3y agoHN ↗

Or it's a US/normal date format confusion?

3y agoHN ↗

Aliens are really sloppy these days. A real human would never do AVX512 in Golang and travel in time.

3y agoHN ↗

I've been trying to make this clear to every one who whines about "oh no the clock rate goes down a little if you use this":

AVX-512 is VERY fast, time even gets ripped asunder.

3y agoHN ↗

Not really related to golang but: AVX512 is THE sweet spot to go for that for vector instructions as 512bits=64bytes=x86_64 cache line size.

3y agoHN ↗

Dumb question but do you have to do anything manually to ensure it’s actually aligned to a single cache line or does it just happen because of the way things work?

3y agoHN ↗

Not a dumb question. In theory, yes you want it to be aligned for performance reasons, and you can do this with one of the _aligned_malloc()/aligned_alloc() variants. In reality though, for any non-trivial algorithm, you may not be able to always enforce this.

3y agoHN ↗

Usually you alloc some slack memory to be able to re-align on a cache line. But yeah, it seems better if the allocator can cleanely deal with that.

3y agoHN ↗

Upcoming .NET 8 will get native support for Vector512 (AVX512) in runtime, and you can write platform-independent code today with Vector<T> for length-agnostic algorithms that will automatically take advantage of it. No need to ever write assembly, or some other special syntax - just pure C#.

3y agoHN ↗

That is fantastic. Swift in the Mac has something similar thanks to the Accelerate framework. What I’ve seen, however, is that if you are targeting a very specific platform (for example, the M1 family), you get better performance by directly using the intrinsics supported by that platform. In the real world, you are unlikely to actually have such a specific target, so this may not be so important.

I look forward to seeing some benchmarks with .NET - Microsoft needs to support a pretty wide variety of platforms. It will be interesting to see if their implementation is better!

3y agoHN ↗

Accelerate is a bit different in being both overall more high level API and specific to Apple (and abstracts away the usage of AMX and ANE too). On the other hand, Vector<T>/Vector128/256/512<T> in .NET is what is 'portable-simd' to Rust except it is not in preview and widely used across standard library where applicable.

As of now, Vector<T> automatically targets AVX2, SSE4.2 and AdvSimd (NEON). Vector256<T> targets AVX2 (for the lack of ARM counterpart) and Vector128<T> targets SSE / AdvSimd respectively.