Permalink
Browse files

Decoder redesign in preparation for packed fields and start/endseq.

  • Loading branch information...
1 parent 4a99abb commit f74534b42ac9ac8b0ff496cb0da83f1201bbf8da @haberman committed May 8, 2011
Showing with 480 additions and 431 deletions.
  1. +9 −4 Makefile
  2. +1 −0 perf-regression-test.py
  3. +4 −8 perf-tests.sh
  4. +23 −24 src/upb.c
  5. +1 −7 src/upb.h
  6. +232 −231 src/upb_decoder.c
  7. +4 −0 src/upb_decoder.h
  8. +22 −42 src/upb_decoder_x86.dasc
  9. +6 −4 src/upb_def.h
  10. +5 −4 src/upb_msg.c
  11. +29 −20 src/upb_stream.c
  12. +24 −22 src/upb_stream.h
  13. +5 −0 src/upb_string.h
  14. +6 −3 src/upb_textprinter.c
  15. +54 −0 src/upb_varint.c
  16. +4 −46 src/upb_varint.h
  17. +51 −16 tests/test_decoder.c
View
@@ -77,6 +77,7 @@ CORE= \
src/upb_string.c \
src/upb_def.c \
src/upb_msg.c \
+ src/upb_varint.c \
# Common encoders/decoders -- you're almost certain to want these.
STREAM= \
@@ -211,9 +212,13 @@ SIMPLE_TESTS= \
tests/test_string \
tests/test_def \
tests/test_varint \
- tests/tests
-# tests/test_decoder \
- tests/test_stream \
+ tests/tests \
+
+INTERACTIVE_TESTS= \
+ tests/test_decoder \
+
+# tests/test_stream \
+
SIMPLE_CXX_TESTS= \
tests/test_table
@@ -225,7 +230,7 @@ VARIADIC_TESTS= \
TESTS=$(SIMPLE_TESTS) $(SIMPLE_CXX_TESTS) $(VARIADIC_TESTS)
-tests: $(TESTS)
+tests: $(TESTS) $(INTERACTIVE_TESTS)
$(TESTS): $(LIBUPB)
tests/tests: tests/test.proto.pb
View
@@ -10,6 +10,7 @@
# Generate numbers for baseline.
rm -rf perf-tmp
git clone . perf-tmp
+cp perf-tests.sh perf-tmp
(cd perf-tmp && ./perf-tests.sh upb)
cp perf-tmp/perf-tests.out perf-tests.baseline
View
@@ -16,20 +16,16 @@ run_with_flags () {
NAME=$2
make clean
- echo "$FLAGS -fprofile-generate" > perf-cppflags
- make upb_benchmarks
- make benchmark
-
- make clean_leave_profile
- echo "$FLAGS -fprofile-use" > perf-cppflags
+ echo "$FLAGS" > perf-cppflags
make upb_benchmarks
make benchmark | sed -e "s/^/$NAME./g" | tee -a perf-tests.out
}
-if [ x`uname -m` = xx86_64 ]; then
+#if [ x`uname -m` = xx86_64 ]; then
run_with_flags "-DNDEBUG -m32" "plain32"
run_with_flags "-DNDEBUG -fomit-frame-pointer -m32" "omitfp32"
-fi
+#fi
run_with_flags "-DNDEBUG " "plain"
run_with_flags "-DNDEBUG -fomit-frame-pointer" "omitfp"
+run_with_flags "-DNDEBUG -DUPB_USE_JIT_X64" "jit"
View
@@ -13,31 +13,30 @@
#include "upb_string.h"
#define alignof(t) offsetof(struct { char c; t x; }, x)
-#define TYPE_INFO(wire_type, ctype, allows_delimited, inmemory_type) \
- {alignof(ctype), sizeof(ctype), wire_type, \
- (1 << wire_type) | (allows_delimited << UPB_WIRE_TYPE_DELIMITED), \
- UPB_TYPE(inmemory_type), #ctype},
+#define TYPE_INFO(wire_type, ctype, inmemory_type) \
+ {alignof(ctype), sizeof(ctype), wire_type, UPB_TYPE(inmemory_type), #ctype},
const upb_type_info upb_types[] = {
- {0, 0, 0, 0, 0, ""}, // There is no type 0.
- TYPE_INFO(UPB_WIRE_TYPE_64BIT, double, 1, DOUBLE) // DOUBLE
- TYPE_INFO(UPB_WIRE_TYPE_32BIT, float, 1, FLOAT) // FLOAT
- TYPE_INFO(UPB_WIRE_TYPE_VARINT, int64_t, 1, INT64) // INT64
- TYPE_INFO(UPB_WIRE_TYPE_VARINT, uint64_t, 1, UINT64) // UINT64
- TYPE_INFO(UPB_WIRE_TYPE_VARINT, int32_t, 1, INT32) // INT32
- TYPE_INFO(UPB_WIRE_TYPE_64BIT, uint64_t, 1, UINT64) // FIXED64
- TYPE_INFO(UPB_WIRE_TYPE_32BIT, uint32_t, 1, UINT32) // FIXED32
- TYPE_INFO(UPB_WIRE_TYPE_VARINT, bool, 1, BOOL) // BOOL
- TYPE_INFO(UPB_WIRE_TYPE_DELIMITED, void*, 1, STRING) // STRING
- TYPE_INFO(UPB_WIRE_TYPE_START_GROUP, void*, 0, MESSAGE) // GROUP
- TYPE_INFO(UPB_WIRE_TYPE_DELIMITED, void*, 1, MESSAGE) // MESSAGE
- TYPE_INFO(UPB_WIRE_TYPE_DELIMITED, void*, 1, STRING) // BYTES
- TYPE_INFO(UPB_WIRE_TYPE_VARINT, uint32_t, 1, UINT32) // UINT32
- TYPE_INFO(UPB_WIRE_TYPE_VARINT, uint32_t, 1, INT32) // ENUM
- TYPE_INFO(UPB_WIRE_TYPE_32BIT, int32_t, 1, INT32) // SFIXED32
- TYPE_INFO(UPB_WIRE_TYPE_64BIT, int64_t, 1, INT64) // SFIXED64
- TYPE_INFO(UPB_WIRE_TYPE_VARINT, int32_t, 1, INT32) // SINT32
- TYPE_INFO(UPB_WIRE_TYPE_VARINT, int64_t, 1, INT64) // SINT64
+ {0, 0, 0, 0, ""}, // There is no type 0.
+ TYPE_INFO(UPB_WIRE_TYPE_64BIT, double, DOUBLE) // DOUBLE
+ TYPE_INFO(UPB_WIRE_TYPE_32BIT, float, FLOAT) // FLOAT
+ TYPE_INFO(UPB_WIRE_TYPE_VARINT, int64_t, INT64) // INT64
+ TYPE_INFO(UPB_WIRE_TYPE_VARINT, uint64_t, UINT64) // UINT64
+ TYPE_INFO(UPB_WIRE_TYPE_VARINT, int32_t, INT32) // INT32
+ TYPE_INFO(UPB_WIRE_TYPE_64BIT, uint64_t, UINT64) // FIXED64
+ TYPE_INFO(UPB_WIRE_TYPE_32BIT, uint32_t, UINT32) // FIXED32
+ TYPE_INFO(UPB_WIRE_TYPE_VARINT, bool, BOOL) // BOOL
+ TYPE_INFO(UPB_WIRE_TYPE_DELIMITED, void*, STRING) // STRING
+ TYPE_INFO(UPB_WIRE_TYPE_START_GROUP, void*, MESSAGE) // GROUP
+ TYPE_INFO(UPB_WIRE_TYPE_DELIMITED, void*, MESSAGE) // MESSAGE
+ TYPE_INFO(UPB_WIRE_TYPE_DELIMITED, void*, STRING) // BYTES
+ TYPE_INFO(UPB_WIRE_TYPE_VARINT, uint32_t, UINT32) // UINT32
+ TYPE_INFO(UPB_WIRE_TYPE_VARINT, uint32_t, INT32) // ENUM
+ TYPE_INFO(UPB_WIRE_TYPE_32BIT, int32_t, INT32) // SFIXED32
+ TYPE_INFO(UPB_WIRE_TYPE_64BIT, int64_t, INT64) // SFIXED64
+ TYPE_INFO(UPB_WIRE_TYPE_VARINT, int32_t, INT32) // SINT32
+ TYPE_INFO(UPB_WIRE_TYPE_VARINT, int64_t, INT64) // SINT64
+ TYPE_INFO(UPB_WIRE_TYPE_END_GROUP, void*, INT64) // SINT64
};
#ifdef NDEBUG
@@ -64,7 +63,7 @@ void upb_copyerr(upb_status *to, upb_status *from)
void upb_clearerr(upb_status *status) {
status->code = UPB_OK;
- upb_string_recycle(&status->str);
+ if (status->str) upb_string_recycle(&status->str);
}
void upb_printerr(upb_status *status) {
View
@@ -126,7 +126,6 @@ typedef struct {
uint8_t align;
uint8_t size;
upb_wire_type_t native_wire_type;
- uint8_t allowed_wire_types; // For packable fields, also allows delimited.
uint8_t inmemory_type; // For example, INT32, SINT32, and SFIXED32 -> INT32
char *ctype;
} upb_type_info;
@@ -168,11 +167,11 @@ typedef int32_t upb_strlen_t;
// The type of a upb_value. This is like a upb_fieldtype_t, but adds the
// constant UPB_VALUETYPE_ARRAY to represent an array.
typedef uint8_t upb_valuetype_t;
+#define UPB_TYPE_ENDGROUP 19 // Need to increase if more real types are added!
#define UPB_VALUETYPE_ARRAY 32
#define UPB_VALUETYPE_BYTESRC 32
#define UPB_VALUETYPE_RAW 33
#define UPB_VALUETYPE_FIELDDEF 34
-#define UPB_TYPE_ENDGROUP 35
// A single .proto value. The owner must have an out-of-band way of knowing
// the type, so that it knows which union member to use.
@@ -231,11 +230,6 @@ UPB_VALUE_ACCESSORS(fielddef, fielddef, upb_fielddef*, UPB_VALUETYPE_FIELDDEF);
extern upb_value UPB_NO_VALUE;
-INLINE void upb_value_setraw(upb_value *val, uint64_t cval) {
- SET_TYPE(val->type, UPB_VALUETYPE_RAW);
- val->val.uint64 = cval;
-}
-
INLINE upb_atomic_refcount_t *upb_value_getrefcount(upb_value val) {
assert(val.type == UPB_TYPE(MESSAGE) ||
val.type == UPB_TYPE(STRING) ||
Oops, something went wrong.

0 comments on commit f74534b

Please sign in to comment.