summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SConstruct57
-rw-r--r--src/mongo/SConscript5
-rw-r--r--src/mongo/config.h.in13
-rw-r--r--src/mongo/db/fts/unicode/byte_vector_altivec.h3
4 files changed, 70 insertions, 8 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 )
diff --git a/src/mongo/SConscript b/src/mongo/SConscript
index c7ae4b645c4..ab5d89cb24c 100644
--- a/src/mongo/SConscript
+++ b/src/mongo/SConscript
@@ -239,8 +239,10 @@ if env.TargetOSIs('windows'):
env.Alias('generated-sources', generatedResourceConstantFile)
config_header_substs = (
+ ('@mongo_config_altivec_vec_vbpermq_output_index@', 'MONGO_CONFIG_ALTIVEC_VEC_VBPERMQ_OUTPUT_INDEX'),
('@mongo_config_byte_order@', 'MONGO_CONFIG_BYTE_ORDER'),
('@mongo_config_debug_build@', 'MONGO_CONFIG_DEBUG_BUILD'),
+ ('@mongo_config_has_ssl_set_ecdh_auto@', 'MONGO_CONFIG_HAS_SSL_SET_ECDH_AUTO'),
('@mongo_config_have_execinfo_backtrace@', 'MONGO_CONFIG_HAVE_EXECINFO_BACKTRACE'),
('@mongo_config_have_fips_mode_set@', 'MONGO_CONFIG_HAVE_FIPS_MODE_SET'),
('@mongo_config_have_header_unistd_h@', 'MONGO_CONFIG_HAVE_HEADER_UNISTD_H'),
@@ -253,9 +255,8 @@ config_header_substs = (
('@mongo_config_max_extended_alignment@', 'MONGO_CONFIG_MAX_EXTENDED_ALIGNMENT'),
('@mongo_config_optimized_build@', 'MONGO_CONFIG_OPTIMIZED_BUILD'),
('@mongo_config_ssl@', 'MONGO_CONFIG_SSL'),
- ('@mongo_config_ssl_provider@', 'MONGO_CONFIG_SSL_PROVIDER'),
('@mongo_config_ssl_has_asn1_any_definitions@', 'MONGO_CONFIG_HAVE_ASN1_ANY_DEFINITIONS'),
- ('@mongo_config_has_ssl_set_ecdh_auto@', 'MONGO_CONFIG_HAS_SSL_SET_ECDH_AUTO'),
+ ('@mongo_config_ssl_provider@', 'MONGO_CONFIG_SSL_PROVIDER'),
('@mongo_config_wiredtiger_enabled@', 'MONGO_CONFIG_WIREDTIGER_ENABLED'),
)
diff --git a/src/mongo/config.h.in b/src/mongo/config.h.in
index 39a6541ce73..9121a5c8448 100644
--- a/src/mongo/config.h.in
+++ b/src/mongo/config.h.in
@@ -33,12 +33,18 @@
#define SSL_PROVIDER_WINDOWS 2
#define SSL_PROVIDER_APPLE 3
+// Define altivec vec_vbpermq output index
+@mongo_config_altivec_vec_vbpermq_output_index@
+
// Define to target byte order (1234 vs 4321)
@mongo_config_byte_order@
// Define if building a debug build
@mongo_config_debug_build@
+// Defined if OpenSSL has `SSL_CTX_set_ecdh_auto` and `SSL_set_ecdh_auto`
+@mongo_config_has_ssl_set_ecdh_auto@
+
// Defined if execinfo.h and backtrace are available
@mongo_config_have_execinfo_backtrace@
@@ -72,14 +78,11 @@
// Defined if SSL support is enabled
@mongo_config_ssl@
-// Defined if SSL support is enabled with chosen ssl provider
-@mongo_config_ssl_provider@
-
// Defined if OpenSSL has SEQUENCE_ANY
@mongo_config_ssl_has_asn1_any_definitions@
-// Defined if OpenSSL has `SSL_CTX_set_ecdh_auto` and `SSL_set_ecdh_auto`
-@mongo_config_has_ssl_set_ecdh_auto@
+// Defined if SSL support is enabled with chosen ssl provider
+@mongo_config_ssl_provider@
// Defined if WiredTiger storage engine is enabled
@mongo_config_wiredtiger_enabled@
diff --git a/src/mongo/db/fts/unicode/byte_vector_altivec.h b/src/mongo/db/fts/unicode/byte_vector_altivec.h
index f7a07ac0743..0797443f72f 100644
--- a/src/mongo/db/fts/unicode/byte_vector_altivec.h
+++ b/src/mongo/db/fts/unicode/byte_vector_altivec.h
@@ -34,6 +34,7 @@
#include <cstdint>
+#include "mongo/config.h"
#include "mongo/platform/bits.h"
namespace mongo {
@@ -98,7 +99,7 @@ public:
// big endian by comparison.
const Native bits = {120, 112, 104, 96, 88, 80, 72, 64, 56, 48, 40, 32, 24, 16, 8, 0};
- return vec_extract(vec_vbpermq(_data, bits), 0);
+ return vec_extract(vec_vbpermq(_data, bits), MONGO_CONFIG_ALTIVEC_VEC_VBPERMQ_OUTPUT_INDEX);
}
/**