Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: src/x64/assembler-x64.h

Issue 391051: Allow a platform to indicate that some CPU features are always... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 1994-2006 Sun Microsystems Inc. 1 // Copyright (c) 1994-2006 Sun Microsystems Inc.
2 // All Rights Reserved. 2 // All Rights Reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // - Redistributions of source code must retain the above copyright notice, 8 // - Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer. 9 // this list of conditions and the following disclaimer.
10 // 10 //
(...skipping 19 matching lines...) Expand all
30 30
31 // The original source code covered by the above license above has been 31 // The original source code covered by the above license above has been
32 // modified significantly by Google Inc. 32 // modified significantly by Google Inc.
33 // Copyright 2006-2009 the V8 project authors. All rights reserved. 33 // Copyright 2006-2009 the V8 project authors. All rights reserved.
34 34
35 // A lightweight X64 Assembler. 35 // A lightweight X64 Assembler.
36 36
37 #ifndef V8_X64_ASSEMBLER_X64_H_ 37 #ifndef V8_X64_ASSEMBLER_X64_H_
38 #define V8_X64_ASSEMBLER_X64_H_ 38 #define V8_X64_ASSEMBLER_X64_H_
39 39
40 #include "serialize.h"
41
40 namespace v8 { 42 namespace v8 {
41 namespace internal { 43 namespace internal {
42 44
43 // Utility functions 45 // Utility functions
44 46
45 // Test whether a 64-bit value is in a specific range. 47 // Test whether a 64-bit value is in a specific range.
46 static inline bool is_uint32(int64_t x) { 48 static inline bool is_uint32(int64_t x) {
47 static const int64_t kUInt32Mask = V8_INT64_C(0xffffffff); 49 static const int64_t kUInt32Mask = V8_INT64_C(0xffffffff);
48 return x == (x & kUInt32Mask); 50 return x == (x & kUInt32Mask);
49 } 51 }
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 // Supported features must be enabled by a Scope before use. 357 // Supported features must be enabled by a Scope before use.
356 // Example: 358 // Example:
357 // if (CpuFeatures::IsSupported(SSE3)) { 359 // if (CpuFeatures::IsSupported(SSE3)) {
358 // CpuFeatures::Scope fscope(SSE3); 360 // CpuFeatures::Scope fscope(SSE3);
359 // // Generate SSE3 floating point code. 361 // // Generate SSE3 floating point code.
360 // } else { 362 // } else {
361 // // Generate standard x87 or SSE2 floating point code. 363 // // Generate standard x87 or SSE2 floating point code.
362 // } 364 // }
363 class CpuFeatures : public AllStatic { 365 class CpuFeatures : public AllStatic {
364 public: 366 public:
365 // Feature flags bit positions. They are mostly based on the CPUID spec.
366 // (We assign CPUID itself to one of the currently reserved bits --
367 // feel free to change this if needed.)
368 enum Feature { SSE3 = 32,
369 SSE2 = 26,
370 CMOV = 15,
371 RDTSC = 4,
372 CPUID = 10,
373 SAHF = 0};
374 // Detect features of the target CPU. Set safe defaults if the serializer 367 // Detect features of the target CPU. Set safe defaults if the serializer
375 // is enabled (snapshots must be portable). 368 // is enabled (snapshots must be portable).
376 static void Probe(); 369 static void Probe();
377 // Check whether a feature is supported by the target CPU. 370 // Check whether a feature is supported by the target CPU.
378 static bool IsSupported(Feature f) { 371 static bool IsSupported(CpuFeature f) {
379 if (f == SSE2 && !FLAG_enable_sse2) return false; 372 if (f == SSE2 && !FLAG_enable_sse2) return false;
380 if (f == SSE3 && !FLAG_enable_sse3) return false; 373 if (f == SSE3 && !FLAG_enable_sse3) return false;
381 if (f == CMOV && !FLAG_enable_cmov) return false; 374 if (f == CMOV && !FLAG_enable_cmov) return false;
382 if (f == RDTSC && !FLAG_enable_rdtsc) return false; 375 if (f == RDTSC && !FLAG_enable_rdtsc) return false;
383 if (f == SAHF && !FLAG_enable_sahf) return false; 376 if (f == SAHF && !FLAG_enable_sahf) return false;
384 return (supported_ & (V8_UINT64_C(1) << f)) != 0; 377 return (supported_ & (V8_UINT64_C(1) << f)) != 0;
385 } 378 }
386 // Check whether a feature is currently enabled. 379 // Check whether a feature is currently enabled.
387 static bool IsEnabled(Feature f) { 380 static bool IsEnabled(CpuFeature f) {
388 return (enabled_ & (V8_UINT64_C(1) << f)) != 0; 381 return (enabled_ & (V8_UINT64_C(1) << f)) != 0;
389 } 382 }
390 // Enable a specified feature within a scope. 383 // Enable a specified feature within a scope.
391 class Scope BASE_EMBEDDED { 384 class Scope BASE_EMBEDDED {
392 #ifdef DEBUG 385 #ifdef DEBUG
393 public: 386 public:
394 explicit Scope(Feature f) { 387 explicit Scope(CpuFeature f) {
388 uint64_t mask = (V8_UINT64_C(1) << f);
395 ASSERT(CpuFeatures::IsSupported(f)); 389 ASSERT(CpuFeatures::IsSupported(f));
390 ASSERT(!Serializer::enabled() || (found_by_runtime_probing_ & mask) == 0);
396 old_enabled_ = CpuFeatures::enabled_; 391 old_enabled_ = CpuFeatures::enabled_;
397 CpuFeatures::enabled_ |= (V8_UINT64_C(1) << f); 392 CpuFeatures::enabled_ |= mask;
398 } 393 }
399 ~Scope() { CpuFeatures::enabled_ = old_enabled_; } 394 ~Scope() { CpuFeatures::enabled_ = old_enabled_; }
400 private: 395 private:
401 uint64_t old_enabled_; 396 uint64_t old_enabled_;
402 #else 397 #else
403 public: 398 public:
404 explicit Scope(Feature f) {} 399 explicit Scope(CpuFeature f) {}
405 #endif 400 #endif
406 }; 401 };
407 private: 402 private:
408 // Safe defaults include SSE2 and CMOV for X64. It is always available, if 403 // Safe defaults include SSE2 and CMOV for X64. It is always available, if
409 // anyone checks, but they shouldn't need to check. 404 // anyone checks, but they shouldn't need to check.
410 static const uint64_t kDefaultCpuFeatures = 405 static const uint64_t kDefaultCpuFeatures = (1 << SSE2 | 1 << CMOV);
411 (1 << CpuFeatures::SSE2 | 1 << CpuFeatures::CMOV);
412 static uint64_t supported_; 406 static uint64_t supported_;
413 static uint64_t enabled_; 407 static uint64_t enabled_;
408 static uint64_t found_by_runtime_probing_;
414 }; 409 };
415 410
416 411
417 class Assembler : public Malloced { 412 class Assembler : public Malloced {
418 private: 413 private:
419 // We check before assembling an instruction that there is sufficient 414 // We check before assembling an instruction that there is sufficient
420 // space to write an instruction and its relocation information. 415 // space to write an instruction and its relocation information.
421 // The relocation writer's position must be kGap bytes above the end of 416 // The relocation writer's position must be kGap bytes above the end of
422 // the generated instructions. This leaves enough space for the 417 // the generated instructions. This leaves enough space for the
423 // longest possible x64 instruction, 15 bytes, and the longest possible 418 // longest possible x64 instruction, 15 bytes, and the longest possible
(...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 private: 1384 private:
1390 Assembler* assembler_; 1385 Assembler* assembler_;
1391 #ifdef DEBUG 1386 #ifdef DEBUG
1392 int space_before_; 1387 int space_before_;
1393 #endif 1388 #endif
1394 }; 1389 };
1395 1390
1396 } } // namespace v8::internal 1391 } } // namespace v8::internal
1397 1392
1398 #endif // V8_X64_ASSEMBLER_X64_H_ 1393 #endif // V8_X64_ASSEMBLER_X64_H_
OLDNEW
« src/arm/assembler-arm.h ('K') | « src/serialize.cc ('k') | src/x64/assembler-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698