From 0b7904e18cad70e17a2dbed5f1362ccdc62fd385 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Tue, 19 Sep 2017 14:23:36 -0700 Subject: Reserve unknown fields in upb 1. For decoding, an unknownfields will be lazily created on message, which contains bytes of unknown fields. 2. For encoding, if the unknownfields is present on message, all bytes contained in it will be serialized. --- upb/pb/decoder.c | 11 +++++++++++ upb/pb/encoder.c | 13 +++++++++++++ upb/pb/encoder.h | 2 ++ 3 files changed, 26 insertions(+) (limited to 'upb/pb') diff --git a/upb/pb/decoder.c b/upb/pb/decoder.c index 182ecc9..79142bf 100644 --- a/upb/pb/decoder.c +++ b/upb/pb/decoder.c @@ -543,6 +543,9 @@ UPB_NOINLINE int32_t upb_pbdecoder_checktag_slow(upb_pbdecoder *d, int32_t upb_pbdecoder_skipunknown(upb_pbdecoder *d, int32_t fieldnum, uint8_t wire_type) { + upb_addunknown_handlerfunc *addunknown; + const void* hd; + if (fieldnum >= 0) goto have_tag; @@ -596,6 +599,14 @@ have_tag: } if (d->top->groupnum >= 0) { + addunknown = (upb_addunknown_handlerfunc *)upb_handlers_gethandler( + (d->top->sink).handlers, UPB_UNKNOWN_SELECTOR); + if (addunknown != NULL) { + hd = upb_handlers_gethandlerdata((d->top->sink).handlers, + UPB_UNKNOWN_SELECTOR); + addunknown((d->top->sink).closure, hd, d->checkpoint, + d->ptr - d->checkpoint); + } return DECODE_OK; } diff --git a/upb/pb/encoder.c b/upb/pb/encoder.c index b457867..b8e9191 100644 --- a/upb/pb/encoder.c +++ b/upb/pb/encoder.c @@ -374,6 +374,12 @@ static void *encode_startdelimfield(void *c, const void *hd) { return ok ? c : UPB_BREAK; } +static bool encode_unknown(void *c, const void *hd, const char *buf, + size_t len) { + UPB_UNUSED(hd); + return encode_bytes(c, buf, len) && commit(c); +} + static bool encode_enddelimfield(void *c, const void *hd) { UPB_UNUSED(hd); return end_delim(c); @@ -436,6 +442,7 @@ static void newhandlers_callback(const void *closure, upb_handlers *h) { upb_handlers_setstartmsg(h, startmsg, NULL); upb_handlers_setendmsg(h, endmsg, NULL); + upb_handlers_setunknown(h, encode_unknown, NULL); m = upb_handlers_msgdef(h); for(upb_msg_field_begin(&i, m); @@ -564,3 +571,9 @@ upb_pb_encoder *upb_pb_encoder_create(upb_env *env, const upb_handlers *h, } upb_sink *upb_pb_encoder_input(upb_pb_encoder *e) { return &e->input_; } + +void upb_pb_encoder_encode_unknown(upb_pb_encoder *p, const char *buf, + size_t size) { + encode_bytes(p, buf, size); + commit(p); +} diff --git a/upb/pb/encoder.h b/upb/pb/encoder.h index 41b7e7b..3d8dce1 100644 --- a/upb/pb/encoder.h +++ b/upb/pb/encoder.h @@ -64,6 +64,8 @@ const upb_handlers *upb_pb_encoder_newhandlers(const upb_msgdef *m, upb_sink *upb_pb_encoder_input(upb_pb_encoder *p); upb_pb_encoder* upb_pb_encoder_create(upb_env* e, const upb_handlers* h, upb_bytessink* output); +void upb_pb_encoder_encode_unknown(upb_pb_encoder* p, const char* buf, + size_t size); UPB_END_EXTERN_C -- cgit v1.2.3 From dc9d15084fa02c69c277cd730862e49ec10cd38e Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Tue, 19 Sep 2017 16:22:32 -0700 Subject: Remove upb_addunknown_handlerfunc and upb_handlers_setaddunknown --- upb/handlers.c | 7 ------- upb/handlers.h | 3 --- upb/pb/decoder.c | 4 ++-- 3 files changed, 2 insertions(+), 12 deletions(-) (limited to 'upb/pb') diff --git a/upb/handlers.c b/upb/handlers.c index b9dc8f3..8799ed0 100644 --- a/upb/handlers.c +++ b/upb/handlers.c @@ -372,13 +372,6 @@ SETTER(endseq, upb_endfield_handlerfunc*, UPB_HANDLER_ENDSEQ) #undef SETTER -bool upb_handlers_setaddunknown(upb_handlers *h, - upb_addunknown_handlerfunc *func, - upb_handlerattr *attr) { - return doset(h, UPB_UNKNOWN_SELECTOR, NULL, UPB_HANDLER_INT32, - (upb_func *)func, attr); -} - bool upb_handlers_setunknown(upb_handlers *h, upb_unknown_handlerfunc *func, upb_handlerattr *attr) { return doset(h, UPB_UNKNOWN_SELECTOR, NULL, UPB_HANDLER_INT32, diff --git a/upb/handlers.h b/upb/handlers.h index 0f28f19..33cdf86 100644 --- a/upb/handlers.h +++ b/upb/handlers.h @@ -691,9 +691,6 @@ const upb_status *upb_handlers_status(upb_handlers *h); void upb_handlers_clearerr(upb_handlers *h); const upb_msgdef *upb_handlers_msgdef(const upb_handlers *h); bool upb_handlers_addcleanup(upb_handlers *h, void *p, upb_handlerfree *hfree); -bool upb_handlers_setaddunknown(upb_handlers *h, - upb_addunknown_handlerfunc *func, - upb_handlerattr *attr); bool upb_handlers_setunknown(upb_handlers *h, upb_unknown_handlerfunc *func, upb_handlerattr *attr); diff --git a/upb/pb/decoder.c b/upb/pb/decoder.c index 79142bf..32509b5 100644 --- a/upb/pb/decoder.c +++ b/upb/pb/decoder.c @@ -543,7 +543,7 @@ UPB_NOINLINE int32_t upb_pbdecoder_checktag_slow(upb_pbdecoder *d, int32_t upb_pbdecoder_skipunknown(upb_pbdecoder *d, int32_t fieldnum, uint8_t wire_type) { - upb_addunknown_handlerfunc *addunknown; + upb_unknown_handlerfunc *addunknown; const void* hd; if (fieldnum >= 0) @@ -599,7 +599,7 @@ have_tag: } if (d->top->groupnum >= 0) { - addunknown = (upb_addunknown_handlerfunc *)upb_handlers_gethandler( + addunknown = (upb_unknown_handlerfunc *)upb_handlers_gethandler( (d->top->sink).handlers, UPB_UNKNOWN_SELECTOR); if (addunknown != NULL) { hd = upb_handlers_gethandlerdata((d->top->sink).handlers, -- cgit v1.2.3 From 5aa27d91c6f25705c89ec56c5a33f6bd20d9c124 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Tue, 19 Sep 2017 16:45:55 -0700 Subject: Use upb_sink_putunknown for reserve unknown --- upb/pb/decoder.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'upb/pb') diff --git a/upb/pb/decoder.c b/upb/pb/decoder.c index 32509b5..30a1945 100644 --- a/upb/pb/decoder.c +++ b/upb/pb/decoder.c @@ -599,14 +599,7 @@ have_tag: } if (d->top->groupnum >= 0) { - addunknown = (upb_unknown_handlerfunc *)upb_handlers_gethandler( - (d->top->sink).handlers, UPB_UNKNOWN_SELECTOR); - if (addunknown != NULL) { - hd = upb_handlers_gethandlerdata((d->top->sink).handlers, - UPB_UNKNOWN_SELECTOR); - addunknown((d->top->sink).closure, hd, d->checkpoint, - d->ptr - d->checkpoint); - } + upb_sink_putunknown(&d->top->sink, d->checkpoint, d->ptr - d->checkpoint); return DECODE_OK; } -- cgit v1.2.3 From 6a6e192375076aa1fdc9f08c1a8b5ca98fdc04f9 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Tue, 19 Sep 2017 16:51:38 -0700 Subject: Remove unused declaration. --- upb/pb/decoder.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'upb/pb') diff --git a/upb/pb/decoder.c b/upb/pb/decoder.c index 30a1945..94fa031 100644 --- a/upb/pb/decoder.c +++ b/upb/pb/decoder.c @@ -543,9 +543,6 @@ UPB_NOINLINE int32_t upb_pbdecoder_checktag_slow(upb_pbdecoder *d, int32_t upb_pbdecoder_skipunknown(upb_pbdecoder *d, int32_t fieldnum, uint8_t wire_type) { - upb_unknown_handlerfunc *addunknown; - const void* hd; - if (fieldnum >= 0) goto have_tag; -- cgit v1.2.3 From 69dee545ec95f55f271f5a51ac115deca4b484f9 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Tue, 19 Sep 2017 17:08:20 -0700 Subject: Remove upb_pb_encoder_encode_unknown --- upb/pb/encoder.c | 9 +-------- upb/pb/encoder.h | 4 ++-- 2 files changed, 3 insertions(+), 10 deletions(-) (limited to 'upb/pb') diff --git a/upb/pb/encoder.c b/upb/pb/encoder.c index b8e9191..3734710 100644 --- a/upb/pb/encoder.c +++ b/upb/pb/encoder.c @@ -374,8 +374,7 @@ static void *encode_startdelimfield(void *c, const void *hd) { return ok ? c : UPB_BREAK; } -static bool encode_unknown(void *c, const void *hd, const char *buf, - size_t len) { +bool encode_unknown(void *c, const void *hd, const char *buf, size_t len) { UPB_UNUSED(hd); return encode_bytes(c, buf, len) && commit(c); } @@ -571,9 +570,3 @@ upb_pb_encoder *upb_pb_encoder_create(upb_env *env, const upb_handlers *h, } upb_sink *upb_pb_encoder_input(upb_pb_encoder *e) { return &e->input_; } - -void upb_pb_encoder_encode_unknown(upb_pb_encoder *p, const char *buf, - size_t size) { - encode_bytes(p, buf, size); - commit(p); -} diff --git a/upb/pb/encoder.h b/upb/pb/encoder.h index 3d8dce1..780dfcb 100644 --- a/upb/pb/encoder.h +++ b/upb/pb/encoder.h @@ -64,8 +64,8 @@ const upb_handlers *upb_pb_encoder_newhandlers(const upb_msgdef *m, upb_sink *upb_pb_encoder_input(upb_pb_encoder *p); upb_pb_encoder* upb_pb_encoder_create(upb_env* e, const upb_handlers* h, upb_bytessink* output); -void upb_pb_encoder_encode_unknown(upb_pb_encoder* p, const char* buf, - size_t size); +bool encode_unknown(upb_pb_encoder* p, const void* hd, const char* buf, + size_t size); UPB_END_EXTERN_C -- cgit v1.2.3 From dd77460c65c6b053e7b2eb42249b988b9c9d7cba Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Wed, 20 Sep 2017 16:14:49 -0700 Subject: Do not expose encode_unknown --- upb/pb/encoder.c | 3 ++- upb/pb/encoder.h | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'upb/pb') diff --git a/upb/pb/encoder.c b/upb/pb/encoder.c index 3734710..839ede0 100644 --- a/upb/pb/encoder.c +++ b/upb/pb/encoder.c @@ -374,7 +374,8 @@ static void *encode_startdelimfield(void *c, const void *hd) { return ok ? c : UPB_BREAK; } -bool encode_unknown(void *c, const void *hd, const char *buf, size_t len) { +static bool encode_unknown(void *c, const void *hd, const char *buf, + size_t len) { UPB_UNUSED(hd); return encode_bytes(c, buf, len) && commit(c); } diff --git a/upb/pb/encoder.h b/upb/pb/encoder.h index 780dfcb..41b7e7b 100644 --- a/upb/pb/encoder.h +++ b/upb/pb/encoder.h @@ -64,8 +64,6 @@ const upb_handlers *upb_pb_encoder_newhandlers(const upb_msgdef *m, upb_sink *upb_pb_encoder_input(upb_pb_encoder *p); upb_pb_encoder* upb_pb_encoder_create(upb_env* e, const upb_handlers* h, upb_bytessink* output); -bool encode_unknown(upb_pb_encoder* p, const void* hd, const char* buf, - size_t size); UPB_END_EXTERN_C -- cgit v1.2.3 From 0776f64830e8654193b5784e9e124424af8de680 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 25 Sep 2017 10:21:36 -0700 Subject: Fixed JIT for unknown fields. (#1) --- upb/pb/compile_decoder_x64.dasc | 5 + upb/pb/compile_decoder_x64.h | 256 ++++++++++++++++++++-------------------- 2 files changed, 136 insertions(+), 125 deletions(-) (limited to 'upb/pb') diff --git a/upb/pb/compile_decoder_x64.dasc b/upb/pb/compile_decoder_x64.dasc index 0bc0597..7fcd006 100644 --- a/upb/pb/compile_decoder_x64.dasc +++ b/upb/pb/compile_decoder_x64.dasc @@ -776,6 +776,11 @@ static void jitdispatch(jitcompiler *jc, | |5: | // Field isn't in our table. + | + | // For pushing unknown fields to the unknown field handler. + | mov64 rax, (uintptr_t)method->dest_handlers_ + | mov FRAME->sink.handlers, rax + | | call ->parse_unknown | test eax, eax // ENDGROUP? | jz <1 diff --git a/upb/pb/compile_decoder_x64.h b/upb/pb/compile_decoder_x64.h index f78ee65..2c07063 100644 --- a/upb/pb/compile_decoder_x64.h +++ b/upb/pb/compile_decoder_x64.h @@ -21,7 +21,7 @@ /*| */ /*|.arch x64 */ /*|.actionlist upb_jit_actionlist */ -static const unsigned char upb_jit_actionlist[2459] = { +static const unsigned char upb_jit_actionlist[2467] = { 249,255,248,10,248,1,85,65,87,65,86,65,85,65,84,83,72,137,252,243,73,137, 252,255,72,184,237,237,65,84,73,137,228,72,129,228,239,252,255,208,76,137, 228,65,92,133,192,15,137,244,247,73,137,167,233,72,137,216,77,139,183,233, @@ -119,28 +119,29 @@ static const unsigned char upb_jit_actionlist[2459] = { 225,7,255,248,2,129,252,250,239,255,15,131,244,253,255,15,131,244,251,255, 72,184,237,237,72,139,4,208,255,72,139,4,213,237,255,248,3,56,200,255,15, 133,244,252,255,15,133,244,251,255,72,193,232,16,72,141,21,244,250,249,248, - 4,72,1,208,195,248,5,232,244,15,133,192,15,132,244,1,72,141,5,244,255,195, - 255,248,6,56,204,15,133,244,5,72,129,194,239,255,252,233,244,26,255,248,7, - 255,232,244,26,252,233,244,3,255,76,57,227,15,133,244,247,255,76,137,225, - 72,41,217,72,129,252,249,239,15,131,244,247,255,232,244,25,129,252,248,239, - 15,132,244,249,129,252,248,239,15,132,245,252,233,244,251,255,128,59,235, - 255,102,129,59,238,255,102,129,59,238,15,133,244,248,128,187,233,235,248, - 2,255,129,59,239,255,129,59,239,15,133,244,249,128,187,233,235,255,15,132, - 244,250,248,3,255,232,245,72,133,192,15,132,245,252,255,224,255,252,233,245, - 255,248,4,72,129,195,239,248,5,255,248,1,76,137,252,239,255,132,192,15,133, - 244,248,232,244,12,252,233,244,1,248,2,255,144,255,248,9,255,73,139,151,233, - 72,184,237,237,65,84,73,137,228,72,129,228,239,252,255,208,76,137,228,65, - 92,255,249,249,72,131,252,236,8,255,72,137,252,234,72,41,218,255,72,133,192, - 15,133,244,248,232,244,12,252,233,244,1,248,2,255,73,137,197,255,72,57,252, - 235,15,132,244,250,248,1,76,57,227,15,133,244,248,232,244,12,252,233,244, - 1,248,2,255,72,137,218,76,137,225,72,41,217,77,139,135,233,72,184,237,237, - 65,84,73,137,228,72,129,228,239,252,255,208,76,137,228,65,92,72,1,195,255, - 76,57,227,15,132,244,249,232,244,27,248,3,255,76,137,227,255,72,57,252,235, - 15,133,244,1,248,4,255,77,137,174,233,73,199,134,233,0,0,0,0,77,59,183,233, - 15,132,244,28,73,129,198,239,65,199,134,233,237,255,232,244,13,255,73,129, - 252,238,239,77,139,174,233,255,77,139,167,233,73,3,174,233,73,59,175,233, - 15,130,244,247,76,57,229,15,135,244,247,73,137,252,236,248,1,255,72,57,221, - 15,132,245,255,232,245,255,248,9,72,131,196,8,195,255 + 4,72,1,208,195,248,5,72,184,237,237,73,137,134,233,232,244,15,133,192,15, + 132,244,1,72,141,5,244,255,195,255,248,6,56,204,15,133,244,5,72,129,194,239, + 255,252,233,244,26,255,248,7,255,232,244,26,252,233,244,3,255,76,57,227,15, + 133,244,247,255,76,137,225,72,41,217,72,129,252,249,239,15,131,244,247,255, + 232,244,25,129,252,248,239,15,132,244,249,129,252,248,239,15,132,245,252, + 233,244,251,255,128,59,235,255,102,129,59,238,255,102,129,59,238,15,133,244, + 248,128,187,233,235,248,2,255,129,59,239,255,129,59,239,15,133,244,249,128, + 187,233,235,255,15,132,244,250,248,3,255,232,245,72,133,192,15,132,245,252, + 255,224,255,252,233,245,255,248,4,72,129,195,239,248,5,255,248,1,76,137,252, + 239,255,132,192,15,133,244,248,232,244,12,252,233,244,1,248,2,255,144,255, + 248,9,255,73,139,151,233,72,184,237,237,65,84,73,137,228,72,129,228,239,252, + 255,208,76,137,228,65,92,255,249,249,72,131,252,236,8,255,72,137,252,234, + 72,41,218,255,72,133,192,15,133,244,248,232,244,12,252,233,244,1,248,2,255, + 73,137,197,255,72,57,252,235,15,132,244,250,248,1,76,57,227,15,133,244,248, + 232,244,12,252,233,244,1,248,2,255,72,137,218,76,137,225,72,41,217,77,139, + 135,233,72,184,237,237,65,84,73,137,228,72,129,228,239,252,255,208,76,137, + 228,65,92,72,1,195,255,76,57,227,15,132,244,249,232,244,27,248,3,255,76,137, + 227,255,72,57,252,235,15,133,244,1,248,4,255,77,137,174,233,73,199,134,233, + 0,0,0,0,77,59,183,233,15,132,244,28,73,129,198,239,65,199,134,233,237,255, + 232,244,13,255,73,129,252,238,239,77,139,174,233,255,77,139,167,233,73,3, + 174,233,73,59,175,233,15,130,244,247,76,57,229,15,135,244,247,73,137,252, + 236,248,1,255,72,57,221,15,132,245,255,232,245,255,248,9,72,131,196,8,195, + 255 }; # 12 "upb/pb/compile_decoder_x64.dasc" @@ -1170,13 +1171,18 @@ static void jitdispatch(jitcompiler *jc, /*| */ /*|5: */ /*| // Field isn't in our table. */ + /*| */ + /*| // For pushing unknown fields to the unknown field handler. */ + /*| mov64 rax, (uintptr_t)method->dest_handlers_ */ + /*| mov FRAME->sink.handlers, rax */ + /*| */ /*| call ->parse_unknown */ /*| test eax, eax // ENDGROUP? */ /*| jz <1 */ /*| lea rax, [>9] // ENDGROUP; Load address of OP_ENDMSG. */ /*| ret */ - dasm_put(Dst, 2001, define_jmptarget(jc, dispatch->array)); -# 784 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2001, define_jmptarget(jc, dispatch->array), (unsigned int)((uintptr_t)method->dest_handlers_), (unsigned int)(((uintptr_t)method->dest_handlers_)>>32), Dt1(->sink.handlers)); +# 789 "upb/pb/compile_decoder_x64.dasc" if (has_multi_wiretype) { /*|6: */ @@ -1186,8 +1192,8 @@ static void jitdispatch(jitcompiler *jc, /*| // Secondary wire type is a match, look up fn + UPB_MAX_FIELDNUMBER. */ /*| add rdx, UPB_MAX_FIELDNUMBER */ /*| // This key will never be in the array part, so do a hash lookup. */ - dasm_put(Dst, 2035, UPB_MAX_FIELDNUMBER); -# 793 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2043, UPB_MAX_FIELDNUMBER); +# 798 "upb/pb/compile_decoder_x64.dasc" UPB_ASSERT(has_hash_entries); /*| ld64 dispatch */ { @@ -1200,17 +1206,17 @@ static void jitdispatch(jitcompiler *jc, dasm_put(Dst, 454); } } -# 795 "upb/pb/compile_decoder_x64.dasc" +# 800 "upb/pb/compile_decoder_x64.dasc" /*| jmp ->hashlookup // Tail call. */ - dasm_put(Dst, 2048); -# 796 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2056); +# 801 "upb/pb/compile_decoder_x64.dasc" } if (has_hash_entries) { /*|7: */ /*| // Hash table lookup. */ /*| ld64 dispatch */ - dasm_put(Dst, 2053); + dasm_put(Dst, 2061); { uintptr_t v = (uintptr_t)dispatch; if (v > 0xffffffff) { @@ -1221,11 +1227,11 @@ static void jitdispatch(jitcompiler *jc, dasm_put(Dst, 454); } } -# 802 "upb/pb/compile_decoder_x64.dasc" +# 807 "upb/pb/compile_decoder_x64.dasc" /*| call ->hashlookup */ /*| jmp <3 */ - dasm_put(Dst, 2056); -# 804 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2064); +# 809 "upb/pb/compile_decoder_x64.dasc" } } @@ -1248,11 +1254,11 @@ static void jittag(jitcompiler *jc, uint64_t tag, int n, int ofs, /*| chkneob n, >1 */ if (n == 1) { - dasm_put(Dst, 2064); + dasm_put(Dst, 2072); } else { - dasm_put(Dst, 2072, n); + dasm_put(Dst, 2080, n); } -# 825 "upb/pb/compile_decoder_x64.dasc" +# 830 "upb/pb/compile_decoder_x64.dasc" /*| // OPT: this is way too much fallback code to put here. */ /*| // Reduce and/or move to a separate section to make better icache usage. */ @@ -1267,29 +1273,29 @@ static void jittag(jitcompiler *jc, uint64_t tag, int n, int ofs, dasm_put(Dst, 454); } } -# 829 "upb/pb/compile_decoder_x64.dasc" +# 834 "upb/pb/compile_decoder_x64.dasc" /*| call ->checktag_fallback */ /*| cmp eax, DECODE_MISMATCH */ /*| je >3 */ /*| cmp eax, DECODE_EOF */ /*| je =>jmptarget(jc, delimend) */ /*| jmp >5 */ - dasm_put(Dst, 2088, DECODE_MISMATCH, DECODE_EOF, jmptarget(jc, delimend)); -# 835 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2096, DECODE_MISMATCH, DECODE_EOF, jmptarget(jc, delimend)); +# 840 "upb/pb/compile_decoder_x64.dasc" /*|1: */ dasm_put(Dst, 112); -# 837 "upb/pb/compile_decoder_x64.dasc" +# 842 "upb/pb/compile_decoder_x64.dasc" switch (n) { case 1: /*| cmp byte [PTR], tag */ - dasm_put(Dst, 2111, tag); -# 840 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2119, tag); +# 845 "upb/pb/compile_decoder_x64.dasc" break; case 2: /*| cmp word [PTR], tag */ - dasm_put(Dst, 2115, tag); -# 843 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2123, tag); +# 848 "upb/pb/compile_decoder_x64.dasc" break; case 3: /*| // OPT: Slightly more efficient code, but depends on an extra byte. */ @@ -1300,42 +1306,42 @@ static void jittag(jitcompiler *jc, uint64_t tag, int n, int ofs, /*| jne >2 */ /*| cmp byte [PTR + 2], (tag >> 16) */ /*|2: */ - dasm_put(Dst, 2120, (tag & 0xffff), 2, (tag >> 16)); -# 853 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2128, (tag & 0xffff), 2, (tag >> 16)); +# 858 "upb/pb/compile_decoder_x64.dasc" break; case 4: /*| cmp dword [PTR], tag */ - dasm_put(Dst, 2135, tag); -# 856 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2143, tag); +# 861 "upb/pb/compile_decoder_x64.dasc" break; case 5: /*| cmp dword [PTR], (tag & 0xffffffff) */ /*| jne >3 */ /*| cmp byte [PTR + 4], (tag >> 32) */ - dasm_put(Dst, 2139, (tag & 0xffffffff), 4, (tag >> 32)); -# 861 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2147, (tag & 0xffffffff), 4, (tag >> 32)); +# 866 "upb/pb/compile_decoder_x64.dasc" } /*| je >4 */ /*|3: */ - dasm_put(Dst, 2151); -# 864 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2159); +# 869 "upb/pb/compile_decoder_x64.dasc" if (ofs == 0) { /*| call =>jmptarget(jc, &method->dispatch) */ /*| test rax, rax */ /*| jz =>jmptarget(jc, delimend) */ /*| jmp rax */ - dasm_put(Dst, 2158, jmptarget(jc, &method->dispatch), jmptarget(jc, delimend)); -# 869 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2166, jmptarget(jc, &method->dispatch), jmptarget(jc, delimend)); +# 874 "upb/pb/compile_decoder_x64.dasc" } else { /*| jmp =>jmptarget(jc, jc->pc + ofs) */ - dasm_put(Dst, 2170, jmptarget(jc, jc->pc + ofs)); -# 871 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2178, jmptarget(jc, jc->pc + ofs)); +# 876 "upb/pb/compile_decoder_x64.dasc" } /*|4: */ /*| add PTR, n */ /*|5: */ - dasm_put(Dst, 2174, n); -# 875 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2182, n); +# 880 "upb/pb/compile_decoder_x64.dasc" } /* Compile the bytecode to x64. */ @@ -1358,7 +1364,7 @@ static void jitbytecode(jitcompiler *jc) { * TODO: optimize this to only define pclabels that are actually used. */ /*|=>define_jmptarget(jc, jc->pc): */ dasm_put(Dst, 0, define_jmptarget(jc, jc->pc)); -# 896 "upb/pb/compile_decoder_x64.dasc" +# 901 "upb/pb/compile_decoder_x64.dasc" } jc->pc++; @@ -1371,7 +1377,7 @@ static void jitbytecode(jitcompiler *jc) { /*|1: */ /*| mov ARG1_64, CLOSURE */ /*| load_handler_data h, UPB_STARTMSG_SELECTOR */ - dasm_put(Dst, 2183); + dasm_put(Dst, 2191); { uintptr_t v = (uintptr_t)upb_handlers_gethandlerdata(h, UPB_STARTMSG_SELECTOR); if (v > 0xffffffff) { @@ -1382,31 +1388,31 @@ static void jitbytecode(jitcompiler *jc) { dasm_put(Dst, 454); } } -# 908 "upb/pb/compile_decoder_x64.dasc" +# 913 "upb/pb/compile_decoder_x64.dasc" /*| callp startmsg */ dasm_put(Dst, 1793, (unsigned int)((uintptr_t)startmsg), (unsigned int)(((uintptr_t)startmsg)>>32), 0xfffffffffffffff0UL); -# 909 "upb/pb/compile_decoder_x64.dasc" +# 914 "upb/pb/compile_decoder_x64.dasc" if (!alwaysok(h, UPB_STARTMSG_SELECTOR)) { /*| test al, al */ /*| jnz >2 */ /*| call ->suspend */ /*| jmp <1 */ /*|2: */ - dasm_put(Dst, 2190); -# 915 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2198); +# 920 "upb/pb/compile_decoder_x64.dasc" } } else { /*| nop */ - dasm_put(Dst, 2206); -# 918 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2214); +# 923 "upb/pb/compile_decoder_x64.dasc" } break; } case OP_ENDMSG: { upb_func *endmsg = gethandler(h, UPB_ENDMSG_SELECTOR); /*|9: */ - dasm_put(Dst, 2208); -# 924 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2216); +# 929 "upb/pb/compile_decoder_x64.dasc" if (endmsg) { /* bool endmsg(void *closure, const void *hd, upb_status *status) */ /*| mov ARG1_64, CLOSURE */ @@ -1422,11 +1428,11 @@ static void jitbytecode(jitcompiler *jc) { dasm_put(Dst, 454); } } -# 928 "upb/pb/compile_decoder_x64.dasc" +# 933 "upb/pb/compile_decoder_x64.dasc" /*| mov ARG3_64, DECODER->status */ /*| callp endmsg */ - dasm_put(Dst, 2211, Dt2(->status), (unsigned int)((uintptr_t)endmsg), (unsigned int)(((uintptr_t)endmsg)>>32), 0xfffffffffffffff0UL); -# 930 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2219, Dt2(->status), (unsigned int)((uintptr_t)endmsg), (unsigned int)(((uintptr_t)endmsg)>>32), 0xfffffffffffffff0UL); +# 935 "upb/pb/compile_decoder_x64.dasc" } break; } @@ -1458,8 +1464,8 @@ static void jitbytecode(jitcompiler *jc) { /*|=>define_jmptarget(jc, op_pc): */ /*|=>define_jmptarget(jc, method): */ /*| sub rsp, 8 */ - dasm_put(Dst, 2237, define_jmptarget(jc, op_pc), define_jmptarget(jc, method)); -# 961 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2245, define_jmptarget(jc, op_pc), define_jmptarget(jc, method)); +# 966 "upb/pb/compile_decoder_x64.dasc" break; } @@ -1489,7 +1495,7 @@ static void jitbytecode(jitcompiler *jc) { /*|1: */ /*| mov ARG1_64, CLOSURE */ /*| load_handler_data h, arg */ - dasm_put(Dst, 2183); + dasm_put(Dst, 2191); { uintptr_t v = (uintptr_t)upb_handlers_gethandlerdata(h, arg); if (v > 0xffffffff) { @@ -1500,33 +1506,33 @@ static void jitbytecode(jitcompiler *jc) { dasm_put(Dst, 454); } } -# 990 "upb/pb/compile_decoder_x64.dasc" +# 995 "upb/pb/compile_decoder_x64.dasc" if (op == OP_STARTSTR) { /*| mov ARG3_64, DELIMEND */ /*| sub ARG3_64, PTR */ - dasm_put(Dst, 2245); -# 993 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2253); +# 998 "upb/pb/compile_decoder_x64.dasc" } /*| callp start */ dasm_put(Dst, 1793, (unsigned int)((uintptr_t)start), (unsigned int)(((uintptr_t)start)>>32), 0xfffffffffffffff0UL); -# 995 "upb/pb/compile_decoder_x64.dasc" +# 1000 "upb/pb/compile_decoder_x64.dasc" if (!alwaysok(h, arg)) { /*| test rax, rax */ /*| jnz >2 */ /*| call ->suspend */ /*| jmp <1 */ /*|2: */ - dasm_put(Dst, 2253); -# 1001 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2261); +# 1006 "upb/pb/compile_decoder_x64.dasc" } /*| mov CLOSURE, rax */ - dasm_put(Dst, 2270); -# 1003 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2278); +# 1008 "upb/pb/compile_decoder_x64.dasc" } else { /* TODO: nop is only required because of asmlabel(). */ /*| nop */ - dasm_put(Dst, 2206); -# 1006 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2214); +# 1011 "upb/pb/compile_decoder_x64.dasc" } break; } @@ -1541,7 +1547,7 @@ static void jitbytecode(jitcompiler *jc) { /*|1: */ /*| mov ARG1_64, CLOSURE */ /*| load_handler_data h, arg */ - dasm_put(Dst, 2183); + dasm_put(Dst, 2191); { uintptr_t v = (uintptr_t)upb_handlers_gethandlerdata(h, arg); if (v > 0xffffffff) { @@ -1552,24 +1558,24 @@ static void jitbytecode(jitcompiler *jc) { dasm_put(Dst, 454); } } -# 1020 "upb/pb/compile_decoder_x64.dasc" +# 1025 "upb/pb/compile_decoder_x64.dasc" /*| callp end */ dasm_put(Dst, 1793, (unsigned int)((uintptr_t)end), (unsigned int)(((uintptr_t)end)>>32), 0xfffffffffffffff0UL); -# 1021 "upb/pb/compile_decoder_x64.dasc" +# 1026 "upb/pb/compile_decoder_x64.dasc" if (!alwaysok(h, arg)) { /*| test al, al */ /*| jnz >2 */ /*| call ->suspend */ /*| jmp <1 */ /*|2: */ - dasm_put(Dst, 2190); -# 1027 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2198); +# 1032 "upb/pb/compile_decoder_x64.dasc" } } else { /* TODO: nop is only required because of asmlabel(). */ /*| nop */ - dasm_put(Dst, 2206); -# 1031 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2214); +# 1036 "upb/pb/compile_decoder_x64.dasc" } break; } @@ -1583,8 +1589,8 @@ static void jitbytecode(jitcompiler *jc) { /*| call ->suspend */ /*| jmp <1 */ /*|2: */ - dasm_put(Dst, 2274); -# 1044 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2282); +# 1049 "upb/pb/compile_decoder_x64.dasc" if (str) { /* size_t str(void *closure, const void *hd, const char *str, * size_t n) */ @@ -1601,33 +1607,33 @@ static void jitbytecode(jitcompiler *jc) { dasm_put(Dst, 454); } } -# 1049 "upb/pb/compile_decoder_x64.dasc" +# 1054 "upb/pb/compile_decoder_x64.dasc" /*| mov ARG3_64, PTR */ /*| mov ARG4_64, DATAEND */ /*| sub ARG4_64, PTR */ /*| mov ARG5_64, qword DECODER->handle */ /*| callp str */ /*| add PTR, rax */ - dasm_put(Dst, 2301, Dt2(->handle), (unsigned int)((uintptr_t)str), (unsigned int)(((uintptr_t)str)>>32), 0xfffffffffffffff0UL); -# 1055 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2309, Dt2(->handle), (unsigned int)((uintptr_t)str), (unsigned int)(((uintptr_t)str)>>32), 0xfffffffffffffff0UL); +# 1060 "upb/pb/compile_decoder_x64.dasc" if (!alwaysok(h, arg)) { /*| cmp PTR, DATAEND */ /*| je >3 */ /*| call ->strret_fallback */ /*|3: */ - dasm_put(Dst, 2339); -# 1060 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2347); +# 1065 "upb/pb/compile_decoder_x64.dasc" } } else { /*| mov PTR, DATAEND */ - dasm_put(Dst, 2352); -# 1063 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2360); +# 1068 "upb/pb/compile_decoder_x64.dasc" } /*| cmp PTR, DELIMEND */ /*| jne <1 */ /*|4: */ - dasm_put(Dst, 2356); -# 1067 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2364); +# 1072 "upb/pb/compile_decoder_x64.dasc" break; } case OP_PUSHTAGDELIM: @@ -1642,19 +1648,19 @@ static void jitbytecode(jitcompiler *jc) { /*| je ->err */ /*| add FRAME, sizeof(upb_pbdecoder_frame) */ /*| mov dword FRAME->groupnum, arg */ - dasm_put(Dst, 2367, Dt1(->sink.closure), Dt1(->end_ofs), Dt2(->limit), sizeof(upb_pbdecoder_frame), Dt1(->groupnum), arg); -# 1081 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2375, Dt1(->sink.closure), Dt1(->end_ofs), Dt2(->limit), sizeof(upb_pbdecoder_frame), Dt1(->groupnum), arg); +# 1086 "upb/pb/compile_decoder_x64.dasc" break; case OP_PUSHLENDELIM: /*| call ->pushlendelim */ - dasm_put(Dst, 2397); -# 1084 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2405); +# 1089 "upb/pb/compile_decoder_x64.dasc" break; case OP_POP: /*| sub FRAME, sizeof(upb_pbdecoder_frame) */ /*| mov CLOSURE, FRAME->sink.closure */ - dasm_put(Dst, 2401, sizeof(upb_pbdecoder_frame), Dt1(->sink.closure)); -# 1088 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2409, sizeof(upb_pbdecoder_frame), Dt1(->sink.closure)); +# 1093 "upb/pb/compile_decoder_x64.dasc" break; case OP_SETDELIM: /* OPT: experiment with testing vs old offset to optimize away. */ @@ -1666,36 +1672,36 @@ static void jitbytecode(jitcompiler *jc) { /*| ja >1 // OPT: try cmov. */ /*| mov DATAEND, DELIMEND */ /*|1: */ - dasm_put(Dst, 2411, Dt2(->end), Dt1(->end_ofs), Dt2(->buf)); -# 1099 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2419, Dt2(->end), Dt1(->end_ofs), Dt2(->buf)); +# 1104 "upb/pb/compile_decoder_x64.dasc" break; case OP_SETBIGGROUPNUM: /*| mov dword FRAME->groupnum, *jc->pc++ */ - dasm_put(Dst, 2391, Dt1(->groupnum), *jc->pc++); -# 1102 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2399, Dt1(->groupnum), *jc->pc++); +# 1107 "upb/pb/compile_decoder_x64.dasc" break; case OP_CHECKDELIM: /*| cmp DELIMEND, PTR */ /*| je =>jmptarget(jc, jc->pc + longofs) */ - dasm_put(Dst, 2441, jmptarget(jc, jc->pc + longofs)); -# 1106 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2449, jmptarget(jc, jc->pc + longofs)); +# 1111 "upb/pb/compile_decoder_x64.dasc" break; case OP_CALL: /*| call =>jmptarget(jc, jc->pc + longofs) */ - dasm_put(Dst, 2448, jmptarget(jc, jc->pc + longofs)); -# 1109 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2456, jmptarget(jc, jc->pc + longofs)); +# 1114 "upb/pb/compile_decoder_x64.dasc" break; case OP_BRANCH: /*| jmp =>jmptarget(jc, jc->pc + longofs); */ - dasm_put(Dst, 2170, jmptarget(jc, jc->pc + longofs)); -# 1112 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2178, jmptarget(jc, jc->pc + longofs)); +# 1117 "upb/pb/compile_decoder_x64.dasc" break; case OP_RET: /*|9: */ /*| add rsp, 8 */ /*| ret */ - dasm_put(Dst, 2451); -# 1117 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2459); +# 1122 "upb/pb/compile_decoder_x64.dasc" break; case OP_TAG1: jittag(jc, (arg >> 8) & 0xff, 1, (int8_t)arg, method); @@ -1711,8 +1717,8 @@ static void jitbytecode(jitcompiler *jc) { } case OP_DISPATCH: /*| call =>jmptarget(jc, &method->dispatch) */ - dasm_put(Dst, 2448, jmptarget(jc, &method->dispatch)); -# 1132 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2456, jmptarget(jc, &method->dispatch)); +# 1137 "upb/pb/compile_decoder_x64.dasc" break; case OP_HALT: UPB_ASSERT(false); @@ -1721,6 +1727,6 @@ static void jitbytecode(jitcompiler *jc) { asmlabel(jc, "eof"); /*| nop */ - dasm_put(Dst, 2206); -# 1140 "upb/pb/compile_decoder_x64.dasc" + dasm_put(Dst, 2214); +# 1145 "upb/pb/compile_decoder_x64.dasc" } -- cgit v1.2.3 From 1e1c54f77253e7f783df0047a421b3f4d26929cb Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Mon, 25 Sep 2017 11:35:57 -0700 Subject: Change parameter type from enum opcode to int. If the compiler elects to represent enum E as a char rather than an int (per 6.7.2.2p4), the call to va_start() will have undefined behavior. --- upb/pb/compile_decoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'upb/pb') diff --git a/upb/pb/compile_decoder.c b/upb/pb/compile_decoder.c index d86f840..d147edf 100644 --- a/upb/pb/compile_decoder.c +++ b/upb/pb/compile_decoder.c @@ -267,7 +267,7 @@ static void put32(compiler *c, uint32_t v) { *c->pc++ = v; } -static void putop(compiler *c, opcode op, ...) { +static void putop(compiler *c, int op, ...) { va_list ap; va_start(ap, op); -- cgit v1.2.3 From 0a9681874ee9ec1e3104b4bdb8e6b2396561ccb6 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Mon, 25 Sep 2017 17:09:24 -0700 Subject: Modify TODO --- upb/pb/decoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'upb/pb') diff --git a/upb/pb/decoder.c b/upb/pb/decoder.c index 94fa031..0cae05b 100644 --- a/upb/pb/decoder.c +++ b/upb/pb/decoder.c @@ -558,7 +558,6 @@ have_tag: return upb_pbdecoder_suspend(d); } - /* TODO: deliver to unknown field callback. */ switch (wire_type) { case UPB_WIRE_TYPE_32BIT: CHECK_RETURN(skip(d, 4)); @@ -596,6 +595,7 @@ have_tag: } if (d->top->groupnum >= 0) { + /* TODO: More code needed for handling unknown groups. */ upb_sink_putunknown(&d->top->sink, d->checkpoint, d->ptr - d->checkpoint); return DECODE_OK; } -- cgit v1.2.3