[Libreoffice-commits] core.git: tools/CppunitTest_tools_test.mk tools/qa
Dr. David Alan Gilbert (via logerrit)
logerrit at kemper.freedesktop.org
Tue Sep 22 06:33:39 UTC 2020
tools/CppunitTest_tools_test.mk | 3
tools/qa/cppunit/test_cpu_runtime_detection_AVX2.cxx | 38 ---------
tools/qa/cppunit/test_cpu_runtime_detection_AVX2_check.cxx | 54 +++++++++++++
tools/qa/cppunit/test_cpu_runtime_detection_x86_checks.hxx | 21 +++++
4 files changed, 80 insertions(+), 36 deletions(-)
New commits:
commit afb62b0e96e9bf91ec99857cc16ddb094bcaa3be
Author: Dr. David Alan Gilbert <dave at treblig.org>
AuthorDate: Sun Sep 20 16:36:57 2020 +0100
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Tue Sep 22 08:32:58 2020 +0200
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 at gmail.com>
diff --git a/tools/CppunitTest_tools_test.mk b/tools/CppunitTest_tools_test.mk
index aa5ac4606d02..48c667425ce4 100644
--- a/tools/CppunitTest_tools_test.mk
+++ b/tools/CppunitTest_tools_test.mk
@@ -32,10 +32,11 @@ $(eval $(call gb_CppunitTest_add_exception_objects,tools_test, \
tools/qa/cppunit/test_xmlwalker \
tools/qa/cppunit/test_GenericTypeSerializer \
tools/qa/cppunit/test_cpuid \
+ tools/qa/cppunit/test_cpu_runtime_detection_AVX2 \
))
$(eval $(call gb_CppunitTest_add_exception_objects,tools_test,\
- tools/qa/cppunit/test_cpu_runtime_detection_AVX2, $(CXXFLAGS_INTRINSICS_AVX2) \
+ tools/qa/cppunit/test_cpu_runtime_detection_AVX2_check, $(CXXFLAGS_INTRINSICS_AVX2) \
))
$(eval $(call gb_CppunitTest_add_exception_objects,tools_test,\
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: */
More information about the Libreoffice-commits
mailing list