This is an archive of the discontinued LLVM Phabricator instance.

[X86][compiler-rt] Add additional CPUs and features to the cpu detection to match libgcc
ClosedPublic

Authored by craig.topper on Oct 19 2018, 4:56 PM.

Details

Summary

This patch adds additional features and cpus from libgcc. Unfortunately we've overflowed the existing 32-bits of features so we had to add a new __cpu_features2 variable to hold the additional bits. This matches libgcc as far as I can tell.

Diff Detail

Event Timeline

craig.topper created this revision.Oct 19 2018, 4:56 PM
echristo accepted this revision.Oct 19 2018, 5:17 PM

LGTM.

-eric

This revision is now accepted and ready to land.Oct 19 2018, 5:17 PM
This revision was automatically updated to reflect the committed changes.

FYI http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap-ubsan/builds/7970/steps/build%20stage1%20clang/logs/stdio

/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm/projects/compiler-rt/lib/builtins/cpu_model.c: In function ‘getAvailableFeatures’:
/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm/projects/compiler-rt/lib/builtins/cpu_model.c:470:22: warning: left shift count is negative [-Wshift-count-negative]
       Features2 |= 1 << (F - 32);  \
                      ^
/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm/projects/compiler-rt/lib/builtins/cpu_model.c:474:5: note: in expansion of macro ‘setFeature’
     setFeature(FEATURE_CMOV);
     ^~~~~~~~~~
/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm/projects/compiler-rt/lib/builtins/cpu_model.c:470:22: warning: left shift count is negative [-Wshift-count-negative]
       Features2 |= 1 << (F - 32);  \
                      ^
/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm/projects/compiler-rt/lib/builtins/cpu_model.c:476:5: note: in expansion of macro ‘setFeature’
     setFeature(FEATURE_MMX);
     ^~~~~~~~~~
/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm/projects/compiler-rt/lib/builtins/cpu_model.c:470:22: warning: left shift count is negative [-Wshift-count-negative]
       Features2 |= 1 << (F - 32);  \
                      ^
/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm/projects/compiler-rt/lib/builtins/cpu_model.c:478:5: note: in expansion of macro ‘setFeature’
     setFeature(FEATURE_SSE);
     ^~~~~~~~~~
/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm/projects/compiler-rt/lib/builtins/cpu_model.c:470:22: warning: left shift count is negative [-Wshift-count-negative]
       Features2 |= 1 << (F - 32);  \
                      ^
/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm/projects/compiler-rt/lib/builtins/cpu_model.c:480:5: note: in expansion of macro ‘setFeature’
     setFeature(FEATURE_SSE2);
     ^~~~~~~~~~
/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm/projects/compiler-rt/lib/builtins/cpu_model.c:470:22: warning: left shift count is negative [-Wshift-count-negative]
       Features2 |= 1 << (F - 32);  \
                      ^

...

@vitalybuka, the macro in the code specifically checks the value before doing the shift. Is there something wrong with my logic?

#define setFeature(F) \

do {                             \
  if (F < 32)                    \
    Features |= 1 << F;          \
  else if (F < 64)               \
    Features2 |= 1 << (F - 32);  \
} while (0)
lebedev.ri added inline comments.
compiler-rt/trunk/lib/builtins/cpu_model.c
467–468 ↗(On Diff #170297)

F = 31
F < 32
1 << 31
2147483648
which is just the sign bit set

This should probably be

Features |= 1U << F;