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

Side by Side Diff: src/trusted/validator_ragel/decoding.h

Issue 11000033: Move validator_x86_XX.rl out of unreviewed. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 8 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 /* 7 /*
8 * This file contains common parts of x86-32 and x86-64 internals (inline 8 * This file contains common parts of x86-32 and x86-64 internals (inline
9 * functions and defines). 9 * functions and defines).
10 */ 10 */
11 11
12 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODING_H_ 12 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODING_H_
13 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODING_H_ 13 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODING_H_
14 14
15 #include "native_client/src/trusted/validator_ragel/unreviewed/decoder.h" 15 #include "native_client/src/trusted/validator_ragel/decoder.h"
16 16
17 #if NACL_WINDOWS 17 #if NACL_WINDOWS
18 # define FORCEINLINE __forceinline 18 # define FORCEINLINE __forceinline
19 #else 19 #else
20 # define FORCEINLINE __inline __attribute__ ((always_inline)) 20 # define FORCEINLINE __inline __attribute__ ((always_inline))
21 #endif 21 #endif
22 22
23 static FORCEINLINE uint8_t RegFromOpcode(uint8_t modrm) { 23 static FORCEINLINE uint8_t RegFromOpcode(uint8_t modrm) {
24 return modrm & 0x07; 24 return modrm & 0x07;
25 } 25 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 78
79 static FORCEINLINE uint8_t GetOperandFromVexAMD64(uint8_t vex3) { 79 static FORCEINLINE uint8_t GetOperandFromVexAMD64(uint8_t vex3) {
80 return ((~vex3) & 0x78) >> 3; 80 return ((~vex3) & 0x78) >> 3;
81 } 81 }
82 82
83 static FORCEINLINE uint8_t RegisterFromIS4(uint8_t is4) { 83 static FORCEINLINE uint8_t RegisterFromIS4(uint8_t is4) {
84 return is4 >> 4; 84 return is4 >> 4;
85 } 85 }
86 86
87 /*
88 * SignExtendXXBit is used to sign-extend XX-bit value to unsigned 64-bit value.
89 *
90 * To do that you need to pass unsigned value of smaller then 64-bit size
91 * to this function: it will be converted to signed value and then
92 * sign-extended to become 64-bit value.
93 *
94 * Smaller values can be obtained by restricting this value further (which is
95 * safe according to the C language specification: see 6.2.1.2 in C90 and
96 * 6.3.1.3.2 in C99 specification).
97 *
98 * Note that these operations are safe but slightly unusual: they come very
99 * close to the edge of what “well-behaved C program is not supposed to do”,
100 * but they stay on the “safe” side of this boundary. Specifically: this
101 * behavior triggers “implementation-defined behavior” (see 6.2.1.2 in C90
102 * specification and 6.3.1.3.3 in C99 specification) which sounds suspiciously
103 * similar to the dreaded “undefined behavior”, but in reality these two are
104 * quite different: any program which triggers “undefined behavior” is not a
105 * valid C program at all, but program which tirggers “implementation-defined
106 * behavior” is quite valid C program. What this program actually *does*
107 * depends on the specification of a given C compiler: each particular
108 * implementation must decide for itself what it'll do in this particular case
109 * and *stick* *to* *it*. If the implementation uses two's-complement negative
110 * numbers (and all the implementation which can compile this code *must*
111 * support two's-complement arythmetic—see 7.18.1.1 in C99 specification) then
112 * the easiest thing to do is to do what we need here—this is what all known
113 * compilers for all known platforms are actually doing.
114 */
115 static FORCEINLINE uint64_t SignExtend8Bit(int8_t value) {
116 return value;
117 }
118
119 static FORCEINLINE uint64_t SignExtend16Bit(int16_t value) {
120 return value;
121 }
122
123 static FORCEINLINE uint64_t SignExtend32Bit(int32_t value) {
124 return value;
125 }
126
127 static FORCEINLINE uint64_t AnyFieldValue8bit(const uint8_t *start) {
128 return *start;
129 }
130
131 static FORCEINLINE uint64_t AnyFieldValue16bit(const uint8_t *start) {
132 return (start[0] + 256U * start[1]);
133 }
134
135 static FORCEINLINE uint64_t AnyFieldValue32bit(const uint8_t *start) {
136 return (start[0] + 256U * (start[1] + 256U * (start[2] + 256U * (start[3]))));
137 }
138 static FORCEINLINE uint64_t AnyFieldValue64bit(const uint8_t *start) {
139 return (*start + 256ULL * (start[1] + 256ULL * (start[2] + 256ULL *
140 (start[3] + 256ULL * (start[4] + 256ULL * (start[5] + 256ULL *
141 (start[6] + 256ULL * start[7])))))));
142 }
87 static const uint8_t index_registers[] = { 143 static const uint8_t index_registers[] = {
88 /* Note how REG_RIZ falls out of the pattern. */ 144 /* Note how REG_RIZ falls out of the pattern. */
89 REG_RAX, REG_RCX, REG_RDX, REG_RBX, 145 REG_RAX, REG_RCX, REG_RDX, REG_RBX,
90 REG_RIZ, REG_RBP, REG_RSI, REG_RDI, 146 REG_RIZ, REG_RBP, REG_RSI, REG_RDI,
91 REG_R8, REG_R9, REG_R10, REG_R11, 147 REG_R8, REG_R9, REG_R10, REG_R11,
92 REG_R12, REG_R13, REG_R14, REG_R15 148 REG_R12, REG_R13, REG_R14, REG_R15
93 }; 149 };
94 150
95 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODING_H_ */ 151 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODING_H_ */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698