4

Looking at the code of a binary produced by cargo (cargo build --release). I found in the binary that SSSE3 instructions like pshufb were used.

Looking at cfg I have:

$ rustc --print cfg
debug_assertions
target_arch="x86_64"
target_endian="little"
target_env=""
target_family="unix"
target_feature="fxsr"
target_feature="sse"
target_feature="sse2"
target_feature="sse3"
target_feature="ssse3"
target_os="macos"
target_pointer_width="64"
target_vendor="apple"
unix

I have different paths given the SIMD ISA (AVX2 or SSSE3) and expected to have a non SIMD one with the default build.

#[cfg(target_feature = "avx2")]
{
    ...
    return;
}
#[cfg(target_feature = "ssse3")]
{
    ...
    return;
}
// portable Rust code at the end
...

Does this mean that a default release build will always use up to SSSE3 instructions, and not just SSE2 which is mandatory on x86_64?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
elmattic
  • 12,046
  • 5
  • 43
  • 79

1 Answers1

7
target_os="macos"

A default release build on macOS will, yes.

Since Apple has never sold any AMD or Pentium4 CPUs, x86-64 on OS X also implies SSSE3 (first-gen Core2). The first x86 Macs were Core (not Core2), but they were 32-bit only. You unfortunately can't assume SSE4.1 or -mpopcnt.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366