summaryrefslogtreecommitdiff
path: root/tools/qa
diff options
context:
space:
mode:
authorDr. David Alan Gilbert <dave@treblig.org>2020-09-20 16:36:57 +0100
committerTomaž Vajngerl <quikee@gmail.com>2020-09-22 08:32:58 +0200
commitafb62b0e96e9bf91ec99857cc16ddb094bcaa3be (patch)
tree33f75e5b297cd84978943d916c6d1d795fc82cec /tools/qa
parentb51fa6d7e4d6a64f822122eac1fa7ad1dec3574b (diff)
Fix AVX2 cpuid checks
At the moment test_cpu_runtime_detection_AVX2.cxx is compiled with -mavx2 to allow it to use the intrinsics; however the compiler jumps at the chance to use newer instructions outside the actual test; in my case using AVX in the string manipulation in addTestsToSuite when my CPU doesn't actually have AVX. Swing the actual check into a separate file and only compile that with the extra flag. We probably need the same change for the SSE* checks as well. Change-Id: I1683231932fff264a87c96ac95ac1d24b921163a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103075 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'tools/qa')
-rw-r--r--tools/qa/cppunit/test_cpu_runtime_detection_AVX2.cxx38
-rw-r--r--tools/qa/cppunit/test_cpu_runtime_detection_AVX2_check.cxx54
-rw-r--r--tools/qa/cppunit/test_cpu_runtime_detection_x86_checks.hxx21
3 files changed, 78 insertions, 35 deletions
diff --git a/tools/qa/cppunit/test_cpu_runtime_detection_AVX2.cxx b/tools/qa/cppunit/test_cpu_runtime_detection_AVX2.cxx
index 0c98f2fc8c98..5a3a1ee26638 100644
--- a/tools/qa/cppunit/test_cpu_runtime_detection_AVX2.cxx
+++ b/tools/qa/cppunit/test_cpu_runtime_detection_AVX2.cxx
@@ -8,8 +8,7 @@
*/
#include <tools/simdsupport.hxx>
-
-#ifdef LO_AVX2_AVAILABLE
+#include "test_cpu_runtime_detection_x86_checks.hxx"
#include <cppunit/TestAssert.h>
#include <cppunit/TestFixture.h>
@@ -23,7 +22,6 @@ namespace
class CpuRuntimeDetection_AVX2 : public CppUnit::TestFixture
{
public:
- void checkAVX2();
void testCpuRuntimeDetection();
CPPUNIT_TEST_SUITE(CpuRuntimeDetection_AVX2);
@@ -33,43 +31,13 @@ public:
void CpuRuntimeDetection_AVX2::testCpuRuntimeDetection()
{
- // can only run if this function if CPU supports AVX2
+ // can only run this function if CPU supports AVX2
if (cpuid::isCpuInstructionSetSupported(cpuid::InstructionSetFlags::AVX2))
- checkAVX2();
-}
-
-void CpuRuntimeDetection_AVX2::checkAVX2()
-{
- __m256i a = _mm256_set_epi64x(1, 4, 8, 3);
- __m256i b = _mm256_set_epi64x(2, 1, 1, 5);
- __m256i c = _mm256_xor_si256(a, b);
-
- sal_Int64 values[4];
- _mm256_storeu_si256(reinterpret_cast<__m256i*>(&values), c);
-
- CPPUNIT_ASSERT_EQUAL(sal_Int64(6), values[0]);
- CPPUNIT_ASSERT_EQUAL(sal_Int64(9), values[1]);
- CPPUNIT_ASSERT_EQUAL(sal_Int64(5), values[2]);
- CPPUNIT_ASSERT_EQUAL(sal_Int64(3), values[3]);
-
- __m256i d = _mm256_set_epi64x(3, 5, 1, 0);
-
- __m256i result = _mm256_cmpeq_epi64(d, c);
-
- // Compare equals
- sal_Int64 compare[4];
- _mm256_storeu_si256(reinterpret_cast<__m256i*>(&compare), result);
-
- CPPUNIT_ASSERT_EQUAL(sal_Int64(0), compare[0]);
- CPPUNIT_ASSERT_EQUAL(sal_Int64(0), compare[1]);
- CPPUNIT_ASSERT_EQUAL(sal_Int64(-1), compare[2]);
- CPPUNIT_ASSERT_EQUAL(sal_Int64(-1), compare[3]);
+ CpuRuntimeDetectionX86Checks::checkAVX2();
}
CPPUNIT_TEST_SUITE_REGISTRATION(CpuRuntimeDetection_AVX2);
} // end anonymous namespace
-#endif
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/tools/qa/cppunit/test_cpu_runtime_detection_AVX2_check.cxx b/tools/qa/cppunit/test_cpu_runtime_detection_AVX2_check.cxx
new file mode 100644
index 000000000000..b5948223752c
--- /dev/null
+++ b/tools/qa/cppunit/test_cpu_runtime_detection_AVX2_check.cxx
@@ -0,0 +1,54 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/types.h>
+#include <tools/simdsupport.hxx>
+
+#include <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+#include "test_cpu_runtime_detection_x86_checks.hxx"
+
+/* WARNING: This file is compiled with AVX2 support, don't call
+ * any function without checking cpuid to check the CPU can actually
+ * handle it.
+ */
+void CpuRuntimeDetectionX86Checks::checkAVX2()
+{
+#ifdef LO_AVX2_AVAILABLE
+ __m256i a = _mm256_set_epi64x(1, 4, 8, 3);
+ __m256i b = _mm256_set_epi64x(2, 1, 1, 5);
+ __m256i c = _mm256_xor_si256(a, b);
+
+ sal_Int64 values[4];
+ _mm256_storeu_si256(reinterpret_cast<__m256i*>(&values), c);
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(6), values[0]);
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(9), values[1]);
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(5), values[2]);
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(3), values[3]);
+
+ __m256i d = _mm256_set_epi64x(3, 5, 1, 0);
+
+ __m256i result = _mm256_cmpeq_epi64(d, c);
+
+ // Compare equals
+ sal_Int64 compare[4];
+ _mm256_storeu_si256(reinterpret_cast<__m256i*>(&compare), result);
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(0), compare[0]);
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(0), compare[1]);
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(-1), compare[2]);
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(-1), compare[3]);
+#endif
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/tools/qa/cppunit/test_cpu_runtime_detection_x86_checks.hxx b/tools/qa/cppunit/test_cpu_runtime_detection_x86_checks.hxx
new file mode 100644
index 000000000000..94396bf6285d
--- /dev/null
+++ b/tools/qa/cppunit/test_cpu_runtime_detection_x86_checks.hxx
@@ -0,0 +1,21 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDE_TOOLS_QA_CPPUNIT_TEST_CPU_RUNTIME_DETECTION_X86_CHECKS_H
+#define INCLUDE_TOOLS_QA_CPPUNIT_TEST_CPU_RUNTIME_DETECTION_X86_CHECKS_H
+
+class CpuRuntimeDetectionX86Checks
+{
+public:
+ static void checkAVX2();
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */