LCOV - code coverage report
Current view: top level - sc/source/core/opencl - op_spreadsheet.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 184 0.5 %
Date: 2014-11-03 Functions: 2 3 66.7 %
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_spreadsheet.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             : 
      25           0 : void OpVLookup::GenSlidingWindowFunction(std::stringstream &ss,
      26             :             const std::string &sSymName, SubArguments &vSubArguments)
      27             : {
      28           0 :     ss << "\ndouble " << sSymName;
      29           0 :     ss << "_"<< BinFuncName() <<"(";
      30           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
      31             :     {
      32           0 :         if (i)
      33           0 :             ss << ",";
      34           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
      35             :     }
      36           0 :     ss << ")\n    {\n";
      37           0 :     ss << "    int gid0=get_global_id(0);\n";
      38           0 :     ss << "    double tmp = NAN;\n";
      39           0 :     ss << "    double intermediate = DBL_MAX;\n";
      40           0 :     ss << "    int singleIndex = gid0;\n";
      41           0 :     ss << "    int rowNum = -1;\n";
      42           0 :     GenTmpVariables(ss,vSubArguments);
      43           0 :     int arg=0;
      44           0 :     CheckSubArgumentIsNan(ss,vSubArguments,arg++);
      45           0 :     int secondParaWidth = 1;
      46           0 :     if(vSubArguments[1]->GetFormulaToken()->GetType() ==
      47             :     formula::svDoubleVectorRef)
      48             :     {
      49           0 :         FormulaToken *tmpCur = vSubArguments[1]->GetFormulaToken();
      50             :         const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
      51           0 :             formula::DoubleVectorRefToken *>(tmpCur);
      52           0 :         secondParaWidth = pCurDVR->GetArrays().size();
      53             :     }
      54           0 :     arg+=secondParaWidth;
      55           0 :     CheckSubArgumentIsNan(ss,vSubArguments,arg++);
      56           0 :     if(vSubArguments.size() == (unsigned int)(3+(secondParaWidth-1)))
      57             :     {
      58           0 :         ss << "    double tmp";
      59           0 :         ss << 3+(secondParaWidth-1);
      60           0 :         ss << "= 1;\n";
      61             :     }
      62             :     else
      63             :     {
      64           0 :         CheckSubArgumentIsNan(ss,vSubArguments,arg++);
      65             :     }
      66             : 
      67           0 :     if(vSubArguments[1]->GetFormulaToken()->GetType() ==
      68             :     formula::svDoubleVectorRef)
      69             :     {
      70           0 :         FormulaToken *tmpCur = vSubArguments[1]->GetFormulaToken();
      71             :         const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
      72           0 :             formula::DoubleVectorRefToken *>(tmpCur);
      73           0 :         size_t nCurWindowSize = pCurDVR->GetArrayLength() <
      74           0 :         pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
      75           0 :         pCurDVR->GetRefRowSize() ;
      76           0 :         int unrollSize = 8;
      77           0 :         ss << "    int loop;\n";
      78           0 :         if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
      79           0 :             ss << "    loop = ("<<nCurWindowSize<<" - gid0)/";
      80           0 :             ss << unrollSize<<";\n";
      81             : 
      82           0 :         } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) {
      83           0 :             ss << "    loop = ("<<nCurWindowSize<<" + gid0)/";
      84           0 :             ss << unrollSize<<";\n";
      85             : 
      86             :         } else {
      87           0 :             ss << "    loop = "<<nCurWindowSize<<"/"<< unrollSize<<";\n";
      88             :         }
      89             : 
      90           0 :         for(int i=0;i<secondParaWidth;i++)
      91             :         {
      92             : 
      93           0 :             ss << "    for ( int j = 0;j< loop; j++)\n";
      94           0 :             ss << "    {\n";
      95           0 :             ss << "        int i = ";
      96           0 :             if (!pCurDVR->IsStartFixed()&& pCurDVR->IsEndFixed()) {
      97           0 :                ss << "gid0 + j * "<< unrollSize <<";\n";
      98             :             }else {
      99           0 :                ss << "j * "<< unrollSize <<";\n";
     100             :             }
     101           0 :             if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
     102             :             {
     103           0 :                ss << "        int doubleIndex = i+gid0;\n";
     104             :             }else
     105             :             {
     106           0 :                ss << "        int doubleIndex = i;\n";
     107             :             }
     108           0 :             ss << "        if(tmp";
     109           0 :             ss << 3+(secondParaWidth-1);
     110           0 :             ss << " == 1)\n";
     111           0 :             ss << "        {\n";
     112             : 
     113           0 :             for(int j =0;j < unrollSize;j++)
     114             :             {
     115           0 :                 CheckSubArgumentIsNan(ss,vSubArguments,1+i);
     116             : 
     117           0 :                 ss << "            if((tmp0 - tmp";
     118           0 :                 ss << 1+i;
     119           0 :                 ss << ")>=0 && intermediate > ( tmp0 -tmp";
     120           0 :                 ss << 1+i;
     121           0 :                 ss << "))\n";
     122           0 :                 ss << "            {\n";
     123           0 :                 ss << "                rowNum = doubleIndex;\n";
     124           0 :                 ss << "                intermediate = tmp0 - tmp";
     125           0 :                 ss << 1+i;
     126           0 :                 ss << ";\n";
     127           0 :                 ss << "            }\n";
     128           0 :                 ss << "            i++;\n";
     129           0 :                 ss << "            doubleIndex++;\n";
     130             :             }
     131             : 
     132           0 :             ss << "        }else\n";
     133           0 :             ss << "        {\n";
     134           0 :             for(int j =0;j < unrollSize;j++)
     135             :             {
     136           0 :                 CheckSubArgumentIsNan(ss,vSubArguments,1+i);
     137             : 
     138           0 :                 ss << "            if(tmp0 == tmp";
     139           0 :                 ss << 1+i;
     140           0 :                 ss << " && rowNum == -1)\n";
     141           0 :                 ss << "            {\n";
     142           0 :                 ss << "                rowNum = doubleIndex;\n";
     143           0 :                 ss << "            }\n";
     144           0 :                 ss << "            i++;\n";
     145           0 :                 ss << "            doubleIndex++;\n";
     146             :             }
     147           0 :             ss << "        }\n\n";
     148             : 
     149           0 :             ss << "    }\n";
     150           0 :             ss << "    if(rowNum!=-1)\n";
     151           0 :             ss << "    {\n";
     152           0 :             for(int j=0;j< secondParaWidth; j++)
     153             :             {
     154             : 
     155           0 :                 ss << "        if(tmp";
     156           0 :                 ss << 2+(secondParaWidth-1);
     157           0 :                 ss << " == ";
     158           0 :                 ss << j+1;
     159           0 :                 ss << ")\n";
     160           0 :                 if( !(vSubArguments[1+j]->IsMixedArgument()))
     161             :                 {
     162           0 :                     ss << "{";
     163           0 :                     ss << "            tmp = ";
     164           0 :                     vSubArguments[1+j]->GenDeclRef(ss);
     165           0 :                     ss << "[rowNum];\n";
     166           0 :                     ss << "}";
     167             : 
     168             :                 }
     169             :                 else
     170             :                 {
     171           0 :                                     ss << "{";
     172             : 
     173           0 :                     ss << "            tmp = isNan(";
     174           0 :                     vSubArguments[1+j]->GenNumDeclRef(ss);
     175           0 :                     ss << "[rowNum])?";
     176           0 :                     vSubArguments[1+j]->GenNumDeclRef(ss);
     177           0 :                     ss << "[rowNum]:";
     178           0 :                     vSubArguments[1+j]->GenStringDeclRef(ss);
     179           0 :                     ss << "[rowNum];\n";
     180           0 :                     ss << "}";
     181             : 
     182             :                 }
     183             :             }
     184           0 :             ss << "    return tmp;\n";
     185           0 :             ss << "    }\n";
     186           0 :             ss << "    for (int i = ";
     187           0 :             if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
     188           0 :                ss << "gid0 + loop *"<<unrollSize<<"; i < ";
     189           0 :                ss << nCurWindowSize <<"; i++)\n";
     190           0 :             } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) {
     191           0 :                ss << "0 + loop *"<<unrollSize<<"; i < gid0+";
     192           0 :                ss << nCurWindowSize <<"; i++)\n";
     193             :             } else {
     194           0 :                ss << "0 + loop *"<<unrollSize<<"; i < ";
     195           0 :                ss << nCurWindowSize <<"; i++)\n";
     196             :             }
     197           0 :             ss << "    {\n";
     198           0 :             if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
     199             :             {
     200           0 :                ss << "        int doubleIndex = i+gid0;\n";
     201             :             }else
     202             :             {
     203           0 :                ss << "        int doubleIndex = i;\n";
     204             :             }
     205           0 :             CheckSubArgumentIsNan(ss,vSubArguments,1+i);
     206           0 :             ss << "        if(tmp";
     207           0 :             ss << 3+(secondParaWidth-1);
     208           0 :             ss << " == 1)\n";
     209           0 :             ss << "        {\n";
     210           0 :             ss << "            if((tmp0 - tmp";
     211           0 :             ss << 1+i;
     212           0 :             ss << ")>=0 && intermediate > ( tmp0 -tmp";
     213           0 :             ss << 1+i;
     214           0 :             ss << "))\n";
     215           0 :             ss << "            {\n";
     216           0 :             ss << "                rowNum = doubleIndex;\n";
     217           0 :             ss << "                intermediate = tmp0 - tmp";
     218           0 :             ss << 1+i;
     219           0 :             ss << ";\n";
     220           0 :             ss << "            }\n";
     221           0 :             ss << "        }else\n";
     222           0 :             ss << "        {\n";
     223           0 :             ss << "            if(tmp0 == tmp";
     224           0 :             ss << 1+i;
     225           0 :             ss << " && rowNum == -1)\n";
     226           0 :             ss << "            {\n";
     227           0 :             ss << "                rowNum = doubleIndex;\n";
     228           0 :             ss << "            }\n";
     229           0 :             ss << "        }\n";
     230             : 
     231           0 :             ss << "    }\n\n";
     232           0 :             ss << "    if(rowNum!=-1)\n";
     233           0 :             ss << "    {\n";
     234             : 
     235           0 :             for(int j=0;j< secondParaWidth; j++)
     236             :             {
     237             : 
     238           0 :                 ss << "        if(tmp";
     239           0 :                 ss << 2+(secondParaWidth-1);
     240           0 :                 ss << " == ";
     241           0 :                 ss << j+1;
     242           0 :                 ss << ")\n";
     243             :                 ///Add MixedArguments for string support in Vlookup.
     244           0 :                 if( !(vSubArguments[1+j]->IsMixedArgument()))
     245             :                 {
     246           0 :                     ss << "            tmp = ";
     247           0 :                     vSubArguments[1+j]->GenDeclRef(ss);
     248           0 :                     ss << "[rowNum];\n";
     249             :                 }
     250             :                 else
     251             :                 {
     252           0 :                     ss << "            tmp = isNan(";
     253           0 :                     vSubArguments[1+j]->GenNumDeclRef(ss);
     254           0 :                     ss << "[rowNum])?";
     255           0 :                     vSubArguments[1+j]->GenNumDeclRef(ss);
     256           0 :                     ss << "[rowNum]:";
     257           0 :                     vSubArguments[1+j]->GenStringDeclRef(ss);
     258           0 :                     ss << "[rowNum];\n";
     259             :                 }
     260             : 
     261             :             }
     262           0 :             ss << "    return tmp;\n";
     263           0 :             ss << "    }\n";
     264             : 
     265             :         }
     266             : 
     267             :     }
     268             :     else
     269             :     {
     270           0 :         CheckSubArgumentIsNan(ss,vSubArguments,1);
     271           0 :         ss << "    if(tmp3 == 1)\n";
     272           0 :         ss << "    {\n";
     273           0 :         ss << "        tmp = tmp1;\n";
     274           0 :         ss << "    }else\n";
     275           0 :         ss << "    {\n";
     276           0 :         ss << "        if(tmp0 == tmp1)\n";
     277           0 :         ss << "            tmp = tmp1;\n";
     278           0 :         ss << "    }\n";
     279             :     }
     280           0 :     ss << "    return tmp;\n";
     281           0 :     ss << "}";
     282           0 : }
     283             : 
     284         228 : }}
     285             : 
     286             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10