[Libreoffice-commits] core.git: Branch 'feature/calc-group-interpreter-4' - 163 commits - sc/CppunitTest_sc_opencl_test.mk sc/inc sc/Library_scopencl.mk sc/Module_sc.mk sc/qa sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Tue Oct 29 21:57:08 CET 2013


 sc/CppunitTest_sc_opencl_test.mk                            |  114 
 sc/Library_scopencl.mk                                      |    7 
 sc/Module_sc.mk                                             |    1 
 sc/inc/formulagroup.hxx                                     |    3 
 sc/qa/unit/data/ods/OpenCLTests/Compiler/ineq.ods           |binary
 sc/qa/unit/data/ods/OpenCLTests/Compiler/nested.ods         |binary
 sc/qa/unit/data/ods/OpenCLTests/Compiler/string.ods         |binary
 sc/qa/unit/data/ods/OpenCLTests/math/csc.ods                |binary
 sc/qa/unit/data/ods/OpenCLTests/statistical/Correl.ods      |binary
 sc/qa/unit/data/xls/OpenclCase/financial/Accrintm.xls       |binary
 sc/qa/unit/data/xls/OpenclCase/financial/Coupdaybs.xls      |binary
 sc/qa/unit/data/xls/OpenclCase/financial/Coupdays.xls       |binary
 sc/qa/unit/data/xls/OpenclCase/financial/Coupdaysnc.xls     |binary
 sc/qa/unit/data/xls/OpenclCase/financial/Cumipmt.xls        |binary
 sc/qa/unit/data/xls/OpenclCase/financial/Cumprinc.xls       |binary
 sc/qa/unit/data/xls/OpenclCase/financial/DISC.xls           |binary
 sc/qa/unit/data/xls/OpenclCase/financial/Dollarde.xls       |binary
 sc/qa/unit/data/xls/OpenclCase/financial/Dollarfr.xls       |binary
 sc/qa/unit/data/xls/OpenclCase/financial/EFFECT_ADD.xls     |binary
 sc/qa/unit/data/xls/OpenclCase/financial/Fvschedule.xls     |binary
 sc/qa/unit/data/xls/OpenclCase/financial/INTRATE.xls        |binary
 sc/qa/unit/data/xls/OpenclCase/financial/IRR.xls            |binary
 sc/qa/unit/data/xls/OpenclCase/financial/MIRR.xls           |binary
 sc/qa/unit/data/xls/OpenclCase/financial/Nominal.xls        |binary
 sc/qa/unit/data/xls/OpenclCase/financial/PriceMat.xls       |binary
 sc/qa/unit/data/xls/OpenclCase/financial/RATE.xls           |binary
 sc/qa/unit/data/xls/OpenclCase/financial/RRI.xls            |binary
 sc/qa/unit/data/xls/OpenclCase/financial/Received.xls       |binary
 sc/qa/unit/data/xls/OpenclCase/financial/SLN.xls            |binary
 sc/qa/unit/data/xls/OpenclCase/financial/SYD.xls            |binary
 sc/qa/unit/data/xls/OpenclCase/financial/TBILLEQ.xls        |binary
 sc/qa/unit/data/xls/OpenclCase/financial/TBILLPRICE.xls     |binary
 sc/qa/unit/data/xls/OpenclCase/financial/TBILLYIELD.xls     |binary
 sc/qa/unit/data/xls/OpenclCase/financial/XNPV.xls           |binary
 sc/qa/unit/data/xls/OpenclCase/financial/YIELD.xls          |binary
 sc/qa/unit/data/xls/OpenclCase/financial/YIELDDISC.xls      |binary
 sc/qa/unit/data/xls/OpenclCase/financial/YIELDMAT.xls       |binary
 sc/qa/unit/data/xls/OpenclCase/math/cos.xls                 |binary
 sc/qa/unit/data/xls/OpenclCase/statistical/Fisher.xls       |binary
 sc/qa/unit/data/xls/OpenclCase/statistical/FisherInv.xls    |binary
 sc/qa/unit/data/xls/OpenclCase/statistical/Gamma.xls        |binary
 sc/qa/unit/data/xls/OpenclCase/statistical/GammaLn.xls      |binary
 sc/qa/unit/data/xls/OpenclCase/statistical/Gauss.xls        |binary
 sc/qa/unit/data/xls/OpenclCase/statistical/GeoMean.xls      |binary
 sc/qa/unit/data/xls/OpenclCase/statistical/HarMean.xls      |binary
 sc/qa/unit/data/xls/OpenclCase/statistical/Negbinomdist.xls |binary
 sc/qa/unit/data/xls/OpenclCase/statistical/Pearson.xls      |binary
 sc/qa/unit/data/xls/OpenclCase/statistical/Rsq.xls          |binary
 sc/qa/unit/data/xls/sum_ex.xls                              |binary
 sc/qa/unit/opencl-test.cxx                                  | 1487 ++++++
 sc/source/core/opencl/formulagroupcl.cxx                    | 2142 +++++----
 sc/source/core/opencl/formulagroupcl_finacial.hxx           |  758 +++
 sc/source/core/opencl/formulagroupcl_public.hxx             |   23 
 sc/source/core/opencl/op_database.cxx                       |   18 
 sc/source/core/opencl/op_database.hxx                       |   21 
 sc/source/core/opencl/op_financial.cxx                      | 2717 ++++++++++++
 sc/source/core/opencl/op_financial.hxx                      |  337 +
 sc/source/core/opencl/op_math.cxx                           |   85 
 sc/source/core/opencl/op_math.hxx                           |   38 
 sc/source/core/opencl/op_statistical.cxx                    |  697 +++
 sc/source/core/opencl/op_statistical.hxx                    |  109 
 sc/source/core/opencl/opbase.cxx                            |  107 
 sc/source/core/opencl/opbase.hxx                            |  140 
 sc/source/core/opencl/openclwrapper.cxx                     |    9 
 sc/source/core/tool/formulagroup.cxx                        |   29 
 sc/source/core/tool/token.cxx                               |   16 
 66 files changed, 7959 insertions(+), 899 deletions(-)

New commits:
commit 27de26f8bec9c6106fa92e4c50e05af6b1baa6e7
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue Oct 29 16:54:30 2013 -0400

    We don't need these headers.
    
    Change-Id: I8411b605edd27105bdc6cfc04acbd5cd9999e886

diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index 04d505a..5ae04ff 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -16,12 +16,8 @@
 #include "compiler.hxx"
 #include "interpre.hxx"
 #include "formula/vectortoken.hxx"
-#include <list>
-#include <iostream>
 #include <sstream>
-#include <algorithm>
 
