LCOV - code coverage report
Current view: top level - sc/source/core/opencl - op_logical.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 245 0.4 %
Date: 2014-11-03 Functions: 2 7 28.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include "op_logical.hxx"
      11             : 
      12             : #include "formulagroup.hxx"
      13             : #include "document.hxx"
      14             : #include "formulacell.hxx"
      15             : #include "tokenarray.hxx"
      16             : #include "compiler.hxx"
      17             : #include "interpre.hxx"
      18             : #include <formula/vectortoken.hxx>
      19             : #include <sstream>
      20             : 
      21             : using namespace formula;
      22             : 
      23             : namespace sc { namespace opencl {
      24           0 : void OpAnd::GenSlidingWindowFunction(std::stringstream &ss,
      25             :     const std::string &sSymName, SubArguments &vSubArguments)
      26             : {
      27           0 :     ss << "\ndouble " << sSymName;
      28           0 :     ss << "_"<< BinFuncName() <<"(";
      29           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
      30             :     {
      31           0 :         if (i)
      32           0 :             ss << ",";
      33           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
      34             :     }
      35           0 :     ss << ") {\n";
      36           0 :     ss << "    int gid0 = get_global_id(0);\n";
      37           0 :     ss << "    double t = 1,tmp=0;\n";
      38           0 :     for(unsigned int j = 0; j< vSubArguments.size(); j++)
      39             :     {
      40           0 :         ss << "    double tmp"<<j<<" = 1;\n";
      41           0 :         FormulaToken *tmpCur0 = vSubArguments[j]->GetFormulaToken();
      42           0 :         if(tmpCur0->GetType() == formula::svSingleVectorRef)
      43             :         {
      44             :         const formula::SingleVectorRefToken*pCurDVR= static_cast<const
      45           0 :             formula::SingleVectorRefToken *>(tmpCur0);
      46           0 :         ss<< "    int buffer_len"<<j<<" = "<<pCurDVR->GetArrayLength();
      47           0 :         ss<< ";\n";
      48           0 :         ss <<"    if(gid0 >= buffer_len"<<j<<" || isNan(";
      49           0 :         ss <<vSubArguments[j]->GenSlidingWindowDeclRef();
      50           0 :         ss <<"))\n";
      51           0 :         ss <<"        tmp = 1;\n    else\n";
      52           0 :         ss <<"        tmp = ";
      53           0 :         ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
      54           0 :         ss <<"    tmp"<<j<<" = tmp"<<j<<" && tmp;\n";
      55             :         }
      56           0 :         else if(tmpCur0->GetType() == formula::svDouble)
      57             :         {
      58           0 :             ss <<"        tmp = ";
      59           0 :             ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
      60           0 :             ss <<"    tmp"<<j<<" = tmp"<<j<<" && tmp;\n";
      61             :         }
      62           0 :         else if(tmpCur0->GetType() == formula::svDoubleVectorRef)
      63             :         {
      64             :             const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
      65           0 :             formula::DoubleVectorRefToken *>(tmpCur0);
      66           0 :             size_t nCurWindowSize = pCurDVR->GetArrayLength() <
      67           0 :             pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
      68           0 :             pCurDVR->GetRefRowSize() ;
      69           0 :             ss << "    for(int i = ";
      70           0 :             if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
      71           0 :             ss << "gid0; i < " << nCurWindowSize << "; i++) {\n";
      72             :             }
      73           0 :             else if(pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()){
      74           0 :             ss << "0; i < gid0 + " << nCurWindowSize << "; i++) {\n";
      75             :             }
      76             :             else{
      77           0 :             ss << "0; i < " << nCurWindowSize << "; i++) {\n";
      78             :             }
      79             : #ifdef ISNAN
      80           0 :             if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
      81             :                 {
      82           0 :             ss <<"    if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
      83           0 :             ss <<")||i+gid0>="<<pCurDVR->GetArrayLength();
      84           0 :             ss <<")\n";
      85           0 :             ss <<"        tmp = 1;\n    else\n";
      86             :                 }
      87             :             else
      88             :                 {
      89           0 :             ss <<"    if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
      90           0 :             ss <<")||i>="<<pCurDVR->GetArrayLength();
      91           0 :             ss <<")\n";
      92           0 :             ss <<"        tmp = 1;\n    else\n";
      93             :                 }
      94             : #endif
      95           0 :             ss <<"        tmp = ";
      96           0 :             ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
      97           0 :             ss <<"    tmp"<<j<<" = tmp"<<j<<" && tmp;\n";
      98           0 :             ss <<"    }\n";
      99             :         }
     100             :         else
     101             :         {
     102           0 :             ss <<"        tmp"<<j<<" = ";
     103           0 :             ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
     104             :         }
     105           0 :         ss <<"    t = t && tmp"<<j<<";\n";
     106             :     }
     107           0 :     ss << "    return t;\n";
     108           0 :     ss << "}\n";
     109           0 : }
     110             : 
     111           0 : void OpOr::GenSlidingWindowFunction(std::stringstream &ss,
     112             :     const std::string &sSymName, SubArguments &vSubArguments)
     113             : {
     114           0 :     ss << "\ndouble " << sSymName;
     115           0 :     ss << "_"<< BinFuncName() <<"(";
     116           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     117             :     {
     118           0 :         if (i)
     119           0 :             ss << ",";
     120           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     121             :     }
     122           0 :     ss << ") {\n";
     123           0 :     ss << "    int gid0 = get_global_id(0);\n";
     124           0 :     ss << "    double t = 0,tmp=0;\n";
     125           0 :     for(unsigned int j = 0; j< vSubArguments.size(); j++)
     126             :     {
     127           0 :         ss << "    double tmp"<<j<<" = 0;\n";
     128           0 :         FormulaToken *tmpCur0 = vSubArguments[j]->GetFormulaToken();
     129           0 :         if(tmpCur0->GetType() == formula::svSingleVectorRef)
     130             :         {
     131             : #ifdef ISNAN
     132             :         const formula::SingleVectorRefToken*pCurDVR= static_cast<const
     133           0 :             formula::SingleVectorRefToken *>(tmpCur0);
     134           0 :         ss<< "    int buffer_len"<<j<<" = "<<pCurDVR->GetArrayLength();
     135           0 :         ss<< ";\n";
     136           0 :         ss <<"    if(gid0 >= buffer_len"<<j<<" || isNan(";
     137           0 :         ss <<vSubArguments[j]->GenSlidingWindowDeclRef();
     138           0 :         ss <<"))\n";
     139           0 :         ss <<"        tmp = 0;\n    else\n";
     140             : #endif
     141           0 :         ss <<"        tmp = ";
     142           0 :         ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
     143           0 :         ss <<"    tmp"<<j<<" = tmp"<<j<<" || tmp;\n";
     144             :         }
     145           0 :         else if(tmpCur0->GetType() == formula::svDouble)
     146             :         {
     147           0 :             ss <<"        tmp = ";
     148           0 :             ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
     149           0 :             ss <<"    tmp"<<j<<" = tmp"<<j<<" || tmp;\n";
     150             :         }
     151           0 :         else if(tmpCur0->GetType() == formula::svDoubleVectorRef)
     152             :         {
     153             :             const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
     154           0 :             formula::DoubleVectorRefToken *>(tmpCur0);
     155           0 :             size_t nCurWindowSize = pCurDVR->GetArrayLength() <
     156           0 :             pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
     157           0 :             pCurDVR->GetRefRowSize() ;
     158           0 :             ss << "    for(int i = ";
     159           0 :             if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
     160           0 :             ss << "gid0; i < " << nCurWindowSize << "; i++) {\n";
     161             :             }
     162           0 :             else if(pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()){
     163           0 :             ss << "0; i < gid0 + " << nCurWindowSize << "; i++) {\n";
     164             :             }
     165             :             else{
     166           0 :             ss << "0; i < " << nCurWindowSize << "; i++) {\n";
     167             :             }
     168             : #ifdef ISNAN
     169           0 :             if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
     170             :                 {
     171           0 :             ss <<"    if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
     172           0 :             ss <<")||i+gid0>="<<pCurDVR->GetArrayLength();
     173           0 :             ss <<")\n";
     174           0 :             ss <<"        tmp = 0;\n    else\n";
     175             :                 }
     176             :             else
     177             :                 {
     178           0 :             ss <<"    if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
     179           0 :             ss <<")||i>="<<pCurDVR->GetArrayLength();
     180           0 :             ss <<")\n";
     181           0 :             ss <<"        tmp = 0;\n    else\n";
     182             :                 }
     183             : #endif
     184           0 :             ss <<"        tmp = ";
     185           0 :             ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
     186           0 :             ss <<"    tmp"<<j<<" = tmp"<<j<<" || tmp;\n";
     187           0 :             ss <<"    }\n";
     188             :         }
     189           0 :         ss <<"    t = t || tmp"<<j<<";\n";
     190             :     }
     191           0 :     ss << "    return t;\n";
     192           0 :     ss << "}\n";
     193           0 : }
     194           0 : void OpNot::GenSlidingWindowFunction(std::stringstream &ss,
     195             :     const std::string &sSymName, SubArguments &vSubArguments)
     196             : {
     197           0 :     ss << "\ndouble " << sSymName;
     198           0 :     ss << "_"<< BinFuncName() <<"(";
     199           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     200             :     {
     201           0 :         if (i)
     202           0 :             ss << ",";
     203           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     204             :     }
     205           0 :     ss << ") {\n";
     206           0 :     ss << "    int gid0 = get_global_id(0);\n";
     207           0 :     ss << "    double tmp=0;\n";
     208           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
     209           0 :     if(tmpCur0->GetType() == formula::svSingleVectorRef)
     210             :     {
     211             : #ifdef ISNAN
     212             :         const formula::SingleVectorRefToken*pCurDVR= static_cast<const
     213           0 :             formula::SingleVectorRefToken *>(tmpCur0);
     214           0 :         ss <<"    if(gid0 >= "<<pCurDVR->GetArrayLength()<<" || isNan(";
     215           0 :         ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
     216           0 :         ss <<"))\n";
     217           0 :         ss <<"        tmp = 0;\n    else\n";
     218             : #endif
     219           0 :         ss <<"        tmp = ";
     220           0 :         ss <<vSubArguments[0]->GenSlidingWindowDeclRef()<<";\n";
     221           0 :         ss <<"    tmp = (tmp == 0.0);\n";
     222             :     }
     223           0 :     else if(tmpCur0->GetType() == formula::svDouble)
     224             :     {
     225           0 :         ss <<"        tmp = ";
     226           0 :         ss <<vSubArguments[0]->GenSlidingWindowDeclRef()<<";\n";
     227           0 :         ss <<"    tmp = (tmp == 0.0);\n";
     228             :     }
     229           0 :     ss << "    return tmp;\n";
     230           0 :     ss << "}\n";
     231           0 : }
     232             : 
     233           0 : void OpXor::GenSlidingWindowFunction(std::stringstream &ss,
     234             :     const std::string &sSymName, SubArguments &vSubArguments)
     235             : {
     236           0 :     ss << "\ndouble " << sSymName;
     237           0 :     ss << "_"<< BinFuncName() <<"(";
     238           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     239             :     {
     240           0 :         if (i)
     241           0 :             ss << ",";
     242           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     243             :     }
     244           0 :     ss << ") {\n";
     245           0 :     ss << "    int gid0 = get_global_id(0);\n";
     246           0 :     ss << "    int t = 0,tmp0 = 0;\n";
     247           0 :     ss << "    double tmp = 0;\n";
     248           0 :     for(unsigned int j = 0; j< vSubArguments.size(); j++)
     249             :     {
     250           0 :         FormulaToken *tmpCur0 = vSubArguments[j]->GetFormulaToken();
     251           0 :         if(tmpCur0->GetType() == formula::svSingleVectorRef)
     252             :         {
     253             : #ifdef ISNAN
     254             :             const formula::SingleVectorRefToken*pCurDVR= static_cast<const
     255           0 :                 formula::SingleVectorRefToken *>(tmpCur0);
     256           0 :             ss <<"    if(gid0 >= "<<pCurDVR->GetArrayLength()<<" || isNan(";
     257           0 :             ss <<vSubArguments[j]->GenSlidingWindowDeclRef();
     258           0 :             ss <<"))\n";
     259           0 :             ss <<"        tmp = 0;\n    else\n";
     260             : #endif
     261           0 :             ss <<"        tmp = ";
     262           0 :             ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
     263           0 :             ss <<"    tmp0 = (tmp != 0);\n";
     264           0 :             ss <<"    t = t ^tmp0;\n";
     265             :         }
     266           0 :         else if(tmpCur0->GetType() == formula::svDouble)
     267             :         {
     268           0 :             ss <<"        tmp = ";
     269           0 :             ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
     270           0 :             ss <<"    tmp0 = (tmp != 0);\n";
     271           0 :             ss <<"    t = t ^tmp0;\n";
     272             :         }
     273           0 :         else if(tmpCur0->GetType() == formula::svDoubleVectorRef)
     274             :         {
     275             :             const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
     276           0 :             formula::DoubleVectorRefToken *>(tmpCur0);
     277           0 :             size_t nCurWindowSize = pCurDVR->GetArrayLength() <
     278           0 :             pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
     279           0 :             pCurDVR->GetRefRowSize() ;
     280           0 :             ss << "    for(int i = ";
     281           0 :             if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
     282           0 :             ss << "gid0; i < " << nCurWindowSize << "; i++) {\n";
     283             :             }
     284           0 :             else if(pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()){
     285           0 :             ss << "0; i < gid0 + " << nCurWindowSize << "; i++) {\n";
     286             :             }
     287             :             else{
     288           0 :             ss << "0; i < " << nCurWindowSize << "; i++) {\n";
     289             :             }
     290             : #ifdef ISNAN
     291           0 :             if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
     292             :                 {
     293           0 :             ss <<"    if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
     294           0 :             ss <<")||i+gid0>="<<pCurDVR->GetArrayLength();
     295           0 :             ss <<")\n";
     296           0 :             ss <<"        tmp = 0;\n    else\n";
     297             :                 }
     298             :             else
     299             :                 {
     300           0 :             ss <<"    if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
     301           0 :             ss <<")||i>="<<pCurDVR->GetArrayLength();
     302           0 :             ss <<")\n";
     303           0 :             ss <<"        tmp = 0;\n    else\n";
     304             :                 }
     305             : #endif
     306           0 :             ss <<"        tmp = ";
     307           0 :             ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
     308           0 :             ss <<"    tmp0 = (tmp != 0);\n";
     309           0 :             ss <<"    t = t ^tmp0;\n";
     310           0 :             ss <<"    }\n";
     311             :         }
     312             :     }
     313           0 :     ss << "    return t;\n";
     314           0 :     ss << "}\n";
     315           0 : }
     316           0 : void OpIf::GenSlidingWindowFunction(std::stringstream &ss,
     317             :     const std::string &sSymName, SubArguments &vSubArguments)
     318             : {
     319           0 :     ss << "\ndouble " << sSymName;
     320           0 :     ss << "_"<< BinFuncName() <<"(";
     321           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     322             :     {
     323           0 :         if (i)
     324           0 :             ss << ",";
     325           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     326             :     }
     327           0 :     ss << ") {\n";
     328           0 :     ss << "    int gid0 = get_global_id(0);\n";
     329             : 
     330           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
     331           0 :     if(tmpCur0->GetType() == formula::svDoubleVectorRef)
     332             :     {
     333           0 :         throw UnhandledToken(tmpCur0, "unknown operand for ocPush");
     334             :     }
     335             :     else
     336             :     {
     337           0 :         if(vSubArguments.size()==3)
     338             :         {
     339           0 :             ss << "    if(isNan(";
     340           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     341           0 :             ss << ")||  ";
     342           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     343           0 :             ss << " == 0)\n";
     344           0 :             ss << "         return ";
     345           0 :             ss << vSubArguments[2]->GenSlidingWindowDeclRef();
     346           0 :             ss << ";\n";
     347           0 :             ss << "     else";
     348           0 :             ss <<"          return ";
     349           0 :             ss << vSubArguments[1]->GenSlidingWindowDeclRef();
     350           0 :             ss <<";\n";
     351             :         }
     352           0 :         if(vSubArguments.size()==2)
     353             :         {
     354           0 :             ss << "    if(isNan(";
     355           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     356           0 :             ss << ")||  ";
     357           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     358           0 :             ss << " == 0)\n";
     359           0 :             ss << "         return 0;\n";
     360           0 :             ss << "     else";
     361           0 :             ss <<"          return ";
     362           0 :             ss << vSubArguments[1]->GenSlidingWindowDeclRef();
     363           0 :             ss <<";\n";
     364             :         }
     365           0 :         if(vSubArguments.size()==1)
     366             :         {
     367           0 :             ss << "    if(isNan(";
     368           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     369           0 :             ss << ")||  ";
     370           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     371           0 :             ss << " == 0)\n";
     372           0 :             ss << "         return 0;\n";
     373           0 :             ss << "     else";
     374           0 :             ss <<"          return 1;\n";
     375             :         }
     376             :     }
     377           0 :     ss << "}\n";
     378           0 : }
     379             : 
     380         228 : }}
     381             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10