From bd8a89f208c71e51921d5f090179b99b45cc0a5f Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Mon, 30 Nov 2015 09:44:19 +0100 Subject: sc interpreter: Don't hide S/W Interpreter behind an environment variable. Instead provide a user setting that can be enabled so that the S/W Interpreter is used on a subset of the operations. The operations for which it is used are controlled by a whitelist in ScCalcConfig::setOpenCLConfigToDefault(). Change-Id: I7d3f3a864fcb1231e5484ec23961f14fca1466c5 --- sc/inc/calcconfig.hxx | 1 + sc/source/core/data/formulacell.cxx | 2 +- sc/source/core/tool/calcconfig.cxx | 6 ++++++ sc/source/core/tool/formulagroup.cxx | 29 ++++++++++++++++++----------- sc/source/core/tool/token.cxx | 11 ++++++++--- 5 files changed, 34 insertions(+), 15 deletions(-) (limited to 'sc') diff --git a/sc/inc/calcconfig.hxx b/sc/inc/calcconfig.hxx index ec355cfdb844..eaf4f36f143b 100644 --- a/sc/inc/calcconfig.hxx +++ b/sc/inc/calcconfig.hxx @@ -49,6 +49,7 @@ struct SC_DLLPUBLIC ScCalcConfig bool mbHasStringRefSyntax:1; static bool isOpenCLEnabled(); + static bool isSwInterpreterEnabled(); bool mbOpenCLSubsetOnly:1; bool mbOpenCLAutoSelect:1; diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index 9079d560cbed..0c5edae5ebef 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -3952,7 +3952,7 @@ bool ScFormulaCell::InterpretFormulaGroup() return false; } - if (!ScCalcConfig::isOpenCLEnabled() && (getenv("SC_ALLOW_SOFTWARE_INTERPRETER") == nullptr)) + if (!ScCalcConfig::isOpenCLEnabled() && !ScCalcConfig::isSwInterpreterEnabled()) return false; // TODO : Disable invariant formula group interpretation for now in order diff --git a/sc/source/core/tool/calcconfig.cxx b/sc/source/core/tool/calcconfig.cxx index f285e138af99..96277ce01194 100644 --- a/sc/source/core/tool/calcconfig.cxx +++ b/sc/source/core/tool/calcconfig.cxx @@ -38,6 +38,12 @@ bool ScCalcConfig::isOpenCLEnabled() return gOpenCLEnabled.get(); } +bool ScCalcConfig::isSwInterpreterEnabled() +{ + static comphelper::ConfigurationListenerProperty gSwInterpreterEnabled(getMiscListener(), OUString("UseSwInterpreter")); + return gSwInterpreterEnabled.get(); +} + ScCalcConfig::ScCalcConfig() : meStringRefAddressSyntax(formula::FormulaGrammar::CONV_UNSPECIFIED), meStringConversion(StringConversion::LOCALE), // old LibreOffice behavior diff --git a/sc/source/core/tool/formulagroup.cxx b/sc/source/core/tool/formulagroup.cxx index c4abe00f402f..ce5c70a2b5b2 100644 --- a/sc/source/core/tool/formulagroup.cxx +++ b/sc/source/core/tool/formulagroup.cxx @@ -375,7 +375,7 @@ bool FormulaGroupInterpreterSoftware::interpret(ScDocument& rDoc, const ScAddres nRowEnd += i; ScMatrixRef pMat; - if (getenv("SC_ALLOW_SOFTWARE_INTERPRETER") != nullptr) + if (ScCalcConfig::isSwInterpreterEnabled()) { assert(nRowStart <= nRowEnd); pMat.reset(new ScVectorRefMatrix(p2, nRowStart, nRowEnd - nRowStart + 1)); @@ -481,13 +481,14 @@ FormulaGroupInterpreter *FormulaGroupInterpreter::getStatic() if ( !msInstance ) { #if HAVE_FEATURE_OPENCL - const ScCalcConfig& rConfig = ScInterpreter::GetGlobalConfig(); if (ScCalcConfig::isOpenCLEnabled()) + { + const ScCalcConfig& rConfig = ScInterpreter::GetGlobalConfig(); switchOpenCLDevice(rConfig.maOpenCLDevice, rConfig.mbOpenCLAutoSelect); + } #endif - static bool bAllowSoftwareInterpreter = (getenv("SC_ALLOW_SOFTWARE_INTERPRETER") != nullptr); - if ( !msInstance && bAllowSoftwareInterpreter ) // software fallback + if (!msInstance && ScCalcConfig::isSwInterpreterEnabled()) // software interpreter { SAL_INFO("sc.core.formulagroup", "Create S/W interpreter"); msInstance = new sc::FormulaGroupInterpreterSoftware(); @@ -509,20 +510,26 @@ void FormulaGroupInterpreter::fillOpenCLInfo(std::vector& rP bool FormulaGroupInterpreter::switchOpenCLDevice(const OUString& rDeviceId, bool bAutoSelect, bool bForceEvaluation) { bool bOpenCLEnabled = ScCalcConfig::isOpenCLEnabled(); - static bool bAllowSoftwareInterpreter = (getenv("SC_ALLOW_SOFTWARE_INTERPRETER") != nullptr); - if (!bOpenCLEnabled || (bAllowSoftwareInterpreter && rDeviceId == OPENCL_SOFTWARE_DEVICE_CONFIG_NAME)) + if (!bOpenCLEnabled || (rDeviceId == OPENCL_SOFTWARE_DEVICE_CONFIG_NAME)) { - if(msInstance) + bool bSwInterpreterEnabled = ScCalcConfig::isSwInterpreterEnabled(); + if (msInstance) { // if we already have a software interpreter don't delete it - if(dynamic_cast(msInstance)) + if (bSwInterpreterEnabled && dynamic_cast(msInstance)) return true; delete msInstance; + msInstance = nullptr; } - msInstance = new sc::FormulaGroupInterpreterSoftware(); - return true; + if (bSwInterpreterEnabled) + { + msInstance = new sc::FormulaGroupInterpreterSoftware(); + return true; + } + + return false; } bool bSuccess = ::opencl::switchOpenCLDevice(&rDeviceId, bAutoSelect, bForceEvaluation); if(!bSuccess) @@ -531,7 +538,7 @@ bool FormulaGroupInterpreter::switchOpenCLDevice(const OUString& rDeviceId, bool delete msInstance; msInstance = nullptr; - if (ScCalcConfig::isOpenCLEnabled()) + if (bOpenCLEnabled) { msInstance = new sc::opencl::FormulaGroupInterpreterOpenCL(); return msInstance != nullptr; diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index 138e0873c371..41be86a84fe0 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -32,6 +32,7 @@ #include "compiler.hxx" #include "interpre.hxx" #include +#include #include "rechead.hxx" #include "parclass.hxx" #include "jumpmatrix.hxx" @@ -1319,7 +1320,9 @@ void ScTokenArray::CheckToken( const FormulaToken& r ) return; } - if (!ScCalcConfig::isOpenCLEnabled() && getenv("SC_ALLOW_SOFTWARE_INTERPRETER") != nullptr && ScInterpreter::GetGlobalConfig().mpSwInterpreterSubsetOpCodes->find(eOp) == ScInterpreter::GetGlobalConfig().mpSwInterpreterSubsetOpCodes->end()) + // test for OpenCL interpreter first - the assumption is that S/W + // interpreter blacklist is more strict than the OpenCL one + if (ScCalcConfig::isSwInterpreterEnabled() && (dynamic_cast(sc::FormulaGroupInterpreter::getStatic()) != nullptr) && ScInterpreter::GetGlobalConfig().mpSwInterpreterSubsetOpCodes->find(eOp) == ScInterpreter::GetGlobalConfig().mpSwInterpreterSubsetOpCodes->end()) { meVectorState = FormulaVectorDisabled; return; @@ -1566,10 +1569,12 @@ void ScTokenArray::CheckToken( const FormulaToken& r ) return; } + // only when openCL interpreter is not enabled - the assumption is that + // the S/W interpreter blacklist is more strict if (eOp >= SC_OPCODE_START_BIN_OP && eOp <= SC_OPCODE_STOP_UN_OP && - !ScCalcConfig::isOpenCLEnabled() && - getenv("SC_ALLOW_SOFTWARE_INTERPRETER") != nullptr && + ScCalcConfig::isSwInterpreterEnabled() && + (dynamic_cast(sc::FormulaGroupInterpreter::getStatic()) != nullptr) && ScInterpreter::GetGlobalConfig().mpSwInterpreterSubsetOpCodes->find(eOp) == ScInterpreter::GetGlobalConfig().mpSwInterpreterSubsetOpCodes->end()) { meVectorState = FormulaVectorDisabled; -- cgit v1.2.3