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

Side by Side Diff: src/IceUtils.h

Issue 476323004: Start adding an integrated assembler. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: lit test to check encodings, swap complexi8 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
OLDNEW
(Empty)
1 //===- subzero/src/IceUtils.h - Utility functions ---------------*- C++ -*-===//
2 //
3 // The Subzero Code Generator
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares some utility functions
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef SUBZERO_SRC_ICEUTILS_H
15 #define SUBZERO_SRC_ICEUTILS_H
16
17 #include <climits>
18
19 namespace Ice {
20
21 // TODO(jvoung): why are labels offset by this?
22 const uint32_t kWordSize = sizeof(intptr_t);
Jim Stichnoth 2014/09/09 14:58:41 It's hard to search the patchsets for uses of kWor
jvoung (off chromium) 2014/09/15 17:19:15 I moved this to the one place it's being used, whi
23
24 // Similar to bit_cast, but allows copying from types of unrelated
25 // sizes. This method was introduced to enable the strict aliasing
26 // optimizations of GCC 4.4. Basically, GCC mindlessly relies on
27 // obscure details in the C++ standard that make reinterpret_cast
28 // virtually useless.
29 template <class D, class S> inline D bit_copy(const S &source) {
30 D destination;
31 // This use of memcpy is safe: source and destination cannot overlap.
32 memcpy(&destination, reinterpret_cast<const void *>(&source),
33 sizeof(destination));
34 return destination;
35 }
36
37 class Utils {
38 public:
39 // Check whether an N-bit two's-complement representation can hold value.
40 template <typename T> static inline bool IsInt(int N, T value) {
41 assert((0 < N) &&
42 (static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(value))));
Jim Stichnoth 2014/09/09 14:58:42 Same comment as above - is this CHAR_BIT, or the t
jvoung (off chromium) 2014/09/15 17:19:15 I think this is plain CHAR_BIT, since it's used al
43 T limit = static_cast<T>(1) << (N - 1);
44 return (-limit <= value) && (value < limit);
45 }
46
47 template <typename T> static inline bool IsUint(int N, T value) {
48 assert((0 < N) &&
49 (static_cast<unsigned int>(N) < (CHAR_BIT * sizeof(value))));
50 T limit = static_cast<T>(1) << N;
51 return (0 <= value) && (value < limit);
52 }
53 };
54
55 } // end of namespace Ice
56
57 #endif // SUBZERO_SRC_ICEUTILS_H
OLDNEW
« src/IceInstX8632.cpp ('K') | « src/IceTargetLoweringX8632.cpp ('k') | src/assembler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698