include/tools/cpuid.hxx | 28 ------ sc/source/core/inc/arraysumfunctor.hxx | 141 --------------------------------- sc/source/core/tool/interpr6.cxx | 18 ++-- tools/Library_tl.mk | 1 tools/source/misc/cpuid.cxx | 63 -------------- 5 files changed, 11 insertions(+), 240 deletions(-)
New commits: commit 3395c3ed22519c62b091a5065e03862bda587f20 Author: László Németh <[email protected]> Date: Fri Nov 6 01:14:31 2015 +0100 Revert "invalid array index when pCurrent pointer is incremented" This reverts commit b35c38c6e44b0df0fc2c5a3983ecd7547b964691. Revert "Fast array sum: aligned load, process 8 doubles per loop" This reverts commit f814b00bc908c5498156194f45bf8f9c0b8268ac. Revert "arraysumfunctor: fast sum a double array, use for SUM() in Calc" This reverts commit e59e6c572f3e7531800b396f7e4ad5f52f98d987. diff --git a/include/tools/cpuid.hxx b/include/tools/cpuid.hxx deleted file mode 100644 index 316e656..0000000 --- a/include/tools/cpuid.hxx +++ /dev/null @@ -1,28 +0,0 @@ -/* -*- 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 INCLUDED_TOOLS_CPUID_HXX -#define INCLUDED_TOOLS_CPUID_HXX - -#include <sal/config.h> -#include <tools/toolsdllapi.h> - -namespace tools -{ -namespace cpuid -{ - TOOLS_DLLPUBLIC bool hasSSE(); - TOOLS_DLLPUBLIC bool hasSSE2(); -} -} - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/inc/arraysumfunctor.hxx b/sc/source/core/inc/arraysumfunctor.hxx deleted file mode 100644 index 776c514..0000000 --- a/sc/source/core/inc/arraysumfunctor.hxx +++ /dev/null @@ -1,141 +0,0 @@ -/* -*- 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 INCLUDED_SC_SOURCE_CORE_INC_ARRAYSUMFUNCTOR_HXX -#define INCLUDED_SC_SOURCE_CORE_INC_ARRAYSUMFUNCTOR_HXX - -#include <emmintrin.h> -#include <tools/cpuid.hxx> - -namespace sc -{ - -template<typename T, unsigned int N> -inline bool isAligned(const T* pointer) -{ - return 0 == (uintptr_t(pointer) % N); -} - -struct ArraySumFunctor -{ -private: - const double* mpArray; - size_t mnSize; - -public: - ArraySumFunctor(const double* pArray, size_t nSize) - : mpArray(pArray) - , mnSize(nSize) - { - } - - double operator() () - { - static bool hasSSE2 = tools::cpuid::hasSSE2(); - - double fSum = 0.0; - size_t i = 0; - const double* pCurrent = mpArray; - - if (hasSSE2) - { - while (!isAligned<double, 16>(pCurrent)) - { - fSum += *pCurrent++; - i++; - } - fSum += executeSSE2(i, pCurrent); - } - else - fSum += executeUnrolled(i, pCurrent); - - // sum rest of the array - - for (; i < mnSize; ++i) - fSum += mpArray[i]; - - return fSum; - } - -private: - inline double executeSSE2(size_t& i, const double* pCurrent) const - { - double fSum = 0.0; - size_t nRealSize = mnSize - i; - size_t nUnrolledSize = nRealSize - (nRealSize % 8); - - if (nUnrolledSize > 0) - { - __m128d sum1 = _mm_setzero_pd(); - __m128d sum2 = _mm_setzero_pd(); - __m128d sum3 = _mm_setzero_pd(); - __m128d sum4 = _mm_setzero_pd(); - - for (; i < nUnrolledSize; i += 8) - { - __m128d load1 = _mm_load_pd(pCurrent); - sum1 = _mm_add_pd(sum1, load1); - pCurrent += 2; - - __m128d load2 = _mm_load_pd(pCurrent); - sum2 = _mm_add_pd(sum2, load2); - pCurrent += 2; - - __m128d load3 = _mm_load_pd(pCurrent); - sum3 = _mm_add_pd(sum3, load3); - pCurrent += 2; - - __m128d load4 = _mm_load_pd(pCurrent); - sum4 = _mm_add_pd(sum4, load4); - pCurrent += 2; - } - sum1 = _mm_add_pd(_mm_add_pd(sum1, sum2), _mm_add_pd(sum3, sum4)); - - double temp; - - _mm_storel_pd(&temp, sum1); - fSum += temp; - - _mm_storeh_pd(&temp, sum1); - fSum += temp; - } - return fSum; - } - - inline double executeUnrolled(size_t& i, const double* pCurrent) const - { - size_t nRealSize = mnSize - i; - size_t nUnrolledSize = nRealSize - (nRealSize % 4); - - if (nUnrolledSize > 0) - { - double sum0 = 0.0; - double sum1 = 0.0; - double sum2 = 0.0; - double sum3 = 0.0; - - for (; i < nUnrolledSize; i += 4) - { - sum0 += *pCurrent++; - sum1 += *pCurrent++; - sum2 += *pCurrent++; - sum3 += *pCurrent++; - } - return sum0 + sum1 + sum2 + sum3; - } - return 0.0; - } -}; - -} // end namespace sc - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/tool/interpr6.cxx b/sc/source/core/tool/interpr6.cxx index c673fdb..50c0768a 100644 --- a/sc/source/core/tool/interpr6.cxx +++ b/sc/source/core/tool/interpr6.cxx @@ -26,11 +26,8 @@ #include "mtvcellfunc.hxx" #include "scmatrix.hxx" -#include "arraysumfunctor.hxx" - #include <formula/token.hxx> - using namespace formula; double const fHalfMachEps = 0.5 * ::std::numeric_limits<double>::epsilon(); @@ -227,11 +224,18 @@ public: { const puncture_mdds_encap *pBlock = static_cast<const puncture_mdds_encap *>(rNode.data); const double *p = pBlock->getPtr(nOffset); + size_t i, nUnrolled = (nDataSize & 0x3) >> 2; - sc::ArraySumFunctor functor(p, nDataSize); - - mfSum += functor(); - + // Try to encourage the compiler/CPU to do something sensible (?) + for (i = 0; i < nUnrolled; i+=4) + { + mfSum += p[i]; + mfSum += p[i+1]; + mfSum += p[i+2]; + mfSum += p[i+3]; + } + for (; i < nDataSize; ++i) + mfSum += p[i]; break; } diff --git a/tools/Library_tl.mk b/tools/Library_tl.mk index 65ba17c..2d105cd 100644 --- a/tools/Library_tl.mk +++ b/tools/Library_tl.mk @@ -69,7 +69,6 @@ $(eval $(call gb_Library_add_exception_objects,tl,\ tools/source/memtools/multisel \ tools/source/memtools/unqidx \ tools/source/misc/appendunixshellword \ - tools/source/misc/cpuid \ tools/source/misc/extendapplicationenvironment \ tools/source/misc/getprocessworkingdir \ tools/source/misc/solarmutex \ diff --git a/tools/source/misc/cpuid.cxx b/tools/source/misc/cpuid.cxx deleted file mode 100644 index 1d0518c..0000000 --- a/tools/source/misc/cpuid.cxx +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- 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 <tools/cpuid.hxx> -#include <cstdint> - -namespace tools -{ -namespace cpuid -{ - -// First minimize to MSVC / GCC compat. compiler and x86 / x64 architecture -#if (defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))) || (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))) - -namespace -{ -#if defined(_MSC_VER) -#include <intrin.h> -static void getCpuId(uint32_t array[4]) -{ - __cpuid((int*)array, 1); -} -#else -#include <cpuid.h> -static void getCpuId(uint32_t array[4]) -{ - __get_cpuid(1, array + 0, array + 1, array + 2, array + 3); -} -#endif -} - -bool hasSSE() -{ - uint32_t cpuInfoArray[] = {0, 0, 0, 0}; - getCpuId(cpuInfoArray); - return (cpuInfoArray[3] & (1 << 25)) != 0; -} -bool hasSSE2() -{ - uint32_t cpuInfoArray[] = {0, 0, 0, 0}; - getCpuId(cpuInfoArray); - return (cpuInfoArray[3] & (1 << 26)) != 0; -} - -#else - -bool hasSSE() { return false; } -bool hasSSE2() { return false; } - -#endif - -} -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
_______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
