LCOV - code coverage report
Current view: top level - sc/source/core/opencl - op_spreadsheet.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 163 0.0 %
Date: 2014-04-14 Functions: 0 1 0.0 %
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 :                 ss << "            tmp = ";
     161           0 :                 vSubArguments[1+j]->GenDeclRef(ss);
     162           0 :                 ss << "[rowNum];\n";
     163             : 
     164             :             }
     165           0 :             ss << "    return tmp;\n";
     166           0 :             ss << "    }\n";
     167           0 :             ss << "    for (int i = ";
     168           0 :             if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
     169           0 :                ss << "gid0 + loop *"<<unrollSize<<"; i < ";
     170           0 :                ss << nCurWindowSize <<"; i++)\n";
     171           0 :             } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) {
     172           0 :                ss << "0 + loop *"<<unrollSize<<"; i < gid0+";
     173           0 :                ss << nCurWindowSize <<"; i++)\n";
     174             :             } else {
     175           0 :                ss << "0 + loop *"<<unrollSize<<"; i < ";
     176           0 :                ss << nCurWindowSize <<"; i++)\n";
     177             :             }
     178           0 :             ss << "    {\n";
     179           0 :             if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
     180             :             {
     181           0 :                ss << "        int doubleIndex = i+gid0;\n";
     182             :             }else
     183             :             {
     184           0 :                ss << "        int doubleIndex = i;\n";
     185             :             }
     186           0 :             CheckSubArgumentIsNan(ss,vSubArguments,1+i);
     187           0 :             ss << "        if(tmp";
     188           0 :             ss << 3+(secondParaWidth-1);
     189           0 :             ss << " == 1)\n";
     190           0 :             ss << "        {\n";
     191           0 :             ss << "            if((tmp0 - tmp";
     192           0 :             ss << 1+i;
     193           0 :             ss << ")>=0 && intermediate > ( tmp0 -tmp";
     194           0 :             ss << 1+i;
     195           0 :             ss << "))\n";
     196           0 :             ss << "            {\n";
     197           0 :             ss << "                rowNum = doubleIndex;\n";
     198           0 :             ss << "                intermediate = tmp0 - tmp";
     199           0 :             ss << 1+i;
     200           0 :             ss << ";\n";
     201           0 :             ss << "            }\n";
     202           0 :             ss << "        }else\n";
     203           0 :             ss << "        {\n";
     204           0 :             ss << "            if(tmp0 == tmp";
     205           0 :             ss << 1+i;
     206           0 :             ss << " && rowNum == -1)\n";
     207           0 :             ss << "            {\n";
     208           0 :             ss << "                rowNum = doubleIndex;\n";
     209           0 :             ss << "            }\n";
     210           0 :             ss << "        }\n";
     211             : 
     212           0 :             ss << "    }\n\n";
     213           0 :             ss << "    if(rowNum!=-1)\n";
     214           0 :             ss << "    {\n";
     215             : 
     216           0 :             for(int j=0;j< secondParaWidth; j++)
     217             :             {
     218             : 
     219           0 :                 ss << "        if(tmp";
     220           0 :                 ss << 2+(secondParaWidth-1);
     221           0 :                 ss << " == ";
     222           0 :                 ss << j+1;
     223           0 :                 ss << ")\n";
     224           0 :                 ss << "            tmp = ";
     225           0 :                 vSubArguments[1+j]->GenDeclRef(ss);
     226           0 :                 ss << "[rowNum];\n";
     227             : 
     228             :             }
     229           0 :             ss << "    return tmp;\n";
     230           0 :             ss << "    }\n";
     231             : 
     232             :         }
     233             : 
     234             :     }
     235             :     else
     236             :     {
     237           0 :         CheckSubArgumentIsNan(ss,vSubArguments,1);
     238           0 :         ss << "    if(tmp3 == 1)\n";
     239           0 :         ss << "    {\n";
     240           0 :         ss << "        tmp = tmp1;\n";
     241           0 :         ss << "    }else\n";
     242           0 :         ss << "    {\n";
     243           0 :         ss << "        if(tmp0 == tmp1)\n";
     244           0 :         ss << "            tmp = tmp1;\n";
     245           0 :         ss << "    }\n";
     246             :     }
     247           0 :     ss << "    return tmp;\n";
     248           0 :     ss << "}";
     249           0 : }
     250             : 
     251             : }}
     252             : 
     253             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10