sc/source/core/opencl/op_math.cxx | 44 +++++--------------------------------- sc/source/core/opencl/opbase.cxx | 30 +++++++++++++++++++++++++ sc/source/core/opencl/opbase.hxx | 3 ++ 3 files changed, 39 insertions(+), 38 deletions(-)
New commits: commit 6778f8ec5a3fed427ef97293d8e71333c511b613 Author: Luboš Luňák <l.lu...@collabora.com> AuthorDate: Thu Sep 1 14:02:11 2022 +0200 Commit: Luboš Luňák <l.lu...@collabora.com> CommitDate: Tue Sep 6 13:03:42 2022 +0200 fix and simplify opencl COMBIN() Change-Id: I7568e3bb55cab31eb6e9b8644019a465333e8091 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139200 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lu...@collabora.com> diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx index bd058a26a48b..4dec63ac654f 100644 --- a/sc/source/core/opencl/op_math.cxx +++ b/sc/source/core/opencl/op_math.cxx @@ -2615,45 +2615,13 @@ void OpCombin::GenSlidingWindowFunction(outputstream &ss, } ss << ") {\n"; ss << " int gid0 = get_global_id(0);\n"; - ss << " double num = " << GetBottom() << ";\n"; - ss << " double num_chosen = " << GetBottom() << ";\n"; ss << " double result = -1.0;\n"; - FormulaToken *iNum = vSubArguments[0]->GetFormulaToken(); - FormulaToken *iNumChosen = vSubArguments[1]->GetFormulaToken(); - - assert(iNum); - if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode()) - { - if(iNum->GetType() == formula::svSingleVectorRef && - iNumChosen->GetType() == formula::svSingleVectorRef) - { - ss << " if(isnan("; - ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n"; - ss << " num = 0.0;\n"; - ss << " else\n "; - ss << " num = floor("; - ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ");\n"; - ss << " if(isnan("; - ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n"; - ss << " num_chosen = 0.0;\n"; - ss << " else\n "; - ss << " num_chosen = floor("; - ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ");\n"; - } - else if(iNum->GetType() == formula::svDouble && - iNumChosen->GetType() == formula::svDouble) - { - ss << " num = floor(" << iNum->GetDouble() << ");\n"; - ss << " num_chosen = floor("<< iNumChosen->GetDouble()<< ");\n"; - } - } - else - { - ss << " num = floor("; - ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ");\n"; - ss << " num_chosen = floor("; - ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ");\n"; - } + GenerateArg( 0, vSubArguments, ss ); + GenerateArg( 1, vSubArguments, ss ); + ss << " double num = floor( arg0 );\n"; + ss << " double num_chosen = floor( arg1 );\n"; + ss << " if(num < 0 || num_chosen < 0 || num < num_chosen )\n"; + ss << " return CreateDoubleError(IllegalArgument);\n"; ss << " result = select(result, 0.0, (ulong)(num < num_chosen));\n"; ss << " result = select(result, 1.0, (ulong)(num_chosen == 0.0));\n"; ss << " if(result == 0 || result ==1)\n"; diff --git a/sc/source/core/opencl/opbase.cxx b/sc/source/core/opencl/opbase.cxx index 1726b37a9699..9cc69854ca9b 100644 --- a/sc/source/core/opencl/opbase.cxx +++ b/sc/source/core/opencl/opbase.cxx @@ -174,6 +174,36 @@ bool VectorRef::NeedParallelReduction() const return false; } +void SlidingFunctionBase::GenerateArg( int num, SubArguments& vSubArguments, outputstream& ss ) +{ + CHECK_PARAMETER_COUNT_MIN( num ); + FormulaToken *token = vSubArguments[num]->GetFormulaToken(); + if( token == nullptr ) + throw Unhandled( __FILE__, __LINE__ ); + ss << " double arg" << num << ";\n"; + if(token->GetOpCode() == ocPush) + { + if(token->GetType() == formula::svSingleVectorRef) + { + ss << " if(isnan("; + ss << vSubArguments[num]->GenSlidingWindowDeclRef() << "))\n"; + ss << " arg" << num << " = 0.0;\n"; + ss << " else\n"; + ss << " arg" << num << " = "; + ss << vSubArguments[num]->GenSlidingWindowDeclRef() << ";\n"; + } + else if(token->GetType() == formula::svDouble) + ss << " arg" << num << " = " << token->GetDouble() << ";\n"; + else + throw Unhandled( __FILE__, __LINE__ ); + } + else + { + ss << " arg" << num << " = "; + ss << vSubArguments[num]->GenSlidingWindowDeclRef() << ";\n"; + } +} + void Normal::GenSlidingWindowFunction( outputstream& ss, const std::string& sSymName, SubArguments& vSubArguments ) { diff --git a/sc/source/core/opencl/opbase.hxx b/sc/source/core/opencl/opbase.hxx index c56c02c855a3..ea1c7402ab23 100644 --- a/sc/source/core/opencl/opbase.hxx +++ b/sc/source/core/opencl/opbase.hxx @@ -224,6 +224,9 @@ public: typedef std::vector<DynamicKernelArgumentRef> SubArguments; virtual void GenSlidingWindowFunction( outputstream&, const std::string&, SubArguments& ) = 0; +protected: + // generate code for "double arg<num> = <value>;" from vSubArguments + static void GenerateArg( int num, SubArguments& vSubArguments, outputstream& ss ); }; class Normal : public SlidingFunctionBase