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

Side by Side Diff: src/base/bits.h

Issue 555833002: [turbofan] Add support for overflow add/sub to the MachineOperatorReducer. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address nit. Created 6 years, 3 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 | « include/v8config.h ('k') | src/base/bits-unittest.cc » ('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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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_BASE_BITS_H_ 5 #ifndef V8_BASE_BITS_H_
6 #define V8_BASE_BITS_H_ 6 #define V8_BASE_BITS_H_
7 7
8 #include "include/v8stdint.h" 8 #include "include/v8stdint.h"
9 #include "src/base/macros.h"
9 #if V8_CC_MSVC 10 #if V8_CC_MSVC
10 #include <intrin.h> 11 #include <intrin.h>
11 #endif 12 #endif
12 #if V8_OS_WIN32 13 #if V8_OS_WIN32
13 #include "src/base/win32-headers.h" 14 #include "src/base/win32-headers.h"
14 #endif 15 #endif
15 16
16 namespace v8 { 17 namespace v8 {
17 namespace base { 18 namespace base {
18 namespace bits { 19 namespace bits {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 if (shift == 0) return value; 108 if (shift == 0) return value;
108 return (value >> shift) | (value << (32 - shift)); 109 return (value >> shift) | (value << (32 - shift));
109 } 110 }
110 111
111 112
112 inline uint64_t RotateRight64(uint64_t value, uint64_t shift) { 113 inline uint64_t RotateRight64(uint64_t value, uint64_t shift) {
113 if (shift == 0) return value; 114 if (shift == 0) return value;
114 return (value >> shift) | (value << (64 - shift)); 115 return (value >> shift) | (value << (64 - shift));
115 } 116 }
116 117
118
119 // SignedAddOverflow32(lhs,rhs,val) performs a signed summation of |lhs| and
120 // |rhs| and stores the result into the variable pointed to by |val| and
121 // returns true if the signed summation resulted in an overflow.
122 inline bool SignedAddOverflow32(int32_t lhs, int32_t rhs, int32_t* val) {
123 #if V8_HAS_BUILTIN_SADD_OVERFLOW
124 return __builtin_sadd_overflow(lhs, rhs, val);
125 #else
126 uint32_t res = static_cast<uint32_t>(lhs) + static_cast<uint32_t>(rhs);
127 *val = bit_cast<int32_t>(res);
128 return ((res ^ lhs) & (res ^ rhs) & (1U << 31)) != 0;
129 #endif
130 }
131
132
133 // SignedSubOverflow32(lhs,rhs,val) performs a signed subtraction of |lhs| and
134 // |rhs| and stores the result into the variable pointed to by |val| and
135 // returns true if the signed subtraction resulted in an overflow.
136 inline bool SignedSubOverflow32(int32_t lhs, int32_t rhs, int32_t* val) {
137 #if V8_HAS_BUILTIN_SSUB_OVERFLOW
138 return __builtin_ssub_overflow(lhs, rhs, val);
139 #else
140 uint32_t res = static_cast<uint32_t>(lhs) - static_cast<uint32_t>(rhs);
141 *val = bit_cast<int32_t>(res);
142 return ((res ^ lhs) & (res ^ ~rhs) & (1U << 31)) != 0;
143 #endif
144 }
145
117 } // namespace bits 146 } // namespace bits
118 } // namespace base 147 } // namespace base
119 } // namespace v8 148 } // namespace v8
120 149
121 #endif // V8_BASE_BITS_H_ 150 #endif // V8_BASE_BITS_H_
OLDNEW
« no previous file with comments | « include/v8config.h ('k') | src/base/bits-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698