sc/source/core/opencl/op_financial.cxx | 2 sc/source/core/opencl/op_financial_helpers.hxx | 245 +- sc/source/core/opencl/op_math.cxx | 2429 ++++++----------------- sc/source/core/opencl/op_math.hxx | 351 +-- sc/source/core/opencl/op_math_helpers.hxx | 39 sc/source/core/opencl/op_statistical.cxx | 2 sc/source/core/opencl/op_statistical_helpers.hxx | 153 - sc/source/core/opencl/opbase.cxx | 9 sc/source/core/opencl/opbase.hxx | 4 sc/source/core/opencl/utils.hxx | 5 solenv/clang-format/excludelist | 6 11 files changed, 1066 insertions(+), 2179 deletions(-)
New commits: commit aa0d6cb52979e29830596ec5a4e8e625500d6cb9 Author: Luboš Luňák <l.lu...@collabora.com> AuthorDate: Tue Sep 6 12:38:00 2022 +0200 Commit: Luboš Luňák <l.lu...@collabora.com> CommitDate: Tue Sep 13 09:05:34 2022 +0200 clean up opencl helper functions It seems a bit wasteful to use std::string for const strings. Change-Id: I31bb38f5cdcd0210f6f91144b3c37abae9301333 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139487 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lu...@collabora.com> diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx index 0840c334f7df..863fa2552cab 100644 --- a/sc/source/core/opencl/op_financial.cxx +++ b/sc/source/core/opencl/op_financial.cxx @@ -16,7 +16,7 @@ using namespace formula; namespace sc::opencl { // Definitions of inline functions -#include "opinlinefun_finacial.cxx" +#include "op_financial_helpers.hxx" void RRI::GenSlidingWindowFunction( outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) diff --git a/sc/source/core/opencl/opinlinefun_finacial.cxx b/sc/source/core/opencl/op_financial_helpers.hxx similarity index 94% rename from sc/source/core/opencl/opinlinefun_finacial.cxx rename to sc/source/core/opencl/op_financial_helpers.hxx index dd12767cf93a..eaf688af91c1 100644 --- a/sc/source/core/opencl/opinlinefun_finacial.cxx +++ b/sc/source/core/opencl/op_financial_helpers.hxx @@ -7,19 +7,18 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef SC_OPENCL_OPINLINFUN_finacial -#define SC_OPENCL_OPINLINFUN_finacial +#pragma once -std::string nCorrValDecl ="double constant nCorrVal[]" +const char nCorrValDecl[] ="double constant nCorrVal[]" "= {0, 9e-1, 9e-2, 9e-3, 9e-4, 9e-5, 9e-6, 9e-7, " "9e-8,9e-9, 9e-10, 9e-11, 9e-12, 9e-13, 9e-14, 9e-15};\n"; -std::string SCdEpsilonDecl = +const char SCdEpsilonDecl[] = "constant double SCdEpsilon = 1.0E-7;\n"; -std::string RoundDecl = "double Round(double fValue);\n"; +const char RoundDecl[] = "double Round(double fValue);\n"; -std::string Round = +const char Round[] = "double Round(double fValue)\n" "{\n" " if ( fValue == 0.0 )\n" @@ -40,10 +39,10 @@ std::string Round = " return fValue;\n" "}\n"; -std::string GetPMT_newDecl = +const char GetPMT_newDecl[] = "double GetPMT_new( double fRate, double fNper, double fPv, double fFv," "int nPayType );\n"; -std::string GetPMT_new= +const char GetPMT_new[] = "double GetPMT_new( double fRate, double fNper, double fPv, double fFv," "int nPayType)\n" "{\n" @@ -57,11 +56,11 @@ std::string GetPMT_new= "1.0 - 1.0 / fTerm);\n" " return -fPmt;\n" "}\n"; -std::string GetFVDecl = +const char GetFVDecl[] = "double GetFV( double fRate, double fNper, double fPmt," "double fPv, int nPayType );\n"; -std::string GetFV = +const char GetFV[] = "double GetFV( double fRate, double fNper, double fPmt," "double fPv, int nPayType )\n" "{\n" @@ -80,11 +79,11 @@ std::string GetFV = " return -fFv;\n" "}\n"; -std::string GetFV_newDecl = +const char GetFV_newDecl[] = "double GetFV_new( double fRate, double fNper, double fPmt," "double fPv, int nPayType );\n"; -std::string GetFV_new = +const char GetFV_new[] = "double GetFV_new( double fRate, double fNper, double fPmt," "double fPv, int nPayType )\n" "{\n" @@ -98,20 +97,20 @@ std::string GetFV_new = " return -fFv;\n" "}\n"; -std::string IsLeapYearDecl = +const char IsLeapYearDecl[] = "bool IsLeapYear( int n );\n"; -std::string IsLeapYear = +const char IsLeapYear[] = "bool IsLeapYear( int n )\n" "{\n" " return ( (( ( n % 4 ) == 0 ) && ( ( n % 100 ) != 0)) || ( ( n % 400 ) == " "0 ) );\n" "}\n"; -std::string DaysInMonthDecl= +const char DaysInMonthDecl[] = "int DaysInMonth( int nMonth, int nYear );\n"; -std::string DaysInMonth = +const char DaysInMonth[] = "int DaysInMonth( int nMonth, int nYear )\n" "{\n" " int aDaysInMonth[12] = { 31, 28, 31, 30, 31, 30,\n" @@ -127,10 +126,10 @@ std::string DaysInMonth = " return aDaysInMonth[nMonth-1];\n" " }\n" "}\n"; -std::string DaysInMonth_newDecl= +const char DaysInMonth_newDecl[] = "int DaysInMonth( int nMonth, int nYear );\n"; -std::string DaysInMonth_new = +const char DaysInMonth_new[] = "int DaysInMonth( int nMonth, int nYear )\n" "{\n" " int tmp = 0;\n" @@ -161,10 +160,10 @@ std::string DaysInMonth_new = " return tmp;\n" "}\n"; -std::string DaysToDateDecl = +const char DaysToDateDecl[] = "void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear );\n"; -std::string DaysToDate = +const char DaysToDate[] = "void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear )\n" "{\n" "\n" @@ -208,10 +207,10 @@ std::string DaysToDate = " }\n" "}\n"; -std::string DateToDaysDecl= +const char DateToDaysDecl[] = "int DateToDays( int nDay, int nMonth, int nYear );\n"; -std::string DateToDays= +const char DateToDays[] = "int DateToDays( int nDay, int nMonth, int nYear )\n" "{\n" " int nDays = ((int)nYear-1) * 365;\n" @@ -223,10 +222,10 @@ std::string DateToDays= " return nDays;\n" "}\n"; -std::string DateToDays_newDecl= +const char DateToDays_newDecl[] = "int DateToDays_new( int nDay, int nMonth, int nYear );\n"; -std::string DateToDays_new= +const char DateToDays_new[] = "int DateToDays_new( int nDay, int nMonth, int nYear )\n" "{\n" " int nDays = (nYear-1) * 365;\n" @@ -239,29 +238,29 @@ std::string DateToDays_new= " return nDays;\n" "}\n"; -std::string GetNullDateDecl= +const char GetNullDateDecl[] = "int GetNullDate();\n"; -std::string GetNullDate= +const char GetNullDate[] = "int GetNullDate()\n" "{\n" " return DateToDays(30,12,1899 );\n" "}\n"; -std::string GetNullDate_newDecl= +const char GetNullDate_newDecl[] = "int GetNullDate_new();\n"; -std::string GetNullDate_new= +const char GetNullDate_new[] = "int GetNullDate_new()\n" "{\n" " return DateToDays_new(30,12,1899 );\n" "}\n"; -std::string ScaDateDecl= +const char ScaDateDecl[] = "void ScaDate( int nNullDate, int nDate, int nBase,int *nOrigDay, " "int *nMonth,int *nYear,int *bLastDayMode,int *bLastDay," "int *b30Days,int *bUSMode,int *nDay);\n"; -std::string ScaDate= +const char ScaDate[] = "void ScaDate( int nNullDate, int nDate, int nBase,int *nOrigDay, " "int *nMonth,int *nYear,int *bLastDayMode,int *bLastDay," "int *b30Days,int *bUSMode,int *nDay)\n" @@ -284,10 +283,10 @@ std::string ScaDate= " }\n" "}\n"; -std::string lcl_GetCouppcdDecl= +const char lcl_GetCouppcdDecl[] = "int lcl_GetCouppcd(int nNullDate,int nSettle,int nMat,int nFreq,int nBase);\n"; -std::string lcl_GetCouppcd= +const char lcl_GetCouppcd[] = "int lcl_GetCouppcd(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n" "{\n" " int aDate = nMat;\n" @@ -319,10 +318,10 @@ std::string lcl_GetCouppcd= " return DateToDays( nRealDay, rMonth, rYear ) - nNullDate;\n" "}\n"; -std::string lcl_GetCoupncdDecl= +const char lcl_GetCoupncdDecl[] = "int lcl_GetCoupncd(int nNullDate,int nSettle,int nMat,int nFreq,int nBase);\n"; -std::string lcl_GetCoupncd= +const char lcl_GetCoupncd[] = "int lcl_GetCoupncd(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n" "{\n" " int aDate = nMat;\n" @@ -353,11 +352,11 @@ std::string lcl_GetCoupncd= " return DateToDays( nRealDay, rMonth, rYear ) - nNullDate;\n" "}\n"; -std::string addMonthsDecl= +const char addMonthsDecl[] = "void addMonths(int b30Days,int bLastDay,int *nDay,int nOrigDay," "int *nMonth,int nMonthCount,int *year);\n"; -std::string addMonths= +const char addMonths[] = "void addMonths(int b30Days,int bLastDay,int *nDay,int nOrigDay," "int *nMonth,int nMonthCount,int *year)\n" "{\n" @@ -388,10 +387,10 @@ std::string addMonths= " }\n" "}\n"; -std::string getDaysInMonthRangeDecl= +const char getDaysInMonthRangeDecl[] = "int getDaysInMonthRange( int nFrom, int nTo,int b30Days,int year);\n"; -std::string getDaysInMonthRange= +const char getDaysInMonthRange[] = "int getDaysInMonthRange( int nFrom, int nTo,int b30Days,int year)\n" "{\n" " if( nFrom > nTo )\n" @@ -407,10 +406,10 @@ std::string getDaysInMonthRange= " return nRet;\n" "}\n"; -std::string GetDaysInYearsDecl= +const char GetDaysInYearsDecl[] = "int GetDaysInYears( int nYear1, int nYear2 );\n"; -std::string GetDaysInYears= +const char GetDaysInYears[] = "int GetDaysInYears( int nYear1, int nYear2 )\n" "{\n" " int nLeaps = 0;\n" @@ -427,10 +426,10 @@ std::string GetDaysInYears= " return nSum;\n" "}\n"; -std::string GetDaysInYearDecl= +const char GetDaysInYearDecl[] = "int GetDaysInYear( int nNullDate, int nDate, int nMode );\n"; -std::string GetDaysInYear= +const char GetDaysInYear[] = "int GetDaysInYear( int nNullDate, int nDate, int nMode )\n" "{\n" " switch( nMode )\n" @@ -451,10 +450,10 @@ std::string GetDaysInYear= " }\n" "}\n"; -std::string getDaysInYearRangeDecl = +const char getDaysInYearRangeDecl[] = "int getDaysInYearRange( int nFrom, int nTo,int b30Days );\n"; -std::string getDaysInYearRange= +const char getDaysInYearRange[] = "int getDaysInYearRange( int nFrom, int nTo,int b30Days )\n" "{\n" " if( nFrom > nTo )\n" @@ -463,13 +462,13 @@ std::string getDaysInYearRange= ";\n" "}\n"; -std::string getDiffDecl= +const char getDiffDecl[] = "int getDiff(int rFrom,int rTo,int fDay,int fMonth,int fYear,int fbLastDayMode," "int fbLastDay,int fb30Days,int fbUSMode,int fnDay,int tDay,int tMonth," "int tYear,int tbLastDayMode,int tbLastDay,int tb30Days," "int tbUSMode,int tnDay);\n"; -std::string getDiff= +const char getDiff[] = "int getDiff(int rFrom,int rTo,int fDay,int fMonth,int fYear,int fbLastDayMode," "int fbLastDay,int fb30Days,int fbUSMode,int fnDay,int tDay,int tMonth," "int tYear,int tbLastDayMode,int tbLastDay,int tb30Days," @@ -527,10 +526,10 @@ std::string getDiff= " return nDiff > 0 ? nDiff : 0;\n" "}\n"; -std::string lcl_GetcoupdaybsDecl= +const char lcl_GetcoupdaybsDecl[] = "int lcl_Getcoupdaybs(int nNullDate,int nSettle, int nMat,int nFreq,int nBase);\n"; -std::string lcl_Getcoupdaybs= +const char lcl_Getcoupdaybs[] = "int lcl_Getcoupdaybs(int nNullDate,int nSettle, int nMat,int nFreq,int nBase)\n" "{\n" " int aDate = nMat;\n" @@ -561,11 +560,11 @@ std::string lcl_Getcoupdaybs= "sbLastDay, sb30Days, sbUSMode, snDay);\n" "}\n"; -std::string lcl_Getcoupdaybs_newDecl= +const char lcl_Getcoupdaybs_newDecl[] = "int lcl_Getcoupdaybs_new(int nNullDate,int nSettle,int nMat,int nFreq," "int nBase);\n"; -std::string lcl_Getcoupdaybs_new= +const char lcl_Getcoupdaybs_new[] = "int lcl_Getcoupdaybs_new(int nNullDate,int nSettle,int nMat,int nFreq," "int nBase)\n" "{\n" @@ -600,11 +599,11 @@ std::string lcl_Getcoupdaybs_new= "sb30Days,sbUSMode, snDay);\n" "}\n"; -std::string lcl_GetcoupdaysDecl= +const char lcl_GetcoupdaysDecl[] = "int lcl_Getcoupdays(int nNullDate,int nSettle, " "int nMat,int nFreq,int nBase);\n"; -std::string lcl_Getcoupdays= +const char lcl_Getcoupdays[] = "int lcl_Getcoupdays(int nNullDate,int nSettle, " "int nMat,int nFreq,int nBase)\n" "{\n" @@ -640,11 +639,11 @@ std::string lcl_Getcoupdays= "abLastDay, ab30Days, abUSMode, anDay);\n" "}\n"; -std::string lcl_Getcoupdays_newDecl= +const char lcl_Getcoupdays_newDecl[] = "int lcl_Getcoupdays_new(int nNullDate,int nSettle, " "int nMat,int nFreq,int nBase);\n"; -std::string lcl_Getcoupdays_new= +const char lcl_Getcoupdays_new[] = "int lcl_Getcoupdays_new(int nNullDate,int nSettle, " "int nMat,int nFreq,int nBase)\n" "{\n" @@ -684,10 +683,10 @@ std::string lcl_Getcoupdays_new= "abLastDay, ab30Days, abUSMode, anDay);\n" "}\n"; -std::string lcl_GetcoupnumDecl= +const char lcl_GetcoupnumDecl[] = "int lcl_Getcoupnum(int nNullDate,int nSettle, int nMat,int nFreq);\n"; -std::string lcl_Getcoupnum= +const char lcl_Getcoupnum[] = "int lcl_Getcoupnum(int nNullDate,int nSettle, int nMat,int nFreq)\n" "{\n" " int aDate = nMat;int rDay=0,rMonth=0, rYear=0;int mDay=0,mMonth=0, mYear=" @@ -725,10 +724,10 @@ std::string lcl_Getcoupnum= " n=n*nFreq/12;\n" " return n;\n" "}\n"; -std::string lcl_Getcoupnum_newDecl= +const char lcl_Getcoupnum_newDecl[] = "double lcl_Getcoupnum_new(int nNullDate,int nSettle,int nMat,int nFreq,int" " nBase);\n"; -std::string lcl_Getcoupnum_new= +const char lcl_Getcoupnum_new[] = "double lcl_Getcoupnum_new(int nNullDate,int nSettle, int nMat,int nFreq,int" " nBase)\n" "{\n" @@ -765,10 +764,10 @@ std::string lcl_Getcoupnum_new= " return tmp;\n" "}\n"; -std::string setDayDecl= +const char setDayDecl[] = "void setDay(int nOrigDay, int nMonth,int nYear,int bLastDay,int b30Days," "int *nDay);\n"; -std::string setDay= +const char setDay[] = "void setDay(int nOrigDay, int nMonth,int nYear,int bLastDay,int b30Days," "int *nDay)\n" "{\n" @@ -785,10 +784,10 @@ std::string setDay= " }\n" "}\n"; -std::string coupdaysDecl= +const char coupdaysDecl[] = "double coupdays(int nSettle,int nMat,int nFreq,int nBase);\n"; -std::string coupdays= +const char coupdays[] = "double coupdays(int nSettle,int nMat,int nFreq,int nBase)\n" "{\n" " int nNullDate=GetNullDate();\n" @@ -797,10 +796,10 @@ std::string coupdays= " else\n" " return (double)GetDaysInYear(0,0,nBase)/nFreq;\n" "}\n"; -std::string coupdays_newDecl= +const char coupdays_newDecl[] = "double coupdays_new(int nSettle,int nMat,int nFreq,int nBase);\n"; -std::string coupdays_new= +const char coupdays_new[] = "double coupdays_new(int nSettle,int nMat,int nFreq,int nBase)\n" "{\n" " int nNullDate=693594;\n" @@ -810,30 +809,30 @@ std::string coupdays_new= " return (double)GetDaysInYear(0,0,nBase)/(double)nFreq;\n" "}\n"; -std::string coupdaybsDecl= +const char coupdaybsDecl[] = "double coupdaybs( int nSettle,int nMat,int nFreq,int nBase);\n"; -std::string coupdaybs= +const char coupdaybs[] = "double coupdaybs( int nSettle,int nMat,int nFreq,int nBase)\n" "{\n" " int nNullDate=GetNullDate();\n" " return lcl_Getcoupdaybs(nNullDate, nSettle, nMat,nFreq, nBase);\n" "}\n"; -std::string coupdaybs_newDecl= +const char coupdaybs_newDecl[] = "double coupdaybs_new( int nSettle,int nMat,int nFreq,int nBase);\n"; -std::string coupdaybs_new= +const char coupdaybs_new[] = "double coupdaybs_new( int nSettle,int nMat,int nFreq,int nBase)\n" "{\n" " int nNullDate=693594;\n" " return lcl_Getcoupdaybs_new(nNullDate, nSettle, nMat,nFreq, nBase);\n" "}\n"; -std::string coupdaysncDecl= +const char coupdaysncDecl[] = "double coupdaysnc( int nSettle,int nMat,int nFreq,int nBase);\n"; -std::string coupdaysnc= +const char coupdaysnc[] = "double coupdaysnc( int nSettle,int nMat,int nFreq,int nBase)\n" "{\n" " int nNullDate=GetNullDate();\n" @@ -870,10 +869,10 @@ std::string coupdaysnc= " return coupdays(nSettle,nMat,nFreq,nBase)- coupdaybs( nSettle,nMat," "nFreq,nBase);\n" "}\n"; -std::string coupdaysnc_newDecl= +const char coupdaysnc_newDecl[] = "double coupdaysnc_new( int nSettle,int nMat,int nFreq,int nBase);\n"; -std::string coupdaysnc_new= +const char coupdaysnc_new[] = "double coupdaysnc_new( int nSettle,int nMat,int nFreq,int nBase)\n" "{\n" " int nNullDate=693594;\n" @@ -913,10 +912,10 @@ std::string coupdaysnc_new= "nMat,nFreq,nBase);\n" "}\n"; -std::string checklessthanDecl= +const char checklessthanDecl[] = "int checklessthan(int aYear,int bYear,int aMonth,int bMonth,int anDay,int " "bnDay,int abLastDay,int bbLastDay,int anOrigDay,int bnOrigDay);\n"; -std::string checklessthan= +const char checklessthan[] = "int checklessthan(int aYear,int bYear,int aMonth,int bMonth,int anDay,int " "bnDay,int abLastDay,int bbLastDay,int anOrigDay,int bnOrigDay)\n" "{\n" @@ -931,30 +930,30 @@ std::string checklessthan= " return anOrigDay < bnOrigDay;\n" "}\n"; -std::string coupnumDecl= +const char coupnumDecl[] = "double coupnum( int nSettle,int nMat,int nFreq,int nBase);\n"; -std::string coupnum= +const char coupnum[] = "double coupnum( int nSettle,int nMat,int nFreq,int nBase)\n" "{\n" " int nNullDate=GetNullDate();\n" " return lcl_Getcoupnum(nNullDate,nSettle,nMat,nFreq);\n" "}\n"; -std::string coupnum_newDecl= +const char coupnum_newDecl[] = "double coupnum_new( int nSettle,int nMat,int nFreq,int nBase);\n"; -std::string coupnum_new= +const char coupnum_new[] = "double coupnum_new( int nSettle,int nMat,int nFreq,int nBase)\n" "{\n" " int nNullDate=693594;\n" " return lcl_Getcoupnum_new(nNullDate,nSettle,nMat,nFreq,nBase);\n" "}\n"; -std::string getPrice_Decl= +const char getPrice_Decl[] = "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n" "double fRedemp, int nFreq, int nBase );\n"; -std::string getPrice_= +const char getPrice_[] = "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n" "double fRedemp, int nFreq, int nBase )\n" "{\n" @@ -972,11 +971,11 @@ std::string getPrice_= " fRet += fT1 / pow( fT2, fK + fDSC_E );\n" " return fRet;\n" "}\n"; -std::string getPrice_new_Decl= +const char getPrice_new_Decl[] = "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n" "double fRedemp, int nFreq, int nBase );\n"; -std::string getPrice_new= +const char getPrice_new[] = "double getPrice_(int nSettle, int nMat, double fRate, double fYield,\n" "double fRedemp, int nFreq, int nBase )\n" "{\n" @@ -995,11 +994,11 @@ std::string getPrice_new= " return fRet;\n" "}\n"; -std::string getYield_Decl= +const char getYield_Decl[] = "double getYield_( int nNullDate, int nSettle, int nMat, double fCoup," "double fPrice,double fRedemp, int nFreq, int nBase);\n"; -std::string getYield_= +const char getYield_[] = "double getYield_( int nNullDate, int nSettle, int nMat, double fCoup," "double fPrice,double fRedemp, int nFreq, int nBase )\n" "{\n" @@ -1049,11 +1048,11 @@ std::string getYield_= " return fYieldN;\n" "}\n"; -std::string GetYearFracDecl= +const char GetYearFracDecl[] = "double GetYearFrac( int nNullDate, int nStartDate, int nEndDate," "int nMode );\n"; -std::string GetYearFrac= +const char GetYearFrac[] = "double GetYearFrac( int nNullDate, int nStartDate, int nEndDate," "int nMode ) \n" "{\n" @@ -1187,11 +1186,11 @@ std::string GetYearFrac= " return (double)( nDayDiff ) / (nDaysInYear);\n" "}\n"; -std::string GetYieldmatDecl= +const char GetYieldmatDecl[] = "double GetYieldmat( int nNullDate, int nSettle, int nMat, int nIssue,\n" "double fRate, double fPrice, int nBase );\n"; -std::string GetYieldmat= +const char GetYieldmat[] = "double GetYieldmat( int nNullDate, int nSettle, int nMat, int nIssue,\n" "double fRate, double fPrice, int nBase )\n" "{\n" @@ -1205,11 +1204,11 @@ std::string GetYieldmat= " return y;\n" "}\n"; -std::string GetDiffDateDecl= +const char GetDiffDateDecl[] = "int GetDiffDate( int nNullDate, int nStartDate, int nEndDate, int nMode," " int* pOptDaysIn1stYear );\n"; -std::string GetDiffDate= +const char GetDiffDate[] = "int GetDiffDate( int nNullDate, int nStartDate, int nEndDate, int nMode," " int* pOptDaysIn1stYear )\n" "{\n" @@ -1266,11 +1265,11 @@ std::string GetDiffDate= " return bNeg? -nRet : nRet;\n" "}\n"; -std::string GetYearDiffDecl= +const char GetYearDiffDecl[] = "double GetYearDiff( int nNullDate, int nStartDate, int nEndDate," "int nMode);\n"; -std::string GetYearDiff= +const char GetYearDiff[] = "double GetYearDiff( int nNullDate, int nStartDate, int nEndDate," "int nMode )\n" "{\n" @@ -1281,13 +1280,13 @@ std::string GetYearDiff= " return (double)(nTotalDays)/(double)nDays1stYear;\n" "}\n"; -std::string GetDiffDate360_Decl= +const char GetDiffDate360_Decl[] = "int GetDiffDate360_(\n" " int nDay1, int nMonth1, int nYear1, bool bLeapYear1,\n" " int nDay2, int nMonth2, int nYear2,\n" " bool bUSAMethod );\n"; -std::string GetDiffDate360_= +const char GetDiffDate360_[] = "int GetDiffDate360_(\n" " int nDay1, int nMonth1, int nYear1, bool bLeapYear1,\n" " int nDay2, int nMonth2, int nYear2,\n" @@ -1318,11 +1317,11 @@ std::string GetDiffDate360_= "nYear1 * 360;\n" "}\n"; -std::string GetDiffDate360Decl= +const char GetDiffDate360Decl[] = "int GetDiffDate360( int nNullDate, int nDate1, int nDate2," "bool bUSAMethod);\n"; -std::string GetDiffDate360= +const char GetDiffDate360[] = "int GetDiffDate360( int nNullDate, int nDate1, int nDate2," "bool bUSAMethod )\n" "{\n" @@ -1335,12 +1334,12 @@ std::string GetDiffDate360= "nDay2, nMonth2, nYear2, bUSAMethod );\n" "}\n"; -std::string GetDurationDecl= +const char GetDurationDecl[] = "double GetDuration( \n" " int nNullDate, int nSettle, int nMat, double fCoup,\n" " double fYield, int nFreq, int nBase );\n"; -std::string GetDuration= +const char GetDuration[] = "double GetDuration( \n" " int nNullDate, int nSettle, int nMat, double fCoup,\n" " double fYield, int nFreq, int nBase )\n" @@ -1366,12 +1365,12 @@ std::string GetDuration= " fDur /= nFreq;\n" " return fDur;\n""}\n"; -std::string GetDuration_newDecl= +const char GetDuration_newDecl[] = "double GetDuration_new( \n" " int nNullDate, int nSettle, int nMat, double fCoup,\n" " double fYield, int nFreq, int nBase );\n"; -std::string GetDuration_new= +const char GetDuration_new[] = "double GetDuration_new( \n" " int nNullDate, int nSettle, int nMat, double fCoup,\n" " double fYield, int nFreq, int nBase )\n" @@ -1404,11 +1403,11 @@ std::string GetDuration_new= " return fDur;\n" " }\n"; -std::string ScGetDDBDecl= +const char ScGetDDBDecl[] = "double ScGetDDB(double fCost, double fSalvage, double fLife, double fPeriod," "double fFactor);\n"; -std::string ScGetDDB= +const char ScGetDDB[] = "double ScGetDDB(double fCost, double fSalvage, double fLife, double fPeriod," "double fFactor)\n" "{\n" @@ -1435,20 +1434,20 @@ std::string ScGetDDB= " return fDdb;\n" "}\n"; -std::string DblMinDecl= +const char DblMinDecl[] = "inline double DblMin( double a, double b );\n"; -std::string DblMin= +const char DblMin[] = "inline double DblMin( double a, double b )\n" "{\n" " return (a < b) ? a : b;\n" "}\n"; -std::string ScInterVDBDecl= +const char ScInterVDBDecl[] = "double ScInterVDB(double fCost, double fSalvage, double fLife, double fLife1," "double fPeriod, double fFactor);\n"; -std::string ScInterVDB= +const char ScInterVDB[] = "double ScInterVDB(double fCost, double fSalvage, double fLife, double fLife1," "double fPeriod, double fFactor)\n" "{\n" @@ -1492,11 +1491,11 @@ std::string ScInterVDB= " return fVdb;\n" "}\n"; -std::string VDBImplementDecl= +const char VDBImplementDecl[] = "double VDBImplement(double fCost, double fSalvage, double fLife, double fStart" ", double fEnd, double fFactor, bool bNoSwitch);\n"; -std::string VDBImplement= +const char VDBImplement[] = "double VDBImplement(double fCost, double fSalvage, double fLife, double fStart" ", double fEnd, double fFactor, bool bNoSwitch)\n" "{\n" @@ -1541,11 +1540,11 @@ std::string VDBImplement= " return result;\n" "}\n"; -std::string GetOddlpriceDecl= +const char GetOddlpriceDecl[] = "double GetOddlprice( int nNullDate, int nSettle, int nMat, int nLastCoup,\n" " double fRate, double fYield, double fRedemp, int nFreq, int nBase );\n"; -std::string GetOddlprice= +const char GetOddlprice[] = "double GetOddlprice( int nNullDate, int nSettle, int nMat, int nLastCoup,\n" " double fRate, double fYield, double fRedemp, int nFreq, int nBase )\n" "{\n" @@ -1562,11 +1561,11 @@ std::string GetOddlprice= " return p;\n" "}\n"; -std::string GetOddlyieldDecl= +const char GetOddlyieldDecl[] = "double GetOddlyield( int nNullDate, int nSettle, int nMat, int nLastCoup,\n" " double fRate, double fPrice, double fRedemp, int nFreq, int nBase );\n"; -std::string GetOddlyield= +const char GetOddlyield[] = "double GetOddlyield( int nNullDate, int nSettle, int nMat, int nLastCoup,\n" " double fRate, double fPrice, double fRedemp, int nFreq, int nBase ) \n" "{\n" @@ -1581,11 +1580,11 @@ std::string GetOddlyield= " return y;\n" "}\n"; -std::string GetYearFrac_newDecl= +const char GetYearFrac_newDecl[] = "double GetYearFrac_new( int nNullDate, int nStartDate, int nEndDate," "int nMode );\n"; -std::string GetYearFrac_new= +const char GetYearFrac_new[] = "double GetYearFrac_new( int nNullDate, int nStartDate, int nEndDate," "int nMode ) \n" "{\n" @@ -1710,10 +1709,10 @@ std::string GetYearFrac_new= " return (double)( nDayDiff ) / (nDaysInYear);\n" "}\n"; -std::string DaysToDate_newDecl = +const char DaysToDate_newDecl[] = "void DaysToDate_new( int nDays, int *rDay, int* rMonth, int* rYear );\n"; -std::string DaysToDate_new = +const char DaysToDate_new[] = "void DaysToDate_new( int nDays, int *rDay, int* rMonth, int* rYear )\n" "{\n" " int nTempDays;\n" @@ -1755,10 +1754,10 @@ std::string DaysToDate_new = " }\n" "}\n"; -std::string DaysToDate_LocalBarrierDecl = +const char DaysToDate_LocalBarrierDecl[] = "void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear );\n"; -std::string DaysToDate_LocalBarrier = +const char DaysToDate_LocalBarrier[] = "void DaysToDate( int nDays, int *rDay, int* rMonth, int* rYear )\n" "{\n" " int nTempDays;\n" @@ -1801,11 +1800,11 @@ std::string DaysToDate_LocalBarrier = " }\n" "}\n"; -std::string GetYearDiff_newDecl= +const char GetYearDiff_newDecl[] = "double GetYearDiff_new( int nNullDate, int nStartDate, int nEndDate," "int nMode);\n"; -std::string GetYearDiff_new= +const char GetYearDiff_new[] = "double GetYearDiff_new( int nNullDate, int nStartDate, int nEndDate," "int nMode )\n" "{\n" @@ -1816,11 +1815,11 @@ std::string GetYearDiff_new= " return (double)(nTotalDays) / (double)nDays1stYear;\n" "}\n"; -std::string GetDiffDate_newDecl= +const char GetDiffDate_newDecl[] = "int GetDiffDate_new( int nNullDate, int nStartDate, int nEndDate, int nMode," " int* pOptDaysIn1stYear );\n"; -std::string GetDiffDate_new= +const char GetDiffDate_new[] = "int GetDiffDate_new( int nNullDate, int nStartDate, int nEndDate, int nMode," " int* pOptDaysIn1stYear )\n" "{\n" @@ -1877,6 +1876,4 @@ std::string GetDiffDate_new= " return bNeg? -nRet : nRet;\n" "}\n"; -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx index 550446393a8f..82452b181899 100644 --- a/sc/source/core/opencl/op_math.cxx +++ b/sc/source/core/opencl/op_math.cxx @@ -10,7 +10,7 @@ #include "op_math.hxx" #include <formula/vectortoken.hxx> -#include "opinlinefun_math.hxx" +#include "op_math_helpers.hxx" #include <sstream> using namespace formula; diff --git a/sc/source/core/opencl/opinlinefun_math.hxx b/sc/source/core/opencl/op_math_helpers.hxx similarity index 80% rename from sc/source/core/opencl/opinlinefun_math.hxx rename to sc/source/core/opencl/op_math_helpers.hxx index cee3775773dd..f18cc7f39249 100644 --- a/sc/source/core/opencl/opinlinefun_math.hxx +++ b/sc/source/core/opencl/op_math_helpers.hxx @@ -9,10 +9,8 @@ #pragma once -#include <string> - -std::string Math_IntgDecl="double Intg(double n);\n"; -std::string Math_Intg= +const char Math_IntgDecl[] ="double Intg(double n);\n"; +const char Math_Intg[] = "double Intg(double n)\n" "{\n" " if(trunc(n)==n )\n" @@ -23,8 +21,8 @@ std::string Math_Intg= " return trunc(n)+1;\n" "}\n"; -std::string bikDecl = "double bik(double n,double k);\n"; -std::string bik = +const char bikDecl[] = "double bik(double n,double k);\n"; +const char bik[] = "double bik(double n,double k)\n" "{\n" " double nVal1 = n;\n" @@ -41,8 +39,8 @@ std::string bik = " return (nVal1 / nVal2);\n" "}\n"; -std::string local_cothDecl = "double local_coth(double n);\n"; -std::string local_coth = +const char local_cothDecl[] = "double local_coth(double n);\n"; +const char local_coth[] = "double local_coth(double n)\n" "{\n" " double a = exp(n);\n" @@ -51,15 +49,15 @@ std::string local_coth = " return nVal;\n" "}\n"; -std::string local_coshDecl = "double local_cosh(double n);\n"; -std::string local_cosh = +const char local_coshDecl[] = "double local_cosh(double n);\n"; +const char local_cosh[] = "double local_cosh(double n)\n" "{\n" " double nVal = (exp(n) + exp(-n)) / 2;\n" " return nVal;\n" "}\n"; -std::string atan2Decl = "double arctan2(double y, double x);\n"; -std::string atan2Content = +const char atan2Decl[] = "double arctan2(double y, double x);\n"; +const char atan2Content[] = "double arctan2(double y, double x)\n" "{\n" " if(y==0.0)\n" diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx index 5690d9d9260c..49d26fe5bd4c 100644 --- a/sc/source/core/opencl/op_statistical.cxx +++ b/sc/source/core/opencl/op_statistical.cxx @@ -11,7 +11,7 @@ #include <formula/vectortoken.hxx> #include <sstream> -#include "opinlinefun_statistical.cxx" +#include "op_statistical_helpers.hxx" using namespace formula; diff --git a/sc/source/core/opencl/opinlinefun_statistical.cxx b/sc/source/core/opencl/op_statistical_helpers.hxx similarity index 93% rename from sc/source/core/opencl/opinlinefun_statistical.cxx rename to sc/source/core/opencl/op_statistical_helpers.hxx index 4247e8f2ec32..da86725296fe 100644 --- a/sc/source/core/opencl/opinlinefun_statistical.cxx +++ b/sc/source/core/opencl/op_statistical_helpers.hxx @@ -7,25 +7,25 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef SC_OPENCL_OPINLINFUN_statistical -#define SC_OPENCL_OPINLINFUN_statistical -std::string MinDecl = "#define Min 2.22507e-308\n"; -std::string fBigInvDecl ="#define fBigInv 2.22045e-016\n"; -std::string fMachEpsDecl ="#define fMachEps 2.22045e-016\n"; -std::string fLogDblMaxDecl ="#define fLogDblMax log(1.79769e+308)\n"; -std::string fHalfMachEpsDecl ="#define fHalfMachEps 0.5*2.22045e-016\n"; -std::string fMaxGammaArgumentDecl= +#pragma once + +const char MinDecl[] = "#define Min 2.22507e-308\n"; +const char fBigInvDecl[] ="#define fBigInv 2.22045e-016\n"; +const char fMachEpsDecl[] ="#define fMachEps 2.22045e-016\n"; +const char fLogDblMaxDecl[] ="#define fLogDblMax log(1.79769e+308)\n"; +const char fHalfMachEpsDecl[] ="#define fHalfMachEps 0.5*2.22045e-016\n"; +const char fMaxGammaArgumentDecl[] = "#define fMaxGammaArgument 171.624376956302\n"; -std::string GetValueDecl= +const char GetValueDecl[] = "double GetValue( double x,double fp,double fDF );\n"; -std::string GetValue= +const char GetValue[] = "double GetValue( double x,double fp,double fDF )\n" "{\n" " return fp - 2 * GetTDist(x, fDF);\n" "}\n"; -std::string GetGammaSeriesDecl= +const char GetGammaSeriesDecl[] = "double GetGammaSeries( double fA, double fX );\n"; -std::string GetGammaSeries = +const char GetGammaSeries[] = "double GetGammaSeries( double fA, double fX )\n" "{\n" " double fDenomfactor = fA;\n" @@ -44,9 +44,9 @@ std::string GetGammaSeries = " }\n" " return fSum;\n" "}\n"; -std::string GetGammaContFractionDecl = "double GetGammaContFraction( double " +const char GetGammaContFractionDecl[] = "double GetGammaContFraction( double " "fA, double fX );\n"; -std::string GetGammaContFraction = +const char GetGammaContFraction[] = "double GetGammaContFraction( double fA, double fX )\n" "{\n" " double fBig = 1.0/fBigInv;\n" @@ -94,9 +94,9 @@ std::string GetGammaContFraction = " }\n" " return fApprox;\n" "}\n"; -std::string GetLowRegIGammaDecl = "double GetLowRegIGamma( double " +const char GetLowRegIGammaDecl[] = "double GetLowRegIGamma( double " "fA, double fX );\n"; -std::string GetLowRegIGamma = +const char GetLowRegIGamma[] = "double GetLowRegIGamma( double fA, double fX )\n" "{\n" " double fLnFactor = fA * log(fX) - fX - lgamma(fA);\n" @@ -106,9 +106,9 @@ std::string GetLowRegIGamma = " else\n" " return fFactor * GetGammaSeries(fA,fX);\n" "}\n"; -std::string GetGammaDistDecl = "double GetGammaDist( double fX, double " +const char GetGammaDistDecl[] = "double GetGammaDist( double fX, double " "fAlpha, double fLambda );\n"; -std::string GetGammaDist = +const char GetGammaDist[] = "double GetGammaDist( double fX, double fAlpha, double fLambda )\n" "{\n" " if (fX <= 0.0)\n" @@ -116,9 +116,9 @@ std::string GetGammaDist = " else\n" " return GetLowRegIGamma( fAlpha, fX / fLambda);\n" "}\n"; -std::string GetGammaDistPDFDecl = "double GetGammaDistPDF( double fX" +const char GetGammaDistPDFDecl[] = "double GetGammaDistPDF( double fX" ", double fAlpha, double fLambda );\n"; -std::string GetGammaDistPDF = +const char GetGammaDistPDF[] = "double GetGammaDistPDF( double fX, double fAlpha, double fLambda )\n" "{\n" " if (fX < 0.0)\n" @@ -170,9 +170,9 @@ std::string GetGammaDistPDF = " }\n" " }\n" "}\n"; -std::string GetBetaDistDecl = +const char GetBetaDistDecl[] = "double GetBetaDist(double fXin, double fAlpha, double fBeta);\n"; -std::string GetBetaDist = +const char GetBetaDist[] = "double GetBetaDist(double fXin, double fAlpha, double fBeta)\n" "{\n" " if (fXin <= 0.0)\n" @@ -216,9 +216,9 @@ std::string GetBetaDist = " return fResult;\n" "}\n"; -std::string GetFDistDecl = +const char GetFDistDecl[] = "double GetFDist(double x, double fF1, double fF2);\n"; -std::string GetFDist = +const char GetFDist[] = "double GetFDist(double x, double fF1, double fF2)\n" "{\n" " double arg = fF2/(fF2+fF1*x);\n" @@ -226,9 +226,9 @@ std::string GetFDist = " double beta = fF1/2.0;\n" " return (GetBetaDist(arg, alpha, beta));\n" "}\n"; -std::string GetGammaInvValueDecl = "double" +const char GetGammaInvValueDecl[] = "double" " GetGammaInvValue(double fAlpha,double fBeta,double fX1 );\n"; -std::string GetGammaInvValue = +const char GetGammaInvValue[] = "double GetGammaInvValue(double fAlpha,double fBeta,double fX1 )\n" "{\n" " if (fX1 <= 0.0)\n" @@ -244,9 +244,9 @@ std::string GetGammaInvValue = " return fFactor * GetGammaSeries(fAlpha,fX);\n" " }\n" "}\n"; -std::string GetFInvValueDecl = "double GetFInvValue(double fF1,double fF2" +const char GetFInvValueDecl[] = "double GetFInvValue(double fF1,double fF2" ",double fX1 );"; -std::string GetFInvValue = +const char GetFInvValue[] = "double GetFInvValue(double fF1,double fF2,double fX1 )\n" "{\n" " double arg = fF2/(fF2+fF1*fX1);\n" @@ -297,9 +297,9 @@ std::string GetFInvValue = " fResult = 0.0;\n" " return fResult;\n" "}\n"; -std::string GetBinomDistPMFDecl = +const char GetBinomDistPMFDecl[] = "double GetBinomDistPMF(double x, double n, double p);"; -std::string GetBinomDistPMF = +const char GetBinomDistPMF[] = "double GetBinomDistPMF(double x, double n, double p)\n" "{\n" " double q = (0.5 - p) + 0.5;\n" @@ -326,10 +326,10 @@ std::string GetBinomDistPMF = " }\n" "}\n"; -std::string lcl_GetBinomDistRangeDecl = +const char lcl_GetBinomDistRangeDecl[] = "double lcl_GetBinomDistRange(double n, \n" "double xs, double xe, double fFactor, double p, double q);"; -std::string lcl_GetBinomDistRange= +const char lcl_GetBinomDistRange[] = "double lcl_GetBinomDistRange(double n, double xs, double xe,\n" " double fFactor, double p, double q)\n" "{\n" @@ -348,8 +348,8 @@ std::string lcl_GetBinomDistRange= " return (fSum > 1.0) ? 1.0 : fSum;\n" "}\n"; -std::string GetLogGammaDecl = "double GetLogGamma(double fZ);\n"; -std::string GetLogGamma = +const char GetLogGammaDecl[] = "double GetLogGamma(double fZ);\n"; +const char GetLogGamma[] = "double GetLogGamma(double fZ)\n" "{\n" " if (fZ >= fMaxGammaArgument)\n" @@ -361,8 +361,8 @@ std::string GetLogGamma = " return lcl_GetLogGammaHelper(fZ+2) - log(fZ+1) - log(fZ);\n" "}\n"; -std::string GetChiDistDecl = "double GetChiDist(double fX, double fDF);\n"; -std::string GetChiDist = +const char GetChiDistDecl[] = "double GetChiDist(double fX, double fDF);\n"; +const char GetChiDist[] = "double GetChiDist(double fX, double fDF)\n" "{\n" " if (fX <= 0.0)\n" @@ -371,9 +371,9 @@ std::string GetChiDist = " return GetUpRegIGamma( fDF/2.0, fX/2.0);\n" "}\n"; -std::string GetChiSqDistCDFDecl = +const char GetChiSqDistCDFDecl[] = "double GetChiSqDistCDF(double fX, double fDF);\n"; -std::string GetChiSqDistCDF = +const char GetChiSqDistCDF[] = "double GetChiSqDistCDF(double fX, double fDF)\n" "{\n" " if (fX <= 0.0)\n" @@ -382,9 +382,9 @@ std::string GetChiSqDistCDF = " return GetLowRegIGamma( fDF/2.0, fX/2.0);\n" "}\n"; -std::string GetChiSqDistPDFDecl= +const char GetChiSqDistPDFDecl[] = "double GetChiSqDistPDF(double fX, double fDF);\n"; -std::string GetChiSqDistPDF = +const char GetChiSqDistPDF[] = "double GetChiSqDistPDF(double fX, double fDF)\n" "{\n" " double fValue;\n" @@ -421,10 +421,10 @@ std::string GetChiSqDistPDF = " return fValue;\n" "}\n"; -std::string lcl_IterateInverseBetaInvDecl = +const char lcl_IterateInverseBetaInvDecl[] = "static double lcl_IterateInverseBetaInv(double fp, double fAlpha, \n" " double fBeta, double fAx, double fBx, bool *rConvError );\n"; -std::string lcl_IterateInverseBetaInv = +const char lcl_IterateInverseBetaInv[] = "static double lcl_IterateInverseBetaInv(double fp, double fAlpha, \n" " double fBeta, double fAx, double fBx, bool *rConvError )\n" "{\n" @@ -518,10 +518,10 @@ std::string lcl_IterateInverseBetaInv = " return fRx;\n" "}\n"; -std::string lcl_IterateInverseChiInvDecl = +const char lcl_IterateInverseChiInvDecl[] = "static double lcl_IterateInverseChiInv" "(double fp, double fdf, double fAx, double fBx, bool *rConvError);\n"; -std::string lcl_IterateInverseChiInv = +const char lcl_IterateInverseChiInv[] = "static double lcl_IterateInverseChiInv" "(double fp, double fdf, double fAx, double fBx, bool *rConvError)\n" "{\n" @@ -615,10 +615,10 @@ std::string lcl_IterateInverseChiInv = " return fRx;\n" "}\n"; -std::string lcl_IterateInverseChiSQInvDecl = +const char lcl_IterateInverseChiSQInvDecl[] = "static double lcl_IterateInverseChiSQInv( double fp, double fdf, \n" " double fAx, double fBx, bool *rConvError );\n"; -std::string lcl_IterateInverseChiSQInv = +const char lcl_IterateInverseChiSQInv[] = "static double lcl_IterateInverseChiSQInv( double fp, double fdf, \n" " double fAx, double fBx, bool *rConvError )\n" "{\n" @@ -713,8 +713,8 @@ std::string lcl_IterateInverseChiSQInv = " return fRx;\n" "}\n"; -std::string gaussinvDecl = "double gaussinv(double x);\n"; -std::string gaussinv = +const char gaussinvDecl[] = "double gaussinv(double x);\n"; +const char gaussinv[] = "double gaussinv(double x)\n" "{\n" " double q,t,z;\n" @@ -874,18 +874,18 @@ std::string gaussinv = " return z;\n" "}\n"; -std::string lcl_GetLogGammaHelperDecl= +const char lcl_GetLogGammaHelperDecl[] = "static double lcl_GetLogGammaHelper(double fZ);\n"; -std::string lcl_GetLogGammaHelper = +const char lcl_GetLogGammaHelper[] = "static double lcl_GetLogGammaHelper(double fZ)\n" "{\n" " double fg = 6.024680040776729583740234375;\n" " double fZgHelp = fZ + fg - 0.5;\n" " return log( lcl_getLanczosSum(fZ)) + (fZ-0.5) * log(fZgHelp) - fZgHelp;\n" "}\n"; -std::string lcl_GetGammaHelperDecl= +const char lcl_GetGammaHelperDecl[] = "static double lcl_GetGammaHelper(double fZ);\n"; -std::string lcl_GetGammaHelper = +const char lcl_GetGammaHelper[] = "static double lcl_GetGammaHelper(double fZ)\n" "{\n" " double fGamma = lcl_getLanczosSum(fZ);\n" @@ -902,9 +902,9 @@ std::string lcl_GetGammaHelper = " }\n" " return fGamma;\n" "}\n"; -std::string lcl_getLanczosSumDecl= +const char lcl_getLanczosSumDecl[] = "static double lcl_getLanczosSum(double fZ);\n"; -std::string lcl_getLanczosSum = +const char lcl_getLanczosSum[] = "static double lcl_getLanczosSum(double fZ) \n" "{ \n" " double fNum[13] ={ \n" @@ -1026,9 +1026,9 @@ std::string lcl_getLanczosSum = " return fSumNum/fSumDenom;\n" "}\n"; -std::string GetUpRegIGammaDecl= +const char GetUpRegIGammaDecl[] = " double GetUpRegIGamma( double fA, double fX ) ;\n"; -std::string GetUpRegIGamma = +const char GetUpRegIGamma[] = "double GetUpRegIGamma( double fA, double fX )\n" "{\n" " double fLnFactor= fA*log(fX)-fX-lgamma(fA);\n" @@ -1039,23 +1039,23 @@ std::string GetUpRegIGamma = " return 1.0 -fFactor * GetGammaSeries(fA,fX);\n" "}\n"; -std::string lcl_HasChangeOfSignDecl= +const char lcl_HasChangeOfSignDecl[] = "static inline bool lcl_HasChangeOfSign( double u, double w );\n"; -std::string lcl_HasChangeOfSign = +const char lcl_HasChangeOfSign[] = "static inline bool lcl_HasChangeOfSign( double u, double w )\n" "{\n" " return (u < 0.0 && w > 0.0) || (u > 0.0 && w < 0.0);\n" "}\n"; -std::string GetTDistDecl=" double GetTDist(double T, double fDF);\n"; -std::string GetTDist = +const char GetTDistDecl[] =" double GetTDist(double T, double fDF);\n"; +const char GetTDist[] = "double GetTDist(double T, double fDF)\n" "{\n" " return 0.5 * GetBetaDist(fDF/(fDF+T*T),fDF/2.0, 0.5);\n" "}\n"; -std::string GetBetaDecl=" double GetBeta(double fAlpha, double fBeta);\n"; -std::string GetBeta = +const char GetBetaDecl[] =" double GetBeta(double fAlpha, double fBeta);\n"; +const char GetBeta[] = "double GetBeta(double fAlpha, double fBeta)\n" "{\n" " double fA;\n" @@ -1073,9 +1073,9 @@ std::string GetBeta = " - fB*log1p(fA/(fB + fgm)) - fgm);\n" "}\n"; -std::string GetLogBetaDecl= +const char GetLogBetaDecl[] = " double GetLogBeta(double fAlpha, double fBeta);\n"; -std::string GetLogBeta = +const char GetLogBeta[] = "double GetLogBeta(double fAlpha, double fBeta)\n" "{\n" " double fA;\n" @@ -1092,9 +1092,9 @@ std::string GetLogBeta = " return fResult;\n" "}\n"; -std::string GetBetaDistPDFDecl= +const char GetBetaDistPDFDecl[] = "double GetBetaDistPDF(double fX, double fA, double fB);\n"; -std::string GetBetaDistPDF = +const char GetBetaDistPDF[] = "double GetBetaDistPDF(double fX, double fA, double fB)\n" "{\n" " if (fA == 1.0) \n" @@ -1157,9 +1157,9 @@ std::string GetBetaDistPDF = " return exp( fAm1LogX + fBm1LogY - fLogBeta);\n" "}\n"; -std::string lcl_GetBetaHelperContFracDecl= +const char lcl_GetBetaHelperContFracDecl[] = "double lcl_GetBetaHelperContFrac(double fX, double fA, double fB);\n"; -std::string lcl_GetBetaHelperContFrac = +const char lcl_GetBetaHelperContFrac[] = "double lcl_GetBetaHelperContFrac(double fX, double fA, double fB)\n" "{ \n" @@ -1194,10 +1194,10 @@ std::string lcl_GetBetaHelperContFrac = " return cf;\n" "}\n"; -std::string lcl_IterateInverseDecl= +const char lcl_IterateInverseDecl[] = "double lcl_IterateInverse(" "double fAx, double fBx, bool* rConvError,double fp,double fDF );\n"; -std::string lcl_IterateInverse = +const char lcl_IterateInverse[] = "double lcl_IterateInverse( " "double fAx, double fBx, bool* rConvError,double fp,double fDF )\n" "{\n" @@ -1289,16 +1289,16 @@ std::string lcl_IterateInverse = " }\n" " return fRx;\n" "}\n"; -std::string phiDecl= +const char phiDecl[] = "double phi(double x);\n"; -std::string phi = +const char phi[] = "double phi(double x)\n" "{\n" " return 0.39894228040143268 * exp(-(x * x) / 2.0);\n" "}\n"; -std::string taylorDecl = +const char taylorDecl[] = "double taylor(double* pPolynom, uint nMax, double x);\n"; -std::string taylor = +const char taylor[] = "double taylor(double* pPolynom, uint nMax, double x)\n" "{\n" " double nVal = pPolynom[nMax];\n" @@ -1308,8 +1308,8 @@ std::string taylor = " }\n" " return nVal;\n" "}"; -std::string gaussDecl = "double gauss(double x);\n"; -std::string gauss = +const char gaussDecl[] = "double gauss(double x);\n"; +const char gauss[] = "double gauss(double x)\n" "{\n" " double xAbs = fabs(x);\n" @@ -1359,6 +1359,5 @@ std::string gauss = " else\n" " return nVal;\n" "}\n"; -#endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/opencl/utils.hxx b/sc/source/core/opencl/utils.hxx index 808234d69a91..a0c8ebfd72b1 100644 --- a/sc/source/core/opencl/utils.hxx +++ b/sc/source/core/opencl/utils.hxx @@ -7,8 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef INCLUDED_SC_SOURCE_CORE_OPENCL_UTILS_HXX -#define INCLUDED_SC_SOURCE_CORE_OPENCL_UTILS_HXX +#pragma once #include <sstream> @@ -46,6 +45,4 @@ std::string preciseFloat(long double f) = delete; // we do not use these #define stringstream do_not_use_std_stringstream } // namespace -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist index d1239f3a09fa..640544d2ee11 100644 --- a/solenv/clang-format/excludelist +++ b/solenv/clang-format/excludelist @@ -8191,19 +8191,19 @@ sc/source/core/opencl/op_database.cxx sc/source/core/opencl/op_database.hxx sc/source/core/opencl/op_financial.cxx sc/source/core/opencl/op_financial.hxx +sc/source/core/opencl/op_financial_helpers.hxx sc/source/core/opencl/op_logical.cxx sc/source/core/opencl/op_logical.hxx sc/source/core/opencl/op_math.cxx sc/source/core/opencl/op_math.hxx +sc/source/core/opencl/op_math_helpers.hxx sc/source/core/opencl/op_spreadsheet.cxx sc/source/core/opencl/op_spreadsheet.hxx sc/source/core/opencl/op_statistical.cxx sc/source/core/opencl/op_statistical.hxx +sc/source/core/opencl/op_statistical_helpers.hxx sc/source/core/opencl/opbase.cxx sc/source/core/opencl/opbase.hxx -sc/source/core/opencl/opinlinefun_finacial.cxx -sc/source/core/opencl/opinlinefun_math.hxx -sc/source/core/opencl/opinlinefun_statistical.cxx sc/source/core/tool/addincol.cxx sc/source/core/tool/addinhelpid.cxx sc/source/core/tool/addinlis.cxx commit 85bf78b31b3719edd7a22ae768d8b2e23816cdbd Author: Luboš Luňák <l.lu...@collabora.com> AuthorDate: Tue Sep 6 12:37:55 2022 +0200 Commit: Luboš Luňák <l.lu...@collabora.com> CommitDate: Tue Sep 13 09:05:19 2022 +0200 reduce opencl copy&paste in op_math.cxx Change-Id: Ibe2afa6ca3720a6cec8b74af5c582cb946cf5396 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139486 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lu...@collabora.com> diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx index b837d930910f..550446393a8f 100644 --- a/sc/source/core/opencl/op_math.cxx +++ b/sc/source/core/opencl/op_math.cxx @@ -17,200 +17,63 @@ using namespace formula; namespace sc::opencl { -void OpCos::GenSlidingWindowFunction(outputstream &ss, +void OpMathOneArgument::GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) { - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n"; - ss << " int gid0=get_global_id(0);\n"; - ss << " double arg0 = 0.0f;\n"; - FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken(); - assert(tmpCur); - if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode()) - { - if(tmpCur->GetType() == formula::svSingleVectorRef) - { - const formula::SingleVectorRefToken*tmpCurDVR= - static_cast - <const formula::SingleVectorRefToken *>(tmpCur); - ss << " arg0 = "; - ss << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n"; - ss << " if(isnan("; - ss << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ")||(gid0>="; - ss << tmpCurDVR->GetArrayLength(); - ss << "))\n"; - ss << " { arg0 = 0.0f; }\n"; - } - else if(tmpCur->GetType() == formula::svDouble) - { - ss << " arg0=" << tmpCur->GetDouble() << ";\n"; - } - } - else - { - ss << " arg0 = "; - ss << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n"; - } - ss << " return cos(arg0);\n"; - ss << "}"; - + CHECK_PARAMETER_COUNT( 1, 1 ); + GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); + ss << "{\n"; + ss << " int gid0 = get_global_id(0);\n"; + GenerateArg( 0, vSubArguments, ss ); + GenerateCode( ss ); + ss << "}"; } -void OpSec::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) + +void OpMathTwoArguments::GenSlidingWindowFunction(outputstream &ss, + const std::string &sSymName, SubArguments &vSubArguments) { - FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const - formula::SingleVectorRefToken *>(tmpCur); + CHECK_PARAMETER_COUNT( 2, 2 ); GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); ss << "{\n"; - ss <<" int gid0=get_global_id(0);\n"; - ss <<" double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss <<";\n"; - ss<<" if(isnan(arg0)||(gid0>="; - ss<<tmpCurDVR->GetArrayLength(); - ss<<"))\n"; - ss<<" arg0 = 0;\n"; - ss << " return 1.0 / cos(arg0);\n"; + ss << " double tmp = 0;\n"; + ss << " int gid0 = get_global_id(0);\n"; + GenerateArg( 0, vSubArguments, ss ); + GenerateArg( 1, vSubArguments, ss ); + GenerateCode( ss ); ss << "}"; } -void OpCosh::BinInlineFun(std::set<std::string>& decls, - std::set<std::string>& funs) + +void OpCos::GenerateCode( outputstream& ss ) const { - decls.insert(local_coshDecl); - funs.insert(local_cosh); + ss << " return cos(arg0);\n"; } -void OpSecH::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) + +void OpSec::GenerateCode( outputstream& ss ) const { - FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const - formula::SingleVectorRefToken *>(tmpCur); - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n"; - ss <<" int gid0=get_global_id(0);\n"; - ss <<" double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss <<";\n"; - ss<<" if(isnan(arg0)||(gid0>="; - ss<<tmpCurDVR->GetArrayLength(); - ss<<"))\n"; - ss<<" arg0 = 0;\n"; - ss << " return 1.0 / cosh(arg0);\n"; - ss << "}"; + ss << " return 1.0 / cos(arg0);\n"; } -void OpMROUND::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) + +void OpSecH::GenerateCode( outputstream& ss ) const { - CHECK_PARAMETER_COUNT(2, 2); - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n"; - ss<<" double tmp = 0;\n"; - ss<<" int gid0 = get_global_id(0);\n"; - ss<<" double arg0=0;\n"; - ss<<" double arg1=0;\n"; - ss <<"\n "; - //while (i-- > 1) - for (size_t i = 0; i < vSubArguments.size(); i++) - { - FormulaToken *pCur = vSubArguments[i]->GetFormulaToken(); - assert(pCur); - if (pCur->GetType() == formula::svSingleVectorRef) - { - const formula::SingleVectorRefToken* pSVR = - static_cast< const formula::SingleVectorRefToken* >(pCur); - ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n"; - } - else if (pCur->GetType() == formula::svDouble) - { - ss << "{\n"; - } + ss << " return 1.0 / cosh(arg0);\n"; +} - if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode()) - { - ss << " tmp="; - ss << vSubArguments[i]->GenSlidingWindowDeclRef(); - ss << ";\n"; - ss << " if (isnan(tmp))\n"; - ss << " arg"<<i<<"= 0;\n"; - ss << " else\n"; - ss << " arg"<<i<<"=tmp;\n"; - ss << " }\n"; - } - else - { - ss<<" arg"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef(); - ss<<";\n"; - } - } - ss<<" if(arg1==0)\n"; - ss<<" return arg1;\n"; - ss<<" tmp=arg1 * round(arg0 / arg1);\n"; - ss<<" return tmp;\n"; - ss<<"}"; +void OpCosh::BinInlineFun(std::set<std::string>& decls, + std::set<std::string>& funs) +{ + decls.insert(local_coshDecl); + funs.insert(local_cosh); } -void OpCosh::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) + +void OpCosh::GenerateCode( outputstream& ss ) const { - FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const - formula::SingleVectorRefToken *>(tmpCur); - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n"; - ss <<" int gid0=get_global_id(0);\n"; - ss << " double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n"; - ss<< " if(isnan(arg0)||(gid0>="; - ss<<tmpCurDVR->GetArrayLength(); - ss<<"))\n"; - ss<<" arg0 = 0;\n"; - ss << " double tmp=local_cosh(arg0);\n"; - ss << " return tmp;\n"; - ss << "}"; + ss << " return local_cosh(arg0);\n"; } -void OpCot::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) +void OpCot::GenerateCode( outputstream& ss ) const { - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n"; - ss << " int gid0=get_global_id(0);\n"; - ss << " double arg0 = 0.0f;\n"; - FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken(); - assert(tmpCur); - if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode()) - { - if(tmpCur->GetType() == formula::svSingleVectorRef) - { - const formula::SingleVectorRefToken*tmpCurDVR= - static_cast - <const formula::SingleVectorRefToken *>(tmpCur); - ss << " arg0 = "; - ss << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n"; - ss << " if(isnan("; - ss << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ")||(gid0>="; - ss << tmpCurDVR->GetArrayLength(); - ss << "))\n"; - ss << " { arg0 = 0.0f; }\n"; - } - else if(tmpCur->GetType() == formula::svDouble) - { - ss << " arg0="; - ss << tmpCur->GetDouble() << ";\n"; - } - } - else - { - ss << " arg0 = "; - ss << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n"; - } ss << " arg0 = arg0 * M_1_PI;\n"; ss << " return cospi(arg0) / sinpi(arg0);\n"; - ss << "}"; } void OpCoth::BinInlineFun(std::set<std::string>& decls, @@ -220,98 +83,14 @@ void OpCoth::BinInlineFun(std::set<std::string>& decls, funs.insert(local_coth); } -void OpCoth::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) -{ - FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const - formula::SingleVectorRefToken *>(tmpCur); - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n"; - ss <<" int gid0=get_global_id(0);\n"; - ss << " double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n"; - ss<< " if(isnan(arg0)||(gid0>="; - ss<<tmpCurDVR->GetArrayLength(); - ss<<"))\n"; - ss<<" arg0 = 0;\n"; - ss << " double tmp=local_coth(arg0);\n"; - ss << " return tmp;\n"; - ss << "}"; -} - -void OpCombinA::BinInlineFun(std::set<std::string>& decls, - std::set<std::string>& funs) +void OpCoth::GenerateCode( outputstream& ss ) const { - decls.insert(bikDecl); - funs.insert(bik); + ss << " return local_coth(arg0);\n"; } -void OpCombinA::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) +void OpEven::GenerateCode( outputstream& ss ) const { - CHECK_PARAMETER_COUNT( 2, 2 ); - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n"; - ss << " int gid0 = get_global_id(0);\n"; - ss << " double tem;\n"; - ss << " double arg0,arg1;\n"; - for (size_t i = 0; i < vSubArguments.size(); i++) - { - FormulaToken *pCur = vSubArguments[i]->GetFormulaToken(); - assert(pCur); - ss << " arg"<<i<<" = "<<vSubArguments[i]->GenSlidingWindowDeclRef(); - ss << ";\n"; - if(pCur->GetType() == formula::svSingleVectorRef) - { - const formula::SingleVectorRefToken* pSVR = - static_cast< const formula::SingleVectorRefToken* >(pCur); - ss << " if(isnan(arg" << i <<")||(gid0 >= "; - ss << pSVR->GetArrayLength(); - ss << "))\n"; - ss << " arg" << i << " = 0;\n"; - } - else if (pCur->GetType() == formula::svDouble) - { - ss << " if(isnan(arg" << i <<"))\n"; - ss << " arg" << i << " = 0;\n"; - } - } - ss << " arg0 = trunc(arg0);\n"; - ss << " arg1 = trunc(arg1);\n"; - ss << " if(arg0 >= arg1 && arg0 > 0 && arg1 > 0)\n"; - ss << " tem = bik(arg0+arg1-1,arg1);\n"; - ss << " else if(arg0 == 0 && arg1 == 0)\n"; - ss << " tem = 0;\n"; - ss << " else if(arg0 > 0 && arg1 == 0)\n"; - ss << " tem = 1;\n"; - ss << " else\n"; - ss << " tem = -1;\n"; - ss << " double i = tem - trunc(tem);\n"; - ss << " if(i < 0.5)\n"; - ss << " tem = trunc(tem);\n"; - ss << " else\n"; - ss << " tem = trunc(tem) + 1;\n"; - ss << " return tem;\n"; - ss << "}"; -} -void OpEven::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) -{ - FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const - formula::SingleVectorRefToken *>(tmpCur); - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n"; - ss <<" int gid0=get_global_id(0);\n"; - ss << " double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n"; - ss<< " if(isnan(arg0)||(gid0>="; - ss<<tmpCurDVR->GetArrayLength(); - ss<<"))\n"; - ss<<" arg0 = 0;\n"; - ss << " double tmp;\n"; - ss << " tmp = fabs(arg0 / 2);\n"; + ss << " double tmp = fabs(arg0 / 2);\n"; ss << " if ( trunc(tmp) == tmp )\n"; ss << " tmp = tmp * 2;\n"; ss << " else\n"; @@ -319,1056 +98,689 @@ void OpEven::GenSlidingWindowFunction(outputstream &ss, ss << " if (arg0 < 0)\n"; ss << " tmp = tmp * -1.0;\n"; ss << " return tmp;\n"; - ss << "}"; } -void OpMod::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) +void OpCsc::GenerateCode( outputstream& ss ) const { - CHECK_PARAMETER_COUNT( 2, 2 ); - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n"; - ss <<" int gid0=get_global_id(0);\n"; - ss << " double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n"; - ss << " double arg1 =" << vSubArguments[1]->GenSlidingWindowDeclRef(); - ss << ";\n"; - ss << " if(isnan(arg0)||arg0 == 0)\n"; - ss << " return 0;\n"; - ss << " if(isnan(arg1) || arg1 ==0)\n"; - ss << " return CreateDoubleError(DivisionByZero);\n"; - ss << " double tem;\n"; - ss << " if(arg0 < 0 && arg1 > 0)\n"; - ss << " while(arg0 < 0)\n"; - ss << " arg0 += arg1;\n"; - ss << " else if (arg0 > 0 && arg1 < 0)\n"; - ss << " while(arg0 > 0)\n"; - ss << " arg0 += arg1;\n"; - ss << " tem = fmod(arg0,arg1);\n"; - ss << " if(arg1 < 0 && tem > 0)\n"; - ss << " tem = -tem;\n"; - ss << " return tem;\n"; - ss << "}"; + ss << " return 1/sin(arg0);\n"; } -void OpLog::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) + +void OpCscH::GenerateCode( outputstream& ss ) const { - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n"; - ss << " int gid0 = get_global_id(0);\n"; - ss << " double tem;\n"; - ss << " double arg0,arg1;\n"; - for (size_t i = 0; i < vSubArguments.size(); i++) - { - FormulaToken *pCur = vSubArguments[i]->GetFormulaToken(); - assert(pCur); - ss << " arg"<<i<<" = "<<vSubArguments[i]->GenSlidingWindowDeclRef(); - ss << ";\n"; - if(pCur->GetType() == formula::svSingleVectorRef) - { - const formula::SingleVectorRefToken* pSVR = - static_cast< const formula::SingleVectorRefToken* >(pCur); - ss << " if(isnan(arg" << i <<")||(gid0 >= "; - ss << pSVR->GetArrayLength(); - ss << "))\n"; - if( i == 0) - ss << " arg0 = 0;\n"; - else if ( i == 1) - ss << " arg1 = 10;\n"; - } - else if (pCur->GetType() == formula::svDouble) - { - ss << " if(isnan(arg" << i <<"))\n"; - if( i == 0) - ss << " arg0 = 0;\n"; - else if ( i == 1) - ss << " arg1 = 10;\n"; - } - } - if (vSubArguments.size() < 2) - ss << " arg1 = 10;\n"; - ss << " tem = log10(arg0)/log10(arg1);;\n"; - ss << " return tem;\n"; - ss << "}"; + ss << " return 1/sinh(arg0);\n"; } -void OpCsc::GenSlidingWindowFunction( - outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) + +void OpExp::GenerateCode( outputstream& ss ) const { - FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const - formula::SingleVectorRefToken *>(tmpCur); - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n\t"; - ss <<"int gid0=get_global_id(0);\n\t"; - ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n\t"; - ss<< "if(isnan(arg0)||(gid0>="; - ss<<tmpCurDVR->GetArrayLength(); - ss<<"))\n\t\t"; - ss<<"arg0 = 0;\n\t"; - ss << "double tmp=1/sin(arg0);\n\t"; - ss << "return tmp;\n"; - ss << "}"; + ss << " return pow(M_E, arg0);\n"; } -void OpCountIfs::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) + +void OpLog10::GenerateCode( outputstream& ss ) const { - FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken(); - const formula::DoubleVectorRefToken*pCurDVR= static_cast<const - formula::DoubleVectorRefToken *>(tmpCur); - size_t nCurWindowSize = pCurDVR->GetArrayLength() < - pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength(): - pCurDVR->GetRefRowSize() ; - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n"; - ss <<" int gid0=get_global_id(0);\n"; - ss << " int tmp =0;\n"; - ss << " int loop;\n"; - GenTmpVariables(ss,vSubArguments); + ss << " return log10(arg0);\n"; +} - ss<< " int singleIndex =gid0;\n"; - int m=0; +void OpSinh::GenerateCode( outputstream& ss ) const +{ + ss << " return ( exp(arg0)-exp(-arg0) )/2;\n"; +} - outputstream tmpss; +void OpSin::GenerateCode( outputstream& ss ) const +{ + ss << " arg0 = arg0 * M_1_PI;\n"; + ss << " return sinpi(arg0);\n"; +} - for(size_t j=0;j<vSubArguments.size();j+=2,m++) - { - CheckSubArgumentIsNan(tmpss,vSubArguments,j); - CheckSubArgumentIsNan(ss,vSubArguments,j+1); - tmpss <<" if(isequal("; - tmpss <<"tmp"; - tmpss <<j; - tmpss <<" , "; - tmpss << "tmp"; - tmpss << j+1; - tmpss << ")){\n"; - } - tmpss << " tmp ++;\n"; - for(size_t j=0;j<vSubArguments.size();j+=2,m--) - { - for(int n = 0;n<m+1;n++) - { - tmpss << " "; - } - tmpss<< "}\n"; - } - UnrollDoubleVector(ss,tmpss,pCurDVR,nCurWindowSize); +void OpAbs::GenerateCode( outputstream& ss ) const +{ + ss << " return fabs(arg0);\n"; +} - ss << "return tmp;\n"; - ss << "}"; +void OpArcCos::BinInlineFun(std::set<std::string>& decls, + std::set<std::string>& funs) +{ + decls.insert(atan2Decl); + funs.insert(atan2Content); } -void OpSumIfs::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) + +void OpArcCos::GenerateCode( outputstream& ss ) const { - FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken(); - const formula::DoubleVectorRefToken*pCurDVR= static_cast<const - formula::DoubleVectorRefToken *>(tmpCur); - size_t nCurWindowSize = pCurDVR->GetArrayLength() < - pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength(): - pCurDVR->GetRefRowSize() ; + ss << " return arctan2(sqrt(1.0 - pow(arg0, 2)), arg0);\n"; +} - mNeedReductionKernel = vSubArguments[0]->NeedParallelReduction(); - if (mNeedReductionKernel) - { - // generate reduction functions +void OpArcCosHyp::GenerateCode( outputstream& ss ) const +{ + ss << " if( arg0 < 1 )\n"; + ss << " return CreateDoubleError(IllegalArgument);\n"; + ss << " return log( arg0 + pow( (pown(arg0, 2) - 1.0), 0.5));\n"; +} - ss << "__kernel void "; - ss << vSubArguments[0]->GetName(); - ss << "_SumIfs_reduction( "; - for (size_t i = 0; i < vSubArguments.size(); i++) - { - if (i) - ss << ","; - vSubArguments[i]->GenSlidingWindowDecl(ss); - } - ss << ", __global double *result,int arrayLength,int windowSize"; +void OpTan::GenerateCode( outputstream& ss ) const +{ + ss << " arg0 = arg0 * M_1_PI;\n"; + ss << " return sinpi(arg0) / cospi(arg0);\n"; +} - ss << ")\n{\n"; - ss << " double tmp =0;\n"; - ss << " int i ;\n"; +void OpTanH::GenerateCode( outputstream& ss ) const +{ + ss << " return tanh(arg0);\n"; +} - GenTmpVariables(ss,vSubArguments); - ss << " double current_result = 0.0;\n"; - ss << " int writePos = get_group_id(1);\n"; - if (pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) - ss << " int offset = 0;\n"; - else if (!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) - ss << " int offset = get_group_id(1);\n"; - else - throw Unhandled(__FILE__, __LINE__); - // actually unreachable - ss << " int lidx = get_local_id(0);\n"; - ss << " __local double shm_buf[256];\n"; - ss << " barrier(CLK_LOCAL_MEM_FENCE);\n"; - ss << " int loop = arrayLength/512 + 1;\n"; - ss << " for (int l=0; l<loop; l++){\n"; - ss << " tmp = 0.0;\n"; - ss << " int loopOffset = l*512;\n"; +void OpSqrt::GenerateCode( outputstream& ss ) const +{ + ss << " if( arg0 < 0 )\n"; + ss << " return CreateDoubleError(IllegalArgument);\n"; + ss << " return sqrt(arg0);\n"; +} - ss << " int p1 = loopOffset + lidx + offset, p2 = p1 + 256;\n"; - ss << " if (p2 < min(offset + windowSize, arrayLength)) {\n"; - ss << " tmp0 = 0.0;\n"; - int mm=0; - std::string p1 = "p1"; - std::string p2 = "p2"; - for(size_t j=1;j<vSubArguments.size();j+=2,mm++) - { - CheckSubArgumentIsNan2(ss,vSubArguments,j,p1); - CheckSubArgumentIsNan2(ss,vSubArguments,j+1,p1); - ss << ""; - ss <<" if(isequal("; - ss <<"tmp"; - ss <<j; - ss <<" , "; - ss << "tmp"; - ss << j+1; - ss << "))"; - ss << "{\n"; - } - CheckSubArgumentIsNan2(ss,vSubArguments,0,p1); - ss << " tmp += tmp0;\n"; - for(size_t j=1;j<vSubArguments.size();j+=2,mm--) - { - for(int n = 0;n<mm+1;n++) - { - ss << " "; - } - ss<< "}\n\n"; - } - mm=0; - for(size_t j=1;j<vSubArguments.size();j+=2,mm++) - { - CheckSubArgumentIsNan2(ss,vSubArguments,j,p2); - CheckSubArgumentIsNan2(ss,vSubArguments,j+1,p2); - ss <<" if(isequal("; - ss <<"tmp"; - ss <<j; - ss <<" , "; - ss << "tmp"; - ss << j+1; - ss << ")){\n"; - } - CheckSubArgumentIsNan2(ss,vSubArguments,0,p2); - ss << " tmp += tmp0;\n"; - for(size_t j=1;j< vSubArguments.size();j+=2,mm--) - { - for(int n = 0;n<mm+1;n++) - { - ss << " "; - } - ss<< "}\n"; - } - ss << " }\n"; +void OpArcCot::GenerateCode( outputstream& ss ) const +{ + ss << " return M_PI_2 - atan(arg0);\n"; +} - ss << " else if (p1 < min(arrayLength, offset + windowSize)) {\n"; - mm=0; - for(size_t j=1;j<vSubArguments.size();j+=2,mm++) - { - CheckSubArgumentIsNan2(ss,vSubArguments,j,p1); - CheckSubArgumentIsNan2(ss,vSubArguments,j+1,p1); +void OpArcCotHyp::GenerateCode( outputstream& ss ) const +{ + ss << " return 0.5 * log(1 + 2 / (arg0 - 1.0));\n"; +} - ss <<" if(isequal("; - ss <<"tmp"; - ss <<j; - ss <<" , "; - ss << "tmp"; - ss << j+1; - ss << ")){\n"; - } - CheckSubArgumentIsNan2(ss,vSubArguments,0,p1); - ss << " tmp += tmp0;\n"; - for(size_t j=1;j<vSubArguments.size();j+=2,mm--) - { - for(int n = 0;n<mm+1;n++) - { - ss << " "; - } - ss<< "}\n\n"; - } +void OpArcSin::BinInlineFun(std::set<std::string>& decls, + std::set<std::string>& funs) +{ + decls.insert(atan2Decl); + funs.insert(atan2Content); +} - ss << " }\n"; - ss << " shm_buf[lidx] = tmp;\n"; - ss << " barrier(CLK_LOCAL_MEM_FENCE);\n"; - ss << " for (int i = 128; i >0; i/=2) {\n"; - ss << " if (lidx < i)\n"; - ss << " shm_buf[lidx] += shm_buf[lidx + i];\n"; - ss << " barrier(CLK_LOCAL_MEM_FENCE);\n"; - ss << " }\n"; - ss << " if (lidx == 0)\n"; - ss << " current_result += shm_buf[0];\n"; - ss << " barrier(CLK_LOCAL_MEM_FENCE);\n"; - ss << " }\n"; +void OpArcSin::GenerateCode( outputstream& ss ) const +{ + ss << " return arctan2(arg0, sqrt(1.0 - pow(arg0, 2)));\n"; +} - ss << " if (lidx == 0)\n"; - ss << " result[writePos] = current_result;\n"; - ss << "}\n"; - }// finish generate reduction code - // generate functions as usual - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n"; - ss <<" int gid0=get_global_id(0);\n"; - ss << " double tmp =0;\n"; - if (!mNeedReductionKernel) - { - ss << " int i ;\n"; - GenTmpVariables(ss,vSubArguments); - ss << " for (i = "; - if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) { - ss << "gid0; i < "<< nCurWindowSize <<"; i++)\n"; - } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) { - ss << "0; i < gid0+"<< nCurWindowSize <<"; i++)\n"; - } else { - ss << "0; i < "<< nCurWindowSize <<"; i++)\n"; - } - ss << " {\n"; - if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) - { - ss<< " int doubleIndex =i+gid0;\n"; - }else - { - ss<< " int doubleIndex =i;\n"; - } - ss<< " int singleIndex =gid0;\n"; - int m=0; - for(size_t j=1;j<vSubArguments.size();j+=2,m++) - { - CheckSubArgumentIsNan(ss,vSubArguments,j); - CheckSubArgumentIsNan(ss,vSubArguments,j+1); - ss <<" if(isequal("; - ss <<"tmp"; - ss <<j; - ss <<" , "; - ss << "tmp"; - ss << j+1; - ss << ")){\n"; - } - CheckSubArgumentIsNan(ss,vSubArguments,0); - ss << " tmp += tmp0;\n"; - for(size_t j=1;j<=vSubArguments.size();j+=2,m--) - { - for(int n = 0;n<m+1;n++) - { - ss << " "; - } - ss<< "}\n"; - } - } - if (mNeedReductionKernel) - { - ss << "tmp ="; - vSubArguments[0]->GenDeclRef(ss); - ss << "[gid0];\n"; - } - ss << "return tmp;\n"; - ss << "}"; +void OpArcSinHyp::GenerateCode( outputstream& ss ) const +{ + ss << " return log( arg0 + pow((pown(arg0, 2) + 1.0), 0.5));\n"; +} + +void OpArcTan::GenerateCode( outputstream& ss ) const +{ + ss << " return atan(arg0);\n"; +} + +void OpArcTanH::GenerateCode( outputstream& ss ) const +{ + ss << " double a = 1.0 + arg0;\n"; + ss << " double b = 1.0 - arg0;\n"; + ss << " return log(pow(a/b, 0.5));\n"; +} + +void OpLn::GenerateCode( outputstream& ss ) const +{ + ss << " return log1p(arg0-1);\n"; +} + +void OpInt::GenerateCode( outputstream& ss ) const +{ + ss << " int intTmp = (int)arg0;\n"; + // check whether rounding error caused the float to be just less than the int value + ss << " if( arg0 >=0 && approx_equal( intTmp + 1, arg0 ))\n"; + ss << " ++intTmp;\n"; + // negative values are rounded down + ss << " if( arg0 < 0 && !approx_equal( intTmp, arg0 ))\n"; + ss << " --intTmp;\n"; + ss << " return intTmp;\n"; +} + +void OpNegSub::GenerateCode( outputstream& ss ) const +{ + ss << " return -arg0;\n"; +} + +void OpRadians::GenerateCode( outputstream& ss ) const +{ + ss << " return arg0 * M_PI / 180.0;\n"; +} + +void OpIsEven::GenerateCode( outputstream& ss ) const +{ + ss << " return (fmod(floor(fabs(arg0)), 2.0)<0.5);\n"; +} + +void OpIsOdd::GenerateCode( outputstream& ss ) const +{ + ss << " return !(fmod(floor(fabs(arg0)), 2.0)<0.5);\n"; +} + +void OpSqrtPi::GenerateCode( outputstream& ss ) const +{ + ss << " return (double)sqrt(arg0 * M_PI);\n"; +} + +void OpDeg::GenerateCode( outputstream& ss ) const +{ + ss << " return arg0 / M_PI * 180;;\n"; +} + +void OpFact::GenerateCode( outputstream& ss ) const +{ + ss << " arg0 = floor(arg0);\n"; + ss << " if (arg0 < 0.0)\n"; + ss << " return CreateDoubleError(IllegalArgument);\n"; + ss << " else if (arg0 == 0.0)\n"; + ss << " return 1.0;\n"; + ss << " else if (arg0 <= 170.0)\n"; + ss << " {\n"; + ss << " double fTemp = arg0;\n"; + ss << " while (fTemp > 2.0)\n"; + ss << " {\n"; + ss << " fTemp = fTemp - 1;\n"; + ss << " arg0 = arg0 * fTemp;\n"; + ss << " }\n"; + ss << " }\n"; + ss << " else\n"; + ss << " return CreateDoubleError(NoValue);\n"; + ss << " return arg0;\n"; +} + +void OpOdd::BinInlineFun(std::set<std::string>& decls, + std::set<std::string>& funs) +{ + decls.insert(Math_IntgDecl); + funs.insert(Math_Intg); +} + +void OpOdd::GenerateCode( outputstream& ss ) const +{ + ss << " double tmp;\n"; + ss << " if (arg0 > 0.0 ){\n"; + ss << " tmp=Intg(arg0);\n"; + ss << " if(tmp-trunc(tmp/2)*2 == 0)\n"; + ss << " tmp=tmp+1;\n"; + ss << " }else if (arg0 < 0.0 ){\n"; + ss << " tmp=Intg(arg0);\n"; + ss << " if(tmp-trunc(tmp/2)*2 == 0)\n"; + ss << " tmp=tmp-1.0;\n"; + ss << " }else\n"; + ss << " tmp=1.0;\n"; + ss << " return tmp;\n"; +} + +void OpMROUND::GenerateCode( outputstream& ss ) const +{ + ss<<" if(arg1==0)\n"; + ss<<" return arg1;\n"; + ss<<" tmp=arg1 * round(arg0 / arg1);\n"; + ss<<" return tmp;\n"; +} + +void OpCombinA::BinInlineFun(std::set<std::string>& decls, + std::set<std::string>& funs) +{ + decls.insert(bikDecl); + funs.insert(bik); +} + +void OpCombinA::GenerateCode( outputstream& ss ) const +{ + ss << " arg0 = trunc(arg0);\n"; + ss << " arg1 = trunc(arg1);\n"; + ss << " double tem;\n"; + ss << " if(arg0 >= arg1 && arg0 > 0 && arg1 > 0)\n"; + ss << " tem = bik(arg0+arg1-1,arg1);\n"; + ss << " else if(arg0 == 0 && arg1 == 0)\n"; + ss << " tem = 0;\n"; + ss << " else if(arg0 > 0 && arg1 == 0)\n"; + ss << " tem = 1;\n"; + ss << " else\n"; + ss << " tem = -1;\n"; + ss << " double i = tem - trunc(tem);\n"; + ss << " if(i < 0.5)\n"; + ss << " tem = trunc(tem);\n"; + ss << " else\n"; + ss << " tem = trunc(tem) + 1;\n"; + ss << " return tem;\n"; +} + +void OpCombin::GenerateCode( outputstream& ss ) const +{ + ss << " double result = -1.0;\n"; + ss << " double num = floor( arg0 );\n"; + ss << " double num_chosen = floor( arg1 );\n"; + ss << " if(num < 0 || num_chosen < 0 || num < num_chosen )\n"; + ss << " return CreateDoubleError(IllegalArgument);\n"; + ss << " result = select(result, 0.0, (ulong)(num < num_chosen));\n"; + ss << " result = select(result, 1.0, (ulong)(num_chosen == 0.0));\n"; + ss << " if(result == 0 || result ==1)\n"; + ss << " return result;\n"; + ss << " double4 db4num;\n"; + ss << " double4 db4num_chosen;\n"; + ss << " double4 db4result;\n"; + ss << " double2 db2result;\n"; + ss << " result = 1.0;\n"; + ss << " int loop = num_chosen/4;\n"; + ss << " for(int i=0; i<loop; i++)\n"; + ss << " {\n"; + ss << " db4num = (double4){num,\n"; + ss << " num-1.0,\n"; + ss << " num-2.0,\n"; + ss << " num-3.0};\n"; + ss << " db4num_chosen = (double4){num_chosen,\n"; + ss << " num_chosen-1.0,\n"; + ss << " num_chosen-2.0,\n"; + ss << " num_chosen-3.0};\n"; + ss << " db4result = db4num / db4num_chosen;\n"; + ss << " db2result = db4result.xy * db4result.zw;\n"; + ss << " result *= db2result.x * db2result.y;\n"; + ss << " num = num - 4.0;\n"; + ss << " num_chosen = num_chosen - 4.0;\n"; + ss << " }\n"; + ss << " while ( num_chosen > 0){\n"; + ss << " result *= num / num_chosen;\n"; + ss << " num = num - 1.0;\n"; + ss << " num_chosen = num_chosen - 1.0;\n"; + ss << " }\n"; + ss << " return result;\n"; } -void OpCscH::GenSlidingWindowFunction( - outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) + +void OpMod::GenerateCode( outputstream& ss ) const { - FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const - formula::SingleVectorRefToken *>(tmpCur); - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n\t"; - ss <<"int gid0=get_global_id(0);\n\t"; - ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n\t"; - ss<< "if(isnan(arg0)||(gid0>="; - ss<<tmpCurDVR->GetArrayLength(); - ss<<"))\n\t\t"; - ss<<"arg0 = 0;\n\t"; - ss << "double tmp=1/sinh(arg0);\n\t"; - ss << "return tmp;\n"; - ss << "}"; + ss << " if(isnan(arg0)||arg0 == 0)\n"; + ss << " return 0;\n"; + ss << " if(isnan(arg1) || arg1 ==0)\n"; + ss << " return CreateDoubleError(DivisionByZero);\n"; + ss << " double tem;\n"; + ss << " if(arg0 < 0 && arg1 > 0)\n"; + ss << " while(arg0 < 0)\n"; + ss << " arg0 += arg1;\n"; + ss << " else if (arg0 > 0 && arg1 < 0)\n"; + ss << " while(arg0 > 0)\n"; + ss << " arg0 += arg1;\n"; + ss << " tem = fmod(arg0,arg1);\n"; + ss << " if(arg1 < 0 && tem > 0)\n"; + ss << " tem = -tem;\n"; + ss << " return tem;\n"; } -void OpExp::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) + +void OpPower::GenerateCode( outputstream& ss ) const { - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n"; - ss << " int gid0=get_global_id(0);\n"; - ss << " double arg0 = 0.0f;\n"; - FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken(); - assert(tmpCur); - if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode()) - { - if(tmpCur->GetType() == formula::svSingleVectorRef) - { - const formula::SingleVectorRefToken*tmpCurDVR= - static_cast - <const formula::SingleVectorRefToken *>(tmpCur); - ss << " arg0 = "; - ss << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n"; - ss << " if(isnan("; - ss << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ")||(gid0>="; - ss << tmpCurDVR->GetArrayLength(); - ss << "))\n"; - ss << " { arg0 = 0.0f; }\n"; - } - else if(tmpCur->GetType() == formula::svDouble) - { - ss << " arg0=" << tmpCur->GetDouble() << ";\n"; - } - } - else - { - ss << " arg0 = "; - ss << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n"; - } - ss << " return pow(M_E, arg0);\n"; - ss << "}"; + ss << " return pow(arg0,arg1);\n"; } -void OpAverageIfs::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) +void OpArcTan2::BinInlineFun(std::set<std::string>& decls, + std::set<std::string>& funs) { - FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken(); - const formula::DoubleVectorRefToken*pCurDVR= static_cast<const - formula::DoubleVectorRefToken *>(tmpCur); - size_t nCurWindowSize = pCurDVR->GetArrayLength() < - pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength(): - pCurDVR->GetRefRowSize() ; - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n"; - ss <<" int gid0=get_global_id(0);\n"; - ss << " double tmp =0;\n"; - ss << " int count=0;\n"; - ss << " int loop;"; - GenTmpVariables(ss,vSubArguments); - ss<< " int singleIndex =gid0;\n"; - int m=0; - outputstream tmpss; - for(size_t j=1;j<vSubArguments.size();j+=2,m++) - { - CheckSubArgumentIsNan(tmpss,vSubArguments,j); - CheckSubArgumentIsNan(ss,vSubArguments,j+1); - tmpss <<" if(isequal("; - tmpss <<"tmp"; - tmpss <<j; - tmpss <<" , "; - tmpss << "tmp"; - tmpss << j+1; - tmpss << ")){\n"; - } - CheckSubArgumentIsNan(tmpss,vSubArguments,0); - tmpss << " tmp += tmp0;\n"; - tmpss << " count++;\n"; - for(size_t j=1;j<vSubArguments.size();j+=2,m--) - { - for(int n = 0;n<m+1;n++) - { - tmpss << " "; - } - tmpss<< "}\n"; - } + decls.insert(atan2Decl); + funs.insert(atan2Content); +} - UnrollDoubleVector(ss,tmpss,pCurDVR,nCurWindowSize); +void OpArcTan2::GenerateCode( outputstream& ss ) const +{ + ss << " return arctan2(arg1, arg0);\n"; +} - ss << " if(count!=0)\n"; - ss << " tmp=tmp/count;\n"; - ss << " else\n"; - ss << " tmp= 0 ;\n"; - ss << "return tmp;\n"; - ss << "}"; +void OpBitAnd::GenerateCode( outputstream& ss ) const +{ + ss << " if( arg0 < 0 || arg1 < 0 || arg0 >= 281474976710656.0 || arg1 >= 281474976710656.0 )\n"; + ss << " return CreateDoubleError(IllegalArgument);\n"; + ss << " return (long)arg0 & (long)arg1;\n"; } -void OpLog10::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) +void OpBitOr::GenerateCode( outputstream& ss ) const { - FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const - formula::SingleVectorRefToken *>(tmpCur); - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n\t"; - ss <<"int gid0=get_global_id(0);\n\t"; - ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n\t"; - ss<< "if(isnan(arg0)||(gid0>="; - ss<<tmpCurDVR->GetArrayLength(); - ss<<"))\n\t\t"; - ss<<"arg0 = 0;\n\t"; - ss << "double tmp=log10(arg0);\n\t"; - ss << "return tmp;\n"; - ss << "}"; + ss << " if( arg0 < 0 || arg1 < 0 || arg0 >= 281474976710656.0 || arg1 >= 281474976710656.0 )\n"; + ss << " return CreateDoubleError(IllegalArgument);\n"; + ss << " return (long)arg0 | (long)arg1;\n"; } -void OpSinh::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) +void OpBitXor::GenerateCode( outputstream& ss ) const { - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n"; - ss <<" int gid0=get_global_id(0);\n"; - ss <<" double arg0 = " << - vSubArguments[0]->GenSlidingWindowDeclRef(); - ss <<";\n"; - ss<< " if(isnan(arg0))\n"; - ss<<" arg0 = 0;\n"; - ss << " double tmp=( exp(arg0)-exp(-arg0) )/2;\n"; - ss << " return tmp;\n"; - ss << "}"; + ss << " if( arg0 < 0 || arg1 < 0 || arg0 >= 281474976710656.0 || arg1 >= 281474976710656.0 )\n"; + ss << " return CreateDoubleError(IllegalArgument);\n"; + ss << " return (long)arg0 ^ (long)arg1;\n"; } -void OpSin::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) + +void OpBitLshift::GenerateCode( outputstream& ss ) const { - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n"; - ss << " int gid0=get_global_id(0);\n"; - ss << " double arg0 = 0.0f;\n"; - FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken(); - assert(tmpCur); - if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode()) - { - if(tmpCur->GetType() == formula::svSingleVectorRef) - { - const formula::SingleVectorRefToken*tmpCurDVR= - static_cast - <const formula::SingleVectorRefToken *>(tmpCur); - ss << " arg0 = "; - ss << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n"; - ss << " if(isnan("; - ss << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ")||(gid0>="; - ss << tmpCurDVR->GetArrayLength(); - ss << "))\n"; - ss << " { arg0 = 0.0f; }\n"; - } - else if(tmpCur->GetType() == formula::svDouble) - { - ss << " arg0=" << tmpCur->GetDouble() << ";\n"; - } - } - else - { - ss << " arg0 = "; - ss << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n"; - } - ss << " arg0 = arg0 * M_1_PI;\n"; - ss << " return sinpi(arg0);\n"; - ss << "}"; + ss << " double num = floor( arg0 );\n"; + ss << " double shift_amount = floor( arg1 );\n"; + ss << " if( num < 0 || num >= 281474976710656.0 )\n"; + ss << " return CreateDoubleError(IllegalArgument);\n"; + ss << " return floor(shift_amount >= 0 ? "; + ss << "num * pow(2.0, shift_amount) : "; + ss << "num / pow(2.0, fabs(shift_amount)));\n"; } -void OpAbs::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) +void OpBitRshift::GenerateCode( outputstream& ss ) const { - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n"; - ss << " int gid0 = get_global_id(0);\n"; - ss << " double tmp = " << GetBottom() << ";\n"; - FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR0= - static_cast<const formula::SingleVectorRefToken *>(tmpCur0); - ss << " int buffer_len = "; - ss << tmpCurDVR0->GetArrayLength(); - ss << ";\n"; - ss << " if((gid0)>=buffer_len || isnan("; - ss << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << "))\n"; - ss << " tmp = 0.0;\n else \n"; - ss << " tmp = "; - ss << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n"; - ss << " return fabs(tmp);\n"; - ss << "}"; + ss << " double num = floor( arg0 );\n"; + ss << " double shift_amount = floor( arg1 );\n"; + ss << " if( num < 0 || num >= 281474976710656.0 )\n"; + ss << " return CreateDoubleError(IllegalArgument);\n"; + ss << " return floor("; + ss << "shift_amount >= 0 ? num / pow(2.0, shift_amount) : "; + ss << "num * pow(2.0, fabs(shift_amount)));\n"; } -void OpArcCos::BinInlineFun(std::set<std::string>& decls, - std::set<std::string>& funs) + +void OpQuotient::GenerateCode( outputstream& ss ) const { - decls.insert(atan2Decl); - funs.insert(atan2Content); + ss << " return trunc(arg0/arg1);\n"; } -void OpArcCos::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) + +void OpLog::GenSlidingWindowFunction(outputstream &ss, + const std::string &sSymName, SubArguments &vSubArguments) { + CHECK_PARAMETER_COUNT( 1, 2 ); GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); ss << "{\n"; ss << " int gid0 = get_global_id(0);\n"; - ss << " double tmp = " << GetBottom() << ";\n"; - FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR0= - static_cast<const formula::SingleVectorRefToken *>(tmpCur0); - ss << " int buffer_len = "<< tmpCurDVR0->GetArrayLength()<< ";\n"; - ss << " if((gid0)>=buffer_len || isnan("; - ss << vSubArguments[0]->GenSlidingWindowDeclRef()<< "))\n"; - ss << " tmp = 0.0;\n"; - ss << " else \n "; - ss << " tmp = "; - ss << vSubArguments[0]->GenSlidingWindowDeclRef()<< ";\n"; - ss << " return arctan2(sqrt(1.0 - pow(tmp, 2)), tmp);\n"; + GenerateArg( "arg0", 0, vSubArguments, ss ); + GenerateArgWithDefault( "arg1", 1, 10, vSubArguments, ss ); + ss << " return log10(arg0)/log10(arg1);;\n"; ss << "}"; } -void OpArcCosHyp::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) -{ - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n"; - ss << " int gid0 = get_global_id(0);\n"; - ss << " double tmp = " << GetBottom() << ";\n"; - FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken(); - assert(tmpCur0); - if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode()) - { - if(tmpCur0->GetType() == formula::svSingleVectorRef) - { - const formula::SingleVectorRefToken*tmpCurDVR0= - static_cast<const formula::SingleVectorRefToken *>(tmpCur0); - ss << " int buffer_len = "<<tmpCurDVR0->GetArrayLength()<<";\n"; - ss << " if((gid0)>=buffer_len || isnan("; - ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n"; - ss << " tmp = 0.0;\n"; - ss << " else \n "; - ss << " tmp = " << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n"; - } - else if(tmpCur0->GetType() == formula::svDouble) - { - ss << " tmp = " << tmpCur0->GetDouble() << ";\n"; - } - } - else - { - ss << " tmp = " << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n"; - } - ss << " if( tmp < 1 )\n"; - ss << " return CreateDoubleError(IllegalArgument);\n"; - ss << " return log( tmp + pow( (pown(tmp, 2) - 1.0), 0.5));\n"; - ss << "}"; -} -void OpTan::GenSlidingWindowFunction(outputstream &ss, +void OpCountIfs::GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) { + FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken(); + const formula::DoubleVectorRefToken*pCurDVR= static_cast<const + formula::DoubleVectorRefToken *>(tmpCur); + size_t nCurWindowSize = pCurDVR->GetArrayLength() < + pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength(): + pCurDVR->GetRefRowSize() ; GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); ss << "{\n"; - ss << " int gid0=get_global_id(0);\n"; - ss << " double arg0 = 0.0f;\n"; - FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken(); - assert(tmpCur); - if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode()) + ss <<" int gid0=get_global_id(0);\n"; + ss << " int tmp =0;\n"; + ss << " int loop;\n"; + GenTmpVariables(ss,vSubArguments); + + ss<< " int singleIndex =gid0;\n"; + int m=0; + + outputstream tmpss; + + for(size_t j=0;j<vSubArguments.size();j+=2,m++) + { + CheckSubArgumentIsNan(tmpss,vSubArguments,j); + CheckSubArgumentIsNan(ss,vSubArguments,j+1); + tmpss <<" if(isequal("; + tmpss <<"tmp"; + tmpss <<j; + tmpss <<" , "; + tmpss << "tmp"; + tmpss << j+1; + tmpss << ")){\n"; + } + tmpss << " tmp ++;\n"; + for(size_t j=0;j<vSubArguments.size();j+=2,m--) { - if(tmpCur->GetType() == formula::svSingleVectorRef) - { - const formula::SingleVectorRefToken*tmpCurDVR= - static_cast - <const formula::SingleVectorRefToken *>(tmpCur); - ss << " arg0 = "; - ss << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n"; - ss << " if(isnan("; - ss << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ")||(gid0>="; - ss << tmpCurDVR->GetArrayLength(); - ss << "))\n"; - ss << " { arg0 = 0.0f; }\n"; - } - else if(tmpCur->GetType() == formula::svDouble) + for(int n = 0;n<m+1;n++) { - ss << " arg0=" << tmpCur->GetDouble() << ";\n"; + tmpss << " "; } + tmpss<< "}\n"; } - else - { - ss << " arg0 = "; - ss << vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n"; - } - ss << " arg0 = arg0 * M_1_PI;\n"; - ss << " return sinpi(arg0) / cospi(arg0);\n"; + UnrollDoubleVector(ss,tmpss,pCurDVR,nCurWindowSize); + + ss << "return tmp;\n"; ss << "}"; } -void OpTanH::GenSlidingWindowFunction(outputstream &ss, + +void OpSumIfs::GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) { FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken(); - const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const - formula::SingleVectorRefToken *>(tmpCur); - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n"; - ss << " int gid0=get_global_id(0);\n"; - ss << " double arg0 = "<< vSubArguments[0]->GenSlidingWindowDeclRef(); - ss << ";\n"; - ss << " if(isnan(arg0)||(gid0>="; - ss << tmpCurDVR->GetArrayLength(); - ss << "))\n"; - ss << " arg0 = 0;\n"; - ss << " double tmp=tanh(arg0);\n"; - ss << " return tmp;\n"; - ss << "}"; -} -void OpPower::GenSlidingWindowFunction(outputstream &ss, - const std::string &sSymName, SubArguments &vSubArguments) -{ - GenerateFunctionDeclaration( sSymName, vSubArguments, ss ); - ss << "{\n"; - ss << " int gid0=get_global_id(0);\n"; - ss << " double arg[2];\n"; - for( size_t i=0; i < vSubArguments.size(); ++i) + const formula::DoubleVectorRefToken*pCurDVR= static_cast<const + formula::DoubleVectorRefToken *>(tmpCur); + size_t nCurWindowSize = pCurDVR->GetArrayLength() < + pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength(): + pCurDVR->GetRefRowSize() ; + + mNeedReductionKernel = vSubArguments[0]->NeedParallelReduction(); + if (mNeedReductionKernel) { - FormulaToken *tmpCur = vSubArguments[i]->GetFormulaToken(); - assert(tmpCur); - if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode()) + // generate reduction functions + + ss << "__kernel void "; + ss << vSubArguments[0]->GetName(); + ss << "_SumIfs_reduction( "; + for (size_t i = 0; i < vSubArguments.size(); i++) { - if(tmpCur->GetType() == formula::svDoubleVectorRef) - { - const formula::DoubleVectorRefToken* tmpCurDVR = - static_cast< - const formula::DoubleVectorRefToken *>(tmpCur); - ss << " int i = 0;\n"; - ss << " arg["<<i<<"] = "; - ss << vSubArguments[i]->GenSlidingWindowDeclRef(); - ss << ";\n"; - ss << " if(isnan(arg["<<i; - ss << "])||(gid0>="; - ss << tmpCurDVR->GetArrayLength(); - ss << "))\n"; - ss << " arg["<<i; - ss << "] = 0;\n"; - } - else if(tmpCur->GetType() == formula::svSingleVectorRef) - { - const formula::SingleVectorRefToken* tmpCurDVR= - static_cast< - const formula::SingleVectorRefToken *>(tmpCur); - ss << " arg["<<i<<"] = "; - ss << vSubArguments[i]->GenSlidingWindowDeclRef(); - ss << ";\n"; - ss << " if(isnan(arg["<<i; - ss << "])||(gid0>="; - ss << tmpCurDVR->GetArrayLength(); - ss << "))\n"; - ss << " arg["<<i; - ss << "] = 0;\n"; - } - else if(tmpCur->GetType() == formula::svDouble) - { - ss << " arg["<<i<<"] = "; - ss << tmpCur->GetDouble() << ";\n"; - } + if (i) + ss << ","; + vSubArguments[i]->GenSlidingWindowDecl(ss); } + ss << ", __global double *result,int arrayLength,int windowSize"; + + ss << ")\n{\n"; + ss << " double tmp =0;\n"; ... etc. - the rest is truncated