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

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

Issue 170383003: Merge a few A64 utils into the CompilerIntrinsics. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixes and cleaning Created 6 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 | Annotate | Revision Log
« no previous file with comments | « src/compiler-intrinsics.h ('k') | tools/gyp/v8.gyp » ('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 2006-2013 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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #if V8_TARGET_ARCH_A64 28 #include "compiler-intrinsics.h"
29
30 #include "a64/utils-a64.h"
31
32 29
33 namespace v8 { 30 namespace v8 {
34 namespace internal { 31 namespace internal {
35 32
36 #define __ assm-> 33 int C_CountRedundantLeadingSignBits(int64_t value, int width) {
37
38
39 int CountLeadingZeros(uint64_t value, int width) {
40 // TODO(jbramley): Optimize this for A64 hosts.
41 ASSERT((width == 32) || (width == 64)); 34 ASSERT((width == 32) || (width == 64));
42 int count = 0; 35 uint64_t val = static_cast<uint64_t>((value >= 0) ? value : ~value);
43 uint64_t bit_test = 1UL << (width - 1); 36 return CountLeadingZeros(val, width) - 1;
44 while ((count < width) && ((bit_test & value) == 0)) {
45 count++;
46 bit_test >>= 1;
47 }
48 return count;
49 } 37 }
50 38
51 39
52 int CountLeadingSignBits(int64_t value, int width) { 40 int C_CountSetBits(uint64_t value, int width) {
53 // TODO(jbramley): Optimize this for A64 hosts.
54 ASSERT((width == 32) || (width == 64));
55 if (value >= 0) {
56 return CountLeadingZeros(value, width) - 1;
57 } else {
58 return CountLeadingZeros(~value, width) - 1;
59 }
60 }
61
62
63 int CountTrailingZeros(uint64_t value, int width) {
64 // TODO(jbramley): Optimize this for A64 hosts.
65 ASSERT((width == 32) || (width == 64));
66 int count = 0;
67 while ((count < width) && (((value >> count) & 1) == 0)) {
68 count++;
69 }
70 return count;
71 }
72
73
74 int CountSetBits(uint64_t value, int width) {
75 // TODO(jbramley): Would it be useful to allow other widths? The
76 // implementation already supports them.
77 ASSERT((width == 32) || (width == 64));
78
79 // Mask out unused bits to ensure that they are not counted. 41 // Mask out unused bits to ensure that they are not counted.
80 value &= (0xffffffffffffffffUL >> (64-width)); 42 value &= (0xffffffffffffffffUL >> (64 - width));
81 43
82 // Add up the set bits. 44 // Add up the set bits.
83 // The algorithm works by adding pairs of bit fields together iteratively, 45 // The algorithm works by adding pairs of bit fields together iteratively,
84 // where the size of each bit field doubles each time. 46 // where the size of each bit field doubles each time.
85 // An example for an 8-bit value: 47 // An example for an 8-bit value:
86 // Bits: h g f e d c b a 48 // Bits: h g f e d c b a
87 // \ | \ | \ | \ | 49 // \ | \ | \ | \ |
88 // value = h+g f+e d+c b+a 50 // value = h+g f+e d+c b+a
89 // \ | \ | 51 // \ | \ |
90 // value = h+g+f+e d+c+b+a 52 // value = h+g+f+e d+c+b+a
91 // \ | 53 // \ |
92 // value = h+g+f+e+d+c+b+a 54 // value = h+g+f+e+d+c+b+a
93 value = ((value >> 1) & 0x5555555555555555) + (value & 0x5555555555555555); 55 value = ((value >> 1) & 0x5555555555555555) + (value & 0x5555555555555555);
94 value = ((value >> 2) & 0x3333333333333333) + (value & 0x3333333333333333); 56 value = ((value >> 2) & 0x3333333333333333) + (value & 0x3333333333333333);
95 value = ((value >> 4) & 0x0f0f0f0f0f0f0f0f) + (value & 0x0f0f0f0f0f0f0f0f); 57 value = ((value >> 4) & 0x0f0f0f0f0f0f0f0f) + (value & 0x0f0f0f0f0f0f0f0f);
96 value = ((value >> 8) & 0x00ff00ff00ff00ff) + (value & 0x00ff00ff00ff00ff); 58 value = ((value >> 8) & 0x00ff00ff00ff00ff) + (value & 0x00ff00ff00ff00ff);
97 value = ((value >> 16) & 0x0000ffff0000ffff) + (value & 0x0000ffff0000ffff); 59 value = ((value >> 16) & 0x0000ffff0000ffff) + (value & 0x0000ffff0000ffff);
98 value = ((value >> 32) & 0x00000000ffffffff) + (value & 0x00000000ffffffff); 60 value = ((value >> 32) & 0x00000000ffffffff) + (value & 0x00000000ffffffff);
99 61
100 return value; 62 return value;
101 } 63 }
102 64
103 65
104 int MaskToBit(uint64_t mask) {
105 ASSERT(CountSetBits(mask, 64) == 1);
106 return CountTrailingZeros(mask, 64);
107 }
108
109
110 } } // namespace v8::internal 66 } } // namespace v8::internal
111
112 #endif // V8_TARGET_ARCH_A64
OLDNEW
« no previous file with comments | « src/compiler-intrinsics.h ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698