diff options
author | minwang <min@multicorewareinc.com> | 2013-12-24 14:44:39 +0800 |
---|---|---|
committer | I-Jui (Ray) Sung <ray@multicorewareinc.com> | 2013-12-30 15:05:28 -0600 |
commit | 2e5abd41b86e970885e03795bc874cfc31ea54a9 (patch) | |
tree | bdf3208e7e401c46efeece22a65677ac4abaa65a /sc | |
parent | fdbf86457707ffd105fc5e1bae594f0e974f6a5e (diff) |
GPU Calc: Optimized COUPPCD
AMLOEXT-382
Change-Id: I49ed9bdd88a0f00da4475798362750d5a0253c09
Signed-off-by: haochen <haochen@multicorewareinc.com>
Signed-off-by: Wei Wei <weiwei@multicorewareinc.com>
Signed-off-by: I-Jui (Ray) Sung <ray@multicorewareinc.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/opencl/op_financial.cxx | 108 | ||||
-rw-r--r-- | sc/source/core/opencl/opinlinefun_finacial.cxx | 58 |
2 files changed, 77 insertions, 89 deletions
diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx index 62fedd354eaf..5931ab5920cd 100644 --- a/sc/source/core/opencl/op_financial.cxx +++ b/sc/source/core/opencl/op_financial.cxx @@ -3622,11 +3622,17 @@ void OpCouppcd::BinInlineFun(std::set<std::string>& decls, { decls.insert(IsLeapYearDecl); decls.insert(DaysInMonthDecl); decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl); - decls.insert(GetNullDateDecl); decls.insert(ScaDate2Decl); + decls.insert(GetNullDateDecl); + decls.insert(ScaDateDecl); + decls.insert(addMonthsDecl); + decls.insert(setDayDecl);decls.insert(checklessthanDecl); decls.insert(lcl_GetCouppcdDecl); funs.insert(IsLeapYear);funs.insert(DaysInMonth); funs.insert(DaysToDate);funs.insert(DateToDays); - funs.insert(GetNullDate);funs.insert(ScaDate2); + funs.insert(GetNullDate); + funs.insert(ScaDate); + funs.insert(addMonths); + funs.insert(setDay);funs.insert(checklessthan); funs.insert(lcl_GetCouppcd); } void OpCouppcd::GenSlidingWindowFunction( @@ -3637,82 +3643,74 @@ void OpCouppcd::GenSlidingWindowFunction( ss << "_"<< BinFuncName() <<"("; for (unsigned i = 0; i < vSubArguments.size(); i++) { - if (i) - ss << ","; - vSubArguments[i]->GenSlidingWindowDecl(ss); + if (i) + ss << ","; + vSubArguments[i]->GenSlidingWindowDecl(ss); } ss << ") {\n"; ss << " double tmp = 0;\n"; ss << " int gid0 = get_global_id(0);\n"; - ss << " int bLastDayMode =1,bLastDay =0,b30Days= 0,bUSMode = 0;\n"; ss << " int nSettle,nMat,nFreq,nBase;\n"; #ifdef ISNAN - FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const - formula::SingleVectorRefToken *>(tmpCur0); - FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const - formula::SingleVectorRefToken *>(tmpCur1); - FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const - formula::SingleVectorRefToken *>(tmpCur2); - FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const - formula::SingleVectorRefToken *>(tmpCur3); - ss<< " int buffer_nSettle_len = "; - ss<< tmpCurDVR0->GetArrayLength(); - ss << ";\n"; - ss<< " int buffer_nMat_len = "; - ss<< tmpCurDVR1->GetArrayLength(); - ss << ";\n"; - ss<< " int buffer_nFreq_len = "; - ss<< tmpCurDVR2->GetArrayLength(); - ss << ";\n"; - ss<< " int buffer_nBase_len = "; - ss<< tmpCurDVR3->GetArrayLength(); - ss << ";\n"; + FormulaToken* tmpCur0 = vSubArguments[0]->GetFormulaToken(); + FormulaToken* tmpCur1 = vSubArguments[1]->GetFormulaToken(); + FormulaToken* tmpCur2 = vSubArguments[2]->GetFormulaToken(); + FormulaToken* tmpCur3 = vSubArguments[3]->GetFormulaToken(); #endif #ifdef ISNAN - ss <<" if(gid0 >= buffer_nSettle_len || isNan("; - ss <<vSubArguments[0]->GenSlidingWindowDeclRef(); - ss <<"))\n"; + if(tmpCur0->GetType() == formula::svSingleVectorRef) + { + const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const + formula::SingleVectorRefToken *>(tmpCur0); + ss <<" if(isNan("<<vSubArguments[0]->GenSlidingWindowDeclRef(); + ss <<")||(gid0 >="<<tmpCurDVR0->GetArrayLength()<<"))\n"; ss <<" nSettle = 0;\n else\n"; + } #endif - ss << " nSettle=(int)"; - ss << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss <<";\n"; + ss <<" nSettle=(int)"; + ss << vSubArguments[0]->GenSlidingWindowDeclRef(); + ss <<";\n"; #ifdef ISNAN - ss <<" if(gid0 >= buffer_nMat_len || isNan("; - ss <<vSubArguments[1]->GenSlidingWindowDeclRef(); - ss <<"))\n"; + if(tmpCur1->GetType() == formula::svSingleVectorRef) + { + const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const + formula::SingleVectorRefToken *>(tmpCur1); + ss <<" if(isNan("<<vSubArguments[1]->GenSlidingWindowDeclRef(); + ss <<")||(gid0 >="<<tmpCurDVR1->GetArrayLength()<<"))\n"; ss <<" nMat = 0;\n else\n"; + } #endif ss <<" nMat=(int)"; ss << vSubArguments[1]->GenSlidingWindowDeclRef(); - ss << ";\n"; + ss <<";\n"; #ifdef ISNAN - ss <<" if(gid0 >= buffer_nFreq_len || isNan("; - ss <<vSubArguments[2]->GenSlidingWindowDeclRef(); - ss <<"))\n"; + if(tmpCur2->GetType() == formula::svSingleVectorRef) + { + const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const + formula::SingleVectorRefToken *>(tmpCur2); + ss <<" if(isNan("<<vSubArguments[2]->GenSlidingWindowDeclRef(); + ss <<")||(gid0 >="<<tmpCurDVR2->GetArrayLength()<<"))\n"; ss <<" nFreq = 0;\n else\n"; + } #endif - ss <<" nFreq=(int)"; - ss <<vSubArguments[2]->GenSlidingWindowDeclRef(); + ss << " nFreq=(int)"; + ss << vSubArguments[2]->GenSlidingWindowDeclRef(); ss <<";\n"; #ifdef ISNAN - ss <<" if(gid0 >= buffer_nBase_len || isNan("; - ss <<vSubArguments[3]->GenSlidingWindowDeclRef(); - ss <<"))\n"; + if(tmpCur3->GetType() == formula::svSingleVectorRef) + { + const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const + formula::SingleVectorRefToken *>(tmpCur3); + ss <<" if(isNan(" <<vSubArguments[3]->GenSlidingWindowDeclRef(); + ss <<")||(gid0 >="<<tmpCurDVR3->GetArrayLength()<<"))\n"; ss <<" nBase = 0;\n else\n"; + } #endif - ss <<" nBase=(int)"; + ss << " nBase=(int)"; ss << vSubArguments[3]->GenSlidingWindowDeclRef(); - ss <<";\n"; - ss <<" int nNullDate=GetNullDate();\n"; - ss <<" ScaDate2(nNullDate, nMat, nBase,&bLastDayMode,&bLastDay,"; - ss <<"&b30Days,&bUSMode);\n"; - ss <<" tmp = lcl_GetCouppcd(nNullDate,nSettle,nMat,nFreq,"; - ss <<"&bLastDayMode,&bLastDay,&b30Days,&bUSMode);\n"; + ss << ";\n"; + ss <<" int nNullDate=693594;\n"; + ss <<" tmp = lcl_GetCouppcd(nNullDate,nSettle,nMat,nFreq,nBase);\n"; ss <<" return tmp;\n"; ss <<"}"; } diff --git a/sc/source/core/opencl/opinlinefun_finacial.cxx b/sc/source/core/opencl/opinlinefun_finacial.cxx index 052c364e916e..91d04d2e9490 100644 --- a/sc/source/core/opencl/opinlinefun_finacial.cxx +++ b/sc/source/core/opencl/opinlinefun_finacial.cxx @@ -334,46 +334,36 @@ std::string ScaDate2= "}\n"; std::string lcl_GetCouppcdDecl= -"int lcl_GetCouppcd(int nNullDate,int nSettle, int nMat,int nFreq,int *" -"bLastDayMode,int *bLastDay,int *b30Days,int *bUSMode);\n"; +"int lcl_GetCouppcd(int nNullDate,int nSettle,int nMat,int nFreq,int nBase);\n"; std::string lcl_GetCouppcd= -"int lcl_GetCouppcd(int nNullDate,int nSettle, int nMat,int nFreq,int *" -"bLastDayMode,int *bLastDay,int *b30Days,int *bUSMode)\n" +"int lcl_GetCouppcd(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n" "{\n" -" int aDate = nMat;int rDay=0,rMonth=0,rYear=0;int mDay=0,mMonth=0," -"mYear=0;\n" -" int sDay=0,sMonth=0, sYear=0;\n" -" DaysToDate(aDate+nNullDate,&rDay, &rMonth, &rYear );\n" -" DaysToDate(nMat+nNullDate,&mDay, &mMonth, &mYear );\n" -" DaysToDate(nSettle+nNullDate,&sDay, &sMonth, &sYear );\n" -" rYear= sYear;\n" -" nSettle=nSettle+nNullDate;\n" -" aDate=DateToDays( rDay,rMonth,rYear );\n" -" if( aDate < nSettle )\n" -" rYear+= 1;\n" -" int d=DateToDays( rDay,rMonth,rYear );\n" -" int nMonthCount=-1*(12 / nFreq);\n" -" while(d > nSettle )\n" +" int aDate = nMat;\n" +" int rDay=0,rMonth=0, rYear=0,rbLastDayMode=0, rbLastDay=0,rb30Days=0," +"rbUSMode=0,rnDay=0;\n" +" int sDay=0,sMonth=0, sYear=0,sbLastDayMode=0, sbLastDay=0,sb30Days=0," +"sbUSMode=0,snDay=0;\n" +" ScaDate( nNullDate,nSettle,nBase,&sDay,&sMonth,&sYear,&sbLastDayMode," +"&sbLastDay,&sb30Days,&sbUSMode,&snDay);\n" +" ScaDate( nNullDate,aDate,nBase,&rDay,&rMonth,&rYear,&rbLastDayMode," +"&rbLastDay,&rb30Days,&rbUSMode,&rnDay);\n" +" rYear=sYear;\n" +" setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n" +" if(checklessthan(rYear,sYear,rMonth,sMonth,rnDay,snDay,rbLastDay," +"sbLastDay,rDay,sDay))\n" " {\n" -" int nNewMonth = nMonthCount + rMonth;\n" -" if( nNewMonth > 12 )\n" -" {\n" -" --nNewMonth;\n" -" rYear+=nNewMonth / 12;\n" -" rMonth = nNewMonth % 12 + 1;\n" -" }\n" -" else if( nNewMonth < 1 )\n" -" {\n" -" rYear+= nNewMonth / 12 - 1;\n" -" rMonth = nNewMonth % 12 + 12;\n" -" }\n" -" else\n" -" rMonth = nNewMonth;\n" -" d=DateToDays( rDay,rMonth,rYear );\n" +" rYear+=1;\n" +" setDay(rDay,rMonth,rYear,rbLastDay,rb30Days,&rnDay);\n" +" }\n" +" while(checklessthan(sYear,rYear,sMonth,rMonth,snDay,rnDay,sbLastDay," +"rbLastDay,sDay,rDay))\n" +" {\n" +" double d = -1*(12/nFreq);\n" +" addMonths(rb30Days,rbLastDay,&rnDay,rDay,&rMonth,d,&rYear);\n" " }\n" " int nLastDay = DaysInMonth( rMonth, rYear );\n" -" int nRealDay = ((*bLastDayMode) && (*bLastDay)) ? nLastDay :" +" int nRealDay = (rbLastDayMode && rbLastDay) ? nLastDay :" "min( nLastDay, rDay );\n" " return DateToDays( nRealDay, rMonth, rYear ) - nNullDate;\n" "}\n"; |