LCOV - code coverage report
Current view: top level - sc/source/core/opencl - op_logical.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 245 0.4 %
Date: 2015-06-13 12:38:46 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 (size_t 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(size_t 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           0 :             if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
      80             :                 {
      81           0 :             ss <<"    if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
      82           0 :             ss <<")||i+gid0>="<<pCurDVR->GetArrayLength();
      83           0 :             ss <<")\n";
      84           0 :             ss <<"        tmp = 1;\n    else\n";
      85             :                 }
      86             :             else
      87             :                 {
      88           0 :             ss <<"    if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
      89           0 :             ss <<")||i>="<<pCurDVR->GetArrayLength();
      90           0 :             ss <<")\n";
      91           0 :             ss <<"        tmp = 1;\n    else\n";
      92             :                 }
      93           0 :             ss <<"        tmp = ";
      94           0 :             ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
      95           0 :             ss <<"    tmp"<<j<<" = tmp"<<j<<" && tmp;\n";
      96           0 :             ss <<"    }\n";
      97             :         }
      98             :         else
      99             :         {
     100           0 :             ss <<"        tmp"<<j<<" = ";
     101           0 :             ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
     102             :         }
     103           0 :         ss <<"    t = t && tmp"<<j<<";\n";
     104             :     }
     105           0 :     ss << "    return t;\n";
     106           0 :     ss << "}\n";
     107           0 : }
     108             : 
     109           0 : void OpOr::GenSlidingWindowFunction(std::stringstream &ss,
     110             :     const std::string &sSymName, SubArguments &vSubArguments)
     111             : {
     112           0 :     ss << "\ndouble " << sSymName;
     113           0 :     ss << "_"<< BinFuncName() <<"(";
     114           0 :     for (size_t i = 0; i < vSubArguments.size(); i++)
     115             :     {
     116           0 :         if (i)
     117           0 :             ss << ",";
     118           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     119             :     }
     120           0 :     ss << ") {\n";
     121           0 :     ss << "    int gid0 = get_global_id(0);\n";
     122           0 :     ss << "    double t = 0,tmp=0;\n";
     123           0 :     for(size_t j = 0; j< vSubArguments.size(); j++)
     124             :     {
     125           0 :         ss << "    double tmp"<<j<<" = 0;\n";
     126           0 :         FormulaToken *tmpCur0 = vSubArguments[j]->GetFormulaToken();
     127           0 :         if(tmpCur0->GetType() == formula::svSingleVectorRef)
     128             :         {
     129             :         const formula::SingleVectorRefToken*pCurDVR= static_cast<const
     130           0 :             formula::SingleVectorRefToken *>(tmpCur0);
     131           0 :         ss<< "    int buffer_len"<<j<<" = "<<pCurDVR->GetArrayLength();
     132           0 :         ss<< ";\n";
     133           0 :         ss <<"    if(gid0 >= buffer_len"<<j<<" || isNan(";
     134           0 :         ss <<vSubArguments[j]->GenSlidingWindowDeclRef();
     135           0 :         ss <<"))\n";
     136           0 :         ss <<"        tmp = 0;\n    else\n";
     137           0 :         ss <<"        tmp = ";
     138           0 :         ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
     139           0 :         ss <<"    tmp"<<j<<" = tmp"<<j<<" || tmp;\n";
     140             :         }
     141           0 :         else if(tmpCur0->GetType() == formula::svDouble)
     142             :         {
     143           0 :             ss <<"        tmp = ";
     144           0 :             ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
     145           0 :             ss <<"    tmp"<<j<<" = tmp"<<j<<" || tmp;\n";
     146             :         }
     147           0 :         else if(tmpCur0->GetType() == formula::svDoubleVectorRef)
     148             :         {
     149             :             const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
     150           0 :             formula::DoubleVectorRefToken *>(tmpCur0);
     151           0 :             size_t nCurWindowSize = pCurDVR->GetArrayLength() <
     152           0 :             pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
     153           0 :             pCurDVR->GetRefRowSize() ;
     154           0 :             ss << "    for(int i = ";
     155           0 :             if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
     156           0 :             ss << "gid0; i < " << nCurWindowSize << "; i++) {\n";
     157             :             }
     158           0 :             else if(pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()){
     159           0 :             ss << "0; i < gid0 + " << nCurWindowSize << "; i++) {\n";
     160             :             }
     161             :             else{
     162           0 :             ss << "0; i < " << nCurWindowSize << "; i++) {\n";
     163             :             }
     164           0 :             if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
     165             :                 {
     166           0 :             ss <<"    if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
     167           0 :             ss <<")||i+gid0>="<<pCurDVR->GetArrayLength();
     168           0 :             ss <<")\n";
     169           0 :             ss <<"        tmp = 0;\n    else\n";
     170             :                 }
     171             :             else
     172             :                 {
     173           0 :             ss <<"    if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
     174           0 :             ss <<")||i>="<<pCurDVR->GetArrayLength();
     175           0 :             ss <<")\n";
     176           0 :             ss <<"        tmp = 0;\n    else\n";
     177             :                 }
     178           0 :             ss <<"        tmp = ";
     179           0 :             ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
     180           0 :             ss <<"    tmp"<<j<<" = tmp"<<j<<" || tmp;\n";
     181           0 :             ss <<"    }\n";
     182             :         }
     183           0 :         ss <<"    t = t || tmp"<<j<<";\n";
     184             :     }
     185           0 :     ss << "    return t;\n";
     186           0 :     ss << "}\n";
     187           0 : }
     188           0 : void OpNot::GenSlidingWindowFunction(std::stringstream &ss,
     189             :     const std::string &sSymName, SubArguments &vSubArguments)
     190             : {
     191           0 :     ss << "\ndouble " << sSymName;
     192           0 :     ss << "_"<< BinFuncName() <<"(";
     193           0 :     for (size_t i = 0; i < vSubArguments.size(); i++)
     194             :     {
     195           0 :         if (i)
     196           0 :             ss << ",";
     197           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     198             :     }
     199           0 :     ss << ") {\n";
     200           0 :     ss << "    int gid0 = get_global_id(0);\n";
     201           0 :     ss << "    double tmp=0;\n";
     202           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
     203           0 :     if(tmpCur0->GetType() == formula::svSingleVectorRef)
     204             :     {
     205             :         const formula::SingleVectorRefToken*pCurDVR= static_cast<const
     206           0 :             formula::SingleVectorRefToken *>(tmpCur0);
     207           0 :         ss <<"    if(gid0 >= "<<pCurDVR->GetArrayLength()<<" || isNan(";
     208           0 :         ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
     209           0 :         ss <<"))\n";
     210           0 :         ss <<"        tmp = 0;\n    else\n";
     211           0 :         ss <<"        tmp = ";
     212           0 :         ss <<vSubArguments[0]->GenSlidingWindowDeclRef()<<";\n";
     213           0 :         ss <<"    tmp = (tmp == 0.0);\n";
     214             :     }
     215           0 :     else if(tmpCur0->GetType() == formula::svDouble)
     216             :     {
     217           0 :         ss <<"        tmp = ";
     218           0 :         ss <<vSubArguments[0]->GenSlidingWindowDeclRef()<<";\n";
     219           0 :         ss <<"    tmp = (tmp == 0.0);\n";
     220             :     }
     221           0 :     ss << "    return tmp;\n";
     222           0 :     ss << "}\n";
     223           0 : }
     224             : 
     225           0 : void OpXor::GenSlidingWindowFunction(std::stringstream &ss,
     226             :     const std::string &sSymName, SubArguments &vSubArguments)
     227             : {
     228           0 :     ss << "\ndouble " << sSymName;
     229           0 :     ss << "_"<< BinFuncName() <<"(";
     230           0 :     for (size_t i = 0; i < vSubArguments.size(); i++)
     231             :     {
     232           0 :         if (i)
     233           0 :             ss << ",";
     234           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     235             :     }
     236           0 :     ss << ") {\n";
     237           0 :     ss << "    int gid0 = get_global_id(0);\n";
     238           0 :     ss << "    int t = 0,tmp0 = 0;\n";
     239           0 :     ss << "    double tmp = 0;\n";
     240           0 :     for(size_t j = 0; j< vSubArguments.size(); j++)
     241             :     {
     242           0 :         FormulaToken *tmpCur0 = vSubArguments[j]->GetFormulaToken();
     243           0 :         if(tmpCur0->GetType() == formula::svSingleVectorRef)
     244             :         {
     245             :             const formula::SingleVectorRefToken*pCurDVR= static_cast<const
     246           0 :                 formula::SingleVectorRefToken *>(tmpCur0);
     247           0 :             ss <<"    if(gid0 >= "<<pCurDVR->GetArrayLength()<<" || isNan(";
     248           0 :             ss <<vSubArguments[j]->GenSlidingWindowDeclRef();
     249           0 :             ss <<"))\n";
     250           0 :             ss <<"        tmp = 0;\n    else\n";
     251           0 :             ss <<"        tmp = ";
     252           0 :             ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
     253           0 :             ss <<"    tmp0 = (tmp != 0);\n";
     254           0 :             ss <<"    t = t ^tmp0;\n";
     255             :         }
     256           0 :         else if(tmpCur0->GetType() == formula::svDouble)
     257             :         {
     258           0 :             ss <<"        tmp = ";
     259           0 :             ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
     260           0 :             ss <<"    tmp0 = (tmp != 0);\n";
     261           0 :             ss <<"    t = t ^tmp0;\n";
     262             :         }
     263           0 :         else if(tmpCur0->GetType() == formula::svDoubleVectorRef)
     264             :         {
     265             :             const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
     266           0 :             formula::DoubleVectorRefToken *>(tmpCur0);
     267           0 :             size_t nCurWindowSize = pCurDVR->GetArrayLength() <
     268           0 :             pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
     269           0 :             pCurDVR->GetRefRowSize() ;
     270           0 :             ss << "    for(int i = ";
     271           0 :             if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
     272           0 :             ss << "gid0; i < " << nCurWindowSize << "; i++) {\n";
     273             :             }
     274           0 :             else if(pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()){
     275           0 :             ss << "0; i < gid0 + " << nCurWindowSize << "; i++) {\n";
     276             :             }
     277             :             else{
     278           0 :             ss << "0; i < " << nCurWindowSize << "; i++) {\n";
     279             :             }
     280           0 :             if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
     281             :                 {
     282           0 :             ss <<"    if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
     283           0 :             ss <<")||i+gid0>="<<pCurDVR->GetArrayLength();
     284           0 :             ss <<")\n";
     285           0 :             ss <<"        tmp = 0;\n    else\n";
     286             :                 }
     287             :             else
     288             :                 {
     289           0 :             ss <<"    if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
     290           0 :             ss <<")||i>="<<pCurDVR->GetArrayLength();
     291           0 :             ss <<")\n";
     292           0 :             ss <<"        tmp = 0;\n    else\n";
     293             :                 }
     294           0 :             ss <<"        tmp = ";
     295           0 :             ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
     296           0 :             ss <<"    tmp0 = (tmp != 0);\n";
     297           0 :             ss <<"    t = t ^tmp0;\n";
     298           0 :             ss <<"    }\n";
     299             :         }
     300             :     }
     301           0 :     ss << "    return t;\n";
     302           0 :     ss << "}\n";
     303           0 : }
     304           0 : void OpIf::GenSlidingWindowFunction(std::stringstream &ss,
     305             :     const std::string &sSymName, SubArguments &vSubArguments)
     306             : {
     307           0 :     ss << "\ndouble " << sSymName;
     308           0 :     ss << "_"<< BinFuncName() <<"(";
     309           0 :     for (size_t i = 0; i < vSubArguments.size(); i++)
     310             :     {
     311           0 :         if (i)
     312           0 :             ss << ",";
     313           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     314             :     }
     315           0 :     ss << ") {\n";
     316           0 :     ss << "    int gid0 = get_global_id(0);\n";
     317             : 
     318           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
     319           0 :     if(tmpCur0->GetType() == formula::svDoubleVectorRef)
     320             :     {
     321           0 :         throw UnhandledToken(tmpCur0, "unknown operand for ocPush");
     322             :     }
     323             :     else
     324             :     {
     325           0 :         if(vSubArguments.size()==3)
     326             :         {
     327           0 :             ss << "    if(isNan(";
     328           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     329           0 :             ss << ")||  ";
     330           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     331           0 :             ss << " == 0)\n";
     332           0 :             ss << "         return ";
     333           0 :             ss << vSubArguments[2]->GenSlidingWindowDeclRef();
     334           0 :             ss << ";\n";
     335           0 :             ss << "     else";
     336           0 :             ss <<"          return ";
     337           0 :             ss << vSubArguments[1]->GenSlidingWindowDeclRef();
     338           0 :             ss <<";\n";
     339             :         }
     340           0 :         if(vSubArguments.size()==2)
     341             :         {
     342           0 :             ss << "    if(isNan(";
     343           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     344           0 :             ss << ")||  ";
     345           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     346           0 :             ss << " == 0)\n";
     347           0 :             ss << "         return 0;\n";
     348           0 :             ss << "     else";
     349           0 :             ss <<"          return ";
     350           0 :             ss << vSubArguments[1]->GenSlidingWindowDeclRef();
     351           0 :             ss <<";\n";
     352             :         }
     353           0 :         if(vSubArguments.size()==1)
     354             :         {
     355           0 :             ss << "    if(isNan(";
     356           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     357           0 :             ss << ")||  ";
     358           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     359           0 :             ss << " == 0)\n";
     360           0 :             ss << "         return 0;\n";
     361           0 :             ss << "     else";
     362           0 :             ss <<"          return 1;\n";
     363             :         }
     364             :     }
     365           0 :     ss << "}\n";
     366           0 : }
     367             : 
     368         156 : }}
     369             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11