summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2022-09-06 12:37:50 +0200
committerLuboš Luňák <l.lunak@collabora.com>2022-09-13 09:05:06 +0200
commit7ed959dfe96f3a4edc0ee00f23473aac28734e1f (patch)
tree0e8bfe1e3f3a9e37853e7c14dac90caeefc37433 /sc
parentb58acf93626456f9d9b9ff66f9208a3f944180ac (diff)
reduce opencl copy&paste in op_addin.cxx and op_logical.cxx
The svDoubleVectorRef stuff in OpAnd etc. didn't make sense, those operators are required to do implicit intersection (which can be done in sc core in ScCompiler::HandleIIOpCodeInternal()). Change-Id: Ic970c8e649a651f6a804b5ed265fe2e08ff29681 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139485 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/core/opencl/op_addin.cxx103
-rw-r--r--sc/source/core/opencl/op_logical.cxx299
-rw-r--r--sc/source/core/opencl/op_logical.hxx34
-rw-r--r--sc/source/core/opencl/opbase.cxx23
-rw-r--r--sc/source/core/opencl/opbase.hxx4
5 files changed, 69 insertions, 394 deletions
diff --git a/sc/source/core/opencl/op_addin.cxx b/sc/source/core/opencl/op_addin.cxx
index a9c2f9508ac8..602ed2dfb36d 100644
--- a/sc/source/core/opencl/op_addin.cxx
+++ b/sc/source/core/opencl/op_addin.cxx
@@ -23,69 +23,8 @@ void OpBesselj::GenSlidingWindowFunction(outputstream &ss,
GenerateFunctionDeclaration( sSymName, vSubArguments, ss );
ss << "{\n";
ss << " int gid0 = get_global_id(0);\n";
- ss << " double x = 0.0;\n";
- ss << " double N = 0.0;\n";
- FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
- assert(tmpCur0);
- if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
- {
- if(tmpCur0->GetType() == formula::svSingleVectorRef)
- {
- const formula::SingleVectorRefToken*tmpCurSVR0 =
- static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
- ss << " if (gid0 < " << tmpCurSVR0->GetArrayLength() << ")\n";
- ss << " {\n";
- ss << " x = ";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
- ss << " if (isnan(x))\n";
- ss << " x = 0.0;\n";
- ss << " }\n";
- }
- else if(tmpCur0->GetType() == formula::svDouble)
- {
- ss << " x = " << tmpCur0->GetDouble() << ";\n";
- }
- else
- {
- throw Unhandled(__FILE__, __LINE__);
- }
- }
- else
- {
- ss << " x = ";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
- }
-
- FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
- assert(tmpCur1);
- if(ocPush == vSubArguments[1]->GetFormulaToken()->GetOpCode())
- {
- if(tmpCur1->GetType() == formula::svSingleVectorRef)
- {
- const formula::SingleVectorRefToken*tmpCurSVR1 =
- static_cast<const formula::SingleVectorRefToken *>(tmpCur1);
- ss << " if (gid0 < " << tmpCurSVR1->GetArrayLength() << ")\n";
- ss << " {\n";
- ss << " N = ";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
- ss << " if (isnan(N))\n";
- ss << " N = 0.0;\n";
- ss << " }\n";
- }
- else if(tmpCur1->GetType() == formula::svDouble)
- {
- ss << " N = " << tmpCur1->GetDouble() << ";\n";
- }
- else
- {
- throw Unhandled(__FILE__, __LINE__);
- }
- }
- else
- {
- ss << " N = ";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
- }
+ GenerateArg( "x", 0, vSubArguments, ss );
+ GenerateArg( "N", 1, vSubArguments, ss );
ss << " double f_2_DIV_PI = 2.0 / M_PI;\n";
ss << " if( N < 0.0 )\n";
ss << " return CreateDoubleError(IllegalArgument);\n";
@@ -170,44 +109,14 @@ void OpGestep::GenSlidingWindowFunction(
outputstream &ss,const std::string &sSymName,
SubArguments &vSubArguments)
{
+ CHECK_PARAMETER_COUNT( 2, 2 );
GenerateFunctionDeclaration( sSymName, vSubArguments, ss );
ss << "{\n";
- ss << " double tmp=0,tmp0 =0,tmp1 = 0;\n";
+ ss << " double tmp=0;\n";
ss << " int gid0=get_global_id(0);\n";
ss <<"\n";
- for (size_t i = 0; i < vSubArguments.size(); i++)
- {
- FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
- assert(pCur);
- if (pCur->GetType() == formula::svSingleVectorRef)
- {
- const formula::SingleVectorRefToken& rSVR =
- dynamic_cast< const formula::SingleVectorRefToken& >(*pCur);
- ss << " if (gid0 < " << rSVR.GetArrayLength() << ")\n";
- ss << " {\n";
- }
- else if (pCur->GetType() == formula::svDouble)
- {
- ss << " {\n";
- }
-
- if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
- {
- ss << " if (isnan(";
- ss << vSubArguments[i]->GenSlidingWindowDeclRef();
- ss << "))\n";
- ss << " tmp"<<i<<" = 0;\n";
- ss << " else\n";
- ss << " tmp"<<i<<" = ";
- ss << vSubArguments[i]->GenSlidingWindowDeclRef();
- ss << ";\n }\n";
- }
- else
- {
- ss << "tmp"<<i<<" ="<<vSubArguments[i]->GenSlidingWindowDeclRef();
- ss <<";\n";
- }
- }
+ GenerateArg( "tmp0", 0, vSubArguments, ss );
+ GenerateArg( "tmp1", 1, vSubArguments, ss );
ss << " tmp =tmp0 >= tmp1 ? 1 : 0;\n";
ss << " return tmp;\n";
ss << "}\n";
diff --git a/sc/source/core/opencl/op_logical.cxx b/sc/source/core/opencl/op_logical.cxx
index ae4bb9d03de7..2af37c73395e 100644
--- a/sc/source/core/opencl/op_logical.cxx
+++ b/sc/source/core/opencl/op_logical.cxx
@@ -15,158 +15,24 @@
using namespace formula;
namespace sc::opencl {
-void OpAnd::GenSlidingWindowFunction(outputstream &ss,
- const std::string &sSymName, SubArguments &vSubArguments)
-{
- CHECK_PARAMETER_COUNT_MIN( 1 );
- GenerateFunctionDeclaration( sSymName, vSubArguments, ss );
- ss << "{\n";
- ss << " int gid0 = get_global_id(0);\n";
- ss << " double t = 1,tmp=0;\n";
- for(size_t j = 0; j< vSubArguments.size(); j++)
- {
- ss << " double tmp"<<j<<" = 1;\n";
- FormulaToken *tmpCur0 = vSubArguments[j]->GetFormulaToken();
- if(tmpCur0->GetType() == formula::svSingleVectorRef)
- {
- const formula::SingleVectorRefToken*pCurDVR= static_cast<const
- formula::SingleVectorRefToken *>(tmpCur0);
- ss<< " int buffer_len"<<j<<" = "<<pCurDVR->GetArrayLength();
- ss<< ";\n";
- ss <<" if(gid0 >= buffer_len"<<j<<" || isnan(";
- ss <<vSubArguments[j]->GenSlidingWindowDeclRef();
- ss <<"))\n";
- ss <<" tmp = 1;\n else\n";
- ss <<" tmp = ";
- ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
- ss <<" tmp"<<j<<" = tmp"<<j<<" && tmp;\n";
- }
- else if(tmpCur0->GetType() == formula::svDouble)
- {
- ss <<" tmp = ";
- ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
- ss <<" tmp"<<j<<" = tmp"<<j<<" && tmp;\n";
- }
- else if(tmpCur0->GetType() == formula::svDoubleVectorRef)
- {
- const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
- formula::DoubleVectorRefToken *>(tmpCur0);
- size_t nCurWindowSize = pCurDVR->GetArrayLength() <
- pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
- pCurDVR->GetRefRowSize() ;
- ss << " for(int i = ";
- if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
- ss << "gid0; i < " << nCurWindowSize << "; i++) {\n";
- }
- else if(pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()){
- ss << "0; i < gid0 + " << nCurWindowSize << "; i++) {\n";
- }
- else{
- ss << "0; i < " << nCurWindowSize << "; i++) {\n";
- }
- if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
- {
- ss <<" if(isnan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
- ss <<")||i+gid0>="<<pCurDVR->GetArrayLength();
- ss <<")\n";
- ss <<" tmp = 1;\n else\n";
- }
- else
- {
- ss <<" if(isnan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
- ss <<")||i>="<<pCurDVR->GetArrayLength();
- ss <<")\n";
- ss <<" tmp = 1;\n else\n";
- }
- ss <<" tmp = ";
- ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
- ss <<" tmp"<<j<<" = tmp"<<j<<" && tmp;\n";
- ss <<" }\n";
- }
- else
- {
- ss <<" tmp"<<j<<" = ";
- ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
- }
- ss <<" t = t && tmp"<<j<<";\n";
- }
- ss << " return t;\n";
- ss << "}\n";
-}
-void OpOr::GenSlidingWindowFunction(outputstream &ss,
+void OpLogicalBinaryOperator::GenSlidingWindowFunction(outputstream &ss,
const std::string &sSymName, SubArguments &vSubArguments)
{
- CHECK_PARAMETER_COUNT_MIN( 1 );
+ CHECK_PARAMETER_COUNT( 1, 30 );
GenerateFunctionDeclaration( sSymName, vSubArguments, ss );
ss << "{\n";
ss << " int gid0 = get_global_id(0);\n";
- ss << " double t = 0,tmp=0;\n";
+ ss << " bool t = " << defaultOpenclValue() << ";\n";
for(size_t j = 0; j< vSubArguments.size(); j++)
{
- ss << " double tmp"<<j<<" = 0;\n";
- FormulaToken *tmpCur0 = vSubArguments[j]->GetFormulaToken();
- if(tmpCur0->GetType() == formula::svSingleVectorRef)
- {
- const formula::SingleVectorRefToken*pCurDVR= static_cast<const
- formula::SingleVectorRefToken *>(tmpCur0);
- ss<< " int buffer_len"<<j<<" = "<<pCurDVR->GetArrayLength();
- ss<< ";\n";
- ss <<" if(gid0 >= buffer_len"<<j<<" || isnan(";
- ss <<vSubArguments[j]->GenSlidingWindowDeclRef();
- ss <<"))\n";
- ss <<" tmp = 0;\n else\n";
- ss <<" tmp = ";
- ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
- ss <<" tmp"<<j<<" = tmp"<<j<<" || tmp;\n";
- }
- else if(tmpCur0->GetType() == formula::svDouble)
- {
- ss <<" tmp = ";
- ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
- ss <<" tmp"<<j<<" = tmp"<<j<<" || tmp;\n";
- }
- else if(tmpCur0->GetType() == formula::svDoubleVectorRef)
- {
- const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
- formula::DoubleVectorRefToken *>(tmpCur0);
- size_t nCurWindowSize = pCurDVR->GetArrayLength() <
- pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
- pCurDVR->GetRefRowSize() ;
- ss << " for(int i = ";
- if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
- ss << "gid0; i < " << nCurWindowSize << "; i++) {\n";
- }
- else if(pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()){
- ss << "0; i < gid0 + " << nCurWindowSize << "; i++) {\n";
- }
- else{
- ss << "0; i < " << nCurWindowSize << "; i++) {\n";
- }
- if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
- {
- ss <<" if(isnan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
- ss <<")||i+gid0>="<<pCurDVR->GetArrayLength();
- ss <<")\n";
- ss <<" tmp = 0;\n else\n";
- }
- else
- {
- ss <<" if(isnan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
- ss <<")||i>="<<pCurDVR->GetArrayLength();
- ss <<")\n";
- ss <<" tmp = 0;\n else\n";
- }
- ss <<" tmp = ";
- ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
- ss <<" tmp"<<j<<" = tmp"<<j<<" || tmp;\n";
- ss <<" }\n";
- }
- ss <<" t = t || tmp"<<j<<";\n";
+ GenerateArg( j, vSubArguments, ss );
+ ss << " t = t " << openclOperator() << " (arg" << j << " != 0);\n";
}
ss << " return t;\n";
ss << "}\n";
}
+
void OpNot::GenSlidingWindowFunction(outputstream &ss,
const std::string &sSymName, SubArguments &vSubArguments)
{
@@ -174,103 +40,11 @@ void OpNot::GenSlidingWindowFunction(outputstream &ss,
GenerateFunctionDeclaration( sSymName, vSubArguments, ss );
ss << "{\n";
ss << " int gid0 = get_global_id(0);\n";
- ss << " double tmp=0;\n";
- FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
- if(tmpCur0->GetType() == formula::svSingleVectorRef)
- {
- const formula::SingleVectorRefToken*pCurDVR= static_cast<const
- formula::SingleVectorRefToken *>(tmpCur0);
- ss <<" if(gid0 >= "<<pCurDVR->GetArrayLength()<<" || isnan(";
- ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
- ss <<"))\n";
- ss <<" tmp = 0;\n else\n";
- ss <<" tmp = ";
- ss <<vSubArguments[0]->GenSlidingWindowDeclRef()<<";\n";
- ss <<" tmp = (tmp == 0.0);\n";
- }
- else if(tmpCur0->GetType() == formula::svDouble)
- {
- ss <<" tmp = ";
- ss <<vSubArguments[0]->GenSlidingWindowDeclRef()<<";\n";
- ss <<" tmp = (tmp == 0.0);\n";
- }
- ss << " return tmp;\n";
+ GenerateArg( 0, vSubArguments, ss );
+ ss << " return arg0 == 0;\n";
ss << "}\n";
}
-void OpXor::GenSlidingWindowFunction(outputstream &ss,
- const std::string &sSymName, SubArguments &vSubArguments)
-{
- CHECK_PARAMETER_COUNT_MIN( 1 );
- GenerateFunctionDeclaration( sSymName, vSubArguments, ss );
- ss << "{\n";
- ss << " int gid0 = get_global_id(0);\n";
- ss << " int t = 0,tmp0 = 0;\n";
- ss << " double tmp = 0;\n";
- for(DynamicKernelArgumentRef & rArg : vSubArguments)
- {
- FormulaToken *tmpCur0 = rArg->GetFormulaToken();
- if(tmpCur0->GetType() == formula::svSingleVectorRef)
- {
- const formula::SingleVectorRefToken*pCurDVR= static_cast<const
- formula::SingleVectorRefToken *>(tmpCur0);
- ss <<" if(gid0 >= "<<pCurDVR->GetArrayLength()<<" || isnan(";
- ss <<rArg->GenSlidingWindowDeclRef();
- ss <<"))\n";
- ss <<" tmp = 0;\n else\n";
- ss <<" tmp = ";
- ss <<rArg->GenSlidingWindowDeclRef()<<";\n";
- ss <<" tmp0 = (tmp != 0);\n";
- ss <<" t = t ^tmp0;\n";
- }
- else if(tmpCur0->GetType() == formula::svDouble)
- {
- ss <<" tmp = ";
- ss <<rArg->GenSlidingWindowDeclRef()<<";\n";
- ss <<" tmp0 = (tmp != 0);\n";
- ss <<" t = t ^tmp0;\n";
- }
- else if(tmpCur0->GetType() == formula::svDoubleVectorRef)
- {
- const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
- formula::DoubleVectorRefToken *>(tmpCur0);
- size_t nCurWindowSize = pCurDVR->GetArrayLength() <
- pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
- pCurDVR->GetRefRowSize() ;
- ss << " for(int i = ";
- if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
- ss << "gid0; i < " << nCurWindowSize << "; i++) {\n";
- }
- else if(pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()){
- ss << "0; i < gid0 + " << nCurWindowSize << "; i++) {\n";
- }
- else{
- ss << "0; i < " << nCurWindowSize << "; i++) {\n";
- }
- if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
- {
- ss <<" if(isnan("<<rArg->GenSlidingWindowDeclRef();
- ss <<")||i+gid0>="<<pCurDVR->GetArrayLength();
- ss <<")\n";
- ss <<" tmp = 0;\n else\n";
- }
- else
- {
- ss <<" if(isnan("<<rArg->GenSlidingWindowDeclRef();
- ss <<")||i>="<<pCurDVR->GetArrayLength();
- ss <<")\n";
- ss <<" tmp = 0;\n else\n";
- }
- ss <<" tmp = ";
- ss <<rArg->GenSlidingWindowDeclRef()<<";\n";
- ss <<" tmp0 = (tmp != 0);\n";
- ss <<" t = t ^tmp0;\n";
- ss <<" }\n";
- }
- }
- ss << " return t;\n";
- ss << "}\n";
-}
void OpIf::GenSlidingWindowFunction(outputstream &ss,
const std::string &sSymName, SubArguments &vSubArguments)
{
@@ -278,51 +52,20 @@ void OpIf::GenSlidingWindowFunction(outputstream &ss,
GenerateFunctionDeclaration( sSymName, vSubArguments, ss );
ss << "{\n";
ss << " int gid0 = get_global_id(0);\n";
+ GenerateArg( 0, vSubArguments, ss );
+ if(vSubArguments.size()>1)
+ GenerateArg( 1, vSubArguments, ss );
+ else
+ ss << " double arg1 = 1;\n";
+ if(vSubArguments.size()>2)
+ GenerateArg( 2, vSubArguments, ss );
+ else
+ ss << " double arg2 = 0;\n";
- FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
- if(tmpCur0->GetType() == formula::svDoubleVectorRef)
- {
- throw UnhandledToken("unknown operand for ocPush", __FILE__, __LINE__);
- }
- if(vSubArguments.size()==3)
- {
- ss << " if(isnan(";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss << ")|| ";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss << " == 0)\n";
- ss << " return ";
- ss << vSubArguments[2]->GenSlidingWindowDeclRef();
- ss << ";\n";
- ss << " else";
- ss <<" return ";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss <<";\n";
- }
- if(vSubArguments.size()==2)
- {
- ss << " if(isnan(";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss << ")|| ";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss << " == 0)\n";
- ss << " return 0;\n";
- ss << " else";
- ss <<" return ";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss <<";\n";
- }
- if(vSubArguments.size()==1)
- {
- ss << " if(isnan(";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss << ")|| ";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss << " == 0)\n";
- ss << " return 0;\n";
- ss << " else";
- ss <<" return 1;\n";
- }
+ ss << " if(arg0 != 0)\n";
+ ss << " return arg1;\n";
+ ss << " else\n";
+ ss << " return arg2;\n";
ss << "}\n";
}
diff --git a/sc/source/core/opencl/op_logical.hxx b/sc/source/core/opencl/op_logical.hxx
index 18cb0b59001f..f4c6b7a952ef 100644
--- a/sc/source/core/opencl/op_logical.hxx
+++ b/sc/source/core/opencl/op_logical.hxx
@@ -14,23 +14,34 @@
namespace sc::opencl {
-class OpAnd: public Normal
+/// Implements OpAnd, OpOr, OpXor.
+class OpLogicalBinaryOperator : public Normal
{
-public:
virtual void GenSlidingWindowFunction(outputstream &ss,
const std::string &sSymName, SubArguments &vSubArguments) override;
- virtual std::string BinFuncName() const override { return "And"; }
virtual bool canHandleMultiVector() const override { return true; }
+ /// The C operator implementing the function.
+ virtual const char* openclOperator() const = 0;
+ /// Default value when chaining the operator.
+ virtual const char* defaultOpenclValue() const = 0;
};
-class OpOr: public Normal
+class OpAnd: public OpLogicalBinaryOperator
+{
+public:
+ virtual std::string BinFuncName() const override { return "And"; }
+ virtual const char* openclOperator() const override { return "&&"; };
+ virtual const char* defaultOpenclValue() const override { return "true"; }
+};
+
+class OpOr: public OpLogicalBinaryOperator
{
public:
- virtual void GenSlidingWindowFunction(outputstream &ss,
- const std::string &sSymName, SubArguments &vSubArguments) override;
virtual std::string BinFuncName() const override { return "Or"; }
- virtual bool canHandleMultiVector() const override { return true; }
+ virtual const char* openclOperator() const override { return "||"; };
+ virtual const char* defaultOpenclValue() const override { return "false"; }
};
+
class OpNot: public Normal
{
public:
@@ -38,14 +49,15 @@ public:
const std::string &sSymName, SubArguments &vSubArguments) override;
virtual std::string BinFuncName() const override { return "Not"; }
};
-class OpXor: public Normal
+
+class OpXor: public OpLogicalBinaryOperator
{
public:
- virtual void GenSlidingWindowFunction(outputstream &ss,
- const std::string &sSymName, SubArguments &vSubArguments) override;
virtual std::string BinFuncName() const override { return "Xor"; }
- virtual bool canHandleMultiVector() const override { return true; }
+ virtual const char* openclOperator() const override { return "^"; };
+ virtual const char* defaultOpenclValue() const override { return "false"; }
};
+
class OpIf:public Normal
{
public:
diff --git a/sc/source/core/opencl/opbase.cxx b/sc/source/core/opencl/opbase.cxx
index 7f50d5523a15..a10ba9f77b64 100644
--- a/sc/source/core/opencl/opbase.cxx
+++ b/sc/source/core/opencl/opbase.cxx
@@ -174,36 +174,45 @@ bool VectorRef::NeedParallelReduction() const
return false;
}
-void SlidingFunctionBase::GenerateArg( int num, SubArguments& vSubArguments, outputstream& ss )
+void SlidingFunctionBase::GenerateArg( const char* name, 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";
+ ss << " double " << name << ";\n";
if(token->GetOpCode() == ocPush)
{
if(token->GetType() == formula::svSingleVectorRef)
{
- ss << " if(isnan(";
+ const formula::SingleVectorRefToken* svr =
+ static_cast<const formula::SingleVectorRefToken *>(token);
+ ss << " if (gid0 >= " << svr->GetArrayLength() << " || isnan(";
ss << vSubArguments[num]->GenSlidingWindowDeclRef() << "))\n";
- ss << " arg" << num << " = 0.0;\n";
+ ss << " " << name << " = 0.0;\n";
ss << " else\n";
- ss << " arg" << num << " = ";
+ ss << " " << name << " = ";
ss << vSubArguments[num]->GenSlidingWindowDeclRef() << ";\n";
}
else if(token->GetType() == formula::svDouble)
- ss << " arg" << num << " = " << token->GetDouble() << ";\n";
+ ss << " " << name << " = " << token->GetDouble() << ";\n";
else
throw Unhandled( __FILE__, __LINE__ );
}
else
{
- ss << " arg" << num << " = ";
+ ss << " " << name << " = ";
ss << vSubArguments[num]->GenSlidingWindowDeclRef() << ";\n";
}
}
+void SlidingFunctionBase::GenerateArg( int num, SubArguments& vSubArguments, outputstream& ss )
+{
+ char buf[ 30 ];
+ sprintf( buf, "arg%d", num );
+ GenerateArg( buf, num, vSubArguments, ss );
+}
+
void SlidingFunctionBase::GenerateFunctionDeclaration( const std::string& sSymName,
SubArguments& vSubArguments, outputstream& ss )
{
diff --git a/sc/source/core/opencl/opbase.hxx b/sc/source/core/opencl/opbase.hxx
index 1b118d39e93e..46b767062b9a 100644
--- a/sc/source/core/opencl/opbase.hxx
+++ b/sc/source/core/opencl/opbase.hxx
@@ -225,7 +225,9 @@ public:
virtual void GenSlidingWindowFunction( outputstream&,
const std::string&, SubArguments& ) = 0;
protected:
- // generate code for "double arg<num> = <value>;" from vSubArguments
+ // generate code for "double <name> = <value>;" from vSubArguments
+ static void GenerateArg( const char* name, int num, SubArguments& vSubArguments, outputstream& ss );
+ // overload, variable will be named "arg<num>"
static void GenerateArg( int num, SubArguments& vSubArguments, outputstream& ss );
void GenerateFunctionDeclaration( const std::string& sSymName,
SubArguments& vSubArguments, outputstream& ss );