[Libreoffice-commits] core.git: Branch 'libreoffice-4-2' - 220 commits - codemaker/Executable_cppumaker.mk sc/Library_scopencl.mk sc/qa sc/source

haochen haochen at multicorewareinc.com
Tue Dec 31 15:51:53 PST 2013


 codemaker/Executable_cppumaker.mk                   |    1 
 sc/Library_scopencl.mk                              |    2 
 sc/qa/unit/data/ods/opencl/math/Quotient.ods        |binary
 sc/qa/unit/data/ods/opencl/math/sec.ods             |binary
 sc/qa/unit/data/ods/opencl/math/sech.ods            |binary
 sc/qa/unit/data/xls/opencl/addin/besselj.xls        |binary
 sc/qa/unit/data/xls/opencl/database/daverage.xls    |binary
 sc/qa/unit/data/xls/opencl/database/dcount.xls      |binary
 sc/qa/unit/data/xls/opencl/database/dcountA.xls     |binary
 sc/qa/unit/data/xls/opencl/database/dmax.xls        |binary
 sc/qa/unit/data/xls/opencl/database/dmin.xls        |binary
 sc/qa/unit/data/xls/opencl/database/dproduct.xls    |binary
 sc/qa/unit/data/xls/opencl/database/dstdev.xls      |binary
 sc/qa/unit/data/xls/opencl/database/dstdevp.xls     |binary
 sc/qa/unit/data/xls/opencl/database/dsum.xls        |binary
 sc/qa/unit/data/xls/opencl/database/dvar.xls        |binary
 sc/qa/unit/data/xls/opencl/database/dvarp.xls       |binary
 sc/qa/unit/data/xls/opencl/financial/MDuration1.xls |binary
 sc/qa/unit/data/xls/opencl/logical/not.xls          |binary
 sc/qa/unit/data/xls/opencl/logical/or.xls           |binary
 sc/qa/unit/data/xls/opencl/logical/xor.xls          |binary
 sc/qa/unit/data/xls/opencl/math/MROUND.xls          |binary
 sc/qa/unit/data/xls/opencl/math/NegSub.xls          |binary
 sc/qa/unit/data/xls/opencl/math/averageif.xls       |binary
 sc/qa/unit/data/xls/opencl/math/averageif_mix.xls   |binary
 sc/qa/unit/data/xls/opencl/math/countif.xls         |binary
 sc/qa/unit/data/xls/opencl/math/degrees.xls         |binary
 sc/qa/unit/data/xls/opencl/math/fact.xls            |binary
 sc/qa/unit/data/xls/opencl/math/int.xls             |binary
 sc/qa/unit/data/xls/opencl/math/iseven.xls          |binary
 sc/qa/unit/data/xls/opencl/math/isodd.xls           |binary
 sc/qa/unit/data/xls/opencl/math/radians.xls         |binary
 sc/qa/unit/data/xls/opencl/math/rounddown.xls       |binary
 sc/qa/unit/data/xls/opencl/math/roundup.xls         |binary
 sc/qa/unit/data/xls/opencl/math/seriessum.xls       |binary
 sc/qa/unit/data/xls/opencl/math/sumif.xls           |binary
 sc/qa/unit/data/xls/opencl/spreadsheet/VLookup.xls  |binary
 sc/qa/unit/data/xls/opencl/statistical/Avedev.xls   |binary
 sc/qa/unit/data/xls/opencl/statistical/AverageA.xls |binary
 sc/qa/unit/data/xls/opencl/statistical/HarMean1.xls |binary
 sc/qa/unit/data/xls/opencl/statistical/Kurt1.xls    |binary
 sc/qa/unit/data/xls/opencl/statistical/Maxa.xls     |binary
 sc/qa/unit/data/xls/opencl/statistical/Mina.xls     |binary
 sc/qa/unit/data/xls/opencl/statistical/StDevA.xls   |binary
 sc/qa/unit/data/xls/opencl/statistical/StDevA1.xls  |binary
 sc/qa/unit/data/xls/opencl/statistical/StDevPA.xls  |binary
 sc/qa/unit/data/xls/opencl/statistical/StDevPA1.xls |binary
 sc/qa/unit/data/xls/opencl/statistical/VarA.xls     |binary
 sc/qa/unit/data/xls/opencl/statistical/VarA1.xls    |binary
 sc/qa/unit/data/xls/opencl/statistical/VarPA.xls    |binary
 sc/qa/unit/data/xls/opencl/statistical/VarPA1.xls   |binary
 sc/qa/unit/data/xls/opencl/statistical/counta.xls   |binary
 sc/qa/unit/opencl-test.cxx                          | 1313 ++
 sc/source/core/opencl/formulagroupcl.cxx            |  385 
 sc/source/core/opencl/op_addin.cxx                  |  202 
 sc/source/core/opencl/op_addin.hxx                  |   29 
 sc/source/core/opencl/op_database.cxx               | 1664 +++
 sc/source/core/opencl/op_database.hxx               |   90 
 sc/source/core/opencl/op_financial.cxx              | 3690 +++----
 sc/source/core/opencl/op_financial.hxx              |    2 
 sc/source/core/opencl/op_logical.cxx                |  207 
 sc/source/core/opencl/op_logical.hxx                |   23 
 sc/source/core/opencl/op_math.cxx                   | 1929 +++
 sc/source/core/opencl/op_math.hxx                   |  134 
 sc/source/core/opencl/op_spreadsheet.cxx            |  253 
 sc/source/core/opencl/op_spreadsheet.hxx            |   29 
 sc/source/core/opencl/op_statistical.cxx            | 9965 +++++++++++++-------
 sc/source/core/opencl/op_statistical.hxx            |   90 
 sc/source/core/opencl/opbase.cxx                    |   65 
 sc/source/core/opencl/opbase.hxx                    |   13 
 sc/source/core/opencl/opinlinefun_finacial.cxx      |  831 +
 sc/source/core/opencl/opinlinefun_math.hxx          |   54 
 sc/source/core/opencl/opinlinefun_statistical.cxx   |  571 -
 sc/source/core/tool/token.cxx                       |   34 
 74 files changed, 15984 insertions(+), 5592 deletions(-)

New commits:
commit 16c05839601b094beb463e2dd05e7c718fa2e58a
Author: haochen <haochen at multicorewareinc.com>
Date:   Tue Dec 31 16:36:53 2013 +0800

    GPU Calc: Remove unnecessary 'std::cerr'
    
    And add 'exception catching' for return  to CPU caculate
    
    Change-Id: I640894d677eaf73367bb51dec51c8baeb412bca6
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index eec5341..910a128 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1929,7 +1929,8 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
                     mvSubArguments.push_back(
                             SubArgument(new DynamicKernelConstantArgument(ts,
                                     ft->Children[i])));
