From d1a861fa80c66221be8c4d94e51128a4641809da Mon Sep 17 00:00:00 2001 From: Dave Watson Date: Tue, 9 Oct 2018 11:16:19 -0700 Subject: [PATCH] add a check for SC_LARGE_MAXCLASS If we assume SC_LARGE_MAXCLASS will always fit in a SSIZE_T, then we can optimize some checks by unconditional subtraction, and then checking flags only, without a compare statement in x86. --- src/sc.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/sc.c b/src/sc.c index 8784bdd0..89ddb6ba 100644 --- a/src/sc.c +++ b/src/sc.c @@ -244,6 +244,15 @@ size_classes( assert(sc_data->large_minclass == SC_LARGE_MINCLASS); assert(sc_data->lg_large_minclass == SC_LG_LARGE_MINCLASS); assert(sc_data->large_maxclass == SC_LARGE_MAXCLASS); + + /* + * In the allocation fastpath, we want to assume that we can + * unconditionally subtract the requested allocation size from + * a ssize_t, and detect passing through 0 correctly. This + * results in optimal generated code. For this to work, the + * maximum allocation size must be less than SSIZE_MAX. + */ + assert(SC_LARGE_MAXCLASS < SSIZE_MAX); } void