sc/inc/formulagroup.hxx | 4 +- sc/inc/stlalgorithm.hxx | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-)
New commits: commit 5e34a3236258f47374c34e5c7ab92fde9b981bb7 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Wed Feb 26 16:29:27 2014 -0500 Ensure that numeric array storage is aligned to 256-byte boundary. OpenCL devices require this else we would get a performance hit. (cherry picked from commit 03f7a342011a4f69cfcbec7af3e4f1a2e835618b) (cherry picked from commit 757856e9275d19e2c7a3673d10fa8963fb9fbeb3) Change-Id: Ie69e07dc5d9b62abad5cc39d1f30e1d770c56758 Reviewed-on: https://gerrit.libreoffice.org/8466 Reviewed-by: Michael Meeks <michael.me...@collabora.com> Tested-by: Michael Meeks <michael.me...@collabora.com> diff --git a/sc/inc/formulagroup.hxx b/sc/inc/formulagroup.hxx index 3834e49..602c4a4 100644 --- a/sc/inc/formulagroup.hxx +++ b/sc/inc/formulagroup.hxx @@ -13,6 +13,7 @@ #include "address.hxx" #include "types.hxx" #include "platforminfo.hxx" +#include <stlalgorithm.hxx> #include "svl/sharedstringpool.hxx" @@ -28,7 +29,8 @@ namespace sc { struct FormulaGroupContext : boost::noncopyable { - typedef std::vector<double> NumArrayType; + typedef AlignedAllocator<double,256> DoubleAllocType; + typedef std::vector<double, DoubleAllocType> NumArrayType; typedef std::vector<rtl_uString*> StrArrayType; typedef boost::ptr_vector<NumArrayType> NumArrayStoreType; typedef boost::ptr_vector<StrArrayType> StrArrayStoreType; diff --git a/sc/inc/stlalgorithm.hxx b/sc/inc/stlalgorithm.hxx index fb5509f..f788667 100644 --- a/sc/inc/stlalgorithm.hxx +++ b/sc/inc/stlalgorithm.hxx @@ -11,6 +11,10 @@ #define __SC_STLALGORITHM_HXX__ #include <functional> +#include <limits> + +#include <stdlib.h> +#include <malloc.h> /** * Function object to allow deleting instances stored in STL containers as @@ -25,6 +29,81 @@ struct ScDeleteObjectByPtr : public ::std::unary_function<T*, void> } }; +namespace sc { + +/** + * Custom allocator for STL container to ensure that the base address of + * allocated storage is aligned to a specified boundary. + */ +template<typename T, size_t _Alignment> +class AlignedAllocator +{ +public: + typedef T value_type; + typedef size_t size_type; + typedef std::ptrdiff_t difference_type; + + typedef T* pointer; + typedef const T* const_pointer; + typedef T* void_pointer; + + typedef T& reference; + typedef const T& const_reference; + + template<typename _Type2> + struct rebind + { + typedef AlignedAllocator<_Type2,_Alignment> other; + }; + + AlignedAllocator() {} + ~AlignedAllocator() {} + + template<typename _Type2> + AlignedAllocator(const AlignedAllocator<_Type2,_Alignment>&) {} + + void construct(T* p, const value_type& val) { new(p) value_type(val); } + void destroy(T* p) { p->~value_type(); } + + size_type max_size() const + { + return std::numeric_limits<size_type>::max() / sizeof(value_type); + } + + bool operator== (const AlignedAllocator&) const { return true; } + bool operator!= (const AlignedAllocator&) const { return false; } + + pointer allocate(size_type n) + { + if (!n) + return NULL; + + size_type size = n*sizeof(value_type); +#ifdef WNT + return _aligned_malloc(size, _Alignment); +#elif defined __ANDROID__ + return memalign(align, size); +#else + void* ptr; + int err = posix_memalign(&ptr, _Alignment, size); + if (err) + ptr = NULL; + return (pointer)ptr; +#endif + } + + void deallocate(pointer p, size_type) + { +#ifdef WNT + _aligned_free(p); +#else + free(p); +#endif + } +}; + +} + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits