Merge pull request #390 from haberman/musttail

Converted fasttable decoder to use __attribute__((musttail)) when it is available
pull/13171/head
Joshua Haberman 4 years ago committed by GitHub
commit 01e7436ed3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      tools/amalgamate.py
  2. 978
      upb/decode_fast.c
  3. 7
      upb/decode_internal.h
  4. 22
      upb/port_def.inc
  5. 1
      upb/port_undef.inc

@ -47,15 +47,14 @@ class Amalgamator:
self.output_c.write(open("upb/port_def.inc").read())
self.output_h.write("/* Amalgamated source file */\n")
self.output_h.write('#include <stdint.h>')
self.output_h.write(open("upb/port_def.inc").read())
def add_include_path(self, path):
self.include_paths.append(path)
def finish(self):
self.output_c.write(open("upb/port_undef.inc").read())
self.output_h.write(open("upb/port_undef.inc").read())
self._add_header("upb/port_undef.inc")
self.add_src("upb/port_undef.inc")
def _process_file(self, infile_name, outfile):
file = None
@ -69,7 +68,17 @@ class Amalgamator:
if not file:
raise RuntimeError("Couldn't open file " + infile_name)
for line in file:
lines = file.readlines()
has_copyright = lines[1].startswith(" * Copyright")
if has_copyright:
while not lines[0].startswith(" */"):
lines.pop(0)
lines.pop(0)
lines.insert(0, "\n/** " + infile_name + " " + ("*" * 60) +"/");
for line in lines:
if not self._process_include(line, outfile):
outfile.write(line)

File diff suppressed because it is too large Load Diff

@ -142,10 +142,11 @@ bool decode_isdone(upb_decstate *d, const char **ptr) {
}
}
#if UPB_FASTTABLE
UPB_INLINE
const char *fastdecode_tagdispatch(upb_decstate *d, const char *ptr,
upb_msg *msg, intptr_t table,
uint64_t hasbits, uint32_t tag) {
uint64_t hasbits, uint64_t tag) {
const upb_msglayout *table_p = decode_totablep(table);
uint8_t mask = table;
uint64_t data;
@ -153,8 +154,10 @@ const char *fastdecode_tagdispatch(upb_decstate *d, const char *ptr,
UPB_ASSUME((idx & 7) == 0);
idx >>= 3;
data = table_p->fasttable[idx].field_data ^ tag;
return table_p->fasttable[idx].field_parser(d, ptr, msg, table, hasbits, data);
UPB_MUSTTAIL return table_p->fasttable[idx].field_parser(d, ptr, msg, table,
hasbits, data);
}
#endif
UPB_INLINE uint32_t fastdecode_loadtag(const char* ptr) {
uint16_t tag;

@ -167,6 +167,26 @@
/* Configure whether fasttable is switched on or not. *************************/
#if defined(__clang__) && __has_attribute(musttail)
#define UPB_MUSTTAIL __attribute__((musttail))
#else
#define UPB_MUSTTAIL
#endif
/* This check is not fully robust: it does not require that we have "musttail"
* support available. We need tail calls to avoid consuming arbitrary amounts
* of stack space.
*
* GCC/Clang can mostly be trusted to generate tail calls as long as
* optimization is enabled, but, debug builds will not generate tail calls
* unless "musttail" is available.
*
* We should probably either:
* 1. require that the compiler supports musttail.
* 2. add some fallback code for when musttail isn't available (ie. return
* instead of tail calling). This is safe and portable, but this comes at
* a CPU cost.
*/
#if (defined(__x86_64__) || defined(__aarch64__)) && defined(__GNUC__)
#define UPB_FASTTABLE_SUPPORTED 1
#else
@ -178,7 +198,7 @@
* for example for testing or benchmarking. */
#if defined(UPB_ENABLE_FASTTABLE)
#if !UPB_FASTTABLE_SUPPORTED
#error fasttable is x86-64 + Clang/GCC only
#error fasttable is x86-64/ARM64 only and requires GCC or Clang.
#endif
#define UPB_FASTTABLE 1
/* Define UPB_TRY_ENABLE_FASTTABLE to use fasttable if possible.

@ -52,6 +52,7 @@
#undef UPB_SETJMP
#undef UPB_LONGJMP
#undef UPB_PTRADD
#undef UPB_MUSTTAIL
#undef UPB_FASTTABLE_SUPPORTED
#undef UPB_FASTTABLE
#undef UPB_FASTTABLE_INIT

Loading…
Cancel
Save