Search code examples
compiler-optimizationcrystal-lang

Is there an equivalent of march=native in the Crystal compiler?


GCC and Clang support a compiler option named -march=native, which is handy if you want to optimize for the current machine's architecture. The resulting binary might not be portable, but that is OK if it will only be executed on the same machine.

I wondered if the Crystal compiler supports it. I can see the following options --mcpu, --mattr, --mcmodel, which might be want I need. Unfortunately, I could not find a lot of information.

Is there a recommended way in Crystal to optimize for the current machine? Ideally, it should figure out the available CPU instructions automatically (like -march=native).


Background: How to see which flags -march=native will activate?


Solution

  • The Crystal compiler doesn't support -march. Maybe that should be added. From what I hear it's there's often no clear separation between -mcpu and -march.

    As a workaround, you could ask the compiler to emit LLVM IR or byte code. That allows you to compile the binary with LLVM tools directly, which would give full access to LLVM options like -march.