Added #defines UPB_ENABLE_FASTTABLE and UPB_TRY_ENABLE_FASTTABLE.

These control whether fasttable decoding is on.
pull/13171/head
Joshua Haberman 4 years ago
parent dc64613607
commit e8f9eac68c
  1. 7
      BUILD
  2. 1
      bazel/build_defs.bzl
  3. 6
      bazel/upb_proto_library.bzl
  4. 1
      cmake/build_defs.bzl
  5. 5
      upb/bindings/lua/lua_proto_library.bzl
  6. 5
      upb/decode.c
  7. 4
      upb/decode_fast.c
  8. 37
      upb/port_def.inc
  9. 4
      upbc/generator.cc

@ -7,8 +7,8 @@ load(
"//bazel:upb_proto_library.bzl",
"upb_fasttable_enabled",
"upb_proto_library",
"upb_proto_reflection_library",
"upb_proto_library_copts",
"upb_proto_reflection_library",
)
# copybara:strip_for_google3_begin
@ -37,6 +37,11 @@ upb_fasttable_enabled(
visibility = ["//visibility:public"],
)
config_setting(
name = "fasttable_enabled_setting",
flag_values = {"//:fasttable_enabled": "true"},
)
upb_proto_library_copts(
name = "upb_proto_library_copts__for_generated_code_only_do_not_use",
copts = UPB_DEFAULT_COPTS,

@ -16,6 +16,7 @@ UPB_DEFAULT_CPPOPTS = select({
UPB_DEFAULT_COPTS = select({
"//:windows": [],
"//:fasttable_enabled_setting": ["-std=gnu99", "-DUPB_ENABLE_FASTTABLE"],
"//conditions:default": [
# copybara:strip_for_google3_begin
"-std=c99",

@ -126,7 +126,7 @@ def fasttable_enabled_impl(ctx):
upb_fasttable_enabled = rule(
implementation = fasttable_enabled_impl,
build_setting = config.bool(flag = True)
build_setting = config.bool(flag = True),
)
# Dummy rule to expose select() copts to aspects ##############################
@ -285,7 +285,7 @@ _upb_proto_library_aspect = aspect(
"//:upb",
]),
"_ext": attr.string(default = ".upb"),
"_fasttable_enabled": attr.label(default = "//:fasttable_enabled")
"_fasttable_enabled": attr.label(default = "//:fasttable_enabled"),
}),
implementation = _upb_proto_library_aspect_impl,
provides = [
@ -344,7 +344,7 @@ _upb_proto_reflection_library_aspect = aspect(
],
),
"_ext": attr.string(default = ".upbdefs"),
"_fasttable_enabled": attr.label(default = "//:fasttable_enabled")
"_fasttable_enabled": attr.label(default = "//:fasttable_enabled"),
}),
implementation = _upb_proto_reflection_library_aspect_impl,
provides = [

@ -1,4 +1,3 @@
def generated_file_staleness_test(name, outs, generated_pattern):
"""Tests that checked-in file(s) match the contents of generated file(s).

@ -1,4 +1,3 @@
load("@bazel_skylib//lib:paths.bzl", "paths")
# Generic support code #########################################################
@ -12,6 +11,7 @@ def _get_real_short_path(file):
if short_path.startswith("../"):
second_slash = short_path.index("/", 3)
short_path = short_path[second_slash + 1:]
# Sometimes it has another few prefixes like:
# _virtual_imports/any_proto/google/protobuf/any.proto
# We want just google/protobuf/any.proto.
@ -65,7 +65,8 @@ def _lua_proto_rule_impl(ctx):
return [
DefaultInfo(
files = files,
data_runfiles = ctx.runfiles(files = files.to_list())),
data_runfiles = ctx.runfiles(files = files.to_list()),
),
]
def _lua_proto_library_aspect_impl(target, ctx):

@ -535,14 +535,15 @@ static const char *decode_tomsg(upb_decstate *d, const char *ptr, upb_msg *msg,
UPB_FORCEINLINE
static bool decode_tryfastdispatch(upb_decstate *d, const char **ptr,
upb_msg *msg, const upb_msglayout *layout) {
#if UPB_FASTTABLE
if (layout && layout->table_mask != (unsigned char)-1) {
uint16_t tag = fastdecode_loadtag(*ptr);
intptr_t table = decode_totable(layout);
*ptr = fastdecode_tagdispatch(d, *ptr, msg, table, 0, tag);
return true;
} else {
return false;
}
#endif
return false;
}
UPB_NOINLINE

@ -15,6 +15,8 @@
/* Must be last. */
#include "upb/port_def.inc"
#if UPB_FASTTABLE
// The standard set of arguments passed to each parsing function.
// Thanks to x86-64 calling conventions, these will stay in registers.
#define UPB_PARSE_PARAMS \
@ -969,3 +971,5 @@ TAGBYTES(r)
#undef TAGBYTES
#undef SIZES
#undef F
#endif /* UPB_FASTTABLE */

@ -125,6 +125,43 @@
#define UPB_UNREACHABLE() do { assert(0); } while(0)
#endif
/* Configure whether fasttable is switched on or not. *************************/
#if defined(__x86_64__) && defined(__GNUC__)
#define UPB_FASTTABLE_SUPPORTED 1
#else
#define UPB_FASTTABLE_SUPPORTED 0
#endif
/* define UPB_ENABLE_FASTTABLE to force fast table support.
* This is useful when we want to ensure we are really getting fasttable,
* for example for testing or benchmarking. */
#if defined(UPB_ENABLE_FASTTABLE)
#if !UPB_FASTTABLE_SUPPORTED
#error fasttable is x86-64 + Clang/GCC only
#endif
#define UPB_FASTTABLE 1
/* Define UPB_TRY_ENABLE_FASTTABLE to use fasttable if possible.
* This is useful for releasing code that might be used on multiple platforms,
* for example the PHP or Ruby C extensions. */
#elif defined(UPB_TRY_ENABLE_FASTTABLE)
#define UPB_FASTTABLE UPB_FASTTABLE_SUPPORTED
#else
#define UPB_FASTTABLE 0
#endif
/* UPB_FASTTABLE_INIT() allows protos compiled for fasttable to gracefully
* degrade to non-fasttable if we are using UPB_TRY_ENABLE_FASTTABLE. */
#if !UPB_FASTTABLE && defined(UPB_TRY_ENABLE_FASTTABLE)
#define UPB_FASTTABLE_INIT(...)
#else
#define UPB_FASTTABLE_INIT(...) __VA_ARGS__
#endif
#undef UPB_FASTTABLE_SUPPORTED
/* ASAN poisoning (for arena) *************************************************/
#if defined(__SANITIZE_ADDRESS__)
#define UPB_ASAN 1
#ifdef __cplusplus

@ -1037,12 +1037,12 @@ void WriteSource(const protobuf::FileDescriptor* file, Output& output,
table_mask
);
if (!table.empty()) {
output(" {\n");
output(" UPB_FASTTABLE_INIT({\n");
for (const auto& ent : table) {
output(" {0x$1, &$0},\n", ent.first,
absl::StrCat(absl::Hex(ent.second, absl::kZeroPad16)));
}
output(" },\n");
output(" }),\n");
}
output("};\n\n");
}

Loading…
Cancel
Save