Kaydet (Commit) e667e8d6 authored tarafından minwang's avatar minwang Kaydeden (comit) I-Jui (Ray) Sung

GPU Calc: implemented for COUPPCD

AMLOEXT-135 FIX

Change-Id: If16217647f85bdd4a309c81b33bc963b9e54f657
Signed-off-by: 's avatarhaochen <haochen@multicorewareinc.com>
Signed-off-by: 's avatarI-Jui (Ray) Sung <ray@multicorewareinc.com>
üst 246e0148
...@@ -1311,6 +1311,12 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments( ...@@ -1311,6 +1311,12 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts, mvSubArguments.push_back(SoPHelper(ts,
ft->Children[i], new OpPriceDisc)); ft->Children[i], new OpPriceDisc));
} }
else if ( !(pChild->GetExternal().compareTo(OUString(
"com.sun.star.sheet.addin.Analysis.getCouppcd"))))
{
mvSubArguments.push_back(SoPHelper(ts, ft->Children[i],
new OpCouppcd));
}
break; break;
default: default:
throw UnhandledToken(pChild, "unhandled opcode"); throw UnhandledToken(pChild, "unhandled opcode");
......
...@@ -3466,6 +3466,106 @@ void OpCoupdays::GenSlidingWindowFunction( ...@@ -3466,6 +3466,106 @@ void OpCoupdays::GenSlidingWindowFunction(
ss << "return tmp;\n"; ss << "return tmp;\n";
ss << "}"; ss << "}";
} }
void OpCouppcd::BinInlineFun(std::set<std::string>& decls,
std::set<std::string>& funs)
{
decls.insert(IsLeapYearDecl); decls.insert(DaysInMonthDecl);
decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl);
decls.insert(GetNullDateDecl); decls.insert(ScaDate2Decl);
decls.insert(lcl_GetCouppcdDecl);
funs.insert(IsLeapYear);funs.insert(DaysInMonth);
funs.insert(DaysToDate);funs.insert(DateToDays);
funs.insert(GetNullDate);funs.insert(ScaDate2);
funs.insert(lcl_GetCouppcd);
}
void OpCouppcd::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";
ss << " double tmp = 0;\n";
ss << " int gid0 = get_global_id(0);\n";
ss << " int bLastDayMode =1,bLastDay =0,b30Days= 0,bUSMode = 0;\n";
ss << " int nSettle,nMat,nFreq,nBase;\n";
#ifdef ISNAN
FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
formula::SingleVectorRefToken *>(tmpCur0);
FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
formula::SingleVectorRefToken *>(tmpCur1);
FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
formula::SingleVectorRefToken *>(tmpCur2);
FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
formula::SingleVectorRefToken *>(tmpCur3);
ss<< " int buffer_nSettle_len = ";
ss<< tmpCurDVR0->GetArrayLength();
ss << ";\n";
ss<< " int buffer_nMat_len = ";
ss<< tmpCurDVR1->GetArrayLength();
ss << ";\n";
ss<< " int buffer_nFreq_len = ";
ss<< tmpCurDVR2->GetArrayLength();
ss << ";\n";
ss<< " int buffer_nBase_len = ";
ss<< tmpCurDVR3->GetArrayLength();
ss << ";\n";
#endif
#ifdef ISNAN
ss <<" if(gid0 >= buffer_nSettle_len || isNan(";
ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
ss <<"))\n";
ss <<" nSettle = 0;\n else\n";
#endif
ss << " nSettle=(int)";
ss << vSubArguments[0]->GenSlidingWindowDeclRef();
ss <<";\n";
#ifdef ISNAN
ss <<" if(gid0 >= buffer_nMat_len || isNan(";
ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
ss <<"))\n";
ss <<" nMat = 0;\n else\n";
#endif
ss <<" nMat=(int)";
ss << vSubArguments[1]->GenSlidingWindowDeclRef();
ss << ";\n";
#ifdef ISNAN
ss <<" if(gid0 >= buffer_nFreq_len || isNan(";
ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
ss <<"))\n";
ss <<" nFreq = 0;\n else\n";
#endif
ss <<" nFreq=(int)";
ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
ss <<";\n";
#ifdef ISNAN
ss <<" if(gid0 >= buffer_nBase_len || isNan(";
ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
ss <<"))\n";
ss <<" nBase = 0;\n else\n";
#endif
ss <<" nBase=(int)";
ss << vSubArguments[3]->GenSlidingWindowDeclRef();
ss <<";\n";
ss <<" int nNullDate=GetNullDate();\n";
ss <<" ScaDate2(nNullDate, nMat, nBase,&bLastDayMode,&bLastDay,";
ss <<"&b30Days,&bUSMode);\n";
ss <<" tmp = lcl_GetCouppcd(nNullDate,nSettle,nMat,nFreq,";
ss <<"&bLastDayMode,&bLastDay,&b30Days,&bUSMode);\n";
ss <<" return tmp;\n";
ss <<"}";
}
void OpCoupdaysnc::BinInlineFun(std::set<std::string>& decls, void OpCoupdaysnc::BinInlineFun(std::set<std::string>& decls,
std::set<std::string>& funs) std::set<std::string>& funs)
{ {
......
...@@ -410,6 +410,17 @@ public: ...@@ -410,6 +410,17 @@ public:
virtual std::string BinFuncName(void) const { return "Coupdaysnc"; } virtual std::string BinFuncName(void) const { return "Coupdaysnc"; }
}; };
class OpCouppcd:public Normal
{
public:
virtual void GenSlidingWindowFunction(std::stringstream &ss,
const std::string sSymName, SubArguments &vSubArguments);
virtual void BinInlineFun(std::set<std::string>& ,std::set<std::string>& );
virtual std::string BinFuncName(void) const { return "Couppcd"; }
};
class OpCoupnum:public Normal class OpCoupnum:public Normal
{ {
public: public:
......
...@@ -225,6 +225,67 @@ std::string ScaDate= ...@@ -225,6 +225,67 @@ std::string ScaDate=
" }\n" " }\n"
"}\n"; "}\n";
std::string ScaDate2Decl=
"void ScaDate2( int nNullDate, int nDate, int nBase,int *bLastDayMode,int *"
"bLastDay,int *b30Days,int *bUSMode);\n";
std::string ScaDate2=
"void ScaDate2( int nNullDate, int nDate, int nBase,int *bLastDayMode,int *"
"bLastDay,int *b30Days,int *bUSMode)\n"
"{\n"
" int nOrigDay=0, nMonth=0, nYear=0;\n"
" DaysToDate( nNullDate + nDate, &nOrigDay, &nMonth, &nYear );\n"
" *bLastDayMode = (nBase != 5);\n"
" *bLastDay = (nOrigDay >= DaysInMonth( nMonth, nYear ));\n"
" *b30Days = (nBase == 0) || (nBase == 4);\n"
" *bUSMode = (nBase == 0);\n"
"}\n";
std::string lcl_GetCouppcdDecl=
"int lcl_GetCouppcd(int nNullDate,int nSettle, int nMat,int nFreq,int *"
"bLastDayMode,int *bLastDay,int *b30Days,int *bUSMode);\n";
std::string lcl_GetCouppcd=
"int lcl_GetCouppcd(int nNullDate,int nSettle, int nMat,int nFreq,int *"
"bLastDayMode,int *bLastDay,int *b30Days,int *bUSMode)\n"
"{\n"
" int aDate = nMat;int rDay=0,rMonth=0,rYear=0;int mDay=0,mMonth=0,"
"mYear=0;\n"
" int sDay=0,sMonth=0, sYear=0;\n"
" DaysToDate(aDate+nNullDate,&rDay, &rMonth, &rYear );\n"
" DaysToDate(nMat+nNullDate,&mDay, &mMonth, &mYear );\n"
" DaysToDate(nSettle+nNullDate,&sDay, &sMonth, &sYear );\n"
" rYear= sYear;\n"
" nSettle=nSettle+nNullDate;\n"
" aDate=DateToDays( rDay,rMonth,rYear );\n"
" if( aDate < nSettle )\n"
" rYear+= 1;\n"
" int d=DateToDays( rDay,rMonth,rYear );\n"
" int nMonthCount=-1*(12 / nFreq);\n"
" while(d > nSettle )\n"
" {\n"
" int nNewMonth = nMonthCount + rMonth;\n"
" if( nNewMonth > 12 )\n"
" {\n"
" --nNewMonth;\n"
" rYear+=nNewMonth / 12;\n"
" rMonth = nNewMonth % 12 + 1;\n"
" }\n"
" else if( nNewMonth < 1 )\n"
" {\n"
" rYear+= nNewMonth / 12 - 1;\n"
" rMonth = nNewMonth % 12 + 12;\n"
" }\n"
" else\n"
" rMonth = nNewMonth;\n"
" d=DateToDays( rDay,rMonth,rYear );\n"
" }\n"
" int nLastDay = DaysInMonth( rMonth, rYear );\n"
" int nRealDay = ((*bLastDayMode) && (*bLastDay)) ? nLastDay :"
"min( nLastDay, rDay );\n"
" return DateToDays( nRealDay, rMonth, rYear ) - nNullDate;\n"
"}\n";
std::string addMonthsDecl= std::string addMonthsDecl=
"void addMonths(int b30Days,int bLastDay,int *nDay,int nOrigDay," "void addMonths(int b30Days,int bLastDay,int *nDay,int nOrigDay,"
"int *nMonth,int nMonthCount,int *year);\n"; "int *nMonth,int nMonthCount,int *year);\n";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment