Commit b7eea2ff authored by teravest@chromium.org's avatar teravest@chromium.org

Pepper: Refactor cpu feature attributes.

We'll want to break up ppb_nacl_private_impl.cc instead of lumping things into
one large file. This change makes the method for getting CPU feature attributes
easier to reuse, and renames the sandbox_arch.{cc,h} files in the process.

This is split off from a larger change to remove FileDownloader in the trusted
plugin.

BUG=370556
R=bbudge@chromium.org

Review URL: https://codereview.chromium.org/399983002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283861 0039d316-1c4b-4281-b951-d872f2087c98
parent 5dd3ad3e
...@@ -167,14 +167,14 @@ ...@@ -167,14 +167,14 @@
'nacl/renderer/json_manifest.h', 'nacl/renderer/json_manifest.h',
'nacl/renderer/nexe_load_manager.cc', 'nacl/renderer/nexe_load_manager.cc',
'nacl/renderer/nexe_load_manager.h', 'nacl/renderer/nexe_load_manager.h',
'nacl/renderer/platform_info.cc',
'nacl/renderer/platform_info.h',
'nacl/renderer/pnacl_translation_resource_host.cc', 'nacl/renderer/pnacl_translation_resource_host.cc',
'nacl/renderer/pnacl_translation_resource_host.h', 'nacl/renderer/pnacl_translation_resource_host.h',
'nacl/renderer/ppb_nacl_private_impl.cc', 'nacl/renderer/ppb_nacl_private_impl.cc',
'nacl/renderer/ppb_nacl_private_impl.h', 'nacl/renderer/ppb_nacl_private_impl.h',
'nacl/renderer/progress_event.cc', 'nacl/renderer/progress_event.cc',
'nacl/renderer/progress_event.h', 'nacl/renderer/progress_event.h',
'nacl/renderer/sandbox_arch.cc',
'nacl/renderer/sandbox_arch.h',
'nacl/renderer/trusted_plugin_channel.cc', 'nacl/renderer/trusted_plugin_channel.cc',
'nacl/renderer/trusted_plugin_channel.h', 'nacl/renderer/trusted_plugin_channel.h',
], ],
......
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
#include "components/nacl/common/nacl_types.h" #include "components/nacl/common/nacl_types.h"
#include "components/nacl/renderer/histogram.h" #include "components/nacl/renderer/histogram.h"
#include "components/nacl/renderer/manifest_service_channel.h" #include "components/nacl/renderer/manifest_service_channel.h"
#include "components/nacl/renderer/platform_info.h"
#include "components/nacl/renderer/pnacl_translation_resource_host.h" #include "components/nacl/renderer/pnacl_translation_resource_host.h"
#include "components/nacl/renderer/progress_event.h" #include "components/nacl/renderer/progress_event.h"
#include "components/nacl/renderer/sandbox_arch.h"
#include "components/nacl/renderer/trusted_plugin_channel.h" #include "components/nacl/renderer/trusted_plugin_channel.h"
#include "content/public/common/content_client.h" #include "content/public/common/content_client.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
......
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/cpu.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_util.h"
#if defined(OS_WIN) #if defined(OS_WIN)
#include "base/win/windows_version.h" #include "base/win/windows_version.h"
#endif #endif
...@@ -35,4 +37,45 @@ const char* GetSandboxArch() { ...@@ -35,4 +37,45 @@ const char* GetSandboxArch() {
#endif #endif
} }
std::string GetCpuFeatures() {
// PNaCl's translator from pexe to nexe can be told exactly what
// capabilities the user's machine has because the pexe to nexe
// translation is specific to the machine, and CPU information goes
// into the translation cache. This allows the translator to generate
// faster code.
//
// Care must be taken to avoid instructions which aren't supported by
// the NaCl sandbox. Ideally the translator would do this, but there's
// no point in not doing the whitelist here.
//
// TODO(jfb) Some features are missing, either because the NaCl
// sandbox doesn't support them, because base::CPU doesn't
// detect them, or because they don't help vector shuffles
// (and we omit them because it simplifies testing). Add the
// other features.
//
// TODO(jfb) The following is x86-specific. The base::CPU class
// doesn't handle other architectures very well, and we
// should at least detect the presence of ARM's integer
// divide.
std::vector<std::string> features;
base::CPU cpu;
// On x86, SSE features are ordered: the most recent one implies the
// others. Care is taken here to only specify the latest SSE version,
// whereas non-SSE features don't follow this model: POPCNT is
// effectively always implied by SSE4.2 but has to be specified
// separately.
//
// TODO: AVX2, AVX, SSE 4.2.
if (cpu.has_sse41()) features.push_back("+sse4.1");
// TODO: SSE 4A, SSE 4.
else if (cpu.has_ssse3()) features.push_back("+ssse3");
// TODO: SSE 3
else if (cpu.has_sse2()) features.push_back("+sse2");
// TODO: AES, POPCNT, LZCNT, ...
return JoinString(features, ',');
}
} // namespace nacl } // namespace nacl
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// Routines for determining the most appropriate NaCl executable for #ifndef COMPONENTS_NACL_RENDERER_PLATFORM_INFO_H
// the current CPU's architecture. #define COMPONENTS_NACL_RENDERER_PLATFORM_INFO_H
#ifndef COMPONENTS_NACL_RENDERER_SANDBOX_ARCH_H
#define COMPONENTS_NACL_RENDERER_SANDBOX_ARCH_H
namespace nacl { namespace nacl {
// Returns the kind of SFI sandbox implemented by NaCl on this // Returns the kind of SFI sandbox implemented by NaCl on this
// platform. See the implementation in sandbox_arch.cc for possible // platform. See the implementation in platform_info.cc for possible
// values. // values.
const char* GetSandboxArch(); const char* GetSandboxArch();
// Returns the features for the system's processor. Used for PNaCl translation.
std::string GetCpuFeatures();
} // namespace nacl } // namespace nacl
#endif // COMPONENTS_NACL_RENDERER_SANDBOX_ARCH_H #endif // COMPONENTS_NACL_RENDERER_PLATFORM_INFO_H
...@@ -28,9 +28,9 @@ ...@@ -28,9 +28,9 @@
#include "components/nacl/renderer/manifest_downloader.h" #include "components/nacl/renderer/manifest_downloader.h"
#include "components/nacl/renderer/manifest_service_channel.h" #include "components/nacl/renderer/manifest_service_channel.h"
#include "components/nacl/renderer/nexe_load_manager.h" #include "components/nacl/renderer/nexe_load_manager.h"
#include "components/nacl/renderer/platform_info.h"
#include "components/nacl/renderer/pnacl_translation_resource_host.h" #include "components/nacl/renderer/pnacl_translation_resource_host.h"
#include "components/nacl/renderer/progress_event.h" #include "components/nacl/renderer/progress_event.h"
#include "components/nacl/renderer/sandbox_arch.h"
#include "components/nacl/renderer/trusted_plugin_channel.h" #include "components/nacl/renderer/trusted_plugin_channel.h"
#include "content/public/common/content_client.h" #include "content/public/common/content_client.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
...@@ -1219,54 +1219,8 @@ PP_Bool GetPNaClResourceInfo(PP_Instance instance, ...@@ -1219,54 +1219,8 @@ PP_Bool GetPNaClResourceInfo(PP_Instance instance,
return PP_TRUE; return PP_TRUE;
} }
// Helper to std::accumulate that creates a comma-separated list from the input.
std::string CommaAccumulator(const std::string &lhs, const std::string &rhs) {
if (lhs.empty())
return rhs;
return lhs + "," + rhs;
}
PP_Var GetCpuFeatureAttrs() { PP_Var GetCpuFeatureAttrs() {
// PNaCl's translator from pexe to nexe can be told exactly what return ppapi::StringVar::StringToPPVar(GetCpuFeatures());
// capabilities the user's machine has because the pexe to nexe
// translation is specific to the machine, and CPU information goes
// into the translation cache. This allows the translator to generate
// faster code.
//
// Care must be taken to avoid instructions which aren't supported by
// the NaCl sandbox. Ideally the translator would do this, but there's
// no point in not doing the whitelist here.
//
// TODO(jfb) Some features are missing, either because the NaCl
// sandbox doesn't support them, because base::CPU doesn't
// detect them, or because they don't help vector shuffles
// (and we omit them because it simplifies testing). Add the
// other features.
//
// TODO(jfb) The following is x86-specific. The base::CPU class
// doesn't handle other architectures very well, and we
// should at least detect the presence of ARM's integer
// divide.
std::vector<std::string> attrs;
base::CPU cpu;
// On x86, SSE features are ordered: the most recent one implies the
// others. Care is taken here to only specify the latest SSE version,
// whereas non-SSE features don't follow this model: POPCNT is
// effectively always implied by SSE4.2 but has to be specified
// separately.
//
// TODO: AVX2, AVX, SSE 4.2.
if (cpu.has_sse41()) attrs.push_back("+sse4.1");
// TODO: SSE 4A, SSE 4.
else if (cpu.has_ssse3()) attrs.push_back("+ssse3");
// TODO: SSE 3
else if (cpu.has_sse2()) attrs.push_back("+sse2");
// TODO: AES, POPCNT, LZCNT, ...
return ppapi::StringVar::StringToPPVar(std::accumulate(
attrs.begin(), attrs.end(), std::string(), CommaAccumulator));
} }
void PostMessageToJavaScriptMainThread(PP_Instance instance, void PostMessageToJavaScriptMainThread(PP_Instance instance,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment