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

Side by Side Diff: src/arm64/utils-arm64.h

Issue 1698483002: [arm][arm64] Improve CountTrailingZero implementation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: comments addressed Created 4 years, 10 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
« no previous file with comments | « src/arm64/simulator-arm64.cc ('k') | src/base/bits.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_ARM64_UTILS_ARM64_H_ 5 #ifndef V8_ARM64_UTILS_ARM64_H_
6 #define V8_ARM64_UTILS_ARM64_H_ 6 #define V8_ARM64_UTILS_ARM64_H_
7 7
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "src/arm64/constants-arm64.h" 10 #include "src/arm64/constants-arm64.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 // Bit counting. 48 // Bit counting.
49 int CountLeadingZeros(uint64_t value, int width); 49 int CountLeadingZeros(uint64_t value, int width);
50 int CountLeadingSignBits(int64_t value, int width); 50 int CountLeadingSignBits(int64_t value, int width);
51 int CountTrailingZeros(uint64_t value, int width); 51 int CountTrailingZeros(uint64_t value, int width);
52 int CountSetBits(uint64_t value, int width); 52 int CountSetBits(uint64_t value, int width);
53 uint64_t LargestPowerOf2Divisor(uint64_t value); 53 uint64_t LargestPowerOf2Divisor(uint64_t value);
54 int MaskToBit(uint64_t mask); 54 int MaskToBit(uint64_t mask);
55 55
56 56
57 template <typename T> 57 template <typename T>
58 T ReverseBits(T value) {
59 DCHECK((sizeof(value) == 1) || (sizeof(value) == 2) || (sizeof(value) == 4) ||
60 (sizeof(value) == 8));
61 T result = 0;
62 for (unsigned i = 0; i < (sizeof(value) * 8); i++) {
63 result = (result << 1) | (value & 1);
64 value >>= 1;
65 }
66 return result;
67 }
68
69
70 template <typename T>
71 T ReverseBytes(T value, int block_bytes_log2) { 58 T ReverseBytes(T value, int block_bytes_log2) {
72 DCHECK((sizeof(value) == 4) || (sizeof(value) == 8)); 59 DCHECK((sizeof(value) == 4) || (sizeof(value) == 8));
73 DCHECK((1U << block_bytes_log2) <= sizeof(value)); 60 DCHECK((1U << block_bytes_log2) <= sizeof(value));
74 // Split the 64-bit value into an 8-bit array, where b[0] is the least 61 // Split the 64-bit value into an 8-bit array, where b[0] is the least
75 // significant byte, and b[7] is the most significant. 62 // significant byte, and b[7] is the most significant.
76 uint8_t bytes[8]; 63 uint8_t bytes[8];
77 uint64_t mask = 0xff00000000000000; 64 uint64_t mask = 0xff00000000000000;
78 for (int i = 7; i >= 0; i--) { 65 for (int i = 7; i >= 0; i--) {
79 bytes[i] = (static_cast<uint64_t>(value) & mask) >> (i * 8); 66 bytes[i] = (static_cast<uint64_t>(value) & mask) >> (i * 8);
80 mask >>= 8; 67 mask >>= 8;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 129
143 130
144 inline float FusedMultiplyAdd(float op1, float op2, float a) { 131 inline float FusedMultiplyAdd(float op1, float op2, float a) {
145 return fmaf(op1, op2, a); 132 return fmaf(op1, op2, a);
146 } 133 }
147 134
148 } // namespace internal 135 } // namespace internal
149 } // namespace v8 136 } // namespace v8
150 137
151 #endif // V8_ARM64_UTILS_ARM64_H_ 138 #endif // V8_ARM64_UTILS_ARM64_H_
OLDNEW
« no previous file with comments | « src/arm64/simulator-arm64.cc ('k') | src/base/bits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698