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

Side by Side Diff: src/compiler-intrinsics.h

Issue 9638018: [v8-dev] Optimise Math.floor(x/y) to use integer division for specific divisor.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 9 months 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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 22 matching lines...) Expand all
33 33
34 class CompilerIntrinsics { 34 class CompilerIntrinsics {
35 public: 35 public:
36 // Returns number of zero bits preceding least significant 1 bit. 36 // Returns number of zero bits preceding least significant 1 bit.
37 // Undefined for zero value. 37 // Undefined for zero value.
38 INLINE(static int CountTrailingZeros(uint32_t value)); 38 INLINE(static int CountTrailingZeros(uint32_t value));
39 39
40 // Returns number of zero bits following most significant 1 bit. 40 // Returns number of zero bits following most significant 1 bit.
41 // Undefined for zero value. 41 // Undefined for zero value.
42 INLINE(static int CountLeadingZeros(uint32_t value)); 42 INLINE(static int CountLeadingZeros(uint32_t value));
43
44 // Returns the number of bits set.
45 INLINE(static int CountSetBits(uint32_t value));
43 }; 46 };
44 47
45 #ifdef __GNUC__ 48 #ifdef __GNUC__
46 int CompilerIntrinsics::CountTrailingZeros(uint32_t value) { 49 int CompilerIntrinsics::CountTrailingZeros(uint32_t value) {
47 return __builtin_ctz(value); 50 return __builtin_ctz(value);
48 } 51 }
49 52
50 int CompilerIntrinsics::CountLeadingZeros(uint32_t value) { 53 int CompilerIntrinsics::CountLeadingZeros(uint32_t value) {
51 return __builtin_clz(value); 54 return __builtin_clz(value);
52 } 55 }
53 56
57 int CompilerIntrinsics::CountSetBits(uint32_t value) {
58 return __builtin_popcount(value);
59 }
60
54 #elif defined(_MSC_VER) 61 #elif defined(_MSC_VER)
55 62
56 #pragma intrinsic(_BitScanForward) 63 #pragma intrinsic(_BitScanForward)
57 #pragma intrinsic(_BitScanReverse) 64 #pragma intrinsic(_BitScanReverse)
58 65
59 int CompilerIntrinsics::CountTrailingZeros(uint32_t value) { 66 int CompilerIntrinsics::CountTrailingZeros(uint32_t value) {
60 unsigned long result; //NOLINT 67 unsigned long result; //NOLINT
61 _BitScanForward(&result, static_cast<long>(value)); //NOLINT 68 _BitScanForward(&result, static_cast<long>(value)); //NOLINT
62 return static_cast<int>(result); 69 return static_cast<int>(result);
63 } 70 }
64 71
65 int CompilerIntrinsics::CountLeadingZeros(uint32_t value) { 72 int CompilerIntrinsics::CountLeadingZeros(uint32_t value) {
66 unsigned long result; //NOLINT 73 unsigned long result; //NOLINT
67 _BitScanReverse(&result, static_cast<long>(value)); //NOLINT 74 _BitScanReverse(&result, static_cast<long>(value)); //NOLINT
68 return 31 - static_cast<int>(result); 75 return 31 - static_cast<int>(result);
69 } 76 }
70 77
78 int CompilerIntrinsics::CountSetBits(uint32_t value) {
79 return __popcnt(value);
80 }
81
71 #else 82 #else
72 #error Unsupported compiler 83 #error Unsupported compiler
73 #endif 84 #endif
74 85
75 } } // namespace v8::internal 86 } } // namespace v8::internal
76 87
77 #endif // V8_COMPILER_INTRINSICS_H_ 88 #endif // V8_COMPILER_INTRINSICS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698