| OLD | NEW |
| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 return static_cast<int>(result); | 69 return static_cast<int>(result); |
| 70 } | 70 } |
| 71 | 71 |
| 72 int CompilerIntrinsics::CountLeadingZeros(uint32_t value) { | 72 int CompilerIntrinsics::CountLeadingZeros(uint32_t value) { |
| 73 unsigned long result; //NOLINT | 73 unsigned long result; //NOLINT |
| 74 _BitScanReverse(&result, static_cast<long>(value)); //NOLINT | 74 _BitScanReverse(&result, static_cast<long>(value)); //NOLINT |
| 75 return 31 - static_cast<int>(result); | 75 return 31 - static_cast<int>(result); |
| 76 } | 76 } |
| 77 | 77 |
| 78 int CompilerIntrinsics::CountSetBits(uint32_t value) { | 78 int CompilerIntrinsics::CountSetBits(uint32_t value) { |
| 79 // __popcnt is only supported from VS2008. | |
| 80 #define _MSC_VER_VS2008 1500 | |
| 81 #if _MSC_VER >= _MSC_VER_VS2008 | |
| 82 return __popcnt(value); | |
| 83 #else | |
| 84 // Manually count set bits. | 79 // Manually count set bits. |
| 85 value = ((value >> 1) & 0x55555555) + (value & 0x55555555); | 80 value = ((value >> 1) & 0x55555555) + (value & 0x55555555); |
| 86 value = ((value >> 2) & 0x33333333) + (value & 0x33333333); | 81 value = ((value >> 2) & 0x33333333) + (value & 0x33333333); |
| 87 value = ((value >> 4) & 0x0f0f0f0f) + (value & 0x0f0f0f0f); | 82 value = ((value >> 4) & 0x0f0f0f0f) + (value & 0x0f0f0f0f); |
| 88 value = ((value >> 8) & 0x00ff00ff) + (value & 0x00ff00ff); | 83 value = ((value >> 8) & 0x00ff00ff) + (value & 0x00ff00ff); |
| 89 value = ((value >> 16) & 0x0000ffff) + (value & 0x0000ffff); | 84 value = ((value >> 16) & 0x0000ffff) + (value & 0x0000ffff); |
| 90 return value; | 85 return value; |
| 91 #endif | |
| 92 #undef _MSC_VER_VS2008 | |
| 93 } | 86 } |
| 94 | 87 |
| 95 #else | 88 #else |
| 96 #error Unsupported compiler | 89 #error Unsupported compiler |
| 97 #endif | 90 #endif |
| 98 | 91 |
| 99 } } // namespace v8::internal | 92 } } // namespace v8::internal |
| 100 | 93 |
| 101 #endif // V8_COMPILER_INTRINSICS_H_ | 94 #endif // V8_COMPILER_INTRINSICS_H_ |
| OLD | NEW |