]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed static size of benchFnState
authorYann Collet <cyan@fb.com>
Sat, 26 Jan 2019 05:58:44 +0000 (21:58 -0800)
committerYann Collet <cyan@fb.com>
Thu, 31 Jan 2019 01:59:07 +0000 (17:59 -0800)
added a static assert to ensure condition is respected on target platform

programs/benchfn.c
programs/benchfn.h

index a27d91a070c68c9d2653590528215c595c1fda9f..318f4d63b12e8645d3db67eac6909c45fc006562 100644 (file)
@@ -180,9 +180,12 @@ void BMK_freeTimedFnState(BMK_timedFnState_t* state) {
 
 BMK_timedFnState_t* BMK_initStatic_timedFnState(void* buffer, size_t size, unsigned total_ms, unsigned run_ms)
 {
+    enum { timedFnState_staticSize_isLargeEnough=(1/(sizeof(BMK_timedFnState_shell) >= sizeof(struct BMK_timedFnState_s))) };  /* static assert */
+    typedef struct { char c; long long ll; } ll_align;  /* this will force ll to be aligned at its next best position */
+    size_t const ll_alignment = offsetof(ll_align, ll); /* provides the minimal alignment restriction for long long */
     BMK_timedFnState_t* const r = (BMK_timedFnState_t*)buffer;
     if (size < sizeof(struct BMK_timedFnState_s)) return NULL;
-    if ((size_t)buffer % 8) return NULL;  /* must be aligned on 8-bytes boundaries */
+    if ((size_t)buffer % ll_alignment) return NULL;  /* must be aligned to satisfy `long long` alignment requirement */
     BMK_resetTimedFnState(r, total_ms, run_ms);
     return r;
 }
index 737dfa9956e110455c67c0f5c641e311233dcfdf..19e056581a5be81b80c4137fe53b5e66fcfc9a09 100644 (file)
@@ -168,7 +168,7 @@ void BMK_freeTimedFnState(BMK_timedFnState_t* state);
  * It will check if provided buffer is large enough and is correctly aligned,
  * and will return NULL if conditions are not respected.
  */
-#define BMK_TIMEDFNSTATE_SIZE 56
+#define BMK_TIMEDFNSTATE_SIZE 64
 typedef union {
     char never_access_space[BMK_TIMEDFNSTATE_SIZE];
     long long alignment_enforcer;  /* must be aligned on 8-bytes boundaries */