/* * Copyright (c) Meta Platforms, Inc. and affiliates. * All rights reserved. * * This source code is licensed under both the BSD-style license (found in the * LICENSE file in the root directory of this source tree) and the GPLv2 (found * in the COPYING file in the root directory of this source tree). * You may select, at your option, one of the above-listed licenses. */ /* The benchmark implementation lives in rust/src/benchzstd.rs. Keep this * translation unit in the existing C source lists so C build systems retain * the public benchzstd.h declarations and validate the C/Rust ABI without * defining a second set of BMK_* symbols. */ /* This must be included first: it supplies the platform and large-file * configuration expected by the program sources. */ #include "platform.h" #include #include "benchzstd.h" /* * These checks deliberately use the public C declarations. They make the * by-value structures consumed by the Rust benchmark implementation fail at * compile time if their C layout changes. */ #define BMK_C_ABI_ASSERT(name, condition) typedef char name[(condition) ? 1 : -1] BMK_C_ABI_ASSERT(BMK_rust_bench_result_csize_offset, offsetof(BMK_benchResult_t, cSize) == 0); BMK_C_ABI_ASSERT(BMK_rust_bench_result_cspeed_offset, offsetof(BMK_benchResult_t, cSpeed) == sizeof(size_t)); BMK_C_ABI_ASSERT(BMK_rust_bench_result_dspeed_offset, offsetof(BMK_benchResult_t, dSpeed) == sizeof(size_t) + sizeof(unsigned long long)); BMK_C_ABI_ASSERT(BMK_rust_bench_result_cmem_offset, offsetof(BMK_benchResult_t, cMem) == sizeof(size_t) + 2 * sizeof(unsigned long long)); BMK_C_ABI_ASSERT(BMK_rust_bench_result_size, sizeof(BMK_benchResult_t) == 2 * sizeof(size_t) + 2 * sizeof(unsigned long long)); BMK_C_ABI_ASSERT(BMK_rust_bench_outcome_tag_offset, offsetof(BMK_benchOutcome_t, tag) == sizeof(BMK_benchResult_t)); BMK_C_ABI_ASSERT(BMK_rust_mode_is_int, sizeof(BMK_mode_t) == sizeof(int)); BMK_C_ABI_ASSERT(BMK_rust_param_switch_is_int, sizeof(ZSTD_ParamSwitch_e) == sizeof(int)); BMK_C_ABI_ASSERT(BMK_rust_advanced_mode_offset, offsetof(BMK_advancedParams_t, mode) == 0); BMK_C_ABI_ASSERT(BMK_rust_advanced_seconds_offset, offsetof(BMK_advancedParams_t, nbSeconds) == sizeof(BMK_mode_t)); BMK_C_ABI_ASSERT(BMK_rust_advanced_block_offset, offsetof(BMK_advancedParams_t, blockSize) == sizeof(BMK_mode_t) + sizeof(unsigned)); BMK_C_ABI_ASSERT(BMK_rust_advanced_target_block_offset, offsetof(BMK_advancedParams_t, targetCBlockSize) == sizeof(BMK_mode_t) + sizeof(unsigned) + sizeof(size_t)); BMK_C_ABI_ASSERT(BMK_rust_advanced_workers_offset, offsetof(BMK_advancedParams_t, nbWorkers) == sizeof(BMK_mode_t) + sizeof(unsigned) + 2 * sizeof(size_t)); BMK_C_ABI_ASSERT(BMK_rust_advanced_row_match_offset, offsetof(BMK_advancedParams_t, useRowMatchFinder) == offsetof(BMK_advancedParams_t, literalCompressionMode) + sizeof(ZSTD_ParamSwitch_e)); BMK_C_ABI_ASSERT(BMK_rust_compression_strategy_is_int, sizeof(ZSTD_strategy) == sizeof(int)); BMK_C_ABI_ASSERT(BMK_rust_compression_params_strategy_offset, offsetof(ZSTD_compressionParameters, strategy) == 6 * sizeof(unsigned)); BMK_C_ABI_ASSERT(BMK_rust_compression_params_size, sizeof(ZSTD_compressionParameters) == 6 * sizeof(unsigned) + sizeof(ZSTD_strategy)); #undef BMK_C_ABI_ASSERT