Index: src/trusted/validator_ragel/unreviewed/decoding.h |
=================================================================== |
--- src/trusted/validator_ragel/unreviewed/decoding.h (revision 9857) |
+++ src/trusted/validator_ragel/unreviewed/decoding.h (working copy) |
@@ -9,8 +9,8 @@ |
* functions and defines). |
*/ |
-#ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODER_INTERNAL_H_ |
-#define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODER_INTERNAL_H_ |
+#ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODING_H_ |
+#define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODING_H_ |
#include "native_client/src/trusted/validator_ragel/unreviewed/decoder.h" |
@@ -84,6 +84,60 @@ |
return is4 >> 4; |
} |
+/* |
Brad Chen
2012/09/28 23:31:54
Suggestion: use a macro "SIGN_EXTEND" for example,
khim
2012/10/03 22:30:10
Done.
|
+ * AnyFieldValue*Signed follow the very strange pattern: they calculate |
+ * value using unsigned arythmetic, then convert it to signed value and |
+ * finally they convert it back to unsgined uint64_t. |
Brad Chen
2012/09/28 23:31:54
unsigned
khim
2012/10/03 22:30:10
Done.
|
+ * |
+ * This operation looks pointless and dangerous but it's actually safe |
Brad Chen
2012/09/28 23:31:54
Some of the wording is a bit strong for such a com
khim
2012/10/03 22:30:10
Done.
|
+ * and makes sense (even if it's fragile). Conversion from unsigned to |
+ * signed does not change the value but conversion from signed to wider |
+ * unsigned does sing-extension - and this is what we need. |
Brad Chen
2012/09/28 23:31:54
sing => sign
khim
2012/10/03 22:30:10
Done.
|
+ * |
+ * Note: conversion from signed-to-unsigned and back is "implementation |
+ * defined behavior", not "undefined behavior", which means that it may |
+ * differ from implementation-to-implementation but each implementation |
+ * must pick one approach and use it in all the appropriate cases. |
+ * |
+ * This conversion depends on the underlying architecture and on all |
+ * x86-based systems it does what we need and at this point we don't |
+ * care about compatibility of our validator and Cray X1. |
+ */ |
+static FORCEINLINE uint64_t AnyFieldValue8bitSigned(uint8_t *start) { |
+ return (int8_t) *disp; |
+} |
+ |
+static FORCEINLINE uint64_t AnyFieldValue16bitSigned(uint8_t *start) { |
+ return (int16_t) (disp[0] + 256U * disp[1]); |
+} |
+ |
+static FORCEINLINE uint64_t AnyFieldValue32bitSigned(uint8_t *start) { |
+ return (int32_t) (disp[0] + 256U * (disp[1] + |
+ 256U * (disp[2] + 256U * (disp[3])))); |
+} |
+static FORCEINLINE uint64_t AnyFieldValue64bitSigned(uint8_t *start) { |
+ return (int64_t) (*disp + 256ULL * (disp[1] + 256ULL * (disp[2] + |
+ 256ULL * (disp[3] + 256ULL * (disp[4] + |
+ 256ULL * (disp[5] + 256ULL * (disp[6] + |
+ 256ULL * disp[7]))))))); |
+} |
+ |
+static FORCEINLINE uint64_t AnyFieldValue8bitUnsigned(uint8_t *start) { |
+ return *disp; |
+} |
+ |
+static FORCEINLINE uint64_t AnyFieldValue16bitUnsigned(uint8_t *start) { |
+ return (disp[0] + 256U * disp[1]); |
+} |
+ |
+static FORCEINLINE uint64_t AnyFieldValue32bitUnsigned(uint8_t *start) { |
+ return (disp[0] + 256U * (disp[1] + 256U * (disp[2] + 256U * (disp[3])))); |
+} |
+static FORCEINLINE uint64_t AnyFieldValue64bitUnsigned(uint8_t *start) { |
+ return (*disp + 256ULL * (disp[1] + 256ULL * (disp[2] + 256ULL * (disp[3] + |
+ 256ULL * (disp[4] + 256ULL * (disp[5] + 256ULL * (disp[6] + |
+ 256ULL * disp[7]))))))); |
+} |
static const uint8_t index_registers[] = { |
/* Note how REG_RIZ falls out of the pattern. */ |
REG_RAX, REG_RCX, REG_RDX, REG_RBX, |
@@ -92,4 +146,4 @@ |
REG_R12, REG_R13, REG_R14, REG_R15 |
}; |
-#endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODER_INTERNAL_H_ */ |
+#endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_DECODING_H_ */ |