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

Side by Side Diff: runtime/platform/utils.h

Issue 328503003: Extend Range analysis to 64-bit range and mint operations (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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 | « no previous file | runtime/vm/compiler.cc » ('j') | runtime/vm/intermediate_language_test.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef PLATFORM_UTILS_H_ 5 #ifndef PLATFORM_UTILS_H_
6 #define PLATFORM_UTILS_H_ 6 #define PLATFORM_UTILS_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "platform/globals.h" 9 #include "platform/globals.h"
10 10
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // without the risk of integer overflow. 164 // without the risk of integer overflow.
165 static inline bool RangeCheck(intptr_t offset, 165 static inline bool RangeCheck(intptr_t offset,
166 intptr_t count, 166 intptr_t count,
167 intptr_t length) { 167 intptr_t length) {
168 return offset >= 0 && 168 return offset >= 0 &&
169 count >= 0 && 169 count >= 0 &&
170 length >= 0 && 170 length >= 0 &&
171 count <= (length - offset); 171 count <= (length - offset);
172 } 172 }
173 173
174 static inline bool DidAddOverflow(int64_t a, int64_t b, int64_t result) {
175 // a & b have same sign but result has a different sign.
176 return ((a < 0) && (b < 0) && (result > 0)) ||
177 ((a > 0) && (b > 0) && (result < 0));
178 }
179
180 static inline bool DidSubOverflow(int64_t a, int64_t b, int64_t result) {
181 // a & b have different signs and result has a different sign than a.
182 return ((a < 0) && (b > 0) && (result > 0)) ||
183 ((a > 0) && (b < 0) && (result < 0));
184 }
185
186
174 // Utility functions for converting values from host endianess to 187 // Utility functions for converting values from host endianess to
175 // big or little endian values. 188 // big or little endian values.
176 static uint16_t HostToBigEndian16(uint16_t host_value); 189 static uint16_t HostToBigEndian16(uint16_t host_value);
177 static uint32_t HostToBigEndian32(uint32_t host_value); 190 static uint32_t HostToBigEndian32(uint32_t host_value);
178 static uint64_t HostToBigEndian64(uint64_t host_value); 191 static uint64_t HostToBigEndian64(uint64_t host_value);
179 static uint16_t HostToLittleEndian16(uint16_t host_value); 192 static uint16_t HostToLittleEndian16(uint16_t host_value);
180 static uint32_t HostToLittleEndian32(uint32_t host_value); 193 static uint32_t HostToLittleEndian32(uint32_t host_value);
181 static uint64_t HostToLittleEndian64(uint64_t host_value); 194 static uint64_t HostToLittleEndian64(uint64_t host_value);
182 195
183 static bool DoublesBitEqual(const double a, const double b) { 196 static bool DoublesBitEqual(const double a, const double b) {
184 return bit_cast<int64_t, double>(a) == bit_cast<int64_t, double>(b); 197 return bit_cast<int64_t, double>(a) == bit_cast<int64_t, double>(b);
185 } 198 }
186 }; 199 };
187 200
188 } // namespace dart 201 } // namespace dart
189 202
190 #if defined(TARGET_OS_ANDROID) 203 #if defined(TARGET_OS_ANDROID)
191 #include "platform/utils_android.h" 204 #include "platform/utils_android.h"
192 #elif defined(TARGET_OS_LINUX) 205 #elif defined(TARGET_OS_LINUX)
193 #include "platform/utils_linux.h" 206 #include "platform/utils_linux.h"
194 #elif defined(TARGET_OS_MACOS) 207 #elif defined(TARGET_OS_MACOS)
195 #include "platform/utils_macos.h" 208 #include "platform/utils_macos.h"
196 #elif defined(TARGET_OS_WINDOWS) 209 #elif defined(TARGET_OS_WINDOWS)
197 #include "platform/utils_win.h" 210 #include "platform/utils_win.h"
198 #else 211 #else
199 #error Unknown target os. 212 #error Unknown target os.
200 #endif 213 #endif
201 214
202 #endif // PLATFORM_UTILS_H_ 215 #endif // PLATFORM_UTILS_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/compiler.cc » ('j') | runtime/vm/intermediate_language_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698