summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2009-07-07 18:15:50 -0700
committerJoshua Haberman <joshua@reverberate.org>2009-07-07 18:15:50 -0700
commitd7b666ecf47f7f5269ad5b7f826bca98f7350746 (patch)
tree19cefff0725898a24da9db6f55f1a4cc7d2903cf
parent9c88385ba4b369c440a467d19fa656389f9212e5 (diff)
Remove branch prediction hints. They seem to hurt more than help.
-rw-r--r--upb.h9
-rw-r--r--upb_parse.c29
2 files changed, 14 insertions, 24 deletions
diff --git a/upb.h b/upb.h
index eecdba0..64f2c54 100644
--- a/upb.h
+++ b/upb.h
@@ -18,15 +18,6 @@
extern "C" {
#endif
-/* Branch prediction hints for GCC. */
-#ifdef __GNUC__
-#define likely(x) __builtin_expect((x),1)
-#define unlikely(x) __builtin_expect((x),0)
-#else
-#define likely(x) (x)
-#define unlikely(x) (x)
-#endif
-
/* inline if possible, emit standalone code if required. */
#ifndef INLINE
#define INLINE static inline
diff --git a/upb_parse.c b/upb_parse.c
index dcad9c9..3818929 100644
--- a/upb_parse.c
+++ b/upb_parse.c
@@ -38,7 +38,7 @@ static upb_status_t get_v_uint64_t(void *restrict *buf, void *end,
for(int bitpos = 0; b < (uint8_t*)end && (last & 0x80); b++, bitpos += 7)
*val |= ((uint64_t)((last = *b) & 0x7F)) << bitpos;
- if(unlikely(last & 0x80)) return bound_error;
+ if(last & 0x80) return bound_error;
*buf = b;
return UPB_STATUS_OK;
}
@@ -52,7 +52,7 @@ static upb_status_t skip_v_uint64_t(void **buf, void *end)
for(; b < (uint8_t*)end && (last & 0x80); b++)
last = *b;
- if(unlikely(last & 0x80)) return bound_error;
+ if(last & 0x80) return bound_error;
*buf = b;
return UPB_STATUS_OK;
}
@@ -73,7 +73,7 @@ static upb_status_t get_v_uint32_t(void *restrict *buf, void *end,
for(; b < (uint8_t*)end && (last & 0x80); b++)
last = *b;
- if(unlikely(last & 0x80))
+ if(last & 0x80)
return bound_error;
*buf = b;
return UPB_STATUS_OK;
@@ -84,7 +84,7 @@ static upb_status_t get_f_uint32_t(void *restrict *buf, void *end,
{
uint8_t *b = *buf;
void *uint32_end = (uint8_t*)*buf + sizeof(uint32_t);
- if(unlikely(uint32_end > end)) return UPB_STATUS_NEED_MORE_DATA;
+ if(uint32_end > end) return UPB_STATUS_NEED_MORE_DATA;
#if UPB_UNALIGNED_READS_OK
*val = *(uint32_t*)b;
#else
@@ -100,7 +100,7 @@ static upb_status_t get_f_uint64_t(void *restrict *buf, void *end,
uint64_t *restrict val)
{
void *uint64_end = (uint8_t*)*buf + sizeof(uint64_t);
- if(unlikely(uint64_end > end)) return UPB_STATUS_NEED_MORE_DATA;
+ if(uint64_end > end) return UPB_STATUS_NEED_MORE_DATA;
#if UPB_UNALIGNED_READS_OK
*val = *(uint64_t*)*buf;
*buf = uint64_end;
@@ -116,7 +116,7 @@ static upb_status_t get_f_uint64_t(void *restrict *buf, void *end,
static upb_status_t skip_f_uint32_t(void **buf, void *end)
{
void *uint32_end = (uint8_t*)*buf + sizeof(uint32_t);
- if(unlikely(uint32_end > end)) return UPB_STATUS_NEED_MORE_DATA;
+ if(uint32_end > end) return UPB_STATUS_NEED_MORE_DATA;
*buf = uint32_end;
return UPB_STATUS_OK;
}
@@ -124,7 +124,7 @@ static upb_status_t skip_f_uint32_t(void **buf, void *end)
static upb_status_t skip_f_uint64_t(void **buf, void *end)
{
void *uint64_end = (uint8_t*)*buf + sizeof(uint64_t);
- if(unlikely(uint64_end > end)) return UPB_STATUS_NEED_MORE_DATA;
+ if(uint64_end > end) return UPB_STATUS_NEED_MORE_DATA;
*buf = uint64_end;
return UPB_STATUS_OK;
}
@@ -289,7 +289,7 @@ static upb_status_t push_stack_frame(struct upb_parse_state *s, size_t end,
{
s->top++;
s->top = (struct upb_parse_stack_frame*)((char*)s->top + s->udata_size);
- if(unlikely(s->top > s->limit)) return UPB_ERROR_STACK_OVERFLOW;
+ if(s->top > s->limit) return UPB_ERROR_STACK_OVERFLOW;
s->top->end_offset = end;
if(s->submsg_start_cb) s->submsg_start_cb(s, user_field_desc);
return UPB_STATUS_OK;
@@ -308,9 +308,8 @@ static upb_status_t parse_delimited(struct upb_parse_state *s,
* the length. */
UPB_CHECK(get_INT32(buf, end, &delim_len));
upb_field_type_t ft = s->tag_cb(s, tag, &user_field_desc);
- if(unlikely(*buf < bufstart)) return UPB_ERROR_OVERFLOW;
- if(unlikely(*buf > end &&
- ft != GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_MESSAGE)) {
+ if(*buf < bufstart) return UPB_ERROR_OVERFLOW;
+ if(*buf > end && ft != GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_MESSAGE) {
/* Streaming submessages is ok, but for other delimited types (string,
* bytes, and packed arrays) we require that all the delimited data is
* available. This could be relaxed if desired. */
@@ -354,8 +353,8 @@ static upb_status_t parse_nondelimited(struct upb_parse_state *s,
return UPB_STATUS_OK;
}
-upb_status_t upb_parse(struct upb_parse_state *s, void *buf, size_t len,
- size_t *read)
+upb_status_t upb_parse(struct upb_parse_state *restrict s, void *buf, size_t len,
+ size_t *restrict read)
{
void *end = (char*)buf + len;
*read = 0;
@@ -368,8 +367,8 @@ upb_status_t upb_parse(struct upb_parse_state *s, void *buf, size_t len,
struct upb_tag tag;
void *bufstart = buf;
UPB_CHECK(parse_tag(&buf, end, &tag));
- if(unlikely(tag.wire_type == UPB_WIRE_TYPE_END_GROUP)) {
- if(unlikely(s->top->end_offset != UINT32_MAX))
+ if(tag.wire_type == UPB_WIRE_TYPE_END_GROUP) {
+ if(s->top->end_offset != UINT32_MAX)
return UPB_ERROR_SPURIOUS_END_GROUP;
pop_stack_frame(s);
} else if(tag.wire_type == UPB_WIRE_TYPE_DELIMITED) {
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback