summaryrefslogtreecommitdiff
path: root/SConstruct
diff options
context:
space:
mode:
authorJason Carey <jcarey@argv.me>2018-05-02 18:18:09 +0000
committerJason Carey <jcarey@argv.me>2018-05-04 12:23:56 -0400
commitb989fe4b0cfba4062c5bb7fb68337f188070c1c8 (patch)
tree37ddb7fc706c2ca76eb94f82aba94942cb996f37 /SConstruct
parent236bf5f077eb16f7bf8f0f7c5f103240bd061f12 (diff)
downloadmongo-b989fe4b0cfba4062c5bb7fb68337f188070c1c8.tar.gz
SERVER-33395 Add configure check for vec_vbpermq output
GCC changed the output of vec_vbpermq between 5.4.0 and later. This seems likely to be a bug, probably in earlier versions of gcc. Rather than attempt to enumerate how the compiler versions work, this adds a runtime configure check which will select the lane that works.
Diffstat (limited to 'SConstruct')
-rw-r--r--SConstruct57
1 files changed, 57 insertions, 0 deletions
diff --git a/SConstruct b/SConstruct
index 70f32cbd94f..9e7640ecb6b 100644
--- a/SConstruct
+++ b/SConstruct
@@ -3238,6 +3238,63 @@ def doConfigure(myenv):
# ask each module to configure itself and the build environment.
moduleconfig.configure_modules(mongo_modules, conf)
+ if env['TARGET_ARCH'] == "ppc64le":
+ # This checks for an altivec optimization we use in full text search.
+ # Different versions of gcc appear to put output bytes in different
+ # parts of the output vector produced by vec_vbpermq. This configure
+ # check looks to see which format the compiler produces.
+ #
+ # NOTE: This breaks cross compiles, as it relies on checking runtime functionality for the
+ # environment we're in. A flag to choose the index, or the possibility that we don't have
+ # multiple versions to support (after a compiler upgrade) could solve the problem if we
+ # eventually need them.
+ def CheckAltivecVbpermqOutput(context, index):
+ test_body = """
+ #include <altivec.h>
+ #include <cstring>
+ #include <cstdint>
+ #include <cstdlib>
+
+ int main() {{
+ using Native = __vector signed char;
+ const size_t size = sizeof(Native);
+ const Native bits = {{ 120, 112, 104, 96, 88, 80, 72, 64, 56, 48, 40, 32, 24, 16, 8, 0 }};
+
+ uint8_t inputBuf[size];
+ std::memset(inputBuf, 0xFF, sizeof(inputBuf));
+
+ for (size_t offset = 0; offset <= size; offset++) {{
+ Native vec = vec_vsx_ld(0, reinterpret_cast<const Native*>(inputBuf));
+
+ uint64_t mask = vec_extract(vec_vbpermq(vec, bits), {0});
+
+ size_t initialZeros = (mask == 0 ? size : __builtin_ctzll(mask));
+ if (initialZeros != offset) {{
+ return 1;
+ }}
+
+ if (offset < size) {{
+ inputBuf[offset] = 0; // Add an initial 0 for the next loop.
+ }}
+ }}
+
+ return 0;
+ }}
+ """.format(index)
+
+ context.Message('Checking for vec_vbperm output in index {0}... '.format(index))
+ ret = context.TryRun(textwrap.dedent(test_body), ".cpp")
+ context.Result(ret[0])
+ return ret[0]
+
+ conf.AddTest('CheckAltivecVbpermqOutput', CheckAltivecVbpermqOutput)
+
+ outputIndex = next((idx for idx in [0,1] if conf.CheckAltivecVbpermqOutput(idx)), None)
+ if outputIndex is not None:
+ conf.env.SetConfigHeaderDefine("MONGO_CONFIG_ALTIVEC_VEC_VBPERMQ_OUTPUT_INDEX", outputIndex)
+ else:
+ myenv.ConfError("Running on ppc64le, but can't find a correct vec_vbpermq output index. Compiler or platform not supported")
+
return conf.Finish()
env = doConfigure( env )