-#include <memory>
 using namespace formula;
 
 namespace sc { namespace opencl {
diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx
index 83f780a..33ca0e5 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -16,12 +16,8 @@
 #include "compiler.hxx"
 #include "interpre.hxx"
 #include "formula/vectortoken.hxx"
-#include <list>
-#include <iostream>
 #include <sstream>
-#include <algorithm>
 
-#include <memory>
 using namespace formula;
 
 namespace sc { namespace opencl {
diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index ec816c2..134a0ca 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -16,11 +16,7 @@
 #include "compiler.hxx"
 #include "interpre.hxx"
 #include "formula/vectortoken.hxx"
-#include <list>
-#include <iostream>
 #include <sstream>
-#include <algorithm>
-#include <memory>
 
 using namespace formula;
 
commit 4ab0aa496709bf4386caf0d3a6f0d7fd160b198d
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue Oct 29 16:52:01 2013 -0400

    std::shared_ptr is C++11 specific. Use boost::shared_ptr instead.
    
    Change-Id: I8e6780ae5b5042a0521687f3a3535e74d7a35d23

diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index 665f822..1dd7c89 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -93,7 +93,7 @@ class ConstStringArgument: public DynamicKernelArgument
 {
 public:
     ConstStringArgument(const std::string &s,
-        std::shared_ptr<FormulaTreeNode> ft):
+        boost::shared_ptr<FormulaTreeNode> ft):
             DynamicKernelArgument(s, ft) {}
     /// Generate declaration
     virtual void GenDecl(std::stringstream &ss) const
@@ -151,7 +151,7 @@ class DynamicKernelConstantArgument: public DynamicKernelArgument
 {
 public:
     DynamicKernelConstantArgument(const std::string &s,
-        std::shared_ptr<FormulaTreeNode> ft):
+        boost::shared_ptr<FormulaTreeNode> ft):
             DynamicKernelArgument(s, ft) {}
     /// Generate declaration
     virtual void GenDecl(std::stringstream &ss) const
@@ -195,7 +195,7 @@ class DynamicKernelStringArgument: public DynamicKernelArgument
 {
 public:
     DynamicKernelStringArgument(const std::string &s,
-        std::shared_ptr<FormulaTreeNode> ft):
+        boost::shared_ptr<FormulaTreeNode> ft):
         DynamicKernelArgument(s, ft) {}
 
     virtual void GenSlidingWindowFunction(std::stringstream &) {}
@@ -268,7 +268,7 @@ class DynamicKernelSlidingArgument: public Base
 {
 public:
     DynamicKernelSlidingArgument(const std::string &s,
-        std::shared_ptr<FormulaTreeNode> ft):
+        boost::shared_ptr<FormulaTreeNode> ft):
         Base(s, ft)
     {
         FormulaToken *t = ft->GetFormulaToken();
@@ -664,7 +664,7 @@ public:
     typedef std::unique_ptr<DynamicKernelArgument> SubArgument;
 
     DynamicKernelSoPArguments(const std::string &s,
-        std::shared_ptr<FormulaTreeNode> ft);
+        boost::shared_ptr<FormulaTreeNode> ft);
 
     /// Create buffer and pass the buffer to a given kernel
     virtual size_t Marshal(cl_kernel k, int argno, int nVectorWidth)
@@ -763,7 +763,7 @@ private:
 
 template <class Op>
 std::unique_ptr<DynamicKernelArgument> SoPHelper(const std::string &ts,
-    std::shared_ptr<FormulaTreeNode> ft)
+    boost::shared_ptr<FormulaTreeNode> ft)
 {
     return std::unique_ptr<DynamicKernelArgument>(
         new DynamicKernelSoPArguments<Op>(ts, ft));
@@ -771,7 +771,7 @@ std::unique_ptr<DynamicKernelArgument> SoPHelper(const std::string &ts,
 
 template <class Op>
 DynamicKernelSoPArguments<Op>::DynamicKernelSoPArguments(const std::string &s,
-    std::shared_ptr<FormulaTreeNode> ft):
+    boost::shared_ptr<FormulaTreeNode> ft):
     DynamicKernelArgument(s, ft) {
     size_t nChildren = ft->Children.size();
 
@@ -1100,12 +1100,12 @@ DynamicKernelSoPArguments<Op>::DynamicKernelSoPArguments(const std::string &s,
 class SymbolTable {
 public:
     typedef std::map<const FormulaToken *,
-        std::shared_ptr<DynamicKernelArgument> > ArgumentMap;
+        boost::shared_ptr<DynamicKernelArgument> > ArgumentMap;
     // This avoids instability caused by using pointer as the key type
-    typedef std::list< std::shared_ptr<DynamicKernelArgument> > ArgumentList;
+    typedef std::list< boost::shared_ptr<DynamicKernelArgument> > ArgumentList;
     SymbolTable(void):mCurId(0) {}
     template <class T>
-    const DynamicKernelArgument *DeclRefArg(std::shared_ptr<FormulaTreeNode>);
+    const DynamicKernelArgument *DeclRefArg(boost::shared_ptr<FormulaTreeNode>);
     /// Used to generate sliding window helpers
     void DumpSlidingWindowFunctions(std::stringstream &ss)
     {
@@ -1136,7 +1136,7 @@ void SymbolTable::Marshal(cl_kernel k, int nVectorWidth)
 /// Code generation
 class DynamicKernel {
 public:
-    DynamicKernel(std::shared_ptr<FormulaTreeNode> r):mpRoot(r),
+    DynamicKernel(boost::shared_ptr<FormulaTreeNode> r):mpRoot(r),
         mpProgram(NULL), mpKernel(NULL), mpResClmem(NULL) {}
     /// Code generation in OpenCL
     std::string CodeGen() {
@@ -1220,8 +1220,8 @@ public:
     ~DynamicKernel();
     cl_mem GetResultBuffer(void) const { return mpResClmem; }
 private:
-    void TraverseAST(std::shared_ptr<FormulaTreeNode>);
-    std::shared_ptr<FormulaTreeNode> mpRoot;
+    void TraverseAST(boost::shared_ptr<FormulaTreeNode>);
+    boost::shared_ptr<FormulaTreeNode> mpRoot;
     SymbolTable mSyms;
     std::string mKernelSignature, mKernelHash;
     std::string mFullProgramSrc;
@@ -1282,7 +1282,7 @@ void DynamicKernel::CreateKernel(void)
 // The template argument T must be a subclass of DynamicKernelArgument
 template <typename T>
 const DynamicKernelArgument *SymbolTable::DeclRefArg(
-                  std::shared_ptr<FormulaTreeNode> t)
+                  boost::shared_ptr<FormulaTreeNode> t)
 {
     FormulaToken *ref = t->GetFormulaToken();
     ArgumentMap::iterator it = mSymbols.find(ref);
@@ -1291,7 +1291,7 @@ const DynamicKernelArgument *SymbolTable::DeclRefArg(
         std::cerr << "DeclRefArg: Allocate a new symbol:";
         std::stringstream ss;
         ss << "tmp"<< mCurId++;
-        std::shared_ptr<DynamicKernelArgument> new_arg(new T(ss.str(), t));
+        boost::shared_ptr<DynamicKernelArgument> new_arg(new T(ss.str(), t));
         mSymbols[ref] = new_arg;
         mParams.push_back(new_arg);
         std::cerr << ss.str() <<"\n";
@@ -1343,15 +1343,15 @@ bool FormulaGroupInterpreterOpenCL::interpret( ScDocument& rDoc,
     // Constructing "AST"
     FormulaTokenIterator aCode = rCode;
     std::list<FormulaToken *> list;
-    std::map<FormulaToken *, std::shared_ptr<FormulaTreeNode>> m_hash_map;
+    std::map<FormulaToken *, boost::shared_ptr<FormulaTreeNode>> m_hash_map;
     FormulaToken*  pCur;
     while( (pCur = (FormulaToken*)(aCode.Next()) ) != NULL)
     {
         OpCode eOp = pCur->GetOpCode();
         if ( eOp != ocPush )
         {
-            std::shared_ptr<FormulaTreeNode> m_currNode =
-                 std::shared_ptr<FormulaTreeNode>(new FormulaTreeNode(pCur));
+            boost::shared_ptr<FormulaTreeNode> m_currNode =
+                 boost::shared_ptr<FormulaTreeNode>(new FormulaTreeNode(pCur));
             sal_uInt8 m_ParamCount =  pCur->GetParamCount();
             for(int i=0; i<m_ParamCount; i++)
             {
@@ -1365,8 +1365,8 @@ bool FormulaGroupInterpreterOpenCL::interpret( ScDocument& rDoc,
                 }
                 else
                 {
-                    std::shared_ptr<FormulaTreeNode> m_ChildTreeNode =
-                      std::shared_ptr<FormulaTreeNode>(
+                    boost::shared_ptr<FormulaTreeNode> m_ChildTreeNode =
+                      boost::shared_ptr<FormulaTreeNode>(
                                new FormulaTreeNode(m_TempFormula));
                     m_currNode->Children.push_back(m_ChildTreeNode);
                 }
@@ -1378,8 +1378,8 @@ bool FormulaGroupInterpreterOpenCL::interpret( ScDocument& rDoc,
         list.push_back(pCur);
     }
 
-    std::shared_ptr<FormulaTreeNode> Root =
-            std::shared_ptr<FormulaTreeNode>(new FormulaTreeNode(NULL));
+    boost::shared_ptr<FormulaTreeNode> Root =
+            boost::shared_ptr<FormulaTreeNode>(new FormulaTreeNode(NULL));
     Root->Children.push_back(m_hash_map[list.back()]);
     // Code generation
     mpKernel = new DynamicKernel(Root);
diff --git a/sc/source/core/opencl/opbase.cxx b/sc/source/core/opencl/opbase.cxx
index eef9eba..e7eae13 100644
--- a/sc/source/core/opencl/opbase.cxx
+++ b/sc/source/core/opencl/opbase.cxx
@@ -16,7 +16,7 @@ using namespace formula;
 namespace sc { namespace opencl {
 
 DynamicKernelArgument::DynamicKernelArgument(const std::string &s,
-   std::shared_ptr<FormulaTreeNode> ft):
+   boost::shared_ptr<FormulaTreeNode> ft):
     mSymName(s), mFormulaTree(ft), mpClmem(NULL) {}
 
 /// Generate declaration
diff --git a/sc/source/core/opencl/opbase.hxx b/sc/source/core/opencl/opbase.hxx
index 5f17d85..a982533 100644
--- a/sc/source/core/opencl/opbase.hxx
+++ b/sc/source/core/opencl/opbase.hxx
@@ -14,6 +14,8 @@
 
 #include "formula/token.hxx"
 
+#include <boost/shared_ptr.hpp>
+
 #define ISNAN
 
 namespace sc { namespace opencl {
@@ -49,7 +51,7 @@ public:
     {
         Children.reserve(8);
     }
-    std::vector<std::shared_ptr<FormulaTreeNode>> Children;
+    std::vector<boost::shared_ptr<FormulaTreeNode> > Children;
     formula::FormulaToken *GetFormulaToken(void) const
     {
         return mpCurrentFormula;
@@ -66,7 +68,7 @@ private:
 class DynamicKernelArgument
 {
 public:
-    DynamicKernelArgument(const std::string &s, std::shared_ptr<FormulaTreeNode> ft);
+    DynamicKernelArgument(const std::string &s, boost::shared_ptr<FormulaTreeNode> ft);
 
     const std::string &GetNameAsString(void) const { return mSymName; }
     /// Generate declaration
@@ -94,7 +96,7 @@ public:
     const std::string& GetName(void) const { return mSymName; }
 protected:
     const std::string mSymName;
-    std::shared_ptr<FormulaTreeNode> mFormulaTree;
+    boost::shared_ptr<FormulaTreeNode> mFormulaTree;
     // Used by marshaling
     cl_mem mpClmem;
 };
commit f53c5d8ca7f701be0683667e4941ad70ec44578b
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue Oct 29 16:40:57 2013 -0400

    Properly split opbase.hxx into header and source files.
    
    Change-Id: I6ab5a792b5c31b44b8f302e45ec3511d3e2d6cdc

diff --git a/sc/Library_scopencl.mk b/sc/Library_scopencl.mk
index 0efe3cf..2fb8cfc 100644
--- a/sc/Library_scopencl.mk
+++ b/sc/Library_scopencl.mk
@@ -38,6 +38,7 @@ $(eval $(call gb_Library_use_libraries,scopencl,\
 $(eval $(call gb_Library_add_exception_objects,scopencl,\
         sc/source/core/opencl/formulagroupcl \
         sc/source/core/opencl/openclwrapper \
+        sc/source/core/opencl/opbase \
         sc/source/core/opencl/op_financial \
         sc/source/core/opencl/op_database \
         sc/source/core/opencl/op_math \
diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index a638530..04d505a 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -15,6 +15,7 @@
 #include "tokenarray.hxx"
 #include "compiler.hxx"
 #include "interpre.hxx"
+#include "formula/vectortoken.hxx"
 #include <list>
 #include <iostream>
 #include <sstream>
diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx
index 03fc9d3..83f780a 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -15,6 +15,7 @@
 #include "tokenarray.hxx"
 #include "compiler.hxx"
 #include "interpre.hxx"
+#include "formula/vectortoken.hxx"
 #include <list>
 #include <iostream>
 #include <sstream>
diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index 221d241..ec816c2 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -15,6 +15,7 @@
 #include "tokenarray.hxx"
 #include "compiler.hxx"
 #include "interpre.hxx"
+#include "formula/vectortoken.hxx"
 #include <list>
 #include <iostream>
 #include <sstream>
diff --git a/sc/source/core/opencl/opbase.cxx b/sc/source/core/opencl/opbase.cxx
new file mode 100644
index 0000000..eef9eba
--- /dev/null
+++ b/sc/source/core/opencl/opbase.cxx
@@ -0,0 +1,107 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "opbase.hxx"
+
+#include "formula/vectortoken.hxx"
+
+using namespace formula;
+
+namespace sc { namespace opencl {
+
+DynamicKernelArgument::DynamicKernelArgument(const std::string &s,
+   std::shared_ptr<FormulaTreeNode> ft):
+    mSymName(s), mFormulaTree(ft), mpClmem(NULL) {}
+
+/// Generate declaration
+void DynamicKernelArgument::GenDecl(std::stringstream &ss) const
+{
+    ss << "__global double *"<<mSymName;
+}
+
+/// When declared as input to a sliding window function
+void DynamicKernelArgument::GenSlidingWindowDecl(std::stringstream &ss) const
+{
+    GenDecl(ss);
+}
+
+/// When referenced in a sliding window function
+std::string DynamicKernelArgument::GenSlidingWindowDeclRef(bool) const
+{
+    std::stringstream ss;
+    ss << mSymName << "[gid0]";
+    return ss.str();
+}
+
+/// Generate use/references to the argument
+void DynamicKernelArgument::GenDeclRef(std::stringstream &ss) const
+{
+    ss << mSymName;
+}
+
+DynamicKernelArgument::~DynamicKernelArgument()
+{
+    //std::cerr << "~DynamicKernelArgument: " << mSymName <<"\n";
+    if (mpClmem) {
+        //std::cerr << "\tFreeing cl_mem of " << mSymName <<"\n";
+        cl_int ret = clReleaseMemObject(mpClmem);
+        if (ret != CL_SUCCESS)
+            throw OpenCLError(ret);
+    }
+}
+
+FormulaToken* DynamicKernelArgument::GetFormulaToken(void) const
+{
+    return mFormulaTree->GetFormulaToken();
+}
+
+size_t DynamicKernelArgument::GetWindowSize(void) const
+{
+    FormulaToken *pCur = mFormulaTree->GetFormulaToken();
+    assert(pCur);
+    if (auto *pCurDVR =
+            dynamic_cast<const formula::DoubleVectorRefToken *>(pCur))
+    {
+        return pCurDVR->GetRefRowSize();
+    } else if (dynamic_cast<const formula::SingleVectorRefToken *>(pCur))
+    {
+        // Prepare intermediate results (on CPU for now)
+        return 1;
+    } else {
+        throw Unhandled();
+    }
+    return 0;
+}
+
+void Normal::GenSlidingWindowFunction(
+    std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
+{
+    ArgVector argVector;
+    ss << "\ndouble " << sSymName;
+    ss << "_"<< BinFuncName() <<"(";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
+    {
+        if (i)
+            ss << ",";
+        vSubArguments[i]->GenSlidingWindowDecl(ss);
+        argVector.push_back(vSubArguments[i]->GenSlidingWindowDeclRef());
+    }
+    ss << ") {\n\t";
+    ss << "double tmp = " << GetBottom() <<";\n\t";
+    ss << "int gid0 = get_global_id(0);\n\t";
+    ss << "tmp = ";
+    ss << Gen(argVector);
+    ss << ";\n\t";
+    ss << "return tmp;\n";
+    ss << "}";
+}
+
+}}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/opbase.hxx b/sc/source/core/opencl/opbase.hxx
index acde3a9..5f17d85 100644
--- a/sc/source/core/opencl/opbase.hxx
+++ b/sc/source/core/opencl/opbase.hxx
@@ -10,44 +10,34 @@
 #ifndef SC_OPENCL_OPBASE_HXX
 #define SC_OPENCL_OPBASE_HXX
 
-#include "formulagroup.hxx"
-#include "document.hxx"
-#include "formulacell.hxx"
-#include "tokenarray.hxx"
-#include "compiler.hxx"
-#include "interpre.hxx"
-#include "formula/vectortoken.hxx"
-
 #include "clcc/clew.h"
 
-#include <list>
-#include <iostream>
-#include <sstream>
-#include <algorithm>
+#include "formula/token.hxx"
 
-#include <memory>
 #define ISNAN
-using namespace formula;
 
 namespace sc { namespace opencl {
 /// Exceptions
 
 /// Failed in parsing
-class UnhandledToken {
+class UnhandledToken
+{
 public:
-    UnhandledToken(FormulaToken *t): mToken(t) {}
-    FormulaToken *mToken;
+    UnhandledToken(formula::FormulaToken *t): mToken(t) {}
+    formula::FormulaToken *mToken;
 };
 
 /// Failed in marshaling
-class OpenCLError {
+class OpenCLError
+{
 public:
     OpenCLError(cl_int err): mError(err) {}
     cl_int mError;
 };
 
 /// Inconsistent state
-class Unhandled {
+class Unhandled
+{
 public:
     Unhandled() {}
 };
@@ -55,17 +45,17 @@ public:
 class FormulaTreeNode
 {
 public:
-    FormulaTreeNode(FormulaToken *ft): mpCurrentFormula(ft)
+    FormulaTreeNode(formula::FormulaToken *ft): mpCurrentFormula(ft)
     {
         Children.reserve(8);
     }
     std::vector<std::shared_ptr<FormulaTreeNode>> Children;
-    FormulaToken *GetFormulaToken(void) const
+    formula::FormulaToken *GetFormulaToken(void) const
     {
         return mpCurrentFormula;
     }
 private:
-    FormulaToken *const mpCurrentFormula;
+    formula::FormulaToken *const mpCurrentFormula;
 };
 
 /// Holds an input (read-only) argument reference to a SingleVectorRef.
@@ -73,69 +63,33 @@ private:
 /// like SumOfProduct
 /// In most of the cases the argument is introduced
 /// by a Push operation in the given RPN.
-class DynamicKernelArgument {
+class DynamicKernelArgument
+{
 public:
-    DynamicKernelArgument(const std::string &s,
-       std::shared_ptr<FormulaTreeNode> ft):
-        mSymName(s), mFormulaTree(ft), mpClmem(NULL) {}
+    DynamicKernelArgument(const std::string &s, std::shared_ptr<FormulaTreeNode> ft);
+
     const std::string &GetNameAsString(void) const { return mSymName; }
     /// Generate declaration
-    virtual void GenDecl(std::stringstream &ss) const
-    {
-        ss << "__global double *"<<mSymName;
-    }
+    virtual void GenDecl(std::stringstream &ss) const;
+
     /// When declared as input to a sliding window function
-    virtual void GenSlidingWindowDecl(std::stringstream &ss) const
-    {
-        GenDecl(ss);
-    }
+    virtual void GenSlidingWindowDecl(std::stringstream &ss) const;
+
     /// When referenced in a sliding window function
-    virtual std::string GenSlidingWindowDeclRef(bool=false) const
-    {
-        std::stringstream ss;
-        ss << mSymName << "[gid0]";
-        return ss.str();
-    }
+    virtual std::string GenSlidingWindowDeclRef(bool=false) const;
+
     /// Generate use/references to the argument
-    virtual void GenDeclRef(std::stringstream &ss) const
-    {
-        ss << mSymName;
-    }
+    virtual void GenDeclRef(std::stringstream &ss) const;
+
     /// Create buffer and pass the buffer to a given kernel
     virtual size_t Marshal(cl_kernel, int, int);
-    virtual ~DynamicKernelArgument()
-    {
-        //std::cerr << "~DynamicKernelArgument: " << mSymName <<"\n";
-        if (mpClmem) {
-            //std::cerr << "\tFreeing cl_mem of " << mSymName <<"\n";
-            cl_int ret = clReleaseMemObject(mpClmem);
-            if (ret != CL_SUCCESS)
-                throw OpenCLError(ret);
-        }
-    }
-    virtual void GenSlidingWindowFunction(std::stringstream &) {};
+
+    virtual ~DynamicKernelArgument();
+
+    virtual void GenSlidingWindowFunction(std::stringstream &) {}
     const std::string &GetSymName(void) const { return mSymName; }
-    FormulaToken *GetFormulaToken(void) const
-    {
-        return mFormulaTree->GetFormulaToken();
-    }
-    virtual size_t GetWindowSize(void) const
-    {
-        FormulaToken *pCur = mFormulaTree->GetFormulaToken();
-        assert(pCur);
-        if (auto *pCurDVR =
-                dynamic_cast<const formula::DoubleVectorRefToken *>(pCur))
-        {
-            return pCurDVR->GetRefRowSize();
-        } else if (dynamic_cast<const formula::SingleVectorRefToken *>(pCur))
-        {
-            // Prepare intermediate results (on CPU for now)
-            return 1;
-        } else {
-            throw Unhandled();
-        }
-        return 0;
-    }
+    formula::FormulaToken *GetFormulaToken(void) const;
+    virtual size_t GetWindowSize(void) const;
     virtual std::string DumpOpName(void) const { return std::string(""); }
     const std::string& GetName(void) const { return mSymName; }
 protected:
@@ -147,7 +101,8 @@ protected:
 
 /// Abstract class for code generation
 
-class SlidingFunctionBase {
+class SlidingFunctionBase
+{
 public:
     typedef std::unique_ptr<DynamicKernelArgument> SubArgument;
     typedef std::vector<SubArgument> SubArguments;
@@ -156,7 +111,8 @@ public:
     virtual ~SlidingFunctionBase() {};
 };
 
-class OpBase {
+class OpBase
+{
 public:
     typedef std::vector<std::string> ArgVector;
     typedef std::vector<std::string>::iterator ArgVectorIter;
@@ -172,28 +128,9 @@ class Normal: public SlidingFunctionBase, public OpBase
 {
 public:
     virtual void GenSlidingWindowFunction(std::stringstream &ss,
-            const std::string sSymName, SubArguments &vSubArguments)
-    {
-        ArgVector argVector;
-        ss << "\ndouble " << sSymName;
-        ss << "_"<< BinFuncName() <<"(";
-        for (unsigned i = 0; i < vSubArguments.size(); i++)
-        {
-            if (i)
-                ss << ",";
-            vSubArguments[i]->GenSlidingWindowDecl(ss);
-            argVector.push_back(vSubArguments[i]->GenSlidingWindowDeclRef());
-        }
-        ss << ") {\n\t";
-        ss << "double tmp = " << GetBottom() <<";\n\t";
-        ss << "int gid0 = get_global_id(0);\n\t";
-        ss << "tmp = ";
-        ss << Gen(argVector);
-        ss << ";\n\t";
-        ss << "return tmp;\n";
-        ss << "}";
-    }
+            const std::string sSymName, SubArguments &vSubArguments);
 };
+
 }}
 
 #endif
commit 05cde23cb837083ff175dc68708943cf8592390b
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue Oct 29 15:44:27 2013 -0400

    Properly split header and source files.
    
    Without this, formulagroupcl.cxx alone would take minutes to compile.
    
    Change-Id: I7d55ed22fbd7f5c0859d5f1bf2a4e4eafd47ac3b

diff --git a/sc/Library_scopencl.mk b/sc/Library_scopencl.mk
index b7e4b05..0efe3cf 100644
--- a/sc/Library_scopencl.mk
+++ b/sc/Library_scopencl.mk
@@ -38,6 +38,10 @@ $(eval $(call gb_Library_use_libraries,scopencl,\
 $(eval $(call gb_Library_add_exception_objects,scopencl,\
         sc/source/core/opencl/formulagroupcl \
         sc/source/core/opencl/openclwrapper \
+        sc/source/core/opencl/op_financial \
+        sc/source/core/opencl/op_database \
+        sc/source/core/opencl/op_math \
+        sc/source/core/opencl/op_statistical \
         sc/source/core/opencl/clcc/clew \
 ))
 
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index aca185a..665f822 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -18,10 +18,10 @@
 
 #include "openclwrapper.hxx"
 
-#include "op_financial.cxx"
-#include "op_database.cxx"
-#include "op_math.cxx"
-#include "op_statistical.cxx"
+#include "op_financial.hxx"
+#include "op_database.hxx"
+#include "op_math.hxx"
+#include "op_statistical.hxx"
 #include "formulagroupcl_public.hxx"
 #include "formulagroupcl_finacial.hxx"
 
diff --git a/sc/source/core/opencl/op_database.cxx b/sc/source/core/opencl/op_database.cxx
index 147a862..471ad7c 100644
--- a/sc/source/core/opencl/op_database.cxx
+++ b/sc/source/core/opencl/op_database.cxx
@@ -7,26 +7,12 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-#ifndef OP_DATABASE
-#define OP_DATABASE
-#include "formulagroup.hxx"
-#include "document.hxx"
-#include "formulacell.hxx"
-#include "tokenarray.hxx"
-#include "compiler.hxx"
-#include "interpre.hxx"
-#include "opbase.hxx"
-#include<list>
-#include <iostream>
-#include <sstream>
-#include <algorithm>
-
-#include <memory>
-using namespace formula;
+#include "op_database.hxx"
 
 namespace sc { namespace opencl {
 
+
+
 }}
-#endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/op_database.hxx b/sc/source/core/opencl/op_database.hxx
new file mode 100644
index 0000000..e29cc3f
--- /dev/null
+++ b/sc/source/core/opencl/op_database.hxx
@@ -0,0 +1,21 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef SC_OPENCL_OP_DATABASE_HXX
+#define SC_OPENCL_OP_DATABASE_HXX
+
+namespace sc { namespace opencl {
+
+
+
+}}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index da48e44..a638530 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -7,16 +7,15 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-#ifndef OP_FINACIAL
-#define OP_FINACIAL
+#include "op_financial.hxx"
+
 #include "formulagroup.hxx"
 #include "document.hxx"
 #include "formulacell.hxx"
 #include "tokenarray.hxx"
 #include "compiler.hxx"
 #include "interpre.hxx"
-#include "opbase.hxx"
-#include<list>
+#include <list>
 #include <iostream>
 #include <sstream>
 #include <algorithm>
@@ -25,1411 +24,1316 @@
 using namespace formula;
 
 namespace sc { namespace opencl {
-class RRI: public SlidingFunctionBase, public OpBase
+
+void RRI::GenSlidingWindowFunction(
+    std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
 {
-public:
-    virtual void GenSlidingWindowFunction(std::stringstream &ss,
-            const std::string sSymName, SubArguments &vSubArguments)
+    ss << "\ndouble " << sSymName;
+    ss << "_"<< BinFuncName() <<"(";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
     {
-        ss << "\ndouble " << sSymName;
-        ss << "_"<< BinFuncName() <<"(";
-        for (unsigned i = 0; i < vSubArguments.size(); i++)
-        {
-            if (i)
-                ss << ",";
-            vSubArguments[i]->GenSlidingWindowDecl(ss);
-        }
-        ss << ") {\n\t";
-        ss << "double tmp = " << GetBottom() <<";\n\t";
-        ss << "int gid0 = get_global_id(0);\n\t";
-        ss << "double fv;\n\t";
-        ss << "double pv;\n\t";
-        ss << "double nper;\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_nper_len = ";
-        ss<< tmpCurDVR0->GetArrayLength();
-        ss << ";\n\t";
-
-        ss<< "int buffer_pv_len = ";
-        ss<< tmpCurDVR1->GetArrayLength();
-        ss << ";\n\t";
-
-        ss<< "int buffer_fv_len = ";
-        ss<< tmpCurDVR2->GetArrayLength();
-        ss << ";\n\t";
-#endif
-
-#ifdef ISNAN
-        ss<<"if(gid0>=buffer_nper_len || isNan(";
-        ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-        ss<<"))\n\t\t";
-        ss<<"nper = 0;\n\telse \n\t\t";
-#endif
-        ss<<"nper = ";
-        ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-        ss<<";\n\t";
+        if (i)
+            ss << ",";
+        vSubArguments[i]->GenSlidingWindowDecl(ss);
+    }
+    ss << ") {\n\t";
+    ss << "double tmp = " << GetBottom() <<";\n\t";
+    ss << "int gid0 = get_global_id(0);\n\t";
+    ss << "double fv;\n\t";
+    ss << "double pv;\n\t";
+    ss << "double nper;\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_nper_len = ";
+    ss<< tmpCurDVR0->GetArrayLength();
+    ss << ";\n\t";
+
+    ss<< "int buffer_pv_len = ";
+    ss<< tmpCurDVR1->GetArrayLength();
+    ss << ";\n\t";
+
+    ss<< "int buffer_fv_len = ";
+    ss<< tmpCurDVR2->GetArrayLength();
+    ss << ";\n\t";
+#endif
 
 #ifdef ISNAN
-        ss<<"if(gid0>=buffer_pv_len || isNan(";
-        ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-        ss<<"))\n\t\t";
-        ss<<"pv = 0;\n\telse \n\t\t";
+    ss<<"if(gid0>=buffer_nper_len || isNan(";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss<<"))\n\t\t";
+    ss<<"nper = 0;\n\telse \n\t\t";
 #endif
-        ss<<"pv = ";
-        ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-        ss<<";\n\t";
+    ss<<"nper = ";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss<<";\n\t";
 
 #ifdef ISNAN
-        ss<<"if(gid0>=buffer_pv_len || isNan(";
-        ss << vSubArguments[2]->GenSlidingWindowDeclRef();
-        ss<<"))\n\t\t";
-        ss<<"fv = 0;\n\telse \n\t\t";
+    ss<<"if(gid0>=buffer_pv_len || isNan(";
+    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+    ss<<"))\n\t\t";
+    ss<<"pv = 0;\n\telse \n\t\t";
 #endif
-        ss<<"fv = ";
-        ss << vSubArguments[2]->GenSlidingWindowDeclRef();
-        ss<<";\n\t";
-        ss << "tmp = pow(fv/pv,1.0/nper)-1;\n\t;";
-        ss << "return tmp;\n";
-        ss << "}";
-    }
-};
+    ss<<"pv = ";
+    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+    ss<<";\n\t";
 
-class OpRRI:public RRI
-{
-public:
-    virtual std::string GetBottom(void) { return "0"; }
-    virtual std::string BinFuncName(void) const { return "RRI"; }
-};
+#ifdef ISNAN
+    ss<<"if(gid0>=buffer_pv_len || isNan(";
+    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+    ss<<"))\n\t\t";
+    ss<<"fv = 0;\n\telse \n\t\t";
+#endif
+    ss<<"fv = ";
+    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+    ss<<";\n\t";
+    ss << "tmp = pow(fv/pv,1.0/nper)-1;\n\t;";
+    ss << "return tmp;\n";
+    ss << "}";
+}
 
-class OpNominal: public Normal
+void OpNominal::GenSlidingWindowFunction(
+    std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
 {
-public:
-    virtual void GenSlidingWindowFunction(std::stringstream &ss,
-            const std::string sSymName, SubArguments &vSubArguments)
+    ss << "\ndouble " << sSymName;
+    ss << "_"<< BinFuncName() <<"(";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
     {
-        ss << "\ndouble " << sSymName;
-        ss << "_"<< BinFuncName() <<"(";
-        for (unsigned i = 0; i < vSubArguments.size(); i++)
-        {
-            if (i)
-                ss << ",";
-            vSubArguments[i]->GenSlidingWindowDecl(ss);
-        }
-        ss << ") {\n\t";
-        ss << "double tmp = 0;\n\t";
-        ss << "int gid0 = get_global_id(0);\n\t";
-        ss <<"double tmp0 = ";
-        ss <<vSubArguments[0]->GenSlidingWindowDeclRef()<<";\n\t";
-        ss <<"double tmp1 = ";
-        ss <<vSubArguments[1]->GenSlidingWindowDeclRef()<<";\n\t";
-#ifdef ISNAN
-
-        FormulaToken *tmpCur0 = vSubArguments[0]
-            ->GetFormulaToken();
-        const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
-        formula::SingleVectorRefToken *>(tmpCur0);
-        ss<<"if("<<tmpCurDVR0->GetArrayLength()<<"<=gid0||";
-        ss <<"isNan(tmp0))\n\t\t";
-        ss<<" tmp0= 0;\n\t";
-        FormulaToken *tmpCur1 = vSubArguments[1]
-            ->GetFormulaToken();
-        const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
-        formula::SingleVectorRefToken *>(tmpCur1);
-        ss<<"if("<<tmpCurDVR1->GetArrayLength()<<"<=gid0||";
-        ss <<"isNan(tmp1))\n\t\t";
-        ss<<" tmp1= 0;\n\t";
-#endif
-        ss<<"if(tmp1==0)\n\t";
-        ss<<"\treturn 0;\n\t";
-        ss<<"tmp=( pow( tmp0+ 1.0, 1.0 / tmp1 ) - 1.0 ) *";
-        ss<<"tmp1;\n\t";
-        ss << "return tmp;\n";
-        ss << "}";
+        if (i)
+            ss << ",";
+        vSubArguments[i]->GenSlidingWindowDecl(ss);
     }
-    virtual std::string BinFuncName(void) const { return "NOMINAL_ADD"; }
-};
+    ss << ") {\n\t";
+    ss << "double tmp = 0;\n\t";
+    ss << "int gid0 = get_global_id(0);\n\t";
+    ss <<"double tmp0 = ";
+    ss <<vSubArguments[0]->GenSlidingWindowDeclRef()<<";\n\t";
+    ss <<"double tmp1 = ";
+    ss <<vSubArguments[1]->GenSlidingWindowDeclRef()<<";\n\t";
+#ifdef ISNAN
+
+    FormulaToken *tmpCur0 = vSubArguments[0]
+        ->GetFormulaToken();
+    const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+    formula::SingleVectorRefToken *>(tmpCur0);
+    ss<<"if("<<tmpCurDVR0->GetArrayLength()<<"<=gid0||";
+    ss <<"isNan(tmp0))\n\t\t";
+    ss<<" tmp0= 0;\n\t";
+    FormulaToken *tmpCur1 = vSubArguments[1]
+        ->GetFormulaToken();
+    const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
+    formula::SingleVectorRefToken *>(tmpCur1);
+    ss<<"if("<<tmpCurDVR1->GetArrayLength()<<"<=gid0||";
+    ss <<"isNan(tmp1))\n\t\t";
+    ss<<" tmp1= 0;\n\t";
+#endif
+    ss<<"if(tmp1==0)\n\t";
+    ss<<"\treturn 0;\n\t";
+    ss<<"tmp=( pow( tmp0+ 1.0, 1.0 / tmp1 ) - 1.0 ) *";
+    ss<<"tmp1;\n\t";
+    ss << "return tmp;\n";
+    ss << "}";
+}
 
-class OpDollarde:public Normal
+void OpDollarde::GenSlidingWindowFunction(
+    std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
 {
-public:
-        virtual std::string GetBottom(void) { return "0"; }
-        virtual void GenSlidingWindowFunction(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);
-            }
-            ss << ") {\n\t";
-            ss << "double tmp = " << GetBottom() <<";\n\t";
-            ss << "int gid0 = get_global_id(0);\n\t";
-            ss << "double fInt = " << GetBottom() <<";\n\t";
-            ss << "double dollar;\n\t";
-            ss << "double fFrac;\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);
-            ss<< "int buffer_dollar_len = ";
-            ss<< tmpCurDVR0->GetArrayLength();
-            ss << ";\n\t";
-            ss<< "int buffer_frac_len = ";
-            ss<< tmpCurDVR1->GetArrayLength();
-            ss << ";\n\t";
-            #endif
-            #ifdef ISNAN
-            ss<<"if((gid0)>=buffer_dollar_len || isNan(";
-            ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-            ss<<"))\n\t\t";
-            ss<<"dollar = 0;\n\telse \n\t\t";
-            #endif
-            ss<<"dollar = ";
-            ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-            ss<<";\n\t";
-            #ifdef ISNAN
-            ss<<"if((gid0)>=buffer_frac_len || isNan(";
-            ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-            ss<<"))\n\t\t";
-            ss<<"fFrac = 0;\n\telse \n\t\t";
-            #endif
-            ss<<"fFrac = ";
-            ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-            ss<<";\n\t";
-            ss << "tmp = modf( dollar , &fInt );\n\t";
-            ss << "tmp /= fFrac;\n\t";
-            ss << "tmp *= pow( 10.0 , ceil( log10(fFrac ) ) );\n\t";
-            ss << "tmp += fInt;\t";
-            ss << "\n\treturn tmp;\n";
-            ss << "}";
-        }
-virtual std::string BinFuncName(void) const { return "Dollarde"; }
-
-};
-class OpDollarfr:public Normal
-{
-public:
-        virtual std::string GetBottom(void) { return "0"; }
-        virtual void GenSlidingWindowFunction(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);
-            }
-            ss << ") {\n\t";
-            ss << "double tmp = " << GetBottom() <<";\n\t";
-            ss << "int gid0 = get_global_id(0);\n\t";
-            ss << "double fInt = " << GetBottom() <<";\n\t";
-            ss << "double dollar;\n\t";
-            ss << "double fFrac;\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);
-            ss<< "int buffer_dollar_len = ";
-            ss<< tmpCurDVR0->GetArrayLength();
-            ss << ";\n\t";
-            ss<< "int buffer_frac_len = ";
-            ss<< tmpCurDVR1->GetArrayLength();
-            ss << ";\n\t";
-            #endif
-            #ifdef  ISNAN
-            ss<<"if((gid0)>=buffer_dollar_len || isNan(";
-            ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-            ss<<"))\n\t\t";
-            ss<<"dollar = 0;\n\telse \n\t\t";
-            #endif
-            ss<<"dollar = ";
-            ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-            ss<<";\n\t";
-            #ifdef  ISNAN
-            ss<<"if((gid0)>=buffer_frac_len || isNan(";
-            ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-            ss<<"))\n\t\t";
-            ss<<"fFrac = 0;\n\telse \n\t\t";
-            #endif
-            ss<<"fFrac = ";
-            ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-            ss<<";\n\t";
-            ss << "tmp = modf( dollar , &fInt );\n\t";
-            ss << "tmp *= fFrac;\n\t";
-            ss << "tmp *= pow( 10.0 , -ceil( log10(fFrac ) ) );\n\t";
-            ss << "tmp += fInt;\t";
-            ss << "\n\treturn tmp;\n";
-            ss << "}";
-        }
-        virtual std::string BinFuncName(void) const { return "Dollarfr"; }
-
-};
-class OpDISC: public Normal {
-public:
-    virtual std::string GetBottom(void) { return "0"; }
-
-    virtual void GenSlidingWindowFunction(std::stringstream &ss,
-            const std::string sSymName, SubArguments &vSubArguments)
+    ss << "\ndouble " << sSymName;
+    ss << "_"<< BinFuncName() <<"(";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
     {
-
-        ss << "\ndouble " << sSymName;
-        ss << "_"<< BinFuncName() <<"(";
-        for (unsigned i = 0; i < vSubArguments.size(); i++)
-        {
-            if (i)
-                ss << ",";
-            vSubArguments[i]->GenSlidingWindowDecl(ss);
-        }
-        ss << ") {\n\t";
-        ss << "double tmp = " << GetBottom() <<";\n\t";
-        ss << "int gid0 = get_global_id(0);\n\t";
-        ss << "double settle = " << GetBottom() <<";\n\t";
-        ss << "double maturity = " << GetBottom() <<";\n\t";
-        ss << "double price = " << GetBottom() <<";\n\t";
-        ss << "double redemp = " << GetBottom() <<";\n\t";
-        ss << "int mode = " << GetBottom() <<";\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);
-        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);
-        ss<< "int buffer_settle_len = ";
-        ss<< tmpCurDVR0->GetArrayLength();
-        ss << ";\n\t";
-        ss<< "int buffer_maturity_len = ";
-        ss<< tmpCurDVR1->GetArrayLength();
-        ss << ";\n\t";
-        ss<< "int buffer_price_len = ";
-        ss<< tmpCurDVR2->GetArrayLength();
-        ss << ";\n\t";
-        ss<< "int buffer_redemp_len = ";
-        ss<< tmpCurDVR3->GetArrayLength();
-        ss << ";\n\t";
-        ss<< "int buffer_mode_len = ";
-        ss<< tmpCurDVR4->GetArrayLength();
-        ss << ";\n\t";
-        #endif
-        #ifdef  ISNAN
-        ss<<"if((gid0)>=buffer_settle_len || isNan(";
-        ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-        ss<<"))\n\t\t";
-        ss<<"settle = 0;\n\telse \n\t\t";
-        #endif
-        ss<<"settle = ";
-        ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-        ss<<";\n\t";
-        #ifdef  ISNAN
-        ss<<"if((gid0)>=buffer_maturity_len || isNan(";
-        ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-        ss<<"))\n\t\t";
-        ss<<"maturity = 0;\n\telse \n\t\t";
-        #endif
-        ss<<"maturity = ";
-        ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-        ss<<";\n\t";
-        #ifdef  ISNAN
-        ss<<"if((gid0)>=buffer_price_len || isNan(";
-        ss << vSubArguments[2]->GenSlidingWindowDeclRef();
-        ss<<"))\n\t\t";
-        ss<<"price = 0;\n\telse \n\t\t";
-        #endif
-        ss<<"price = ";
-        ss << vSubArguments[2]->GenSlidingWindowDeclRef();
-        ss<<";\n\t";
-        #ifdef  ISNAN
-        ss<<"if((gid0)>=buffer_redemp_len || isNan(";
-        ss << vSubArguments[3]->GenSlidingWindowDeclRef();
-        ss<<"))\n\t\t";
-        ss<<"redemp = 0;\n\telse \n\t\t";
-        #endif
-        ss<<"redemp = ";
-        ss << vSubArguments[3]->GenSlidingWindowDeclRef();
-        ss<<";\n\t";
-        #ifdef  ISNAN
-        ss<<"if((gid0)>=buffer_mode_len || isNan(";
-        ss << vSubArguments[4]->GenSlidingWindowDeclRef();
-        ss<<"))\n\t\t";
-        ss<<"mode = 0;\n\telse \n\t\t";
-        #endif
-        ss<<"mode = ";
-        ss << vSubArguments[4]->GenSlidingWindowDeclRef();
-        ss<<";\n\t";
-        ss << "int nNullDate = GetNullDate( 30 , 12 , 1899 );\n\t";
-        ss << "tmp = 1.0 - price / redemp;\n\t";
-        ss << "tmp /= GetYearFrac( nNullDate , settle , maturity , mode );\n\t";
-        ss << "return tmp;\n";
-        ss << "}";
+        if (i)
+            ss << ",";
+        vSubArguments[i]->GenSlidingWindowDecl(ss);
     }
-    virtual std::string BinFuncName(void) const { return "DISC"; }
-};
-class OpINTRATE: public Normal {
-public:
-    virtual std::string GetBottom(void) { return "0"; }
-
-    virtual void GenSlidingWindowFunction(std::stringstream &ss,
-            const std::string sSymName, SubArguments &vSubArguments)
-    {
+    ss << ") {\n\t";
+    ss << "double tmp = " << GetBottom() <<";\n\t";
+    ss << "int gid0 = get_global_id(0);\n\t";
+    ss << "double fInt = " << GetBottom() <<";\n\t";
+    ss << "double dollar;\n\t";
+    ss << "double fFrac;\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);
+    ss<< "int buffer_dollar_len = ";
+    ss<< tmpCurDVR0->GetArrayLength();
+    ss << ";\n\t";
+    ss<< "int buffer_frac_len = ";
+    ss<< tmpCurDVR1->GetArrayLength();
+    ss << ";\n\t";
+#endif
+#ifdef ISNAN
+    ss<<"if((gid0)>=buffer_dollar_len || isNan(";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss<<"))\n\t\t";
+    ss<<"dollar = 0;\n\telse \n\t\t";
+#endif
+    ss<<"dollar = ";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss<<";\n\t";
+#ifdef ISNAN
+    ss<<"if((gid0)>=buffer_frac_len || isNan(";
+    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+    ss<<"))\n\t\t";
+    ss<<"fFrac = 0;\n\telse \n\t\t";
+#endif
+    ss<<"fFrac = ";
+    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+    ss<<";\n\t";
+    ss << "tmp = modf( dollar , &fInt );\n\t";
+    ss << "tmp /= fFrac;\n\t";
+    ss << "tmp *= pow( 10.0 , ceil( log10(fFrac ) ) );\n\t";
+    ss << "tmp += fInt;\t";
+    ss << "\n\treturn tmp;\n";
+    ss << "}";
+}
 
-        ss << "\ndouble " << sSymName;
-        ss << "_"<< BinFuncName() <<"(";
-        for (unsigned i = 0; i < vSubArguments.size(); i++)
-        {
-            if (i)
-                ss << ",";
-            vSubArguments[i]->GenSlidingWindowDecl(ss);
-        }
-        ss << ") {\n\t";
-        ss << "double tmp = " << GetBottom() <<";\n\t";
-        ss << "int gid0 = get_global_id(0);\n\t";
-        ss << "double settle = " << GetBottom() <<";\n\t";
-        ss << "double maturity = " << GetBottom() <<";\n\t";
-        ss << "double price = " << GetBottom() <<";\n\t";
-        ss << "double redemp = " << GetBottom() <<";\n\t";
-        ss << "int mode = " << GetBottom() <<";\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);
-        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);
-        ss << "int buffer_settle_len = ";
-        ss << tmpCurDVR0->GetArrayLength();
-        ss << ";\n\t";
-        ss << "int buffer_maturity_len = ";
-        ss << tmpCurDVR1->GetArrayLength();
-        ss << ";\n\t";
-        ss << "int buffer_price_len = ";
-        ss << tmpCurDVR2->GetArrayLength();
-        ss << ";\n\t";
-        ss << "int buffer_redemp_len = ";
-        ss << tmpCurDVR3->GetArrayLength();
-        ss << ";\n\t";
-        ss << "int buffer_mode_len = ";
-        ss << tmpCurDVR4->GetArrayLength();
-        ss << ";\n\t";
-        #endif
-        #ifdef  ISNAN
-        ss << "if((gid0)>=buffer_settle_len || isNan(";
-        ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-        ss << "))\n\t\t";
-        ss << "settle = 0;\n\telse \n\t\t";
-        #endif
-        ss << "settle = ";
-        ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-        ss << ";\n\t";
-        #ifdef  ISNAN
-        ss << "if((gid0)>=buffer_maturity_len || isNan(";
-        ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-        ss << "))\n\t\t";
-        ss << "maturity = 0;\n\telse \n\t\t";
-        #endif
-        ss << "maturity = ";
-        ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-        ss << ";\n\t";
-        #ifdef  ISNAN
-        ss << "if((gid0)>=buffer_price_len || isNan(";
-        ss << vSubArguments[2]->GenSlidingWindowDeclRef();
-        ss << "))\n\t\t";
-        ss << "price = 0;\n\telse \n\t\t";
-        #endif
-        ss << "price = ";
-        ss << vSubArguments[2]->GenSlidingWindowDeclRef();
-        ss << ";\n\t";
-        #ifdef  ISNAN
-        ss << "if((gid0)>=buffer_redemp_len || isNan(";
-        ss << vSubArguments[3]->GenSlidingWindowDeclRef();
-        ss << "))\n\t\t";
-        ss << "redemp = 0;\n\telse \n\t\t";
-        #endif
-        ss << "redemp = ";
-        ss << vSubArguments[3]->GenSlidingWindowDeclRef();
-        ss << ";\n\t";
-        #ifdef  ISNAN
-        ss << "if((gid0)>=buffer_mode_len || isNan(";
-        ss << vSubArguments[4]->GenSlidingWindowDeclRef();
-        ss << "))\n\t\t";
-        ss << "mode = 0;\n\telse \n\t\t";
-        #endif
-        ss << "mode = ";
-        ss << vSubArguments[4]->GenSlidingWindowDeclRef();
-        ss << ";\n\t";
-        ss << "int nNullDate = GetNullDate(30,12,1899);\n\t";
-        ss << "tmp = (redemp / price - 1.0) / GetYearDiff(nNullDate, settle, maturity, mode);\n\t";
-        ss << "return tmp;\n";
-        ss << "}";
-    }
-    virtual std::string BinFuncName(void) const { return "INTRATE"; }
-};
-class Fvschedule: public Normal
+void OpDollarfr::GenSlidingWindowFunction(std::stringstream &ss,
+        const std::string sSymName, SubArguments &vSubArguments)
 {
-public:
-    virtual void GenSlidingWindowFunction(std::stringstream &ss,
-            const std::string sSymName, SubArguments &vSubArguments)
+    ss << "\ndouble " << sSymName;
+    ss << "_"<< BinFuncName() <<"(";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
     {
-        FormulaToken* pCur = vSubArguments[1]->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 (i)
-                ss << ",";
-            vSubArguments[i]->GenSlidingWindowDecl(ss);
-        }
-        ss << ") {\n\t";
-        ss << "double tmp = 1.0;\n\t";
-        ss << "int gid0 = get_global_id(0);\n\t";
-        ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
-        ss << ";\n\t";
-        #ifdef  ISNAN
-        ss << "if (isNan(arg0))\n\t\t";
-        ss << "arg0 = 0;\n\t";
-        #endif
-        ss << "double arg1;\n\t";
-        ss << "int arrayLength = " << pCurDVR->GetArrayLength() << ";\n\t";
-        #ifdef  ISNAN
-        ss << "for (int i = 0; i + gid0 < arrayLength &&";
-        ss << " i < " << nCurWindowSize << "; i++){\n\t\t";
-        #else
-        ss << "for (int i = 0; i < " << nCurWindowSize << "; i++){\n\t\t";
-        #endif
-        ss << "arg1 = ";
-        ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n\t\t\t";
-        #ifdef ISNAN
-        ss << "if (isNan(arg1))\n\t\t\t\t";
-        ss << "arg1 = 0;\n\t\t\t";
-        #endif
-        ss << "tmp *= arg1 + 1.0;\n\t\t";
-        ss << "}\n\t";
-        ss << "return (double)tmp * arg0";
-        ss << ";\n}";
+        if (i)
+            ss << ",";
+        vSubArguments[i]->GenSlidingWindowDecl(ss);
     }
-};
+    ss << ") {\n\t";
+    ss << "double tmp = " << GetBottom() <<";\n\t";
+    ss << "int gid0 = get_global_id(0);\n\t";
+    ss << "double fInt = " << GetBottom() <<";\n\t";
+    ss << "double dollar;\n\t";
+    ss << "double fFrac;\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);
+    ss<< "int buffer_dollar_len = ";
+    ss<< tmpCurDVR0->GetArrayLength();
+    ss << ";\n\t";
+    ss<< "int buffer_frac_len = ";
+    ss<< tmpCurDVR1->GetArrayLength();
+    ss << ";\n\t";
+#endif
+#ifdef  ISNAN
+    ss<<"if((gid0)>=buffer_dollar_len || isNan(";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss<<"))\n\t\t";
+    ss<<"dollar = 0;\n\telse \n\t\t";
+#endif
+    ss<<"dollar = ";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss<<";\n\t";
+#ifdef  ISNAN
+    ss<<"if((gid0)>=buffer_frac_len || isNan(";
+    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+    ss<<"))\n\t\t";
+    ss<<"fFrac = 0;\n\telse \n\t\t";
+#endif
+    ss<<"fFrac = ";
+    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+    ss<<";\n\t";
+    ss << "tmp = modf( dollar , &fInt );\n\t";
+    ss << "tmp *= fFrac;\n\t";
+    ss << "tmp *= pow( 10.0 , -ceil( log10(fFrac ) ) );\n\t";
+    ss << "tmp += fInt;\t";
+    ss << "\n\treturn tmp;\n";
+    ss << "}";
+}
 
-class Cumipmt: public Normal
+void OpDISC::GenSlidingWindowFunction(
+    std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
 {
-public:
-    virtual void GenSlidingWindowFunction(std::stringstream &ss,
-            const std::string sSymName, SubArguments &vSubArguments)
+    ss << "\ndouble " << sSymName;
+    ss << "_"<< BinFuncName() <<"(";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
     {
-        ss << "\ndouble " << sSymName;
-        ss << "_"<< BinFuncName() <<"(";
-        for (unsigned i = 0; i < vSubArguments.size(); i++)
-        {
-            if (i)
-                ss << ",";
-            vSubArguments[i]->GenSlidingWindowDecl(ss);
-        }
-        ss << ") {\n\t";
-
-        ss << "   int gid0 = get_global_id(0);\n";
-        ss << "double fRate,fVal;\n\t";
-        ss <<"int nStartPer,nEndPer,nNumPeriods,nPayType;\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);
-        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);
-        ss<< "int buffer_rate_len = ";
-        ss<< tmpCurDVR0->GetArrayLength();
-        ss << ";\n\t";
-        ss<< "int buffer_NumPeriods_len = ";
-        ss<< tmpCurDVR1->GetArrayLength();
-        ss << ";\n\t";
-        ss<< "int buffer_Val_len = ";
-        ss<< tmpCurDVR2->GetArrayLength();
-        ss << ";\n\t";
-        ss<< "int buffer_StartPer_len = ";
-        ss<< tmpCurDVR3->GetArrayLength();
-        ss << ";\n\t";
-        ss<< "int buffer_EndPer_len = ";
-        ss<< tmpCurDVR4->GetArrayLength();
-        ss << ";\n\t";
-        ss<< "int buffer_PayType_len = ";
-        ss<< tmpCurDVR5->GetArrayLength();
-        ss << ";\n\t";
-#endif
-#ifdef ISNAN
-        ss <<"if(gid0 >= buffer_rate_len || isNan(";
-        ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
-        ss <<"))\n\t\t";
-        ss <<"fRate = 0;\n\telse\n\t\t";
-#endif
-        ss <<"fRate = "<<vSubArguments[0]->GenSlidingWindowDeclRef();
-        ss <<";\n\t";
-#ifdef ISNAN
-        ss <<"if(gid0 >= buffer_NumPeriods_len || isNan(";
-        ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
-        ss <<"))\n\t\t";
-        ss <<"nNumPeriods = 0;\n\telse\n\t\t";
-#endif
-        ss <<"nNumPeriods = (int)";
-        ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
-        ss <<";\n\t";
-#ifdef ISNAN
-        ss <<"if(gid0 >= buffer_Val_len || isNan(";
-        ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
-        ss <<"))\n\t\t";
-        ss <<"fVal = 0;\n\telse\n\t\t";
-#endif
-        ss <<"fVal = "<<vSubArguments[2]->GenSlidingWindowDeclRef();
-        ss <<";\n\t";
-#ifdef ISNAN
-        ss <<"if(gid0 >= buffer_StartPer_len || isNan(";
-        ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
-        ss <<"))\n\t\t";
-        ss <<"nStartPer = 0;\n\telse\n\t\t";
-#endif
-        ss <<"nStartPer = (int)"<<vSubArguments[3]->GenSlidingWindowDeclRef();
-        ss <<";\n\t";
-#ifdef ISNAN
-        ss <<"if(gid0 >= buffer_EndPer_len || isNan(";
-        ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
-        ss <<"))\n\t\t";
-        ss <<"nEndPer = 0;\n\telse\n\t\t";
-#endif
-        ss <<"nEndPer = (int)"<<vSubArguments[4]->GenSlidingWindowDeclRef();
-        ss <<";\n\t";
-#ifdef ISNAN
-        ss <<"if(gid0 >= buffer_PayType_len || isNan(";
-        ss <<vSubArguments[5]->GenSlidingWindowDeclRef();
-        ss <<"))\n\t\t";
-        ss <<"nPayType = 0;\n\telse\n\t\t";
-#endif
-        ss <<"nPayType = (int)"<<vSubArguments[5]->GenSlidingWindowDeclRef();
-        ss <<";\n\t";
-        ss << "   double fRmz;\n";
-        ss << "fRmz = GetRmz( fRate, nNumPeriods, fVal, 0.0, nPayType );\n";
-        ss << "double tmp = 0.0;\n";
-        ss << "uint  nStart =  nStartPer ;\n";
-        ss << "uint  nEnd =  nEndPer ;\n";
-        ss << " if( nStart == 1 )\n";
-        ss << "    {\n";
-        ss << "        if( nPayType <= 0 )\n";
-        ss << "            tmp = -fVal;\n";
-        ss << "        nStart++;\n";
-        ss << "    }\n";
-        ss << " for( uint i = nStart ; i <= nEnd ; i++ )\n";
-        ss << " {\n";
-        ss << "     if( nPayType > 0 )\n";
-        ss << "        tmp += GetZw( fRate, convert_double( i - 2 ), ";
-        ss << "fRmz, fVal, 1 ) - fRmz;\n";
-        ss << "     else\n";
-        ss << "        tmp += GetZw( fRate, convert_double( i - 1 ), ";
-        ss << "fRmz, fVal, 0 );\n";
-        ss << " }\n";
-        ss << "tmp *= fRate;\n";
-        ss << "return tmp;\n";
-        ss << "}";
-
+        if (i)
+            ss << ",";
+        vSubArguments[i]->GenSlidingWindowDecl(ss);
     }
-};
+    ss << ") {\n\t";
+    ss << "double tmp = " << GetBottom() <<";\n\t";
+    ss << "int gid0 = get_global_id(0);\n\t";
+    ss << "double settle = " << GetBottom() <<";\n\t";
+    ss << "double maturity = " << GetBottom() <<";\n\t";
+    ss << "double price = " << GetBottom() <<";\n\t";
+    ss << "double redemp = " << GetBottom() <<";\n\t";
+    ss << "int mode = " << GetBottom() <<";\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);
+    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);
+    ss<< "int buffer_settle_len = ";
+    ss<< tmpCurDVR0->GetArrayLength();
+    ss << ";\n\t";
+    ss<< "int buffer_maturity_len = ";
+    ss<< tmpCurDVR1->GetArrayLength();
+    ss << ";\n\t";
+    ss<< "int buffer_price_len = ";
+    ss<< tmpCurDVR2->GetArrayLength();
+    ss << ";\n\t";
+    ss<< "int buffer_redemp_len = ";
+    ss<< tmpCurDVR3->GetArrayLength();
+    ss << ";\n\t";
+    ss<< "int buffer_mode_len = ";
+    ss<< tmpCurDVR4->GetArrayLength();
+    ss << ";\n\t";
+#endif
+#ifdef  ISNAN
+    ss<<"if((gid0)>=buffer_settle_len || isNan(";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss<<"))\n\t\t";
+    ss<<"settle = 0;\n\telse \n\t\t";
+#endif
+    ss<<"settle = ";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss<<";\n\t";
+#ifdef  ISNAN
+    ss<<"if((gid0)>=buffer_maturity_len || isNan(";
+    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+    ss<<"))\n\t\t";
+    ss<<"maturity = 0;\n\telse \n\t\t";
+#endif
+    ss<<"maturity = ";
+    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+    ss<<";\n\t";
+#ifdef  ISNAN
+    ss<<"if((gid0)>=buffer_price_len || isNan(";
+    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+    ss<<"))\n\t\t";
+    ss<<"price = 0;\n\telse \n\t\t";
+#endif
+    ss<<"price = ";
+    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+    ss<<";\n\t";
+#ifdef  ISNAN
+    ss<<"if((gid0)>=buffer_redemp_len || isNan(";
+    ss << vSubArguments[3]->GenSlidingWindowDeclRef();
+    ss<<"))\n\t\t";
+    ss<<"redemp = 0;\n\telse \n\t\t";
+#endif
+    ss<<"redemp = ";
+    ss << vSubArguments[3]->GenSlidingWindowDeclRef();
+    ss<<";\n\t";
+#ifdef  ISNAN
+    ss<<"if((gid0)>=buffer_mode_len || isNan(";
+    ss << vSubArguments[4]->GenSlidingWindowDeclRef();
+    ss<<"))\n\t\t";
+    ss<<"mode = 0;\n\telse \n\t\t";
+#endif
+    ss<<"mode = ";
+    ss << vSubArguments[4]->GenSlidingWindowDeclRef();
+    ss<<";\n\t";
+    ss << "int nNullDate = GetNullDate( 30 , 12 , 1899 );\n\t";
+    ss << "tmp = 1.0 - price / redemp;\n\t";
+    ss << "tmp /= GetYearFrac( nNullDate , settle , maturity , mode );\n\t";
+    ss << "return tmp;\n";
+    ss << "}";
+}
 
-class IRR: public Normal
+void OpINTRATE::GenSlidingWindowFunction(
+    std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
 {
-public:
-    virtual void GenSlidingWindowFunction(std::stringstream &ss,
-            const std::string sSymName, SubArguments &vSubArguments)
+    ss << "\ndouble " << sSymName;
+    ss << "_"<< BinFuncName() <<"(";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
     {
-        FormulaToken* pCur = vSubArguments[0]->GetFormulaToken();
-        assert(pCur);
-        const formula::DoubleVectorRefToken* pCurDVR =
-            dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
-        size_t nCurWindowSize = pCurDVR->GetRefRowSize();
-        FormulaToken* pCur1 = vSubArguments[1]->GetFormulaToken();
-        assert(pCur1);
-        const formula::SingleVectorRefToken* pSVR1 =
-            dynamic_cast< const formula::SingleVectorRefToken* >(pCur1);
-        assert(pSVR1);
-        ss << "\ndouble " << sSymName;
-        ss << "_"<< BinFuncName() <<"(";
-        for (unsigned i = 0; i < vSubArguments.size(); i++)
-        {
-            if (i)
-                ss << ",";
-            vSubArguments[i]->GenSlidingWindowDecl(ss);
-        }
-        ss << ") {\n";
-        ss << "#define  Epsilon   1.0E-7\n\t";
-        ss << "int gid0 = get_global_id(0);\n\t";
-        ss << "double fSchaetzwert = ";
-        ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n\t";
-        ss << "double fEps = 1.0;\n\t";
-        ss << "double x = 0.0, xNeu = 0.0, fZaehler = 0.0, fNenner = 0.0;\n\t";
-        ss << "double nCount = 0.0;\n\t";
-        ss << "int argLen1 = " << pSVR1->GetArrayLength() << ";\n\t";
-        #ifdef  ISNAN
-        ss << "if (gid0 >= argLen1)\n\t\t";
-        ss << "fSchaetzwert = 0.1;\n\t";
-        ss << "if (isNan(fSchaetzwert))\n\t\t";
-        ss << "x = 0.1;\n\t";
-        ss << "else\n\t\t";
-        #endif
-        ss << "x = fSchaetzwert;\n\t";
-        ss << "unsigned short nItCount = 0;\n\t";
-        ss << "while (fEps > Epsilon && nItCount < 20){\n\t\t";
-        ss << "nCount = 0.0;\n\t\tfZaehler = 0.0;\n\t\tfNenner = 0.0;\n\t\t";
-        ss << "double arg0;\n\t\t";
-        ss << "int arrayLength = " << pCurDVR->GetArrayLength() << ";\n\t";
-        #ifdef  ISNAN
-        ss << "for (int i = 0; i + gid0 < arrayLength &&";
-        ss << " i < " << nCurWindowSize << "; i++){\n\t\t\t";
-        #else
-        ss << "for (int i = 0; i < " << nCurWindowSize << "; i++){\n\t\t\t";
-        #endif
-        ss << "arg0 = ";
-        ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n\t\t\t";
-        #ifdef  ISNAN
-        ss << "if (isNan(arg0))\n\t\t\t\t";
-        ss << "continue;\n\t\t\t";
-        #endif
-        ss << "fZaehler += arg0  / pow(1.0+x, nCount);\n\t\t\t";
-        ss << "fNenner  += -nCount * arg0 / pow(1.0+x,nCount+1.0);\n\t\t\t";
-        ss << "nCount+=1;\n";
-        ss << "\n\t\t}\n\t\t";
-        ss << "xNeu = x - fZaehler / fNenner;\n\t\t";
-        ss << "fEps = fabs(xNeu - x);\n\t\t";
-        ss << "x = xNeu;\n\t\t";
-        ss << "nItCount++;\n\t}\n\t";
-        ss << "if (fSchaetzwert == 0.0 && fabs(x) < Epsilon)\n\t\t";
-        ss << "x = 0.0;\n\t";
-        ss << "if (fEps < Epsilon)\n\t\t";
-        ss << "return x;\n\t";
-        ss << "else\n\t\t";
-        ss << "return (double)523;\n";
-        ss << "}";
+        if (i)
+            ss << ",";
+        vSubArguments[i]->GenSlidingWindowDecl(ss);
     }
-};
-class OpIRR: public IRR{
-public:
-    virtual std::string GetBottom(void) { return "0"; }
-    virtual std::string BinFuncName(void) const { return "IRR"; }
-};
-
-class XNPV: public Normal
+    ss << ") {\n\t";
+    ss << "double tmp = " << GetBottom() <<";\n\t";
+    ss << "int gid0 = get_global_id(0);\n\t";
+    ss << "double settle = " << GetBottom() <<";\n\t";
+    ss << "double maturity = " << GetBottom() <<";\n\t";
+    ss << "double price = " << GetBottom() <<";\n\t";
+    ss << "double redemp = " << GetBottom() <<";\n\t";
+    ss << "int mode = " << GetBottom() <<";\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);
+    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);
+    ss << "int buffer_settle_len = ";
+    ss << tmpCurDVR0->GetArrayLength();
+    ss << ";\n\t";
+    ss << "int buffer_maturity_len = ";
+    ss << tmpCurDVR1->GetArrayLength();
+    ss << ";\n\t";
+    ss << "int buffer_price_len = ";
+    ss << tmpCurDVR2->GetArrayLength();
+    ss << ";\n\t";
+    ss << "int buffer_redemp_len = ";
+    ss << tmpCurDVR3->GetArrayLength();
+    ss << ";\n\t";
+    ss << "int buffer_mode_len = ";
+    ss << tmpCurDVR4->GetArrayLength();
+    ss << ";\n\t";
+#endif
+#ifdef  ISNAN
+    ss << "if((gid0)>=buffer_settle_len || isNan(";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss << "))\n\t\t";
+    ss << "settle = 0;\n\telse \n\t\t";
+#endif
+    ss << "settle = ";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss << ";\n\t";
+#ifdef  ISNAN
+    ss << "if((gid0)>=buffer_maturity_len || isNan(";
+    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+    ss << "))\n\t\t";
+    ss << "maturity = 0;\n\telse \n\t\t";
+#endif
+    ss << "maturity = ";
+    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+    ss << ";\n\t";
+#ifdef  ISNAN
+    ss << "if((gid0)>=buffer_price_len || isNan(";
+    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+    ss << "))\n\t\t";
+    ss << "price = 0;\n\telse \n\t\t";
+#endif
+    ss << "price = ";
+    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+    ss << ";\n\t";
+#ifdef  ISNAN
+    ss << "if((gid0)>=buffer_redemp_len || isNan(";
+    ss << vSubArguments[3]->GenSlidingWindowDeclRef();
+    ss << "))\n\t\t";
+    ss << "redemp = 0;\n\telse \n\t\t";
+#endif
+    ss << "redemp = ";
+    ss << vSubArguments[3]->GenSlidingWindowDeclRef();
+    ss << ";\n\t";
+#ifdef  ISNAN
+    ss << "if((gid0)>=buffer_mode_len || isNan(";
+    ss << vSubArguments[4]->GenSlidingWindowDeclRef();
+    ss << "))\n\t\t";
+    ss << "mode = 0;\n\telse \n\t\t";
+#endif
+    ss << "mode = ";
+    ss << vSubArguments[4]->GenSlidingWindowDeclRef();
+    ss << ";\n\t";
+    ss << "int nNullDate = GetNullDate(30,12,1899);\n\t";
+    ss << "tmp = (redemp / price - 1.0) / GetYearDiff(nNullDate, settle, maturity, mode);\n\t";
+    ss << "return tmp;\n";
+    ss << "}";
+}
+
+void Fvschedule::GenSlidingWindowFunction(
+    std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
 {
-    public:
-    virtual void GenSlidingWindowFunction(std::stringstream &ss,
-            const std::string sSymName, SubArguments &vSubArguments)
+    FormulaToken* pCur = vSubArguments[1]->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++)
     {
-        FormulaToken *pCur = vSubArguments[1]->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 (i)
-                ss << ",";
-            vSubArguments[i]->GenSlidingWindowDecl(ss);
-        }
-
-        ss << ") {\n\t";
-        ss << "double result = 0.0;\n\t";
-        ss << "int gid0 = get_global_id(0);\n\t";
-        ss << "int i=0;\n\t";
-        if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
-            ss<< "i=gid0;\n\t";
-        }
-        ss << "double date;\n\t";
-        ss << "double value;\n\t";
-        ss << "double rate;\n\t";
-        ss << "double dateNull;\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::DoubleVectorRefToken*tmpCurDVR1= dynamic_cast<const
-        formula::DoubleVectorRefToken *>(tmpCur1);
-
-        FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
-        const formula::DoubleVectorRefToken*tmpCurDVR2= dynamic_cast<const
-        formula::DoubleVectorRefToken *>(tmpCur2);
-        ss<< "int buffer_rate_len = ";
-        ss<< tmpCurDVR0->GetArrayLength();
-        ss << ";\n\t";
-        ss<< "int buffer_value_len = ";
-        ss<< tmpCurDVR1->GetArrayLength();
-        ss << ";\n\t";
-        ss<< "int buffer_date_len = ";
-        ss<< tmpCurDVR2->GetArrayLength();
-        ss << ";\n\t";
-#endif
-#ifdef ISNAN
-        ss<<"if((i+gid0)>=buffer_date_len || isNan(";
-        ss << vSubArguments[2]->GenSlidingWindowDeclRef();
-        ss<<"))\n\t\t";
-        ss<<"dateNull = 0;\n\telse \n\t\t";
-#endif
-        ss<<"dateNull = ";
-        ss << vSubArguments[2]->GenSlidingWindowDeclRef();
-        ss<<";\n\t";
+        if (i)
+            ss << ",";
+        vSubArguments[i]->GenSlidingWindowDecl(ss);
+    }
+    ss << ") {\n\t";
+    ss << "double tmp = 1.0;\n\t";
+    ss << "int gid0 = get_global_id(0);\n\t";
+    ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss << ";\n\t";
 #ifdef ISNAN
-        ss<<"if((i+gid0)>=buffer_rate_len || isNan(";
-        ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-        ss<<"))\n\t\t";
-        ss<<"rate = 0;\n\telse \n\t\t";
+    ss << "if (isNan(arg0))\n\t\t";
+    ss << "arg0 = 0;\n\t";
 #endif
-        ss<<"rate = ";
-        ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-        ss<<";\n\t";
-        ss << "for (int i = ";
-         if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
-             ss << "gid0; i < "<< nCurWindowSize <<"; i++)\n\t\t";
-         } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) {
-             ss << "0; i < gid0+"<< nCurWindowSize <<"; i++)\n\t\t";
-         } else {
-             ss << "0; i < "<< nCurWindowSize <<"; i++)\n\t\t";
-         }
-        ss << "{\n\t";
-        ss << "result += ";
-        ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-        ss << "/(pow((";
-        ss<<vSubArguments[0]->GenSlidingWindowDeclRef();
-        ss <<"+1),(";
-        ss << vSubArguments[2]->GenSlidingWindowDeclRef();
-        ss << "-dateNull)/365));\n\t";
-        ss <<"}\n\t";
-
-        ss << "return result;\n";
-        ss << "}";
-    }
-};
-class PriceMat: public Normal
+    ss << "double arg1;\n\t";
+    ss << "int arrayLength = " << pCurDVR->GetArrayLength() << ";\n\t";
+#ifdef ISNAN
+    ss << "for (int i = 0; i + gid0 < arrayLength &&";
+    ss << " i < " << nCurWindowSize << "; i++){\n\t\t";
+#else
+    ss << "for (int i = 0; i < " << nCurWindowSize << "; i++){\n\t\t";
+#endif
+    ss << "arg1 = ";
+    ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n\t\t\t";
+#ifdef ISNAN
+    ss << "if (isNan(arg1))\n\t\t\t\t";
+    ss << "arg1 = 0;\n\t\t\t";
+#endif
+    ss << "tmp *= arg1 + 1.0;\n\t\t";
+    ss << "}\n\t";
+    ss << "return (double)tmp * arg0";
+    ss << ";\n}";
+}
+
+void Cumipmt::GenSlidingWindowFunction(
+    std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
 {
-         public:
-    virtual void GenSlidingWindowFunction(std::stringstream &ss,
-            const std::string sSymName, SubArguments &vSubArguments)
+    ss << "\ndouble " << sSymName;
+    ss << "_"<< BinFuncName() <<"(";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
     {
-        ss << "\ndouble " << sSymName;
-        ss << "_"<< BinFuncName() <<"(";
-        for (unsigned i = 0; i < vSubArguments.size(); i++)
-        {
-            if (i)
-                ss << ",";
-            vSubArguments[i]->GenSlidingWindowDecl(ss);
-        }
-        ss << ") {\n\t";
-        ss << "int gid0 = get_global_id(0);\n\t";
-        ss << "double result=0;\n\t";
-        ss<< "int nNullDate = GetNullDate( );\n\t";
-        ss <<"int settle;\n\t";
-        ss <<"int mat;\n\t";
-        ss <<"int issue;\n\t";
-        ss <<"double rate;\n\t";
-        ss <<"double yield;\n\t";
-        ss <<"int  nBase;\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);
-        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);
-
-        ss<< "int buffer_settle_len = ";
-        ss<< tmpCurDVR0->GetArrayLength();
-        ss << ";\n\t";
-         ss<< "int buffer_mat_len = ";
-        ss<< tmpCurDVR1->GetArrayLength();
-        ss << ";\n\t";
-        ss<< "int buffer_issue_len = ";
-        ss<< tmpCurDVR2->GetArrayLength();
-        ss << ";\n\t";
-        ss<< "int buffer_rate_len = ";
-        ss<< tmpCurDVR3->GetArrayLength();
-        ss << ";\n\t";
-        ss<< "int buffer_yield_len = ";
-        ss<< tmpCurDVR4->GetArrayLength();
-        ss << ";\n\t";
-        ss<< "int buffer_base_len = ";
-        ss<< tmpCurDVR5->GetArrayLength();
-        ss << ";\n\t";
-#endif
-#ifdef ISNAN
-        ss<<"if(gid0>=buffer_settle_len || isNan(";
-        ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-        ss<<"))\n\t\t";
-        ss<<"settle = 0;\n\telse \n\t\t";
-#endif
-        ss<<"settle = ";
-        ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-        ss<<";\n\t";
+        if (i)
+            ss << ",";
+        vSubArguments[i]->GenSlidingWindowDecl(ss);
+    }
+    ss << ") {\n\t";
+
+    ss << "   int gid0 = get_global_id(0);\n";
+    ss << "double fRate,fVal;\n\t";
+    ss <<"int nStartPer,nEndPer,nNumPeriods,nPayType;\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);
+    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);
+    ss<< "int buffer_rate_len = ";
+    ss<< tmpCurDVR0->GetArrayLength();
+    ss << ";\n\t";
+    ss<< "int buffer_NumPeriods_len = ";
+    ss<< tmpCurDVR1->GetArrayLength();
+    ss << ";\n\t";
+    ss<< "int buffer_Val_len = ";
+    ss<< tmpCurDVR2->GetArrayLength();
+    ss << ";\n\t";
+    ss<< "int buffer_StartPer_len = ";
+    ss<< tmpCurDVR3->GetArrayLength();
+    ss << ";\n\t";
+    ss<< "int buffer_EndPer_len = ";
+    ss<< tmpCurDVR4->GetArrayLength();
+    ss << ";\n\t";
+    ss<< "int buffer_PayType_len = ";
+    ss<< tmpCurDVR5->GetArrayLength();
+    ss << ";\n\t";
+#endif
+#ifdef ISNAN
+    ss <<"if(gid0 >= buffer_rate_len || isNan(";
+    ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss <<"))\n\t\t";
+    ss <<"fRate = 0;\n\telse\n\t\t";
+#endif
+    ss <<"fRate = "<<vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss <<";\n\t";
 #ifdef ISNAN
-        ss<<"if(gid0>=buffer_mat_len || isNan(";
-        ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-        ss<<"))\n\t\t";
-        ss<<"mat = 0;\n\telse \n\t\t";
+    ss <<"if(gid0 >= buffer_NumPeriods_len || isNan(";
+    ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
+    ss <<"))\n\t\t";
+    ss <<"nNumPeriods = 0;\n\telse\n\t\t";
 #endif
-        ss<<"mat = ";
-        ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-        ss<<";\n\t";
+    ss <<"nNumPeriods = (int)";
+    ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
+    ss <<";\n\t";
 #ifdef ISNAN
-        ss<<"if(gid0>=buffer_issue_len || isNan(";
-        ss << vSubArguments[2]->GenSlidingWindowDeclRef();
-        ss<<"))\n\t\t";
-        ss<<"issue = 0;\n\telse \n\t\t";
+    ss <<"if(gid0 >= buffer_Val_len || isNan(";
+    ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
+    ss <<"))\n\t\t";
+    ss <<"fVal = 0;\n\telse\n\t\t";
 #endif
-        ss<<"issue = ";
-        ss << vSubArguments[2]->GenSlidingWindowDeclRef();
-        ss<<";\n\t";
+    ss <<"fVal = "<<vSubArguments[2]->GenSlidingWindowDeclRef();
+    ss <<";\n\t";
 #ifdef ISNAN
-        ss<<"if(gid0>=buffer_rate_len || isNan(";
-        ss << vSubArguments[3]->GenSlidingWindowDeclRef();
-        ss<<"))\n\t\t";
-        ss<<"rate = 0;\n\telse \n\t\t";
+    ss <<"if(gid0 >= buffer_StartPer_len || isNan(";
+    ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
+    ss <<"))\n\t\t";
+    ss <<"nStartPer = 0;\n\telse\n\t\t";
 #endif
-        ss<<"rate = ";
-        ss << vSubArguments[3]->GenSlidingWindowDeclRef();
-        ss<<";\n\t";
+    ss <<"nStartPer = (int)"<<vSubArguments[3]->GenSlidingWindowDeclRef();
+    ss <<";\n\t";
 #ifdef ISNAN
-        ss<<"if(gid0>=buffer_yield_len || isNan(";
-        ss << vSubArguments[4]->GenSlidingWindowDeclRef();
-        ss<<"))\n\t\t";
-        ss<<"yield = 0;\n\telse \n\t\t";
+    ss <<"if(gid0 >= buffer_EndPer_len || isNan(";
+    ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
+    ss <<"))\n\t\t";
+    ss <<"nEndPer = 0;\n\telse\n\t\t";
 #endif
-        ss<<"yield = ";
-        ss << vSubArguments[4]->GenSlidingWindowDeclRef();
-        ss<<";\n\t";
+    ss <<"nEndPer = (int)"<<vSubArguments[4]->GenSlidingWindowDeclRef();
+    ss <<";\n\t";
 #ifdef ISNAN
-        ss<<"if(gid0>=buffer_base_len || isNan(";
-        ss << vSubArguments[5]->GenSlidingWindowDeclRef();
-        ss<<"))\n\t\t";
-        ss<<"nBase = 0;\n\telse \n\t\t";
+    ss <<"if(gid0 >= buffer_PayType_len || isNan(";
+    ss <<vSubArguments[5]->GenSlidingWindowDeclRef();
+    ss <<"))\n\t\t";
+    ss <<"nPayType = 0;\n\telse\n\t\t";
 #endif
-        ss<<"nBase = ";
-        ss << vSubArguments[5]->GenSlidingWindowDeclRef();
-        ss<<";\n\t";
-        ss<< "double fIssMat = GetYearFrac( nNullDate, issue, mat, nBase);\n";
-        ss<<"double fIssSet = GetYearFrac( nNullDate, issue, settle,nBase);\n";
-        ss<<"double fSetMat = GetYearFrac( nNullDate, settle, mat, nBase);\n";
-        ss<<"result = 1.0 + fIssMat * rate;\n\t";
-        ss<<"result /= 1.0 + fSetMat * yield;\n\t";
-        ss<<"result -= fIssSet * rate;\n\t";
-        ss<<"result*= 100.0;\n\t";
-        ss<<"return result;\n\t";
-        ss<<"}\n";
-        }
-};
-class OpSYD: public Normal
+    ss <<"nPayType = (int)"<<vSubArguments[5]->GenSlidingWindowDeclRef();
+    ss <<";\n\t";
+    ss << "   double fRmz;\n";
+    ss << "fRmz = GetRmz( fRate, nNumPeriods, fVal, 0.0, nPayType );\n";
+    ss << "double tmp = 0.0;\n";
+    ss << "uint  nStart =  nStartPer ;\n";
+    ss << "uint  nEnd =  nEndPer ;\n";
+    ss << " if( nStart == 1 )\n";
+    ss << "    {\n";
+    ss << "        if( nPayType <= 0 )\n";
+    ss << "            tmp = -fVal;\n";
+    ss << "        nStart++;\n";
+    ss << "    }\n";
+    ss << " for( uint i = nStart ; i <= nEnd ; i++ )\n";
+    ss << " {\n";
+    ss << "     if( nPayType > 0 )\n";
+    ss << "        tmp += GetZw( fRate, convert_double( i - 2 ), ";
+    ss << "fRmz, fVal, 1 ) - fRmz;\n";
+    ss << "     else\n";
+    ss << "        tmp += GetZw( fRate, convert_double( i - 1 ), ";
+    ss << "fRmz, fVal, 0 );\n";
+    ss << " }\n";
+    ss << "tmp *= fRate;\n";
+    ss << "return tmp;\n";
+    ss << "}";
+}
+
+void IRR::GenSlidingWindowFunction(std::stringstream &ss,
+            const std::string sSymName, SubArguments &vSubArguments)
+{
+    FormulaToken* pCur = vSubArguments[0]->GetFormulaToken();
+    assert(pCur);
+    const formula::DoubleVectorRefToken* pCurDVR =
+        dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+    size_t nCurWindowSize = pCurDVR->GetRefRowSize();
+    FormulaToken* pCur1 = vSubArguments[1]->GetFormulaToken();
+    assert(pCur1);
+    const formula::SingleVectorRefToken* pSVR1 =
+        dynamic_cast< const formula::SingleVectorRefToken* >(pCur1);
+    assert(pSVR1);
+    ss << "\ndouble " << sSymName;
+    ss << "_"<< BinFuncName() <<"(";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
+    {
+        if (i)
+            ss << ",";
+        vSubArguments[i]->GenSlidingWindowDecl(ss);
+    }
+    ss << ") {\n";
+    ss << "#define  Epsilon   1.0E-7\n\t";
+    ss << "int gid0 = get_global_id(0);\n\t";
+    ss << "double fSchaetzwert = ";
+    ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n\t";
+    ss << "double fEps = 1.0;\n\t";
+    ss << "double x = 0.0, xNeu = 0.0, fZaehler = 0.0, fNenner = 0.0;\n\t";
+    ss << "double nCount = 0.0;\n\t";
+    ss << "int argLen1 = " << pSVR1->GetArrayLength() << ";\n\t";
+#ifdef ISNAN
+    ss << "if (gid0 >= argLen1)\n\t\t";
+    ss << "fSchaetzwert = 0.1;\n\t";
+    ss << "if (isNan(fSchaetzwert))\n\t\t";
+    ss << "x = 0.1;\n\t";
+    ss << "else\n\t\t";
+#endif
+    ss << "x = fSchaetzwert;\n\t";
+    ss << "unsigned short nItCount = 0;\n\t";
+    ss << "while (fEps > Epsilon && nItCount < 20){\n\t\t";
+    ss << "nCount = 0.0;\n\t\tfZaehler = 0.0;\n\t\tfNenner = 0.0;\n\t\t";
+    ss << "double arg0;\n\t\t";
+    ss << "int arrayLength = " << pCurDVR->GetArrayLength() << ";\n\t";
+#ifdef ISNAN
+    ss << "for (int i = 0; i + gid0 < arrayLength &&";
+    ss << " i < " << nCurWindowSize << "; i++){\n\t\t\t";
+#else
+    ss << "for (int i = 0; i < " << nCurWindowSize << "; i++){\n\t\t\t";
+#endif
+    ss << "arg0 = ";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n\t\t\t";
+#ifdef  ISNAN
+    ss << "if (isNan(arg0))\n\t\t\t\t";
+    ss << "continue;\n\t\t\t";
+#endif
+    ss << "fZaehler += arg0  / pow(1.0+x, nCount);\n\t\t\t";
+    ss << "fNenner  += -nCount * arg0 / pow(1.0+x,nCount+1.0);\n\t\t\t";
+    ss << "nCount+=1;\n";
+    ss << "\n\t\t}\n\t\t";
+    ss << "xNeu = x - fZaehler / fNenner;\n\t\t";
+    ss << "fEps = fabs(xNeu - x);\n\t\t";
+    ss << "x = xNeu;\n\t\t";
+    ss << "nItCount++;\n\t}\n\t";
+    ss << "if (fSchaetzwert == 0.0 && fabs(x) < Epsilon)\n\t\t";
+    ss << "x = 0.0;\n\t";
+    ss << "if (fEps < Epsilon)\n\t\t";
+    ss << "return x;\n\t";
+    ss << "else\n\t\t";
+    ss << "return (double)523;\n";
+    ss << "}";
+}
+
+void XNPV::GenSlidingWindowFunction(
+    std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
+{
+    FormulaToken *pCur = vSubArguments[1]->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 (i)
+            ss << ",";
+        vSubArguments[i]->GenSlidingWindowDecl(ss);
+    }
+
+    ss << ") {\n\t";
+    ss << "double result = 0.0;\n\t";
+    ss << "int gid0 = get_global_id(0);\n\t";
+    ss << "int i=0;\n\t";
+    if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
+        ss<< "i=gid0;\n\t";
+    }
+    ss << "double date;\n\t";
+    ss << "double value;\n\t";
+    ss << "double rate;\n\t";
+    ss << "double dateNull;\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::DoubleVectorRefToken*tmpCurDVR1= dynamic_cast<const
+    formula::DoubleVectorRefToken *>(tmpCur1);
+
+    FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
+    const formula::DoubleVectorRefToken*tmpCurDVR2= dynamic_cast<const
+    formula::DoubleVectorRefToken *>(tmpCur2);
+    ss<< "int buffer_rate_len = ";
+    ss<< tmpCurDVR0->GetArrayLength();
+    ss << ";\n\t";
+    ss<< "int buffer_value_len = ";
+    ss<< tmpCurDVR1->GetArrayLength();
+    ss << ";\n\t";
+    ss<< "int buffer_date_len = ";
+    ss<< tmpCurDVR2->GetArrayLength();
+    ss << ";\n\t";
+#endif
+#ifdef ISNAN
+    ss<<"if((i+gid0)>=buffer_date_len || isNan(";
+    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+    ss<<"))\n\t\t";
+    ss<<"dateNull = 0;\n\telse \n\t\t";
+#endif
+    ss<<"dateNull = ";
+    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+    ss<<";\n\t";
+#ifdef ISNAN
+    ss<<"if((i+gid0)>=buffer_rate_len || isNan(";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss<<"))\n\t\t";
+    ss<<"rate = 0;\n\telse \n\t\t";
+#endif
+    ss<<"rate = ";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss<<";\n\t";
+    ss << "for (int i = ";
+    if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed())
+    {
+        ss << "gid0; i < "<< nCurWindowSize <<"; i++)\n\t\t";
+    }
+    else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
+    {
+        ss << "0; i < gid0+"<< nCurWindowSize <<"; i++)\n\t\t";
+    }
+    else
+    {
+        ss << "0; i < "<< nCurWindowSize <<"; i++)\n\t\t";
+    }
+    ss << "{\n\t";
+    ss << "result += ";
+    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+    ss << "/(pow((";
+    ss<<vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss <<"+1),(";
+    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+    ss << "-dateNull)/365));\n\t";
+    ss <<"}\n\t";
+
+    ss << "return result;\n";
+    ss << "}";
+}
+
+void PriceMat::GenSlidingWindowFunction(
+    std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
 {
-        public:
-    virtual void GenSlidingWindowFunction(std::stringstream &ss,
+    ss << "\ndouble " << sSymName;
+    ss << "_"<< BinFuncName() <<"(";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
+    {
+        if (i)
+            ss << ",";
+        vSubArguments[i]->GenSlidingWindowDecl(ss);
+    }
+    ss << ") {\n\t";
+    ss << "int gid0 = get_global_id(0);\n\t";
+    ss << "double result=0;\n\t";
+    ss<< "int nNullDate = GetNullDate( );\n\t";
+    ss <<"int settle;\n\t";
+    ss <<"int mat;\n\t";
+    ss <<"int issue;\n\t";
+    ss <<"double rate;\n\t";
+    ss <<"double yield;\n\t";
+    ss <<"int  nBase;\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);
+    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);
+
+    ss<< "int buffer_settle_len = ";
+    ss<< tmpCurDVR0->GetArrayLength();
+    ss << ";\n\t";
+     ss<< "int buffer_mat_len = ";
+    ss<< tmpCurDVR1->GetArrayLength();
+    ss << ";\n\t";
+    ss<< "int buffer_issue_len = ";
+    ss<< tmpCurDVR2->GetArrayLength();
+    ss << ";\n\t";
+    ss<< "int buffer_rate_len = ";
+    ss<< tmpCurDVR3->GetArrayLength();
+    ss << ";\n\t";
+    ss<< "int buffer_yield_len = ";
+    ss<< tmpCurDVR4->GetArrayLength();
+    ss << ";\n\t";
+    ss<< "int buffer_base_len = ";
+    ss<< tmpCurDVR5->GetArrayLength();
+    ss << ";\n\t";
+#endif
+#ifdef ISNAN
+    ss<<"if(gid0>=buffer_settle_len || isNan(";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss<<"))\n\t\t";
+    ss<<"settle = 0;\n\telse \n\t\t";
+#endif
+    ss<<"settle = ";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss<<";\n\t";
+#ifdef ISNAN
+    ss<<"if(gid0>=buffer_mat_len || isNan(";
+    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+    ss<<"))\n\t\t";
+    ss<<"mat = 0;\n\telse \n\t\t";
+#endif
+    ss<<"mat = ";
+    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+    ss<<";\n\t";
+#ifdef ISNAN
+    ss<<"if(gid0>=buffer_issue_len || isNan(";
+    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+    ss<<"))\n\t\t";
+    ss<<"issue = 0;\n\telse \n\t\t";
+#endif
+    ss<<"issue = ";
+    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+    ss<<";\n\t";
+#ifdef ISNAN
+    ss<<"if(gid0>=buffer_rate_len || isNan(";
+    ss << vSubArguments[3]->GenSlidingWindowDeclRef();
+    ss<<"))\n\t\t";
+    ss<<"rate = 0;\n\telse \n\t\t";
+#endif
+    ss<<"rate = ";
+    ss << vSubArguments[3]->GenSlidingWindowDeclRef();
+    ss<<";\n\t";
+#ifdef ISNAN
+    ss<<"if(gid0>=buffer_yield_len || isNan(";
+    ss << vSubArguments[4]->GenSlidingWindowDeclRef();
+    ss<<"))\n\t\t";
+    ss<<"yield = 0;\n\telse \n\t\t";
+#endif
+    ss<<"yield = ";
+    ss << vSubArguments[4]->GenSlidingWindowDeclRef();
+    ss<<";\n\t";
+#ifdef ISNAN
+    ss<<"if(gid0>=buffer_base_len || isNan(";
+    ss << vSubArguments[5]->GenSlidingWindowDeclRef();
+    ss<<"))\n\t\t";
+    ss<<"nBase = 0;\n\telse \n\t\t";
+#endif
+    ss<<"nBase = ";
+    ss << vSubArguments[5]->GenSlidingWindowDeclRef();
+    ss<<";\n\t";
+    ss<< "double fIssMat = GetYearFrac( nNullDate, issue, mat, nBase);\n";
+    ss<<"double fIssSet = GetYearFrac( nNullDate, issue, settle,nBase);\n";
+    ss<<"double fSetMat = GetYearFrac( nNullDate, settle, mat, nBase);\n";
+    ss<<"result = 1.0 + fIssMat * rate;\n\t";
+    ss<<"result /= 1.0 + fSetMat * yield;\n\t";
+    ss<<"result -= fIssSet * rate;\n\t";
+    ss<<"result*= 100.0;\n\t";
+    ss<<"return result;\n\t";
+    ss<<"}\n";
+}
+
+void OpSYD::GenSlidingWindowFunction(std::stringstream &ss,
             const std::string sSymName, SubArguments &vSubArguments)
+{
+    ss << "\ndouble " << sSymName;
+    ss << "_"<< BinFuncName() <<"(";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
     {
-        ss << "\ndouble " << sSymName;
-        ss << "_"<< BinFuncName() <<"(";
-        for (unsigned i = 0; i < vSubArguments.size(); i++)
-        {
-            if (i)
-                ss << ",";
-            vSubArguments[i]->GenSlidingWindowDecl(ss);
-        }
-        ss << ") {\n\t";
-        ss << "int gid0 = get_global_id(0);\n\t";
-        ss << "double result=0;\n\t";
-        ss << "double cost;\n\t";
-        ss << "double salvage;\n\t";
-        ss << "double life;\n\t";
-        ss << "double period;\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);
-
-        FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
-        const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
-            formula::SingleVectorRefToken *>(tmpCur3);
-
-        ss<< "int buffer_cost_len = ";
-        ss<< tmpCurDVR0->GetArrayLength();
-        ss << ";\n\t";
-
-         ss<< "int buffer_salvage_len = ";
-        ss<< tmpCurDVR1->GetArrayLength();
-        ss << ";\n\t";
-
-        ss<< "int buffer_life_len = ";
-        ss<< tmpCurDVR2->GetArrayLength();
-        ss << ";\n\t";
-        ss<< "int buffer_period_len = ";
-        ss<< tmpCurDVR3->GetArrayLength();
-        ss << ";\n\t";
-#endif
-
-#ifdef ISNAN
-        ss<<"if(gid0>=buffer_cost_len || isNan(";
-        ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-        ss<<"))\n\t\t";
-        ss<<"cost = 0;\n\telse \n\t\t";
-#endif
-        ss<<"cost = ";
-        ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-        ss<<";\n\t";
+        if (i)
+            ss << ",";
+        vSubArguments[i]->GenSlidingWindowDecl(ss);
+    }
+    ss << ") {\n\t";
+    ss << "int gid0 = get_global_id(0);\n\t";
+    ss << "double result=0;\n\t";
+    ss << "double cost;\n\t";
+    ss << "double salvage;\n\t";
+    ss << "double life;\n\t";
+    ss << "double period;\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);
+

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list