5 ms·
Re: performance claims, I wonder if the C sha256 implementation would have been more competitive with -march=native -mtune=native?
by loeg 8y ago
Re: performance claims, I wonder if the C sha256 implementation would have been more competitive with -march=native -mtune=native?
- tom_mellior 8y agoI think it would. I posted some observations on this the last time this video was discussed: https://news.ycombinator.com/item?id=17187140 https://news.ycombinator.com/item?id=17187140 My hypothesis is that Zig's compiler passes the equivalent of -march=native to the backend, which is why it should also be given to the C compiler to give a fair comparison (and a speedup of 30% or so).
- AndyKelley 8y agoI think you are probably right. I will do a follow-up post addressing the performance claims in this talk. I think I owe it to the community.
- loeg 8y agoMuch appreciated. Given Zig's design and use of LLVM, for code translated "line by line" (same algorithm) I don't see any reason for Zig's performance not to be substantially identical to C (compiled with Clang). It wouldn't surprise me if there are reasons Zig can do better or makes it easier to use better algorithms, etc, but you wouldn't expect that to show up in something as computationally straightforward as a cryptographic primitive. By the way, as a C practitioner, I'm a fan of what you're doing with Zig; keep it up! C++, Go, and Rust don't appeal to me for all of the reasons mentioned in your talk.
- Avamander 8y agoWhy isn't `-march=native -mtune=native` enabled by-default for every piece of software compiled unless explicitly specified otherwise?
- loeg 8y agoYou'd have to ask the compiler communities that. As an observer, I notice that C compilers are extremely conservative about changing defaults in new versions. And I could imagine some benefits of that approach, and downsides. But I am not involved in e.g. gcc or clang development.
- jsnell 8y agoCompiling with -march=native makes for brittle binaries, since the binary might contain instructions that are not be available on slightly older CPUs or on virtual machines. So it's only suitable for software that's performance sensitive but won't be distributed to other machines (or at least won't be distributed outside of a strictly controlled environment). It wouldn't make for a good default.
- dman 8y agoWhen you are shipping binaries, you usually do not have control over the cpus your users are using. Setting march/mtune to native breaks if the developers machine is noticeably newer than the users machine. Also letting the build machine configuration decide which level of simd to target is too flakey, so most software specifies the target explicitly.
- ndesaulniers 8y agoBecause your cpu has a base ISA, plus extensions. The compiler doesn't know if you're going to only run this binary on your machine, or distribute it to others that may share your base ISA but possibly not your extensions, so it takes the conservative approach and doesn't use them unless signaled to do so via those compiler flags. Also, I think -march implies -mtune.
- AndyKelley 8y agoIn Zig the default target is native, which turns on all the applicable CPU features. If you want to target something other than the native machine you can use --target-os --target-arch parameters. I haven't exposed extra CPU options for cross compiling yet.