19fa09679c31dd1fc79a07ed24431b6951227240aricow@chromium.org// Copyright 2011 the V8 project authors. All rights reserved.
243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// Redistribution and use in source and binary forms, with or without
343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// modification, are permitted provided that the following conditions are
443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// met:
543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen//
643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen//     * Redistributions of source code must retain the above copyright
743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen//       notice, this list of conditions and the following disclaimer.
843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen//     * Redistributions in binary form must reproduce the above
943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen//       copyright notice, this list of conditions and the following
1043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen//       disclaimer in the documentation and/or other materials provided
1143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen//       with the distribution.
1243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen//     * Neither the name of Google Inc. nor the names of its
1343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen//       contributors may be used to endorse or promote products derived
1443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen//       from this software without specific prior written permission.
1543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen//
1643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
2843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// CPU specific code for ia32 independent of OS goes here.
2943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
305a6af92a1549c81fb61855518f43b712e4c0e469christian.plesner.hansen@gmail.com#ifdef __GNUC__
315a6af92a1549c81fb61855518f43b712e4c0e469christian.plesner.hansen@gmail.com#include "third_party/valgrind/valgrind.h"
325a6af92a1549c81fb61855518f43b712e4c0e469christian.plesner.hansen@gmail.com#endif
335a6af92a1549c81fb61855518f43b712e4c0e469christian.plesner.hansen@gmail.com
3443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen#include "v8.h"
3543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
3693a47f4837f2137c8d8349250fd8e91da3108126jkummerow@chromium.org#if V8_TARGET_ARCH_IA32
379dfbea4c7d423c7bc1db94425cb78e7f7cf41f78erik.corry@gmail.com
3843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen#include "cpu.h"
39061ef74c9b8acd038edf4b4355c50d097c8a9683kasperl@chromium.org#include "macro-assembler.h"
4043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
4171affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.orgnamespace v8 {
4271affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.orgnamespace internal {
4343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
44f2038fb01417bcf7698b87a5dfaa4a861539618aerik.corry@gmail.comvoid CPU::SetUp() {
45c36ce6e8979bbbd43539f0a0effc87ea20dd65cckmillikin@chromium.org  CpuFeatures::Probe();
46c36ce6e8979bbbd43539f0a0effc87ea20dd65cckmillikin@chromium.org}
47c36ce6e8979bbbd43539f0a0effc87ea20dd65cckmillikin@chromium.org
48c36ce6e8979bbbd43539f0a0effc87ea20dd65cckmillikin@chromium.org
49c36ce6e8979bbbd43539f0a0effc87ea20dd65cckmillikin@chromium.orgbool CPU::SupportsCrankshaft() {
50c36ce6e8979bbbd43539f0a0effc87ea20dd65cckmillikin@chromium.org  return CpuFeatures::IsSupported(SSE2);
5143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
5243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
5343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
5443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid CPU::FlushICache(void* start, size_t size) {
5543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  // No need to flush the instruction cache on Intel. On Intel instruction
5643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  // cache flushing is only necessary when multiple cores running the same
5743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  // code simultaneously. V8 (and JavaScript) is single threaded and when code
5843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  // is patched on an intel CPU the core performing the patching will have its
5943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  // own instruction cache updated automatically.
6043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
61b3284ad36ee358a35b81379ad1c449e4f8021362kasperl@chromium.org  // If flushing of the instruction cache becomes necessary Windows has the
6243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  // API function FlushInstructionCache.
635a6af92a1549c81fb61855518f43b712e4c0e469christian.plesner.hansen@gmail.com
645a6af92a1549c81fb61855518f43b712e4c0e469christian.plesner.hansen@gmail.com  // By default, valgrind only checks the stack for writes that might need to
655a6af92a1549c81fb61855518f43b712e4c0e469christian.plesner.hansen@gmail.com  // invalidate already cached translated code.  This leads to random
665a6af92a1549c81fb61855518f43b712e4c0e469christian.plesner.hansen@gmail.com  // instability when code patches or moves are sometimes unnoticed.  One
675a6af92a1549c81fb61855518f43b712e4c0e469christian.plesner.hansen@gmail.com  // solution is to run valgrind with --smc-check=all, but this comes at a big
685a6af92a1549c81fb61855518f43b712e4c0e469christian.plesner.hansen@gmail.com  // performance cost.  We can notify valgrind to invalidate its cache.
695a6af92a1549c81fb61855518f43b712e4c0e469christian.plesner.hansen@gmail.com#ifdef VALGRIND_DISCARD_TRANSLATIONS
709fa09679c31dd1fc79a07ed24431b6951227240aricow@chromium.org  unsigned res = VALGRIND_DISCARD_TRANSLATIONS(start, size);
719fa09679c31dd1fc79a07ed24431b6951227240aricow@chromium.org  USE(res);
725a6af92a1549c81fb61855518f43b712e4c0e469christian.plesner.hansen@gmail.com#endif
7343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
7443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
7543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen} }  // namespace v8::internal
769dfbea4c7d423c7bc1db94425cb78e7f7cf41f78erik.corry@gmail.com
779dfbea4c7d423c7bc1db94425cb78e7f7cf41f78erik.corry@gmail.com#endif  // V8_TARGET_ARCH_IA32
78