From 28788431c6e606f33ca8a9ae1a56e3aee1aae2b6 Mon Sep 17 00:00:00 2001 From: azv Date: Wed, 27 Nov 2013 09:59:18 +0400 Subject: [PATCH] 0024238: Made some changes to work with static aligned array --- src/BSplSLib/BSplSLib.cxx | 17 ++-- src/NCollection/FILES | 2 + .../NCollection_AlignedLocalArray.hxx | 85 +++++++++++++++++++ src/PLib/PLib.cdl | 7 ++ 4 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 src/NCollection/NCollection_AlignedLocalArray.hxx diff --git a/src/BSplSLib/BSplSLib.cxx b/src/BSplSLib/BSplSLib.cxx index 0775da830e..6bd2d3cce0 100755 --- a/src/BSplSLib/BSplSLib.cxx +++ b/src/BSplSLib/BSplSLib.cxx @@ -36,7 +36,7 @@ #include #include #include -#include +#include // for null derivatives static Standard_Real BSplSLib_zero[3] = {0.0, 0.0, 0.0}; @@ -2102,7 +2102,8 @@ void BSplSLib::CacheD0( dimension = 4 * (VDegree + 1); } - Standard_Real* locpoles = (Standard_Real*) NCollection_AlignAllocator::Allocate(dimension*sizeof(Standard_Real), DATA_ALIGNMENT); + NCollection_AlignedLocalArray locpoles(dimension); +// Standard_Real* locpoles = (Standard_Real*) NCollection_AlignAllocator::Allocate(dimension*sizeof(Standard_Real), DATA_ALIGNMENT); PLib::NoDerivativeEvalPolynomial(new_parameter[0], max_degree, @@ -2133,7 +2134,7 @@ void BSplSLib::CacheD0( myPoint[2] = local_pole_and_weight[2]; } - NCollection_AlignAllocator::Free(locpoles); +// NCollection_AlignAllocator::Free(locpoles); } @@ -2203,7 +2204,8 @@ void BSplSLib::CacheD1( my_vec_max = (Standard_Real *) &aVecU; } - Standard_Real* locpoles = (Standard_Real*) NCollection_AlignAllocator::Allocate(2*dimension*sizeof(Standard_Real), DATA_ALIGNMENT); + NCollection_AlignedLocalArray locpoles(2*dimension); +// Standard_Real* locpoles = (Standard_Real*) NCollection_AlignAllocator::Allocate(2*dimension*sizeof(Standard_Real), DATA_ALIGNMENT); PLib::EvalPolynomialWithAlignedData(new_parameter[0], 1, @@ -2252,7 +2254,7 @@ void BSplSLib::CacheD1( } } - NCollection_AlignAllocator::Free(locpoles); +// NCollection_AlignAllocator::Free(locpoles); } @@ -2339,7 +2341,8 @@ void BSplSLib::CacheD2( my_vec_max_max = (Standard_Real *) &aVecUU; } - Standard_Real* locpoles = (Standard_Real*) NCollection_AlignAllocator::Allocate(3*dimension*sizeof(Standard_Real), DATA_ALIGNMENT); + NCollection_AlignedLocalArray locpoles(3*dimension); +// Standard_Real* locpoles = (Standard_Real*) NCollection_AlignAllocator::Allocate(3*dimension*sizeof(Standard_Real), DATA_ALIGNMENT); // // initialize in case min or max degree are less than 2 @@ -2425,7 +2428,7 @@ void BSplSLib::CacheD2( } } - NCollection_AlignAllocator::Free(locpoles); +// NCollection_AlignAllocator::Free(locpoles); } //======================================================================= diff --git a/src/NCollection/FILES b/src/NCollection/FILES index 2ecd6d92a3..e91bb56712 100755 --- a/src/NCollection/FILES +++ b/src/NCollection/FILES @@ -7,6 +7,7 @@ NCollection_IncAllocator.cxx NCollection_HeapAllocator.hxx NCollection_HeapAllocator.cxx NCollection_StdAllocator.hxx +NCollection_AlignAllocator.cxx NCollection_AlignAllocator.hxx NCollection_ListNode.hxx @@ -75,6 +76,7 @@ NCollection_UtfString.hxx NCollection_UtfString.lxx NCollection_String.hxx +NCollection_AlignedLocalArray.hxx NCollection_LocalArray.hxx NCollection_SparseArray.hxx NCollection_SparseArrayBase.hxx diff --git a/src/NCollection/NCollection_AlignedLocalArray.hxx b/src/NCollection/NCollection_AlignedLocalArray.hxx new file mode 100644 index 0000000000..0268c86aaf --- /dev/null +++ b/src/NCollection/NCollection_AlignedLocalArray.hxx @@ -0,0 +1,85 @@ +// Created on: 2009-09-23 +// Copyright (c) 2009-2012 OPEN CASCADE SAS +// +// The content of this file is subject to the Open CASCADE Technology Public +// License Version 6.5 (the "License"). You may not use the content of this file +// except in compliance with the License. Please obtain a copy of the License +// at http://www.opencascade.org and read it completely before using this file. +// +// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its +// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. +// +// The Original Code and all software distributed under the License is +// distributed on an "AS IS" basis, without warranty of any kind, and the +// Initial Developer hereby disclaims all such warranties, including without +// limitation, any warranties of merchantability, fitness for a particular +// purpose or non-infringement. Please see the License for the specific terms +// and conditions governing the rights and limitations under the License. + + +#ifndef _NCollection_AlignedLocalArray_HeaderFile +#define _NCollection_AlignedLocalArray_HeaderFile + +#include +#include + +#include + +//! Auxiliary class optimizing creation of aligned array buffer +//! (using stack allocation for small arrays). +template class NCollection_AlignedLocalArray +{ +public: + + // 1K * sizeof (theItem) + static const size_t MAX_ARRAY_SIZE = 1024; + + NCollection_AlignedLocalArray (const size_t theSize) + : myPtr (myBuffer) + { + Allocate(theSize); + } + + NCollection_AlignedLocalArray () + : myPtr (myBuffer) {} + + virtual ~NCollection_AlignedLocalArray() + { + Deallocate(); + } + + void Allocate (const size_t theSize) + { + Deallocate(); + if (theSize > MAX_ARRAY_SIZE) + myPtr = (theItem*) NCollection_AlignAllocator::Allocate(theSize * sizeof(theItem), DATA_ALIGNMENT); + else + myPtr = myBuffer; + } + + operator theItem*() const + { + return myPtr; + } + +private: + + NCollection_AlignedLocalArray (const NCollection_AlignedLocalArray& ); + NCollection_AlignedLocalArray& operator= (const NCollection_AlignedLocalArray& ); + +protected: + + void Deallocate() + { + if (myPtr != myBuffer) + NCollection_AlignAllocator::Free(*(Standard_Address*)&myPtr); + } + +protected: + + MEMALIGN(theItem, myBuffer[MAX_ARRAY_SIZE]); + MEMALIGN(theItem*, myPtr); + +}; + +#endif // _NCollection_AlignedLocalArray_HeaderFile diff --git a/src/PLib/PLib.cdl b/src/PLib/PLib.cdl index ca190f6558..e74ebdcbba 100755 --- a/src/PLib/PLib.cdl +++ b/src/PLib/PLib.cdl @@ -174,6 +174,13 @@ is Dimension : Integer ; PolynomialCoeff : in out Real ; Results : in out Real) ; + ---Purpose: Makes the same as EvalPolynomial but with data aligned for support of SSE + EvalPolynomialWithAlignedData(U : Real; + DerivativeOrder : Integer ; + Degree : Integer ; + Dimension : Integer ; + PolynomialCoeff : in out Real ; + Results : in out Real) ; ---Purpose: Performs Horner method with synthethic division -- for derivatives -- 2.39.5