-                } else if (pChild->GetType() == formula::svString) {
+                } else if (pChild->GetType() == formula::svString
+                && pCodeGen->takeString()) {
                     mvSubArguments.push_back(
                             SubArgument(new ConstStringArgument(ts,
                                     ft->Children[i])));
@@ -3042,19 +3043,16 @@ void DynamicKernel::CreateKernel(void)
     std::string KernelHash = mKernelSignature+GetMD5();
     if (lastOneKernelHash == KernelHash && lastOneProgram)
     {
-        std::cerr<<"cl_program cache hit: "<< KernelHash << "\n";
         mpProgram = lastOneProgram;
     }
     else if(lastSecondKernelHash == KernelHash && lastSecondProgram)
     {
-        std::cerr<<"cl_program cache hit: "<< KernelHash << "\n";
         mpProgram = lastSecondProgram;
     }
     else
     {   // doesn't match the last compiled formula.
 
         if (lastSecondProgram) {
-            std::cerr<<"Freeing lastsecond program: "<< GetMD5() << "\n";
             clReleaseProgram(lastSecondProgram);
         }
         if (OpenclDevice::buildProgramFromBinary("",
@@ -3198,6 +3196,10 @@ DynamicKernel* DynamicKernel::create(ScDocument& /* rDoc */,
         return NULL;
 #endif
     }
+    catch (...) {
+        std::cerr << "Dynamic formula compiler: unhandled compiler error\n";
+        return NULL;
+    }
     return pDynamicKernel;
 }
 
diff --git a/sc/source/core/opencl/op_math.hxx b/sc/source/core/opencl/op_math.hxx
index 80b3a8e..29214bc 100644
--- a/sc/source/core/opencl/op_math.hxx
+++ b/sc/source/core/opencl/op_math.hxx
@@ -364,6 +364,8 @@ public:
     virtual void GenSlidingWindowFunction(std::stringstream &ss,
         const std::string sSymName, SubArguments &vSubArguments);
     virtual std::string BinFuncName(void) const { return "Convert"; }
+    virtual bool takeString() const { return true; }
+
 };
 class OpEven: public Normal
 {
commit 9bbe7f7078b0c85523090437c3488e2254aa1bce
Author: xinjiang <xinjiang at multicorewareinc.com>
Date:   Tue Dec 31 15:08:49 2013 +0800

    GPU Calc: Fix accuracy not reach 11 in MDURATION
    
    AMLOEXT-223 FIX
    
    Change-Id: Ic7f35d85cc10f14487411633a54c43bbfafe688f
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index e13b86c..2bd250e 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -761,13 +761,15 @@ void OpDuration_ADD::GenSlidingWindowFunction(std::stringstream& ss,
 void OpMDuration::BinInlineFun(std::set<std::string>& decls,
     std::set<std::string>& funs)
 {
-    decls.insert(GetDurationDecl);decls.insert(lcl_GetcoupnumDecl);
+    decls.insert(GetDuration_newDecl);decls.insert(lcl_Getcoupnum_newDecl);
+    decls.insert(addMonthsDecl);decls.insert(checklessthanDecl);
+    decls.insert(setDayDecl);decls.insert(ScaDateDecl);
     decls.insert(GetYearFracDecl);decls.insert(DaysToDateDecl);
-    decls.insert(GetNullDateDecl);decls.insert(DateToDaysDecl);
     decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
-    funs.insert(GetDuration);funs.insert(lcl_Getcoupnum);
+    funs.insert(GetDuration_new);funs.insert(lcl_Getcoupnum_new);
+    funs.insert(addMonths);funs.insert(checklessthan);
+    funs.insert(setDay);funs.insert(ScaDate);
     funs.insert(GetYearFrac);funs.insert(DaysToDate);
-    funs.insert(GetNullDate);funs.insert(DateToDays);
     funs.insert(DaysInMonth);funs.insert(IsLeapYear);
 }
 
@@ -791,31 +793,50 @@ void OpMDuration::GenSlidingWindowFunction(std::stringstream& ss,
     ss << "    double arg3 = " << GetBottom() << ";\n";
     ss << "    double arg4 = " << GetBottom() << ";\n";
     ss << "    double arg5 = " << GetBottom() << ";\n";
-    unsigned j = vSubArguments.size();
-    while (j--)
-        {
-        FormulaToken* pCur = vSubArguments[j]->GetFormulaToken();
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
+    {
+        FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
         assert(pCur);
-        if(pCur->GetType() == formula::svSingleVectorRef)
-            {
+        if (pCur->GetType() == formula::svSingleVectorRef)
+        {
 #ifdef  ISNAN
             const formula::SingleVectorRefToken* pSVR =
-            dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
-            ss << "    if(gid0 >= " << pSVR->GetArrayLength() << " || isNan(";
-            ss << vSubArguments[j]->GenSlidingWindowDeclRef();
-            ss << "))\n";
-            ss << "        arg" << j << " = " <<GetBottom() << ";\n";
-            ss << "    else\n";
+                dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
+            ss << "    if (gid0 < " << pSVR->GetArrayLength() << "){\n";
 #endif
-            ss << "        arg" << j << " = ";
-            ss << vSubArguments[j]->GenSlidingWindowDeclRef();
-            ss << ";\n";
-            }
         }
-    ss << "    int nNullDate = GetNullDate();\n";
-    ss << "    tmp = GetDuration( nNullDate, (int)arg0, (int)arg1, arg2,";
+        else if (pCur->GetType() == formula::svDouble)
+        {
+#ifdef  ISNAN
+            ss << "    {\n";
+#endif
+        }
+#ifdef  ISNAN
+        if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
+        {
+            ss << "        if (isNan(";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << "))\n";
+            ss << "            arg" << i << " = 0;\n";
+            ss << "        else\n";
+            ss << "            arg" << i << " = ";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
+            ss << "    }\n";
+        }
+        else
+        {
+            ss << "    arg" << i << " = ";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
+        }
+#else
+        ss << "    arg" << i;
+        ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
+#endif
+    }
+    ss << "    int nNullDate = 693594;\n";
+    ss << "    tmp = GetDuration_new( nNullDate, (int)arg0, (int)arg1, arg2,";
     ss << " arg3, (int)arg4, (int)arg5);\n";
-    ss << "    tmp /= 1.0 + arg3 / (int)arg4;\n";
+    ss << "    tmp = tmp * pow(1.0 + arg3 * pow((int)arg4, -1.0), -1);\n";
     ss << "    return tmp;\n";
     ss << "}";
 }
diff --git a/sc/source/core/opencl/opinlinefun_finacial.cxx b/sc/source/core/opencl/opinlinefun_finacial.cxx
index 91d04d2..154a9f5 100644
--- a/sc/source/core/opencl/opinlinefun_finacial.cxx
+++ b/sc/source/core/opencl/opinlinefun_finacial.cxx
@@ -1428,6 +1428,44 @@ std::string GetDuration=
 "    fDur /= nFreq;\n"
 "    return fDur;\n""}\n";
 
+std::string GetDuration_newDecl=
+"double GetDuration_new( \n"
+"                int nNullDate, int nSettle, int nMat, double fCoup,\n"
+"                double fYield, int nFreq, int nBase );\n";
+
+std::string GetDuration_new=
+"double GetDuration_new( \n"
+"                int nNullDate, int nSettle, int nMat, double fCoup,\n"
+"                double fYield, int nFreq, int nBase )\n"
+"    {\n"
+"        double fYearfrac = GetYearFrac(nNullDate,nSettle,nMat,nBase);\n"
+"        double fNumOfCoups = lcl_Getcoupnum_new(nNullDate,nSettle,nMat,"
+"nFreq,nBase);\n"
+"        double fDur = 0.0;\n"
+"        fCoup = fCoup * 100.0 * pow(nFreq, -1.0);\n"
+"        fYield = fYield * pow(nFreq, -1.0);\n"
+"        fYield += 1.0;\n"
+"        double nDiff = fYearfrac * nFreq - fNumOfCoups;\n"
+"        int  t;\n"
+"        double tmp0 = 0, tmp1 = 0, tmp2 = 0;\n"
+"        for( t = 1 ; t < fNumOfCoups ; t++ ){\n"
+"            tmp0 = (t + nDiff) * ( fCoup ) ;\n"
+"            tmp1 = pow( fYield, t + nDiff ) ;\n"
+"            tmp2 = tmp0 * pow(tmp1, -1);\n"
+"            fDur += tmp2;\n"
+"        }\n"
+"        fDur += (fNumOfCoups + nDiff) * (fCoup + 100.0) * pow(pow(fYield,"
+" fNumOfCoups + nDiff ),-1);\n"
+"        double  p = 0.0;\n"
+"        for( t = 1 ; t < fNumOfCoups ; t++ ){\n"
+"            tmp0 = pow( fYield, t + nDiff );\n"
+"            p += fCoup * pow(tmp0, -1);}\n"
+"        p += (fCoup + 100.0) * pow(pow(fYield, fNumOfCoups + nDiff), -1);\n"
+"        fDur = fDur * pow(p, -1.0);\n"
+"        fDur = fDur * pow(nFreq, -1.0);\n"
+"        return fDur;\n"
+"    }\n";
+
 std::string ScGetGDADecl=
 "double ScGetGDA(double fWert, double fRest, double fDauer, double fPeriode,"
 "double fFaktor);\n";
commit 2263e435686f223bade8a0b5e05a9c60167a219a
Author: xinjiang <xinjiang at multicorewareinc.com>
Date:   Tue Dec 31 15:04:24 2013 +0800

    GPU Calc: unit test cases for accuracy not reach 11 in MDURATION
    
    AMLOEXT-223 BUG
    
    Change-Id: Ib8349015152da6b641193b8558cb8a2959513631
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/qa/unit/data/xls/opencl/financial/MDuration1.xls b/sc/qa/unit/data/xls/opencl/financial/MDuration1.xls
new file mode 100644
index 0000000..c382aa8
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/financial/MDuration1.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 95eeb04..843c9a9 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -293,6 +293,7 @@ public:
     void testStatisticalFormulaVarPA1();
     void testStatisticalFormulaStDevA1();
     void testStatisticalFormulaStDevPA1();
+    void testFinancialMDurationFormula1();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -517,6 +518,7 @@ public:
     CPPUNIT_TEST(testStatisticalFormulaVarPA1);
     CPPUNIT_TEST(testStatisticalFormulaStDevA1);
     CPPUNIT_TEST(testStatisticalFormulaStDevPA1);
+    CPPUNIT_TEST(testFinancialMDurationFormula1);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -5162,6 +5164,28 @@ void ScOpenclTest::testStatisticalFormulaStDevPA()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-223]
+void ScOpenclTest:: testFinancialMDurationFormula1()
+{
+    if (!detectOpenCLDevice())
+        return;
+    ScDocShellRef xDocSh = loadDoc("opencl/financial/MDuration1.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+    ScDocShellRef xDocShRes = loadDoc("opencl/financial/MDuration1.", XLS);
+    ScDocument* pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    for (SCROW i = 0; i <= 9; ++i)
+    {
+        double fLibre = pDoc->GetValue(ScAddress(6, i, 0));
+        double fExcel = pDocRes->GetValue(ScAddress(6, i, 0));
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel,fLibre,fabs(0.00000000001*fExcel));
+    }
+    xDocSh->DoClose();
+    xDocShRes->DoClose();
+}
 //[AMLOEXT-245]
 void ScOpenclTest::testMathFormulaSumProduct2()
 {
commit 25c538477c833ef7394535f654f19bd1d7e29bfa
Author: haochen <haochen at multicorewareinc.com>
Date:   Tue Dec 31 14:25:40 2013 +0800

    GPU Calc: Optimize Vlookup
    
    AMLOEXT-406
    
    Change-Id: Ibd1ad4e93ccfa1bb3a64545f4f007e4116691791
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_spreadsheet.cxx b/sc/source/core/opencl/op_spreadsheet.cxx
index 9d3db14..abb7568 100644
--- a/sc/source/core/opencl/op_spreadsheet.cxx
+++ b/sc/source/core/opencl/op_spreadsheet.cxx
@@ -73,9 +73,8 @@ void OpVLookup::GenSlidingWindowFunction(std::stringstream &ss,
         size_t nCurWindowSize = pCurDVR->GetArrayLength() <
         pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
         pCurDVR->GetRefRowSize() ;
-        int unrollSize = 16;
+        int unrollSize = 8;
         ss << "    int loop;\n";
-        ss << "    int remainder;\n";
         if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
             ss << "    loop = ("<<nCurWindowSize<<" - gid0)/";
             ss << unrollSize<<";\n";
@@ -126,7 +125,6 @@ void OpVLookup::GenSlidingWindowFunction(std::stringstream &ss,
                 ss << 1+i;
                 ss << ";\n";
                 ss << "            }\n";
-
                 ss << "            i++;\n";
                 ss << "            doubleIndex++;\n";
             }
@@ -143,13 +141,29 @@ void OpVLookup::GenSlidingWindowFunction(std::stringstream &ss,
                 ss << "            {\n";
                 ss << "                rowNum = doubleIndex;\n";
                 ss << "            }\n";
-
                 ss << "            i++;\n";
                 ss << "            doubleIndex++;\n";
             }
             ss << "        }\n\n";
 
             ss << "    }\n";
+            ss << "    if(rowNum!=-1)\n";
+            ss << "    {\n";
+            for(int j=0;j< secondParaWidth; j++)
+            {
+
+                ss << "        if(tmp";
+                ss << 2+(secondParaWidth-1);
+                ss << " == ";
+                ss << j+1;
+                ss << ")\n";
+                ss << "            tmp = ";
+                vSubArguments[1+j]->GenDeclRef(ss);
+                ss << "[rowNum];\n";
+
+            }
+            ss << "    return tmp;\n";
+            ss << "    }\n";
             ss << "    for (int i = ";
             if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
                ss << "gid0 + loop *"<<unrollSize<<"; i < ";
@@ -196,25 +210,27 @@ void OpVLookup::GenSlidingWindowFunction(std::stringstream &ss,
             ss << "        }\n";
 
             ss << "    }\n\n";
+            ss << "    if(rowNum!=-1)\n";
+            ss << "    {\n";
 
-        }
+            for(int j=0;j< secondParaWidth; j++)
+            {
 
-        ss << "    if(rowNum!=-1)\n";
-        ss << "    {\n";
+                ss << "        if(tmp";
+                ss << 2+(secondParaWidth-1);
+                ss << " == ";
+                ss << j+1;
+                ss << ")\n";
+                ss << "            tmp = ";
+                vSubArguments[1+j]->GenDeclRef(ss);
+                ss << "[rowNum];\n";
 
-        for(int j=0;j< secondParaWidth; j++)
-        {
+            }
+            ss << "    return tmp;\n";
+            ss << "    }\n";
 
-            ss << "        if(tmp";
-            ss << 2+(secondParaWidth-1);
-            ss << " == ";
-            ss << j+1;
-            ss << ")\n";
-            ss << "            tmp = ";
-            vSubArguments[1+j]->GenDeclRef(ss);
-            ss << "[rowNum];\n";
         }
-        ss << "    }\n";
+
     }
     else
     {
@@ -228,7 +244,6 @@ void OpVLookup::GenSlidingWindowFunction(std::stringstream &ss,
         ss << "            tmp = tmp1;\n";
         ss << "    }\n";
     }
-
     ss << "    return tmp;\n";
     ss << "}";
 }
commit 52d9f7be1d2dfd478a94dc69d1236487835a7c2f
Author: shiming zhang <shiming at multicorewareinc.com>
Date:   Tue Dec 31 14:20:06 2013 +0800

    GPU Calc: Fix bug of support optional parameter for STDEVPA
    
    AMLOEXT-405 FIX
    
    Change-Id: I7057104900140197a8e018710de863415920827d
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index 659e947..c7bf582 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -11085,6 +11085,7 @@ void OpStDevPA::GenSlidingWindowFunction(std::stringstream &ss,
             {
                 const formula::DoubleVectorRefToken* pDVR =
                     dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+                assert(pDVR);
                 if(pDVR->GetArrays()[0].mpNumericArray
                     && pDVR->GetArrays()[0].mpStringArray)
                     isMixedDV = svDoubleVectorRefDoubleString;
@@ -11297,6 +11298,17 @@ void OpStDevPA::GenSlidingWindowFunction(std::stringstream &ss,
             {
                 const formula::DoubleVectorRefToken* pDVR =
                     dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+                assert(pDVR);
+                if(pDVR->GetArrays()[0].mpNumericArray
+                    && pDVR->GetArrays()[0].mpStringArray)
+                    isMixedDV = svDoubleVectorRefDoubleString;
+                else if(pDVR->GetArrays()[0].mpNumericArray)
+                    isMixedDV = svDoubleVectorRefDouble;
+                else if(pDVR->GetArrays()[0].mpStringArray)
+                    isMixedDV = svDoubleVectorRefString;
+                else
+                    isMixedDV = svDoubleVectorRefNULL;
+
                 size_t nCurWindowSize = pDVR->GetRefRowSize();
                 ss << "    for (int i = ";
                 if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
@@ -11395,6 +11407,16 @@ void OpStDevPA::GenSlidingWindowFunction(std::stringstream &ss,
                 const formula::SingleVectorRefToken* pSVR =
                     dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
                 assert(pSVR);
+                if(pSVR->GetArray().mpNumericArray
+                    && pSVR->GetArray().mpStringArray)
+                    isMixedSV = svSingleVectorRefDoubleString;
+                else if(pSVR->GetArray().mpNumericArray)
+                    isMixedSV = svSingleVectorRefDouble;
+                else if(pSVR->GetArray().mpStringArray)
+                    isMixedSV = svSingleVectorRefString;
+                else
+                    isMixedSV = svSingleVectorRefNULL;
+
                 if(isMixedSV == svSingleVectorRefDoubleString)
                 {
 #ifdef  ISNAN
@@ -11474,6 +11496,7 @@ void OpStDevPA::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "        return sqrt(vSum * pow(fCount,-1.0));\n";
     ss << "}\n";
 }
+
 void OpAveDev:: GenSlidingWindowFunction(std::stringstream &ss,
             const std::string sSymName, SubArguments &vSubArguments)
 {
commit 06df5100882c0f4e96795ea3c0a22b327794688d
Author: shiming zhang <shiming at multicorewareinc.com>
Date:   Tue Dec 31 14:07:16 2013 +0800

    GPU Calc: unit test cases for support optional parameter for STDEVPA
    
    AMLOEXT-405 BUG
    
    Change-Id: I65cf098eefbffd5c1c838a2f4d91ba3472caf50c
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/qa/unit/data/xls/opencl/statistical/StDevPA1.xls b/sc/qa/unit/data/xls/opencl/statistical/StDevPA1.xls
new file mode 100644
index 0000000..e9c9957
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/StDevPA1.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index eafa228..95eeb04 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -292,6 +292,7 @@ public:
     void testStatisticalFormulaVarA1();
     void testStatisticalFormulaVarPA1();
     void testStatisticalFormulaStDevA1();
+    void testStatisticalFormulaStDevPA1();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -515,6 +516,7 @@ public:
     CPPUNIT_TEST(testStatisticalFormulaVarA1);
     CPPUNIT_TEST(testStatisticalFormulaVarPA1);
     CPPUNIT_TEST(testStatisticalFormulaStDevA1);
+    CPPUNIT_TEST(testStatisticalFormulaStDevPA1);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -6100,6 +6102,31 @@ void ScOpenclTest::testStatisticalFormulaStDevA1()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-405]
+void ScOpenclTest::testStatisticalFormulaStDevPA1()
+{
+    if (!detectOpenCLDevice())
+        return;
+
+    ScDocShellRef xDocSh = loadDoc("opencl/statistical/StDevPA1.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+
+    ScDocShellRef xDocShRes = loadDoc("opencl/statistical/StDevPA1.", XLS);
+    ScDocument* pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    // Check the results of formula cells in the shared formula range.
+    for (SCROW i = 1; i <= 20; ++i)
+    {
+        double fLibre = pDoc->GetValue(ScAddress(1,i,0));
+        double fExcel = pDocRes->GetValue(ScAddress(1,i,0));
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+    }
+    xDocSh->DoClose();
+    xDocShRes->DoClose();
+}
 ScOpenclTest::ScOpenclTest()
       : ScBootstrapFixture( "/sc/qa/unit/data" )
 {
commit a11fcc996fca18944e980714eb8b5ac4bbba6db9
Author: shiming zhang <shiming at multicorewareinc.com>
Date:   Tue Dec 31 14:01:08 2013 +0800

    GPU Calc: Fix bug of support optional parameter for STDEVA
    
    AMLOEXT-404 FIX
    
    Change-Id: Idb3dae8907b753c8680de8673621102128e43ef0
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index 0bcf111..659e947 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -10641,6 +10641,7 @@ void OpStDevA::GenSlidingWindowFunction(std::stringstream &ss,
             {
                 const formula::DoubleVectorRefToken* pDVR =
                     dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+                assert(pDVR);
                 if(pDVR->GetArrays()[0].mpNumericArray
                     && pDVR->GetArrays()[0].mpStringArray)
                     isMixedDV = svDoubleVectorRefDoubleString;
@@ -10853,6 +10854,17 @@ void OpStDevA::GenSlidingWindowFunction(std::stringstream &ss,
             {
                 const formula::DoubleVectorRefToken* pDVR =
                     dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+                assert(pDVR);
+                if(pDVR->GetArrays()[0].mpNumericArray
+                    && pDVR->GetArrays()[0].mpStringArray)
+                    isMixedDV = svDoubleVectorRefDoubleString;
+                else if(pDVR->GetArrays()[0].mpNumericArray)
+                    isMixedDV = svDoubleVectorRefDouble;
+                else if(pDVR->GetArrays()[0].mpStringArray)
+                    isMixedDV = svDoubleVectorRefString;
+                else
+                    isMixedDV = svDoubleVectorRefNULL;
+
                 size_t nCurWindowSize = pDVR->GetRefRowSize();
                 ss << "    for (int i = ";
                 if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
@@ -10951,6 +10963,16 @@ void OpStDevA::GenSlidingWindowFunction(std::stringstream &ss,
                 const formula::SingleVectorRefToken* pSVR =
                     dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
                 assert(pSVR);
+                if(pSVR->GetArray().mpNumericArray
+                    && pSVR->GetArray().mpStringArray)
+                    isMixedSV = svSingleVectorRefDoubleString;
+                else if(pSVR->GetArray().mpNumericArray)
+                    isMixedSV = svSingleVectorRefDouble;
+                else if(pSVR->GetArray().mpStringArray)
+                    isMixedSV = svSingleVectorRefString;
+                else
+                    isMixedSV = svSingleVectorRefNULL;
+
                 if(isMixedSV == svSingleVectorRefDoubleString)
                 {
 #ifdef  ISNAN
@@ -11030,6 +11052,7 @@ void OpStDevA::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "        return sqrt(vSum * pow(fCount - 1.0,-1.0));\n";
     ss << "}\n";
 }
+
 void OpStDevPA::GenSlidingWindowFunction(std::stringstream &ss,
             const std::string sSymName, SubArguments &vSubArguments)
 {
commit 8893db1f6af0a79f00085b3386c74de640f7cbba
Author: shiming zhang <shiming at multicorewareinc.com>
Date:   Tue Dec 31 14:00:28 2013 +0800

    GPU Calc: unit test cases for support optional parameter for STDEVA
    
    AMLOEXT-404 BUG
    
    Change-Id: I7dfbbecee5f178a42b28d9df0f4f205fa694d152
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/qa/unit/data/xls/opencl/statistical/StDevA1.xls b/sc/qa/unit/data/xls/opencl/statistical/StDevA1.xls
new file mode 100644
index 0000000..e17e90d
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/StDevA1.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 8e14c27..eafa228 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -291,6 +291,7 @@ public:
     void testStatisticalFormulaHarMean1();
     void testStatisticalFormulaVarA1();
     void testStatisticalFormulaVarPA1();
+    void testStatisticalFormulaStDevA1();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -513,6 +514,7 @@ public:
     CPPUNIT_TEST(testStatisticalFormulaHarMean1);
     CPPUNIT_TEST(testStatisticalFormulaVarA1);
     CPPUNIT_TEST(testStatisticalFormulaVarPA1);
+    CPPUNIT_TEST(testStatisticalFormulaStDevA1);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -6073,6 +6075,31 @@ void ScOpenclTest::testStatisticalFormulaVarPA1()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-404]
+void ScOpenclTest::testStatisticalFormulaStDevA1()
+{
+    if (!detectOpenCLDevice())
+        return;
+
+    ScDocShellRef xDocSh = loadDoc("opencl/statistical/StDevA1.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+
+    ScDocShellRef xDocShRes = loadDoc("opencl/statistical/StDevA1.", XLS);
+    ScDocument* pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    // Check the results of formula cells in the shared formula range.
+    for (SCROW i = 1; i <= 20; ++i)
+    {
+        double fLibre = pDoc->GetValue(ScAddress(1,i,0));
+        double fExcel = pDocRes->GetValue(ScAddress(1,i,0));
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+    }
+    xDocSh->DoClose();
+    xDocShRes->DoClose();
+}
 ScOpenclTest::ScOpenclTest()
       : ScBootstrapFixture( "/sc/qa/unit/data" )
 {
commit 237bd7f1ac640a2eecf533ecc0d3a735b6bc5131
Author: shiming zhang <shiming at multicorewareinc.com>
Date:   Tue Dec 31 13:36:50 2013 +0800

    GPU Calc: Fix bug of support optional parameter for VARPA
    
    AMLOEXT-403 FIX
    
    Change-Id: I21e0cd502abfa081885327316bd42e3c1702c494
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index cb020ce..0bcf111 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -10198,6 +10198,7 @@ void OpVarPA::GenSlidingWindowFunction(std::stringstream &ss,
             {
                 const formula::DoubleVectorRefToken* pDVR =
                     dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+                assert(pDVR);
                 if(pDVR->GetArrays()[0].mpNumericArray
                     && pDVR->GetArrays()[0].mpStringArray)
                     isMixedDV = svDoubleVectorRefDoubleString;
@@ -10410,6 +10411,17 @@ void OpVarPA::GenSlidingWindowFunction(std::stringstream &ss,
             {
                 const formula::DoubleVectorRefToken* pDVR =
                     dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+                assert(pDVR);
+                if(pDVR->GetArrays()[0].mpNumericArray
+                    && pDVR->GetArrays()[0].mpStringArray)
+                    isMixedDV = svDoubleVectorRefDoubleString;
+                else if(pDVR->GetArrays()[0].mpNumericArray)
+                    isMixedDV = svDoubleVectorRefDouble;
+                else if(pDVR->GetArrays()[0].mpStringArray)
+                    isMixedDV = svDoubleVectorRefString;
+                else
+                    isMixedDV = svDoubleVectorRefNULL;
+
                 size_t nCurWindowSize = pDVR->GetRefRowSize();
                 ss << "    for (int i = ";
                 if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
@@ -10508,6 +10520,16 @@ void OpVarPA::GenSlidingWindowFunction(std::stringstream &ss,
                 const formula::SingleVectorRefToken* pSVR =
                     dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
                 assert(pSVR);
+                if(pSVR->GetArray().mpNumericArray
+                    && pSVR->GetArray().mpStringArray)
+                    isMixedSV = svSingleVectorRefDoubleString;
+                else if(pSVR->GetArray().mpNumericArray)
+                    isMixedSV = svSingleVectorRefDouble;
+                else if(pSVR->GetArray().mpStringArray)
+                    isMixedSV = svSingleVectorRefString;
+                else
+                    isMixedSV = svSingleVectorRefNULL;
+
                 if(isMixedSV == svSingleVectorRefDoubleString)
                 {
 #ifdef  ISNAN
commit 8eacfeda44c6d28aa3170e73a73de893b419d6f8
Author: shiming zhang <shiming at multicorewareinc.com>
Date:   Tue Dec 31 13:24:24 2013 +0800

    GPU Calc: unit test cases for support optional parameter for VARPA
    
    AMLOEXT-403 BUG
    
    Change-Id: Ie48f1e6a6abb6dae95477902a5211729dd91ee5e
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/qa/unit/data/xls/opencl/statistical/VarPA1.xls b/sc/qa/unit/data/xls/opencl/statistical/VarPA1.xls
new file mode 100644
index 0000000..dc09093
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/VarPA1.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 9a83989..8e14c27 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -290,6 +290,7 @@ public:
     void testStatisticalFormulaKurt1();
     void testStatisticalFormulaHarMean1();
     void testStatisticalFormulaVarA1();
+    void testStatisticalFormulaVarPA1();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -511,6 +512,7 @@ public:
     CPPUNIT_TEST(testStatisticalFormulaKurt1);
     CPPUNIT_TEST(testStatisticalFormulaHarMean1);
     CPPUNIT_TEST(testStatisticalFormulaVarA1);
+    CPPUNIT_TEST(testStatisticalFormulaVarPA1);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -6046,7 +6048,31 @@ void ScOpenclTest::testStatisticalFormulaVarA1()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-403]
+void ScOpenclTest::testStatisticalFormulaVarPA1()
+{
+    if (!detectOpenCLDevice())
+        return;
+
+    ScDocShellRef xDocSh = loadDoc("opencl/statistical/VarPA1.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
 
+    ScDocShellRef xDocShRes = loadDoc("opencl/statistical/VarPA1.", XLS);
+    ScDocument* pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    // Check the results of formula cells in the shared formula range.
+    for (SCROW i = 1; i <= 20; ++i)
+    {
+        double fLibre = pDoc->GetValue(ScAddress(1,i,0));
+        double fExcel = pDocRes->GetValue(ScAddress(1,i,0));
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+    }
+    xDocSh->DoClose();
+    xDocShRes->DoClose();
+}
 ScOpenclTest::ScOpenclTest()
       : ScBootstrapFixture( "/sc/qa/unit/data" )
 {
commit 8b3632fbeeb1dbb297dd2c5c3c7c676448a3a25a
Author: shiming zhang <shiming at multicorewareinc.com>
Date:   Tue Dec 31 13:09:33 2013 +0800

    GPU Calc: Fix bug of support optional parameter for VARA
    
    AMLOEXT-402 FIX
    
    Change-Id: I61b051324bb1421aafb048d3b76b50e182734076
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index 334a40b..cb020ce 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -9754,6 +9754,7 @@ void OpVarA::GenSlidingWindowFunction(std::stringstream &ss,
             {
                 const formula::DoubleVectorRefToken* pDVR =
                     dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+                assert(pDVR);
                 if(pDVR->GetArrays()[0].mpNumericArray
                     && pDVR->GetArrays()[0].mpStringArray)
                     isMixedDV = svDoubleVectorRefDoubleString;
@@ -9966,6 +9967,17 @@ void OpVarA::GenSlidingWindowFunction(std::stringstream &ss,
             {
                 const formula::DoubleVectorRefToken* pDVR =
                     dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+                assert(pDVR);
+                if(pDVR->GetArrays()[0].mpNumericArray
+                    && pDVR->GetArrays()[0].mpStringArray)
+                    isMixedDV = svDoubleVectorRefDoubleString;
+                else if(pDVR->GetArrays()[0].mpNumericArray)
+                    isMixedDV = svDoubleVectorRefDouble;
+                else if(pDVR->GetArrays()[0].mpStringArray)
+                    isMixedDV = svDoubleVectorRefString;
+                else
+                    isMixedDV = svDoubleVectorRefNULL;
+
                 size_t nCurWindowSize = pDVR->GetRefRowSize();
                 ss << "    for (int i = ";
                 if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
@@ -10064,6 +10076,16 @@ void OpVarA::GenSlidingWindowFunction(std::stringstream &ss,
                 const formula::SingleVectorRefToken* pSVR =
                     dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
                 assert(pSVR);
+                if(pSVR->GetArray().mpNumericArray
+                    && pSVR->GetArray().mpStringArray)
+                    isMixedSV = svSingleVectorRefDoubleString;
+                else if(pSVR->GetArray().mpNumericArray)
+                    isMixedSV = svSingleVectorRefDouble;
+                else if(pSVR->GetArray().mpStringArray)
+                    isMixedSV = svSingleVectorRefString;
+                else
+                    isMixedSV = svSingleVectorRefNULL;
+
                 if(isMixedSV == svSingleVectorRefDoubleString)
                 {
 #ifdef  ISNAN
@@ -10143,6 +10165,7 @@ void OpVarA::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "        return vSum * pow(fCount - 1.0,-1.0);\n";
     ss << "}\n";
 }
+
 void OpVarPA::GenSlidingWindowFunction(std::stringstream &ss,
             const std::string sSymName, SubArguments &vSubArguments)
 {
commit bea76c6b1a898b57abbe7da534f164a0ee5e974e
Author: shiming zhang <shiming at multicorewareinc.com>
Date:   Tue Dec 31 13:00:43 2013 +0800

    GPU Calc: unit test cases for support optional parameter for VARA
    
    AMLOEXT-402 BUG
    
    Change-Id: If6f4064d3e706957cc1db0c668f42675642455c3
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/qa/unit/data/xls/opencl/statistical/VarA1.xls b/sc/qa/unit/data/xls/opencl/statistical/VarA1.xls
new file mode 100644
index 0000000..4aa4082
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/VarA1.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 98e8917..9a83989 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -289,6 +289,7 @@ public:
     void testMathFormulaAverageIf_Mix();
     void testStatisticalFormulaKurt1();
     void testStatisticalFormulaHarMean1();
+    void testStatisticalFormulaVarA1();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -509,6 +510,7 @@ public:
     CPPUNIT_TEST(testMathFormulaAverageIf_Mix);
     CPPUNIT_TEST(testStatisticalFormulaKurt1);
     CPPUNIT_TEST(testStatisticalFormulaHarMean1);
+    CPPUNIT_TEST(testStatisticalFormulaVarA1);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -6019,6 +6021,32 @@ void ScOpenclTest::testStatisticalFormulaHarMean1()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-402]
+void ScOpenclTest::testStatisticalFormulaVarA1()
+{
+    if (!detectOpenCLDevice())
+        return;
+
+    ScDocShellRef xDocSh = loadDoc("opencl/statistical/VarA1.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+
+    ScDocShellRef xDocShRes = loadDoc("opencl/statistical/VarA1.", XLS);
+    ScDocument* pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    // Check the results of formula cells in the shared formula range.
+    for (SCROW i = 1; i <= 20; ++i)
+    {
+        double fLibre = pDoc->GetValue(ScAddress(1,i,0));
+        double fExcel = pDocRes->GetValue(ScAddress(1,i,0));
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+    }
+    xDocSh->DoClose();
+    xDocShRes->DoClose();
+}
+
 ScOpenclTest::ScOpenclTest()
       : ScBootstrapFixture( "/sc/qa/unit/data" )
 {
commit 18212c3d4a74cc92c2510fc55672d5a70c3837ea
Author: mingli <mingli at multicorewareinc.com>
Date:   Tue Dec 31 12:42:07 2013 +0800

    GPU Calc: Fix Not support multiple data types of HARMEAN
    
    AMLOEXT-401 FIX
    
    Change-Id: If398e6abfb7eec11033290fb7e9c87c26829ef90
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index 72a3fe7..334a40b 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -4429,26 +4429,29 @@ vSubArguments)
         }
         else if (pCur->GetType() == formula::svSingleVectorRef)
         {
-            ss << "    double arg0 = ";
+            ss << "    tmp = ";
             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
             ss << ";\n";
 #ifdef ISNAN
-            ss << "    if(isNan(arg0))\n";
+            ss << "    if(!isNan(tmp))\n";
             ss << "    {\n";
-            ss << "        continue;\n";
+            ss << "        nVal += (1.0 * pow( tmp,-1));\n";
+            ss << "        totallength +=1;\n";
             ss << "    }\n";
 #endif
-            ss << "    nVal += (1.0 * pow( arg0,-1));\n";
-            ss << "    totallength +=1;\n";
         }
         else if (pCur->GetType() == formula::svDouble)
         {
-           ss << "    double arg0 = ";
+           ss << "    tmp = ";
            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
            ss << ";\n";
-           ss << "    nVal += (1.0 *pow( arg0,-1));\n";
+           ss << "    nVal += (1.0 *pow( tmp,-1));\n";
            ss << "    totallength +=1;\n";
         }
+        else
+        {
+            ss << "    return DBL_MIN;\n";
+        }
     }
     ss << "    tmp = totallength*pow(nVal,-1);\n";
     ss << "    return tmp;\n";
commit 979567eea57751bf1c1195371bdf2c6c17d0d828
Author: mingli <mingli at multicorewareinc.com>
Date:   Tue Dec 31 12:38:44 2013 +0800

    GPU Calc: unit test cases for Not support multiple data types of HARMEAN
    
    AMLOEXT-401 BUG
    
    Change-Id: I7960b47c62a4a5d65e0ae5814d5b14763cea4e74
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/qa/unit/data/xls/opencl/statistical/HarMean1.xls b/sc/qa/unit/data/xls/opencl/statistical/HarMean1.xls
new file mode 100644
index 0000000..ab9bc58
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/HarMean1.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 2635988..98e8917 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -288,6 +288,7 @@ public:
     void testStatisticalFormulaAvedev();
     void testMathFormulaAverageIf_Mix();
     void testStatisticalFormulaKurt1();
+    void testStatisticalFormulaHarMean1();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -507,6 +508,7 @@ public:
     CPPUNIT_TEST(testStatisticalFormulaAvedev);
     CPPUNIT_TEST(testMathFormulaAverageIf_Mix);
     CPPUNIT_TEST(testStatisticalFormulaKurt1);
+    CPPUNIT_TEST(testStatisticalFormulaHarMean1);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -5994,6 +5996,29 @@ void ScOpenclTest::testStatisticalFormulaKurt1()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-401]
+void ScOpenclTest::testStatisticalFormulaHarMean1()
+{
+    if (!detectOpenCLDevice())
+        return;
+    ScDocShellRef xDocSh = loadDoc("opencl/statistical/HarMean1.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+    ScDocShellRef xDocShRes = loadDoc("opencl/statistical/HarMean1.", XLS);
+    ScDocument* pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    // Check the results of formula cells in the shared formula range.
+    for (SCROW i = 1; i <= 19; ++i)
+    {
+        double fLibre = pDoc->GetValue(ScAddress(1,i,0));
+        double fExcel = pDocRes->GetValue(ScAddress(1,i,0));
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+    }
+    xDocSh->DoClose();
+    xDocShRes->DoClose();
+}
 ScOpenclTest::ScOpenclTest()
       : ScBootstrapFixture( "/sc/qa/unit/data" )
 {
commit 01ae85fdd1c8f5e06ff8e25a75bbeb0325768acc
Author: mingli <mingli at multicorewareinc.com>
Date:   Tue Dec 31 12:00:14 2013 +0800

    GPU Calc: Fix Not support multiple data types of KURT
    
    AMLOEXT-387 FIX
    
    Change-Id: I7faa87205bc82a1078f29bcb763d9ba3c3c20f2f
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index 24f6994..72a3fe7 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -5802,109 +5802,185 @@ void OpMedian::GenSlidingWindowFunction(
 void OpKurt:: GenSlidingWindowFunction(std::stringstream &ss,
             const std::string sSymName, SubArguments &vSubArguments)
 {
-        FormulaToken *pCur = vSubArguments[0]->GetFormulaToken();
+    ss << "\ndouble " << sSymName;
+    ss << "_"<< BinFuncName() <<"( ";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
+    {
+        if (i)
+            ss << ",";
+        vSubArguments[i]->GenSlidingWindowDecl(ss);
+    }
+    ss << ")\n";
+    ss <<"{\n";
+    ss << "    int gid0 = get_global_id(0);\n";
+    ss << "    double fSum = 0.0;\n";
+    ss << "    double vSum = 0.0;\n";
+    ss << "    double length;\n";
+    ss << "    double totallength=0;\n";
+    ss << "    double tmp = 0;\n";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
+    {
+        FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
         assert(pCur);
-        const formula::DoubleVectorRefToken* pCurDVR =
-            dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
-        size_t nCurWindowSize = pCurDVR->GetRefRowSize();
-        ss << "\ndouble " << sSymName;
-        ss << "_"<< BinFuncName() <<"( ";
-        for (unsigned i = 0; i < vSubArguments.size(); i++)
+        if (pCur->GetType() == formula::svDoubleVectorRef)
         {
-            if (i)
-                ss << ",";
-            vSubArguments[i]->GenSlidingWindowDecl(ss);
+            const formula::DoubleVectorRefToken* pDVR =
+            dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+            size_t nCurWindowSize = pDVR->GetRefRowSize();
+            ss << "    length="<<nCurWindowSize;
+            ss << ";\n";
+            ss << "    for (int i = ";
+            ss << "0; i < "<< nCurWindowSize << "; i++)\n";
+            ss << "    {\n";
+            ss << "        double arg"<<i<<" = ";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << ";\n";
+#ifdef ISNAN
+            ss << "        if(isNan(arg"<<i<<")||((gid0+i)>=";
+            ss << pDVR->GetArrayLength();
+            ss << "))\n";
+            ss << "        {\n";
+            ss << "            length-=1.0;\n";
+            ss << "            continue;\n";
+            ss << "        }\n";
+#endif
+            ss << "        fSum +=  arg"<<i<<";\n";
+            ss << "    }\n";
+            ss << "    totallength +=length;\n";
         }
-        ss << ") {\n";
-        ss << "    int gid0 = get_global_id(0);\n";
-        ss << "    double fSum = 0.0;\n";
-        ss<<  "    double xpower4 = 0.0;\n";
-        ss<<  "    double fMean =0.0;\n";
-        ss<<  "    double fStdDev = 0.0;\n";
-        ss << "    int length="<<nCurWindowSize<<";\n";
-        ss << "    double tmp = 0;\n";
-        for (unsigned i = 0; i < vSubArguments.size(); i++)
+        else if (pCur->GetType() == formula::svSingleVectorRef)
         {
-            pCur = vSubArguments[i]->GetFormulaToken();
-            assert(pCur);
-            if (pCur->GetType() == formula::svDoubleVectorRef)
-            {
-                const formula::DoubleVectorRefToken* pDVR =
-                dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
-                nCurWindowSize = pDVR->GetRefRowSize();
-                ss << "    for (int i = 0; i <" << nCurWindowSize;
-                ss << "; i++)\n";
-                ss << "    {\n";
-                ss << "        double arg0 = ";
-                ss<< vSubArguments[i]->GenSlidingWindowDeclRef();
-                ss << ";\n";
+            ss << "    tmp = ";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << ";\n";
 #ifdef ISNAN
-                ss<< "        if(isNan(arg0)||((gid0+i)>=";
-                ss<<pCurDVR->GetArrayLength();
-                ss<< "))\n";
-                ss<< "        {\n";
-                ss<< "            length--;\n";
-                ss<< "            continue;\n";
-                ss<< "        }\n";
-#endif
-                ss<< "        fSum += arg0;\n";
-                ss<< "    }\n";
-                ss<< "    fMean = fSum / length;\n";
-                ss<< "    fSum=0.0;\n";
-                ss<< "    for (int i = 0; i <" << nCurWindowSize << "; i++)\n";
-                ss<< "    {\n";
-                ss<< "        double arg0 = ";
-                ss<< vSubArguments[i]->GenSlidingWindowDeclRef();
-                ss<< ";\n";
+            ss << "    if(!isNan(tmp))\n";
+            ss << "    {\n";
+            ss << "        fSum += tmp;\n";
+            ss << "        totallength +=1;\n";
+            ss << "    }\n";
+#endif
+        }
+        else if (pCur->GetType() == formula::svDouble)
+        {
+           ss << "    tmp = ";
+           ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+           ss << ";\n";
+           ss << "    fSum += tmp;\n";
+           ss << "    totallength +=1;\n";
+        }
+        else
+        {
+            ss << "    return DBL_MIN;\n";
+        }
+    }
+    ss << "    double fMean = fSum * pow(totallength,-1);\n";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
+    {
+        FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
+        assert(pCur);
+        if (pCur->GetType() == formula::svDoubleVectorRef)
+        {
+            const formula::DoubleVectorRefToken* pDVR =
+            dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+            size_t nCurWindowSize = pDVR->GetRefRowSize();
+            ss << "    for (int i = ";
+            ss << "0; i < "<< nCurWindowSize << "; i++)\n";
+            ss << "    {\n";
+            ss << "        double arg"<<i<<" = ";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << ";\n";
 #ifdef ISNAN
-                ss<< "        if(isNan(arg0)||((gid0+i)>=";
-                ss<< pCurDVR->GetArrayLength();
-                ss<< "))\n";
-                ss<< "        {\n";
-                ss<< "            continue;\n";
-                ss<< "        }\n";
-#endif
-                ss<< "        fSum += pow(arg0 - fMean, 2);\n";
-                ss<< "    }\n";
-                ss<< "    fStdDev = sqrt(fSum / (length - 1.0));\n";
-                ss<< "    fSum = 0.0;\n";
-                ss<< "    for (int i = 0; i <" << nCurWindowSize << "; i++)\n";
-                ss<< "    {\n";
-                ss<< "        double arg0 = ";
-                ss<< vSubArguments[i]->GenSlidingWindowDeclRef();
-                ss<< ";\n";
+            ss << "        if(isNan(arg"<<i<<")||((gid0+i)>=";
+            ss << pDVR->GetArrayLength();
+            ss << "))\n";
+            ss << "        {\n";
+            ss << "            continue;\n";
+            ss << "        }\n";
+#endif
+            ss << "        vSum +=  (arg"<<i<<"-fMean)*(arg"<<i<<"-fMean);\n";
+            ss << "    }\n";
+        }
+        else if (pCur->GetType() == formula::svSingleVectorRef)
+        {
+            ss << "    tmp = ";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << ";\n";
 #ifdef ISNAN
-                ss<< "        if(isNan(arg0)||((gid0+i)>=";
-                ss<< pCurDVR->GetArrayLength();
-                ss<< "))\n";
-                ss<< "        {\n";
-                ss<< "            continue;\n";
-                ss<< "        }\n";
+            ss << "    if(!isNan(tmp))\n";
+            ss << "    {\n";
+            ss << "        vSum += (tmp-fMean)*(tmp-fMean);\n";
+            ss << "    }\n";
 #endif
-                ss<< "        fSum = (arg0 -fMean) / fStdDev;\n";
-                ss<< "        xpower4 += pow(fSum, 4);\n";
-                ss<< "    }\n";
-            }
-            else if (pCur->GetType() == formula::svSingleVectorRef)
-            {
-#ifdef  ISNAN
-                ss << "return HUGE_VAL";
+        }
+        else if (pCur->GetType() == formula::svDouble)
+        {
+           ss << "    tmp = ";
+           ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+           ss << ";\n";
+           ss << "    vSum += (tmp-fMean)*(tmp-fMean);\n";
+        }
+    }
+    ss << "    double fStdDev = sqrt(vSum / (totallength - 1.0));\n";
+    ss << "    double dx = 0.0;\n";
+    ss << "    double xpower4 = 0.0;\n";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
+    {
+        FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
+        assert(pCur);
+        if (pCur->GetType() == formula::svDoubleVectorRef)
+        {
+            const formula::DoubleVectorRefToken* pDVR =
+            dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+            size_t nCurWindowSize = pDVR->GetRefRowSize();
+            ss << "    for (int i = ";
+            ss << "0; i < "<< nCurWindowSize << "; i++)\n";
+            ss << "    {\n";
+            ss << "        double arg"<<i<<" = ";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << ";\n";
+#ifdef ISNAN
+            ss << "        if(isNan(arg"<<i<<")||((gid0+i)>=";
+            ss << pDVR->GetArrayLength();
+            ss << "))\n";
+            ss << "        {\n";
+            ss << "            continue;\n";
+            ss << "        }\n";
 #endif
-            }
-            else if (pCur->GetType() == formula::svDouble)
-            {
-#ifdef  ISNAN
-                ss << "return HUGE_VAL";
+            ss<< "        dx = (arg"<<i<<" -fMean) / fStdDev;\n";
+            ss<< "        xpower4 = xpower4 + (dx * dx * dx * dx);\n";
+            ss << "    }\n";
+        }
+        else if (pCur->GetType() == formula::svSingleVectorRef)
+        {
+            ss << "    tmp = ";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << ";\n";
+#ifdef ISNAN
+            ss << "    if(!isNan(tmp))\n";
+            ss << "    {\n";
+            ss<< "        dx = (tmp -fMean) / fStdDev;\n";
+            ss<< "        xpower4 = xpower4 + (dx * dx * dx * dx);\n";
+            ss << "    }\n";
 #endif
-            }
         }
-        ss<< "    fSum = (length - 2.0) * (length - 3.0);\n";
-        ss<< "    fMean = length * (length + 1.0) /";
-        ss<< "((length - 1.0) * fSum);\n";
-        ss<< "    fStdDev = 3.0 * (length - 1.0) * (length - 1.0) / fSum;\n";
-        ss<< "    tmp = xpower4 * fMean - fStdDev;\n";
-        ss<< "    return tmp;\n";
-        ss<< "}";
+        else if (pCur->GetType() == formula::svDouble)
+        {
+           ss << "    tmp = ";
+           ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+           ss << ";\n";
+           ss<< "        dx = (tmp -fMean) / fStdDev;\n";
+           ss<< "        xpower4 = xpower4 + (dx * dx * dx * dx);\n";
+        }
+    }
+    ss<< "    double k_d = (totallength - 2.0) * (totallength - 3.0);\n";
+    ss<< "    double k_l = totallength * (totallength + 1.0) /";
+    ss<< "((totallength - 1.0) * k_d);\n";
+    ss<< "    double k_t = 3.0 * (totallength - 1.0) * ";
+    ss<< "(totallength - 1.0) / k_d;\n";
+    ss<< "    tmp = xpower4 * k_l - k_t;\n";
+    ss<< "    return tmp;\n";
+    ss << "}";
 }
 
 void OpIntercept::GenSlidingWindowFunction(std::stringstream &ss,
commit d9106391ec8001d40c7bc14d423ebdac0817feff
Author: mingli <mingli at multicorewareinc.com>
Date:   Tue Dec 31 11:54:03 2013 +0800

    GPU Calc: unit test cases for Not support multiple data types of KURT
    
    AMLOEXT-387 BUG
    
    Change-Id: I491dfd98183691033a15f21f41efe514bf96de85
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/qa/unit/data/xls/opencl/statistical/Kurt1.xls b/sc/qa/unit/data/xls/opencl/statistical/Kurt1.xls
new file mode 100644
index 0000000..24f489f
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/Kurt1.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index cf3e014..2635988 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -287,6 +287,7 @@ public:
     void testNegSub();
     void testStatisticalFormulaAvedev();
     void testMathFormulaAverageIf_Mix();
+    void testStatisticalFormulaKurt1();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -505,6 +506,7 @@ public:
     CPPUNIT_TEST(testNegSub);
     CPPUNIT_TEST(testStatisticalFormulaAvedev);
     CPPUNIT_TEST(testMathFormulaAverageIf_Mix);
+    CPPUNIT_TEST(testStatisticalFormulaKurt1);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -5969,6 +5971,29 @@ void ScOpenclTest::testMathFormulaAverageIf_Mix()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-387]
+void ScOpenclTest::testStatisticalFormulaKurt1()
+{
+    if (!detectOpenCLDevice())
+        return;
+    ScDocShellRef xDocSh = loadDoc("opencl/statistical/Kurt1.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+    ScDocShellRef xDocShRes = loadDoc("opencl/statistical/Kurt1.", XLS);
+    ScDocument* pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    // Check the results of formula cells in the shared formula range.
+    for (SCROW i = 1; i <= 19; ++i)
+    {
+        double fLibre = pDoc->GetValue(ScAddress(2,i,0));
+        double fExcel = pDocRes->GetValue(ScAddress(2,i,0));
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+    }
+    xDocSh->DoClose();
+    xDocShRes->DoClose();
+}
 ScOpenclTest::ScOpenclTest()
       : ScBootstrapFixture( "/sc/qa/unit/data" )
 {
commit a64c293fc1f72ba91ba739058fb84a09ba5b1456
Author: yiming ju <yiming at multicorewareinc.com>
Date:   Tue Dec 31 11:35:26 2013 +0800

    GPU Calc: Optimized TBILLPRICE
    
    AMLOEXT-386
    
    Change-Id: Ida4704f9864e0ba3fe043f33ac58b8ae1a7ab098
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index 5931ab5..e13b86c 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -4571,11 +4571,11 @@ void OpYielddisc::GenSlidingWindowFunction(
  void OpTbillprice::BinInlineFun(std::set<std::string>& decls,
     std::set<std::string>& funs)
 {
-    decls.insert(GetYearFracDecl);decls.insert(GetNullDateDecl);
+    decls.insert(GetYearFracDecl);
     decls.insert(DateToDaysDecl);decls.insert(DaysToDateDecl);
     decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
 
-    funs.insert(GetYearFrac);funs.insert(GetNullDate);
+    funs.insert(GetYearFrac);
     funs.insert(DateToDays);funs.insert(DaysToDate);
     funs.insert(DaysInMonth);funs.insert(IsLeapYear);
 }
@@ -4591,75 +4591,20 @@ void OpTbillprice::GenSlidingWindowFunction(
             ss << ",";
         vSubArguments[i]->GenSlidingWindowDecl(ss);
     }
-    ss << ") {\n\t";
-    ss << "int gid0 = get_global_id(0);\n\t";
-    ss << "double tmp = 0;\n\t";
-    ss << "double tmp000;\n\t";
-    ss << "double tmp001;\n\t";
-    ss << "double tmp002;\n\t";
-
-
-
-#ifdef ISNAN
-    FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
-    formula::SingleVectorRefToken *>(tmpCur0);
-
-    FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
-    formula::SingleVectorRefToken *>(tmpCur1);
-
-    FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
-    formula::SingleVectorRefToken *>(tmpCur2);
-
-    ss<< "int buffer_tmp000_len = ";
-    ss<< tmpCurDVR0->GetArrayLength();
-    ss << ";\n\t";
-
-    ss<< "int buffer_tmp001_len = ";
-    ss<< tmpCurDVR1->GetArrayLength();
-    ss << ";\n\t";
-
-    ss<< "int buffer_tmp002_len = ";
-    ss<< tmpCurDVR2->GetArrayLength();
-    ss << ";\n\t";
-#endif
-
-#ifdef ISNAN
-    ss<<"if(gid0>=buffer_tmp000_len || isNan(";
-    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-    ss<<"))\n\t\t";
-    ss<<"tmp000 = 0;\n\telse \n\t\t";
-#endif
-    ss<<"tmp000 = ";
-    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-    ss<<";\n\t";
-
-#ifdef ISNAN
-    ss<<"if(gid0>=buffer_tmp001_len || isNan(";
-    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-    ss<<"))\n\t\t";
-    ss<<"tmp001 = 0;\n\telse \n\t\t";
-#endif
-    ss<<"tmp001 = ";
-    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-    ss<<";\n\t";
+    ss << ") {\n";
+    ss << "    int gid0 = get_global_id(0);\n";
+    ss << "    double tmp = 0;\n";
 
-#ifdef ISNAN
-    ss<<"if(gid0>=buffer_tmp002_len || isNan(";
-    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
-    ss<<"))\n\t\t";
-    ss<<"tmp002 = 0;\n\telse \n\t\t";
-#endif
-    ss<<"tmp002 = ";
-    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
-    ss<<";\n\t";
+    ss << "    int singleIndex = gid0;\n";
+    ss << "    int doubleIndex = gid0;\n";
+    ss << "    int i = gid0;\n";
+    GenTmpVariables(ss,vSubArguments);
+    CheckAllSubArgumentIsNan(ss,vSubArguments);
 
-    ss<<"tmp001+=1.0;\n";
-    ss<<"double  fFraction =GetYearFrac(GetNullDate(),tmp000,tmp001,0);\n";
-    ss<<"tmp = 100.0 * ( 1.0 - tmp002 * fFraction );\n";
-    ss << "return tmp;\n";
+    ss << "    tmp1+=1.0;\n";
+    ss << "    double  fFraction =GetYearFrac(693594,tmp0,tmp1,0);\n";
+    ss << "    tmp = 100.0 * ( 1.0 - tmp2 * fFraction );\n";
+    ss << "    return tmp;\n";
     ss << "}\n";
 }
  void RATE::BinInlineFun(std::set<std::string>& decls,
diff --git a/sc/source/core/opencl/op_financial.hxx b/sc/source/core/opencl/op_financial.hxx
index 11d5fcd..34019be 100644
--- a/sc/source/core/opencl/op_financial.hxx
+++ b/sc/source/core/opencl/op_financial.hxx
@@ -503,7 +503,7 @@ public:
     virtual void BinInlineFun(std::set<std::string>& ,std::set<std::string>& );
 };
 
-class OpTbillprice: public Normal
+class OpTbillprice: public CheckVariables
 {
 public:
     virtual void GenSlidingWindowFunction(std::stringstream &ss,
commit f23ccedea955d02a5e080c15080cd42e5144c29c
Author: yiming ju <yiming at multicorewareinc.com>
Date:   Tue Dec 31 11:23:54 2013 +0800

    GPU Calc: Fix bug of Averageif not support double vector
    
    AMLOEXT-386 FIX
    
    Change-Id: If8bd95079c725c690e5ca10c6c5954d01f971c0e
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx
index 3422b3b..9b7dca0 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -2961,12 +2961,7 @@ void OpProduct::GenSlidingWindowFunction(std::stringstream &ss,
 void OpAverageIf::GenSlidingWindowFunction(std::stringstream &ss,
     const std::string sSymName, SubArguments &vSubArguments)
 {
-    FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
-    const formula::DoubleVectorRefToken*pCurDVR= dynamic_cast<const
-        formula::DoubleVectorRefToken *>(tmpCur);
-    size_t nCurWindowSize = pCurDVR->GetArrayLength() <
-        pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
-        pCurDVR->GetRefRowSize() ;
+
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (unsigned i = 0; i < vSubArguments.size(); i++)
@@ -2978,39 +2973,143 @@ void OpAverageIf::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "    int gid0=get_global_id(0);\n";
     ss << "    double tmp =0;\n";
     ss << "    double count=0;\n";
+    ss << "    int singleIndex =gid0;\n";
+    ss << "    int doubleIndex;\n";
     ss << "    int i ;\n";
+    ss << "    int j ;\n";
     GenTmpVariables(ss,vSubArguments);
-    ss << "    for (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";
+
+    unsigned paraOneIsDoubleVector = 0;
+    unsigned paraOneWidth = 1;
+    unsigned paraTwoWidth = 1;
+    unsigned paraThreeWidth = 1;
+    unsigned loopTimes = 0;
+    unsigned loopIndex = 0;
+    if(vSubArguments[0]->GetFormulaToken()->GetType() ==
+    formula::svDoubleVectorRef)
+    {
+        paraOneIsDoubleVector = 1;
+        FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+        const formula::DoubleVectorRefToken*pCurDVR0= dynamic_cast<const
+            formula::DoubleVectorRefToken *>(tmpCur0);
+        paraOneWidth = pCurDVR0->GetArrays().size();
+        loopTimes = paraOneWidth;
+        if(paraOneWidth > 1)
+        {
+            throw Unhandled();
+        } 
     }
-    ss << "    {\n";
-    if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
-    {
-        ss << "        int doubleIndex =i+gid0;\n";
-    }else
+
+    if(vSubArguments[paraOneWidth]->GetFormulaToken()->GetType() ==
+     formula::svDoubleVectorRef)
+ 
     {
-        ss << "        int doubleIndex =i;\n";
+        FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
+        const formula::DoubleVectorRefToken*pCurDVR1= dynamic_cast<const
+            formula::DoubleVectorRefToken *>(tmpCur1);
+        paraTwoWidth = pCurDVR1->GetArrays().size();
+        if(paraTwoWidth > 1)
+        {
+            throw Unhandled();
+        }
+        ss << "    i = ";
+        if (!pCurDVR1->IsStartFixed() && pCurDVR1->IsEndFixed()) {
+            ss << "gid0;\n";
+        } else {
+            ss << "0;\n";
+        }
+        if(!pCurDVR1->IsStartFixed() && !pCurDVR1->IsEndFixed())
+        {
+            ss << "        doubleIndex =i+gid0;\n";
+        }else
+        {
+            ss << "        doubleIndex =i;\n";
+        }
     }
-    ss << "        int singleIndex =gid0;\n";
-    CheckSubArgumentIsNan(ss,vSubArguments,0);
-    CheckSubArgumentIsNan(ss,vSubArguments,1);
-    ss << "        if ( isequal( tmp0 , tmp1 ) ) \n";
-    ss << "        {";
-    if(vSubArguments.size() == 2)
-        ss << "            tmp += tmp0;\n";
-    else
+
+    CheckSubArgumentIsNan(ss,vSubArguments,paraOneWidth);
+
+    unsigned paraThreeIndex = paraOneWidth + paraTwoWidth;
+    if(vSubArguments.size() > paraThreeIndex)
+    {
+        if(vSubArguments[paraThreeIndex]->GetFormulaToken()->GetType() ==
+        formula::svDoubleVectorRef)
+        {
+            FormulaToken *tmpCur2 =
+            vSubArguments[paraThreeIndex]->GetFormulaToken();
+            const formula::DoubleVectorRefToken*pCurDVR2= dynamic_cast<const
+                formula::DoubleVectorRefToken *>(tmpCur2);
+            paraThreeWidth = pCurDVR2->GetArrays().size();
+             if(paraThreeWidth > 1)
+            {
+                throw Unhandled();
+            }
+        }
+    }
+
+    if(paraOneIsDoubleVector)
+    {
+        FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+        const formula::DoubleVectorRefToken*pCurDVR0= dynamic_cast<const
+            formula::DoubleVectorRefToken *>(tmpCur0);
+        size_t nCurWindowSize = pCurDVR0->GetArrayLength() <
+            pCurDVR0->GetRefRowSize() ? pCurDVR0->GetArrayLength():
+            pCurDVR0->GetRefRowSize() ;
+
+        for(loopIndex =0; loopIndex < loopTimes; loopIndex++)
+        {
+            ss << "    for (i = ";
+            if (!pCurDVR0->IsStartFixed() && pCurDVR0->IsEndFixed()) {
+                ss << "gid0; i < "<< nCurWindowSize <<"; i++)\n";
+            } else if (pCurDVR0->IsStartFixed() && !pCurDVR0->IsEndFixed()) {
+                ss << "0; i < gid0+"<< nCurWindowSize <<"; i++)\n";
+            } else {
+                ss << "0; i < "<< nCurWindowSize <<"; i++)\n";
+            }
+            ss << "    {\n";
+            if(!pCurDVR0->IsStartFixed() && !pCurDVR0->IsEndFixed())
+            {
+                ss << "        doubleIndex =i+gid0;\n";
+            }else
+            {
+                ss << "        doubleIndex =i;\n";
+            }
+
+            CheckSubArgumentIsNan(ss,vSubArguments, loopIndex);
+
+            ss << "        if ( isequal( tmp";
+            ss << loopIndex<<" , tmp"<<paraOneWidth<<") ) \n";
+            ss << "        {\n";
+            if(vSubArguments.size() == paraThreeIndex)
+                ss << "            tmp += tmp"<<loopIndex<<";\n";
+            else
+            {
+                CheckSubArgumentIsNan(ss,vSubArguments,
+                paraThreeIndex+loopIndex);
+                ss << "            tmp += tmp";
+                ss << paraThreeIndex+loopIndex<<";\n";
+            }
+            ss << "            count+=1.0;\n";
+            ss << "        }\n";
+            ss << "    }\n";
+        }
+    }
+      else
     {
-        CheckSubArgumentIsNan(ss,vSubArguments,2);
-        ss << "            tmp += tmp2;\n";
+        CheckSubArgumentIsNan(ss,vSubArguments, 0);
+        ss << "        if ( isequal( tmp0 , tmp1 ) ) \n";
+        ss << "        {\n";
+        if(vSubArguments.size() == 2)
+            ss << "            tmp += tmp0;\n";
+        else
+        {
+            CheckSubArgumentIsNan(ss,vSubArguments,2);
+            ss << "            tmp += tmp2;\n";
+        }
+        ss << "            count+=1.0;\n";
+        ss << "        }\n";
     }
-    ss << "            count+=1.0;\n";
-    ss << "        }\n";
-    ss << "    }\n";
+  
     ss << "    if(count!=0)\n";
     ss << "        tmp=tmp/count;\n";
     ss << "    else\n";
commit 35764e147a11721a574069b31dcacdf095139841
Author: yiming ju <yiming at multicorewareinc.com>
Date:   Tue Dec 31 11:16:23 2013 +0800

    GPU Calc: unit test cases for Averageif not support double vector
    
    AMLOEXT-386 BUG
    
    Change-Id: Ie7c20cf9e354ca4c88388238ba735262098bb09f
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/qa/unit/data/xls/opencl/math/averageif_mix.xls b/sc/qa/unit/data/xls/opencl/math/averageif_mix.xls
new file mode 100644
index 0000000..0fd3f8d
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/math/averageif_mix.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 4103dad..cf3e014 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -286,6 +286,7 @@ public:
     void testAddInFormulaBesseLJ();
     void testNegSub();
     void testStatisticalFormulaAvedev();
+    void testMathFormulaAverageIf_Mix();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -503,6 +504,7 @@ public:
     CPPUNIT_TEST(testAddInFormulaBesseLJ);
     CPPUNIT_TEST(testNegSub);
     CPPUNIT_TEST(testStatisticalFormulaAvedev);
+    CPPUNIT_TEST(testMathFormulaAverageIf_Mix);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -5945,7 +5947,28 @@ void ScOpenclTest::testNegSub()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
-
+//[AMLOEXT-386]
+void ScOpenclTest::testMathFormulaAverageIf_Mix()
+{
+    if (!detectOpenCLDevice())
+        return;
+    ScDocShellRef xDocSh = loadDoc("opencl/math/averageif_mix.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+    ScDocShellRef xDocShRes = loadDoc("opencl/math/averageif_mix.", XLS);
+    ScDocument* pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    for (SCROW i = 0; i <= 9; ++i)
+    {
+        double fLibre = pDoc->GetValue(ScAddress(2,i,0));
+        double fExcel = pDocRes->GetValue(ScAddress(2,i,0));
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+    }
+    xDocSh->DoClose();
+    xDocShRes->DoClose();
+}
 ScOpenclTest::ScOpenclTest()
       : ScBootstrapFixture( "/sc/qa/unit/data" )
 {
commit c19298d12baf22d7d1e44da5717371e9ca3ffc7b
Author: I-Jui (Ray) Sung <ray at multicorewareinc.com>
Date:   Mon Dec 30 16:34:29 2013 -0600

    GPU Calc: fix compiler warning
    
    Change-Id: Iaadf726cbece3d077667175f3f60bf2345179202
    
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx
index 7db5462..3422b3b 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -1344,7 +1344,6 @@ void OpSqrt::GenSlidingWindowFunction(std::stringstream &ss,
         }
         else if(tmpCur->GetType() == formula::svDouble)
         {
-        printf("const\n");
             ss << "    arg0=";
             ss << tmpCur->GetDouble() << ";\n";
         }
commit 2096b746a9013c93afb94469e9e983d65e1fffd2
Author: Isamu Mogi <saturday6c at gmail.com>
Date:   Wed Dec 18 21:43:13 2013 +0900

    Add sal_textenc dependency to cppumaker
    
    In Japanese localized Windows, cppumaker requires sal_textenclo.dll
    but that rule isn't written in .mk. It causes build failure.
    
    Change-Id: Icab74493a4a3b445144bb9d969b79636dbd17162
    Reviewed-on: https://gerrit.libreoffice.org/7134
    Reviewed-by: Kohei Yoshida <libreoffice at kohei.us>
    Tested-by: Kohei Yoshida <libreoffice at kohei.us>
    
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/codemaker/Executable_cppumaker.mk b/codemaker/Executable_cppumaker.mk
index 26347a0..049e0c7 100644
--- a/codemaker/Executable_cppumaker.mk
+++ b/codemaker/Executable_cppumaker.mk
@@ -13,6 +13,7 @@ $(eval $(call gb_Executable_use_external,cppumaker,boost_headers))
 
 $(eval $(call gb_Executable_use_libraries,cppumaker,\
     sal \
+    sal_textenc \
     salhelper \
     unoidl \
 ))
commit a429db404f376fd3d3d7a50f7da8d4ce59caa289
Author: minwang <min at multicorewareinc.com>
Date:   Tue Dec 24 14:44:39 2013 +0800

    GPU Calc: Optimized COUPPCD
    
    AMLOEXT-382
    
    Change-Id: I49ed9bdd88a0f00da4475798362750d5a0253c09
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index 62fedd3..5931ab5 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -3622,11 +3622,17 @@ void OpCouppcd::BinInlineFun(std::set<std::string>& decls,
 {
     decls.insert(IsLeapYearDecl); decls.insert(DaysInMonthDecl);
     decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl);
-    decls.insert(GetNullDateDecl); decls.insert(ScaDate2Decl);
+    decls.insert(GetNullDateDecl);
+    decls.insert(ScaDateDecl);
+    decls.insert(addMonthsDecl);
+    decls.insert(setDayDecl);decls.insert(checklessthanDecl);
     decls.insert(lcl_GetCouppcdDecl);
     funs.insert(IsLeapYear);funs.insert(DaysInMonth);
     funs.insert(DaysToDate);funs.insert(DateToDays);
-    funs.insert(GetNullDate);funs.insert(ScaDate2);
+    funs.insert(GetNullDate);
+    funs.insert(ScaDate);
+    funs.insert(addMonths);
+    funs.insert(setDay);funs.insert(checklessthan);
     funs.insert(lcl_GetCouppcd);
 }
 void OpCouppcd::GenSlidingWindowFunction(
@@ -3637,82 +3643,74 @@ void OpCouppcd::GenSlidingWindowFunction(
     ss << "_"<< BinFuncName() <<"(";
     for (unsigned i = 0; i < vSubArguments.size(); i++)
     {
-        if (i)
-            ss << ",";
-        vSubArguments[i]->GenSlidingWindowDecl(ss);
+      if (i)
+      ss << ",";
+      vSubArguments[i]->GenSlidingWindowDecl(ss);
     }
     ss << ") {\n";
     ss << "    double tmp = 0;\n";
     ss << "    int gid0 = get_global_id(0);\n";
-    ss << "    int bLastDayMode =1,bLastDay =0,b30Days= 0,bUSMode = 0;\n";
     ss << "    int nSettle,nMat,nFreq,nBase;\n";
 #ifdef ISNAN
-    FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
-    formula::SingleVectorRefToken *>(tmpCur0);
-    FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
-    formula::SingleVectorRefToken *>(tmpCur1);
-    FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
-    formula::SingleVectorRefToken *>(tmpCur2);
-    FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
-    formula::SingleVectorRefToken *>(tmpCur3);
-    ss<< "    int buffer_nSettle_len = ";
-    ss<< tmpCurDVR0->GetArrayLength();
-    ss << ";\n";
-    ss<< "    int buffer_nMat_len = ";
-    ss<< tmpCurDVR1->GetArrayLength();
-    ss << ";\n";
-    ss<< "    int buffer_nFreq_len = ";
-    ss<< tmpCurDVR2->GetArrayLength();
-    ss << ";\n";
-    ss<< "    int buffer_nBase_len = ";
-    ss<< tmpCurDVR3->GetArrayLength();
-    ss << ";\n";
+    FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
+    FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken();
+    FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
+    FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
 #endif
 #ifdef ISNAN
-    ss <<"    if(gid0 >= buffer_nSettle_len || isNan(";
-    ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
-    ss <<"))\n";
+    if(tmpCur0->GetType() == formula::svSingleVectorRef)
+    {
+    const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+    formula::SingleVectorRefToken *>(tmpCur0);
+    ss <<"    if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n";
     ss <<"        nSettle = 0;\n    else\n";
+    }
 #endif
-   ss << "        nSettle=(int)";
-   ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-   ss <<";\n";
+    ss <<"        nSettle=(int)";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss <<";\n";
 #ifdef ISNAN
-    ss <<"    if(gid0 >= buffer_nMat_len || isNan(";
-    ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
-    ss <<"))\n";
+    if(tmpCur1->GetType() == formula::svSingleVectorRef)
+    {
+    const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
+        formula::SingleVectorRefToken *>(tmpCur1);
+    ss <<"    if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef();
+    ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n";
     ss <<"        nMat = 0;\n    else\n";
+    }
 #endif
     ss <<"        nMat=(int)";
     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-    ss << ";\n";
+    ss <<";\n";
 #ifdef ISNAN
-    ss <<"    if(gid0 >= buffer_nFreq_len || isNan(";
-    ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
-    ss <<"))\n";
+    if(tmpCur2->GetType() == formula::svSingleVectorRef)
+    {
+    const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
+    formula::SingleVectorRefToken *>(tmpCur2);
+    ss <<"    if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef();
+    ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n";
     ss <<"        nFreq = 0;\n    else\n";
+    }
 #endif
-    ss <<"        nFreq=(int)";
-    ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
+    ss << "        nFreq=(int)";
+    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
     ss <<";\n";
 #ifdef ISNAN
-    ss <<"    if(gid0 >= buffer_nBase_len || isNan(";
-    ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
-    ss <<"))\n";
+    if(tmpCur3->GetType() == formula::svSingleVectorRef)
+    {
+    const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
+        formula::SingleVectorRefToken *>(tmpCur3);
+    ss <<"    if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef();
+    ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n";
     ss <<"        nBase = 0;\n    else\n";
+    }
 #endif
-    ss <<"        nBase=(int)";
+    ss << "        nBase=(int)";
     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
-    ss <<";\n";
-    ss <<"    int nNullDate=GetNullDate();\n";
-    ss <<"    ScaDate2(nNullDate, nMat, nBase,&bLastDayMode,&bLastDay,";
-    ss <<"&b30Days,&bUSMode);\n";
-    ss <<"    tmp = lcl_GetCouppcd(nNullDate,nSettle,nMat,nFreq,";
-    ss <<"&bLastDayMode,&bLastDay,&b30Days,&bUSMode);\n";
+    ss << ";\n";
+    ss <<"    int nNullDate=693594;\n";
+    ss <<"    tmp = lcl_GetCouppcd(nNullDate,nSettle,nMat,nFreq,nBase);\n";
     ss <<"    return tmp;\n";
     ss <<"}";
 }
diff --git a/sc/source/core/opencl/opinlinefun_finacial.cxx b/sc/source/core/opencl/opinlinefun_finacial.cxx
index 052c364..91d04d2 100644
--- a/sc/source/core/opencl/opinlinefun_finacial.cxx
+++ b/sc/source/core/opencl/opinlinefun_finacial.cxx
@@ -334,46 +334,36 @@ std::string ScaDate2=
 "}\n";
 
 std::string lcl_GetCouppcdDecl=
-"int lcl_GetCouppcd(int nNullDate,int nSettle, int nMat,int nFreq,int *"
-"bLastDayMode,int *bLastDay,int *b30Days,int *bUSMode);\n";
+"int lcl_GetCouppcd(int nNullDate,int nSettle,int nMat,int nFreq,int nBase);\n";
 
 std::string lcl_GetCouppcd=
-"int lcl_GetCouppcd(int nNullDate,int nSettle, int nMat,int nFreq,int *"
-"bLastDayMode,int *bLastDay,int *b30Days,int *bUSMode)\n"
+"int lcl_GetCouppcd(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n"
 "{\n"
-"    int aDate = nMat;int rDay=0,rMonth=0,rYear=0;int mDay=0,mMonth=0,"
-"mYear=0;\n"
-"    int sDay=0,sMonth=0, sYear=0;\n"
-"    DaysToDate(aDate+nNullDate,&rDay, &rMonth, &rYear );\n"
-"    DaysToDate(nMat+nNullDate,&mDay, &mMonth, &mYear );\n"
-"    DaysToDate(nSettle+nNullDate,&sDay, &sMonth, &sYear );\n"
-"    rYear= sYear;\n"
-"    nSettle=nSettle+nNullDate;\n"
-"    aDate=DateToDays( rDay,rMonth,rYear );\n"
-"    if( aDate < nSettle )\n"
-"        rYear+= 1;\n"
-"    int d=DateToDays( rDay,rMonth,rYear );\n"
-"    int nMonthCount=-1*(12 / nFreq);\n"
-"    while(d > nSettle )\n"
+"    int aDate = nMat;\n"
+"    int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
+"rbUSMode=0,rnDay=0;\n"
+"    int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
+"sbUSMode=0,snDay=0;\n"
+"    ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
+"&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
+"    ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
+"&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
+"    rYear=sYear;\n"
+"    setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
+"    if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay,"
+"sbLastDay,rDay,sDay))\n"
 "    {\n"
-"        int nNewMonth = nMonthCount + rMonth;\n"
-"        if( nNewMonth > 12 )\n"
-"        {\n"
-"           --nNewMonth;\n"
-"           rYear+=nNewMonth / 12;\n"
-"           rMonth = nNewMonth % 12 + 1;\n"
-"         }\n"
-"        else if( nNewMonth < 1 )\n"
-"        {\n"
-"           rYear+= nNewMonth / 12 - 1;\n"
-"           rMonth = nNewMonth % 12 + 12;\n"
-"        }\n"
-"        else\n"
-"            rMonth =  nNewMonth;\n"
-"        d=DateToDays( rDay,rMonth,rYear );\n"
+"        rYear+=1;\n"
+"        setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
+"    }\n"
+"    while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
+"rbLastDay,sDay,rDay))\n"
+"    {\n"
+"        double d = -1*(12/nFreq);\n"
+"        addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n"
 "    }\n"
 "    int nLastDay = DaysInMonth( rMonth, rYear );\n"
-"    int nRealDay = ((*bLastDayMode) && (*bLastDay)) ? nLastDay :"
+"    int nRealDay = (rbLastDayMode && rbLastDay) ? nLastDay :"
 "min( nLastDay, rDay );\n"
 "    return DateToDays( nRealDay, rMonth, rYear ) - nNullDate;\n"
 "}\n";
commit 45cc16ea99a71126f35a8105d484727baf7112bc
Author: minwang <min at multicorewareinc.com>
Date:   Tue Dec 24 14:41:41 2013 +0800

    GPU Calc: Optimized COUPNCD
    
    AMLOEXT-381
    
    Change-Id: Iccae2ddd0bbfc598016ca331402003625251d99b
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index 17f37bf..62fedd3 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -3721,100 +3721,99 @@ void OpCoupncd::BinInlineFun(std::set<std::string>& decls,
 {
     decls.insert(IsLeapYearDecl); decls.insert(DaysInMonthDecl);
     decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl);
-    decls.insert(GetNullDateDecl); decls.insert(ScaDate2Decl);
+    decls.insert(GetNullDateDecl);
+    decls.insert(ScaDateDecl);
+    decls.insert(addMonthsDecl);
+    decls.insert(setDayDecl);decls.insert(checklessthanDecl);
     decls.insert(lcl_GetCoupncdDecl);
     funs.insert(IsLeapYear);funs.insert(DaysInMonth);
     funs.insert(DaysToDate);funs.insert(DateToDays);
-    funs.insert(GetNullDate);funs.insert(ScaDate2);
+    funs.insert(GetNullDate);
+    funs.insert(ScaDate);
+    funs.insert(addMonths);
+    funs.insert(setDay);funs.insert(checklessthan);
     funs.insert(lcl_GetCoupncd);
 }
 void OpCoupncd::GenSlidingWindowFunction(
-    std::stringstream &ss, const std::string sSymName,
-    SubArguments &vSubArguments)
+    std::stringstream &ss, const std::string sSymName, SubArguments &
+vSubArguments)
 {
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (unsigned i = 0; i < vSubArguments.size(); i++)
     {
-        if (i)
-            ss << ",";
-        vSubArguments[i]->GenSlidingWindowDecl(ss);
+      if (i)
+      ss << ",";
+      vSubArguments[i]->GenSlidingWindowDecl(ss);
     }
     ss << ") {\n";
     ss << "    double tmp = 0;\n";
     ss << "    int gid0 = get_global_id(0);\n";
-    ss << "    int bLastDayMode =1,bLastDay =0,b30Days= 0,bUSMode = 0;\n";
     ss << "    int nSettle,nMat,nFreq,nBase;\n";
 #ifdef ISNAN
-    FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
-    formula::SingleVectorRefToken *>(tmpCur0);
-    FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
-    formula::SingleVectorRefToken *>(tmpCur1);
-    FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
-    formula::SingleVectorRefToken *>(tmpCur2);
-    FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
-    formula::SingleVectorRefToken *>(tmpCur3);
-    ss<< "    int buffer_nSettle_len = ";
-    ss<< tmpCurDVR0->GetArrayLength();
-    ss << ";\n";
-    ss<< "    int buffer_nMat_len = ";
-    ss<< tmpCurDVR1->GetArrayLength();
-    ss << ";\n";
-    ss<< "    int buffer_nFreq_len = ";
-    ss<< tmpCurDVR2->GetArrayLength();
-    ss << ";\n";
-    ss<< "    int buffer_nBase_len = ";
-    ss<< tmpCurDVR3->GetArrayLength();
-    ss << ";\n";
+    FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken();
+    FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken();
+    FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken();
+    FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken();
 #endif
 #ifdef ISNAN
-    ss <<"    if(gid0 >= buffer_nSettle_len || isNan(";
-    ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
-    ss <<"))\n";
+    if(tmpCur0->GetType() == formula::svSingleVectorRef)
+    {
+    const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+    formula::SingleVectorRefToken *>(tmpCur0);
+    ss <<"    if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n";
     ss <<"        nSettle = 0;\n    else\n";
+    }
 #endif
-   ss << "        nSettle=(int)";
-   ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-   ss <<";\n";
+    ss <<"        nSettle=(int)";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss <<";\n";
 #ifdef ISNAN
-    ss <<"    if(gid0 >= buffer_nMat_len || isNan(";
-    ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
-    ss <<"))\n";
+    if(tmpCur1->GetType() == formula::svSingleVectorRef)
+    {
+    const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
+        formula::SingleVectorRefToken *>(tmpCur1);
+    ss <<"    if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef();
+    ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n";
     ss <<"        nMat = 0;\n    else\n";
+    }
 #endif
     ss <<"        nMat=(int)";
     ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-    ss << ";\n";
+    ss <<";\n";
 #ifdef ISNAN
-    ss <<"    if(gid0 >= buffer_nFreq_len || isNan(";
-    ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
-    ss <<"))\n";
+    if(tmpCur2->GetType() == formula::svSingleVectorRef)
+    {
+    const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
+    formula::SingleVectorRefToken *>(tmpCur2);
+    ss <<"    if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef();
+    ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n";
     ss <<"        nFreq = 0;\n    else\n";
+    }
 #endif
-    ss <<"        nFreq=(int)";
-    ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
+    ss << "        nFreq=(int)";
+    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
     ss <<";\n";
 #ifdef ISNAN
-    ss <<"    if(gid0 >= buffer_nBase_len || isNan(";
-    ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
-    ss <<"))\n";
+    if(tmpCur3->GetType() == formula::svSingleVectorRef)
+    {
+    const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
+        formula::SingleVectorRefToken *>(tmpCur3);
+    ss <<"    if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef();
+    ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n";
     ss <<"        nBase = 0;\n    else\n";
+    }
 #endif
-    ss <<"        nBase=(int)";
+    ss << "        nBase=(int)";
     ss << vSubArguments[3]->GenSlidingWindowDeclRef();
-    ss <<";\n";
-    ss <<"    int nNullDate=GetNullDate();\n";
-    ss <<"    ScaDate2(nNullDate, nMat, nBase,&bLastDayMode,&bLastDay,";
-    ss <<"&b30Days,&bUSMode);\n";
-    ss <<"    tmp = lcl_GetCoupncd(nNullDate,nSettle,nMat,nFreq,";
-    ss <<"&bLastDayMode,&bLastDay,&b30Days,&bUSMode);\n";
+    ss << ";\n";
+    ss <<"    int nNullDate=693594;\n";
+    ss <<"    tmp = lcl_GetCoupncd(nNullDate,nSettle,nMat,nFreq,nBase);\n";
     ss <<"    return tmp;\n";
     ss <<"}";
 }
+
 void OpCoupdaysnc::BinInlineFun(std::set<std::string>& decls,
     std::set<std::string>& funs)
 {
diff --git a/sc/source/core/opencl/opinlinefun_finacial.cxx b/sc/source/core/opencl/opinlinefun_finacial.cxx
index 6cce4af..052c364 100644
--- a/sc/source/core/opencl/opinlinefun_finacial.cxx
+++ b/sc/source/core/opencl/opinlinefun_finacial.cxx
@@ -379,47 +379,35 @@ std::string lcl_GetCouppcd=
 "}\n";
 
 std::string lcl_GetCoupncdDecl=
-"int lcl_GetCoupncd(int nNullDate,int nSettle, int nMat,int nFreq,"
-"int *bLastDayMode,int *bLastDay,int *b30Days,int *bUSMode);\n";
+"int lcl_GetCoupncd(int nNullDate,int nSettle,int nMat,int nFreq,int nBase);\n";
 
 std::string lcl_GetCoupncd=
-"int lcl_GetCoupncd(int nNullDate,int nSettle, int nMat,int nFreq,"
-"int *bLastDayMode,int *bLastDay,int *b30Days,int *bUSMode)\n"
+"int lcl_GetCoupncd(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n"
 "{\n"
-"    int aDate = nMat;int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0,\n"
-"    mYear=0;\n"
-"    int sDay=0,sMonth=0, sYear=0;\n"
-"    DaysToDate(aDate+nNullDate,&rDay, &rMonth, &rYear );\n"
-"    DaysToDate(nMat+nNullDate,&mDay, &mMonth, &mYear );\n"
-"    DaysToDate(nSettle+nNullDate,&sDay, &sMonth, &sYear );\n"
-"    rYear= sYear;\n"
-"    nSettle=nSettle+nNullDate;\n"
-"    aDate=DateToDays( rDay,rMonth,rYear );\n"
-"    if( aDate > nSettle )\n"
-"        rYear+= -1;\n"
-"    int d=DateToDays( rDay,rMonth,rYear );\n"
-"        int nMonthCount=12 / nFreq;\n"
-"    while(d <= nSettle )\n"
+"    int aDate = nMat;\n"
+"    int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0,"
+"rbUSMode=0,rnDay=0;\n"
+"    int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0,"
+"sbUSMode=0,snDay=0;\n"
+"    ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode,"
+"&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n"
+"    ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode,"
+"&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n"
+"    rYear=sYear;\n"
+"    setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
+"    if(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,rbLastDay"
+",sDay,rDay))\n"
 "    {\n"
-"        int nNewMonth = nMonthCount + rMonth;\n"
-"        rMonth=rMonth+ 12 / nFreq ;\n"
-"        if( nNewMonth > 12 )\n"
-"        {\n"
-"            --nNewMonth;\n"
-"            rYear+=nNewMonth / 12;\n"
-"            rMonth = nNewMonth % 12 + 1;\n"
-"        }\n"
-"        else if( nNewMonth < 1 )\n"
-"        {\n"
-"            rYear+= nNewMonth / 12 - 1;\n"
-"            rMonth = nNewMonth % 12 + 12;\n"
-"        }\n"
-"        else\n"
-"            rMonth =  nNewMonth;\n"
-"        d=DateToDays( rDay,rMonth,rYear );\n"
+"        rYear-=1;\n"
+"        setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n"
+"    }\n"
+"    while(!checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay,"
+"rbLastDay,sDay,rDay))\n"
+"    {\n"
+"      addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,12/nFreq,&rYear);\n"
 "    }\n"
 "    int nLastDay = DaysInMonth( rMonth, rYear );\n"
-"    int nRealDay = ((*bLastDayMode) && (*bLastDay)) ? nLastDay :"
+"    int nRealDay = (rbLastDayMode && rbLastDay) ? nLastDay :"
 "min( nLastDay, rDay );\n"
 "    return DateToDays( nRealDay, rMonth, rYear ) - nNullDate;\n"
 "}\n";
commit e74c15d3b8602a7d2a454aaaab3ba71de10e603a
Author: minwang <min at multicorewareinc.com>
Date:   Tue Dec 24 14:35:55 2013 +0800

    GPU Calc: Optimized AMORLINC
    
    AMLOEXT-228
    
    Change-Id: Ie48898fd7b783bb94e3dcf0121ae40d9aa32916e
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index f7b7ed0..17f37bf 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -4189,11 +4189,11 @@ void OpAmorlinc::BinInlineFun(std::set<std::string>& decls,
     decls.insert(nKorrValDecl); decls.insert(RoundDecl);
     decls.insert(IsLeapYearDecl);decls.insert(DaysInMonthDecl);
     decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl);
-    decls.insert(GetNullDateDecl); decls.insert(GetYearFracDecl);
+    decls.insert(GetYearFracDecl);
     funs.insert(Round);
     funs.insert(IsLeapYear);funs.insert(DaysInMonth);
     funs.insert(DaysToDate);funs.insert(DateToDays);
-    funs.insert(GetNullDate);funs.insert(GetYearFrac);
+    funs.insert(GetYearFrac);
 }
 void OpAmorlinc::GenSlidingWindowFunction(std::stringstream &ss,
              const std::string sSymName, SubArguments &vSubArguments)
@@ -4208,112 +4208,105 @@ void OpAmorlinc::GenSlidingWindowFunction(std::stringstream &ss,
     }
     ss << ") {\n";
     ss << "    int gid0 = get_global_id(0);\n";
-    ss << "    double tmp = " << GetBottom() <<";\n";
+    ss << "    double tmp = 0;\n";
     ss << "    double fCost,fRestVal,fPer,fRate;\n";
     ss << "    int nDate,nFirstPer,nBase;\n";
 #ifdef ISNAN
     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
-    formula::SingleVectorRefToken *>(tmpCur0);
     FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
-    formula::SingleVectorRefToken *>(tmpCur1);
     FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
-    formula::SingleVectorRefToken *>(tmpCur2);
     FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
-    formula::SingleVectorRefToken *>(tmpCur3);
     FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR4= dynamic_cast<const
-    formula::SingleVectorRefToken *>(tmpCur4);
     FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR5= dynamic_cast<const
-    formula::SingleVectorRefToken *>(tmpCur5);
     FormulaToken *tmpCur6 = vSubArguments[6]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR6= dynamic_cast<const
-    formula::SingleVectorRefToken *>(tmpCur6);
-    ss<< "    int buffer_Cost_len = ";
-    ss<< tmpCurDVR0->GetArrayLength();
-    ss<< ";\n";
-    ss<< "    int buffer_Date_len = ";
-    ss<< tmpCurDVR1->GetArrayLength();
-    ss << ";\n";
-    ss<< "    int buffer_FirstPer_len = ";
-    ss<< tmpCurDVR2->GetArrayLength();
-    ss << ";\n";
-    ss<< "    int buffer_RestVal_len = ";
-    ss<< tmpCurDVR3->GetArrayLength();
-    ss << ";\n";
-    ss<< "    int buffer_Per_len = ";
-    ss<< tmpCurDVR4->GetArrayLength();
-    ss << ";\n";
-    ss<< "    int buffer_Rate_len = ";
-    ss<< tmpCurDVR5->GetArrayLength();
-    ss << ";\n";
-    ss<< "    int buffer_Base_len = ";
-    ss<< tmpCurDVR6->GetArrayLength();
-    ss << ";\n";
 #endif
 #ifdef ISNAN
-    ss <<"    if(gid0 >= buffer_Cost_len || isNan(";
-    ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
-    ss <<"))\n";
+    if(tmpCur0->GetType() == formula::svSingleVectorRef)
+    {
+    const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+    formula::SingleVectorRefToken *>(tmpCur0);
+    ss <<"    if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n";
     ss <<"        fCost = 0;\n    else\n";
+    }
 #endif
     ss << "        fCost=";
     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     ss <<";\n";
 #ifdef ISNAN
-    ss <<"    if(gid0 >= buffer_Date_len || isNan(";
-    ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
-    ss <<"))\n";
+    if(tmpCur1->GetType() == formula::svSingleVectorRef)
+    {

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list