From fd3974193a7de732940a701670fe04794fee3407 Mon Sep 17 00:00:00 2001 From: Frank Barchard Date: Fri, 29 May 2026 20:04:07 -0700 Subject: [PATCH] Refactor pthreadpool to remove FXdiv dependency from source code. PiperOrigin-RevId: 923722929 --- BUILD.bazel | 4 +- src/fastpath.c | 602 ++++++++++++++++----------------- src/legacy-api.c | 52 +-- src/portable-api.c | 722 ++++++++++++++++++++-------------------- src/pthreads.c | 6 +- src/threadpool-object.h | 110 +++--- src/threadpool-utils.h | 259 ++++++++++++++ 7 files changed, 1006 insertions(+), 749 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 0033f4d..6c7a152 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -116,9 +116,7 @@ cc_library( # These are NOT public headers and should not be included from other targets. textual_hdrs = INTERNAL_HDRS, visibility = ["//visibility:public"], - deps = [ - "@FXdiv", - ] + select({ + deps = [] + select({ ":linux_arm": ["@cpuinfo"], ":linux_armeabi": ["@cpuinfo"], ":linux_armhf": ["@cpuinfo"], diff --git a/src/fastpath.c b/src/fastpath.c index f9ad595..af5e0f0 100644 --- a/src/fastpath.c +++ b/src/fastpath.c @@ -20,7 +20,7 @@ #endif /* Dependencies */ -#include +#include "threadpool-utils.h" /* Public library header */ #include @@ -216,10 +216,10 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_2d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(range_start, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(range_start, range_j); size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; @@ -242,8 +242,8 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(linear_index, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(linear_index, range_j); task(argument, index_i_j.quotient, index_i_j.remainder); } } @@ -268,10 +268,10 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_2d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(range_start, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(range_start, range_j); size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; @@ -294,8 +294,8 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(linear_index, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(linear_index, range_j); task(argument, thread_number, index_i_j.quotient, index_i_j.remainder); } } @@ -320,10 +320,10 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_j = + const struct pthreadpool_divisor_size_t tile_range_j = threadpool->params.parallelize_2d_tile_1d.tile_range_j; - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(range_start, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(range_start, tile_range_j); const size_t tile_j = threadpool->params.parallelize_2d_tile_1d.tile_j; size_t i = tile_index_i_j.quotient; size_t start_j = tile_index_i_j.remainder * tile_j; @@ -349,8 +349,8 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(linear_index, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(linear_index, tile_range_j); const size_t start_j = tile_index_i_j.remainder * tile_j; task(argument, tile_index_i_j.quotient, start_j, min(range_j - start_j, tile_j)); @@ -389,10 +389,10 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_j = + const struct pthreadpool_divisor_size_t tile_range_j = threadpool->params.parallelize_2d_tile_1d_with_uarch.tile_range_j; - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(range_start, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(range_start, tile_range_j); const size_t tile_j = threadpool->params.parallelize_2d_tile_1d_with_uarch.tile_j; size_t i = tile_index_i_j.quotient; @@ -420,8 +420,8 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(linear_index, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(linear_index, tile_range_j); const size_t start_j = tile_index_i_j.remainder * tile_j; task(argument, uarch_index, tile_index_i_j.quotient, start_j, min(range_j - start_j, tile_j)); @@ -460,10 +460,10 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_j = + const struct pthreadpool_divisor_size_t tile_range_j = threadpool->params.parallelize_2d_tile_1d_with_uarch.tile_range_j; - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(range_start, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(range_start, tile_range_j); const size_t tile_j = threadpool->params.parallelize_2d_tile_1d_with_uarch.tile_j; size_t i = tile_index_i_j.quotient; @@ -492,8 +492,8 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(linear_index, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(linear_index, tile_range_j); const size_t start_j = tile_index_i_j.remainder * tile_j; task(argument, uarch_index, thread_number, tile_index_i_j.quotient, start_j, min(range_j - start_j, tile_j)); @@ -520,10 +520,10 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_j = + const struct pthreadpool_divisor_size_t tile_range_j = threadpool->params.parallelize_2d_tile_2d.tile_range_j; - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(range_start, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(range_start, tile_range_j); const size_t tile_i = threadpool->params.parallelize_2d_tile_2d.tile_i; const size_t tile_j = threadpool->params.parallelize_2d_tile_2d.tile_j; size_t start_i = tile_index_i_j.quotient * tile_i; @@ -552,8 +552,8 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(linear_index, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(linear_index, tile_range_j); const size_t start_i = tile_index_i_j.quotient * tile_i; const size_t start_j = tile_index_i_j.remainder * tile_j; task(argument, start_i, start_j, min(range_i - start_i, tile_i), @@ -591,12 +591,12 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa const size_t range_threshold = -threadpool->max_num_threads; /* Process thread's own range of items */ - const struct fxdiv_divisor_size_t tile_range_j = + const struct pthreadpool_divisor_size_t tile_range_j = threadpool->params.parallelize_2d_tile_2d_with_uarch.tile_range_j; const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_result_size_t index = - fxdiv_divide_size_t(range_start, tile_range_j); + const struct pthreadpool_div_result index = + pthreadpool_divide_with_divisor(range_start, tile_range_j); const size_t range_i = threadpool->params.parallelize_2d_tile_2d_with_uarch.range_i; const size_t tile_i = @@ -629,8 +629,8 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(linear_index, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(linear_index, tile_range_j); const size_t start_i = tile_index_i_j.quotient * tile_i; const size_t start_j = tile_index_i_j.remainder * tile_j; task(argument, uarch_index, start_i, start_j, @@ -657,14 +657,14 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t range_k = + const struct pthreadpool_divisor_size_t range_k = threadpool->params.parallelize_3d.range_k; - const struct fxdiv_result_size_t index_ij_k = - fxdiv_divide_size_t(range_start, range_k); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result index_ij_k = + pthreadpool_divide_with_divisor(range_start, range_k); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_3d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_k.quotient, range_j); size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; size_t k = index_ij_k.remainder; @@ -691,10 +691,10 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t index_ij_k = - fxdiv_divide_size_t(linear_index, range_k); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_ij_k = + pthreadpool_divide_with_divisor(linear_index, range_k); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_k.quotient, range_j); task(argument, index_i_j.quotient, index_i_j.remainder, index_ij_k.remainder); } @@ -720,14 +720,14 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_k = + const struct pthreadpool_divisor_size_t tile_range_k = threadpool->params.parallelize_3d_tile_1d.tile_range_k; - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(range_start, tile_range_k); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(range_start, tile_range_k); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_3d_tile_1d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, range_j); const size_t tile_k = threadpool->params.parallelize_3d_tile_1d.tile_k; size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; @@ -757,10 +757,10 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(linear_index, tile_range_k); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, range_j); + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(linear_index, tile_range_k); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, range_j); const size_t start_k = tile_index_ij_k.remainder * tile_k; task(argument, index_i_j.quotient, index_i_j.remainder, start_k, min(range_k - start_k, tile_k)); @@ -787,14 +787,14 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_k = + const struct pthreadpool_divisor_size_t tile_range_k = threadpool->params.parallelize_3d_tile_1d.tile_range_k; - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(range_start, tile_range_k); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(range_start, tile_range_k); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_3d_tile_1d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, range_j); const size_t tile_k = threadpool->params.parallelize_3d_tile_1d.tile_k; size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; @@ -825,10 +825,10 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(linear_index, tile_range_k); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, range_j); + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(linear_index, tile_range_k); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, range_j); const size_t start_k = tile_index_ij_k.remainder * tile_k; task(argument, thread_number, index_i_j.quotient, index_i_j.remainder, start_k, min(range_k - start_k, tile_k)); @@ -867,14 +867,14 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_k = + const struct pthreadpool_divisor_size_t tile_range_k = threadpool->params.parallelize_3d_tile_1d_with_uarch.tile_range_k; - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(range_start, tile_range_k); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(range_start, tile_range_k); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_3d_tile_1d_with_uarch.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, range_j); const size_t tile_k = threadpool->params.parallelize_3d_tile_1d_with_uarch.tile_k; size_t i = index_i_j.quotient; @@ -906,10 +906,10 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(linear_index, tile_range_k); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, range_j); + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(linear_index, tile_range_k); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, range_j); const size_t start_k = tile_index_ij_k.remainder * tile_k; task(argument, uarch_index, index_i_j.quotient, index_i_j.remainder, start_k, min(range_k - start_k, tile_k)); @@ -948,14 +948,14 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_k = + const struct pthreadpool_divisor_size_t tile_range_k = threadpool->params.parallelize_3d_tile_1d_with_uarch.tile_range_k; - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(range_start, tile_range_k); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(range_start, tile_range_k); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_3d_tile_1d_with_uarch.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, range_j); const size_t tile_k = threadpool->params.parallelize_3d_tile_1d_with_uarch.tile_k; size_t i = index_i_j.quotient; @@ -988,10 +988,10 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(linear_index, tile_range_k); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, range_j); + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(linear_index, tile_range_k); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, range_j); const size_t start_k = tile_index_ij_k.remainder * tile_k; task(argument, uarch_index, thread_number, index_i_j.quotient, index_i_j.remainder, start_k, min(range_k - start_k, tile_k)); @@ -1018,14 +1018,14 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_k = + const struct pthreadpool_divisor_size_t tile_range_k = threadpool->params.parallelize_3d_tile_2d.tile_range_k; - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(range_start, tile_range_k); - const struct fxdiv_divisor_size_t tile_range_j = + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(range_start, tile_range_k); + const struct pthreadpool_divisor_size_t tile_range_j = threadpool->params.parallelize_3d_tile_2d.tile_range_j; - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, tile_range_j); const size_t tile_j = threadpool->params.parallelize_3d_tile_2d.tile_j; const size_t tile_k = threadpool->params.parallelize_3d_tile_2d.tile_k; size_t i = tile_index_i_j.quotient; @@ -1059,10 +1059,10 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(linear_index, tile_range_k); - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, tile_range_j); + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(linear_index, tile_range_k); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, tile_range_j); const size_t start_j = tile_index_i_j.remainder * tile_j; const size_t start_k = tile_index_ij_k.remainder * tile_k; task(argument, tile_index_i_j.quotient, start_j, start_k, @@ -1102,14 +1102,14 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_k = + const struct pthreadpool_divisor_size_t tile_range_k = threadpool->params.parallelize_3d_tile_2d_with_uarch.tile_range_k; - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(range_start, tile_range_k); - const struct fxdiv_divisor_size_t tile_range_j = + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(range_start, tile_range_k); + const struct pthreadpool_divisor_size_t tile_range_j = threadpool->params.parallelize_3d_tile_2d_with_uarch.tile_range_j; - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, tile_range_j); const size_t tile_j = threadpool->params.parallelize_3d_tile_2d_with_uarch.tile_j; const size_t tile_k = @@ -1147,10 +1147,10 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(linear_index, tile_range_k); - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, tile_range_j); + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(linear_index, tile_range_k); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, tile_range_j); const size_t start_j = tile_index_i_j.remainder * tile_j; const size_t start_k = tile_index_ij_k.remainder * tile_k; task(argument, uarch_index, tile_index_i_j.quotient, start_j, start_k, @@ -1177,18 +1177,18 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t range_kl = + const struct pthreadpool_divisor_size_t range_kl = threadpool->params.parallelize_4d.range_kl; - const struct fxdiv_result_size_t index_ij_kl = - fxdiv_divide_size_t(range_start, range_kl); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result index_ij_kl = + pthreadpool_divide_with_divisor(range_start, range_kl); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_4d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_kl.quotient, range_j); - const struct fxdiv_divisor_size_t range_l = + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_kl.quotient, range_j); + const struct pthreadpool_divisor_size_t range_l = threadpool->params.parallelize_4d.range_l; - const struct fxdiv_result_size_t index_k_l = - fxdiv_divide_size_t(index_ij_kl.remainder, range_l); + const struct pthreadpool_div_result index_k_l = + pthreadpool_divide_with_divisor(index_ij_kl.remainder, range_l); size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; size_t k = index_k_l.quotient; @@ -1220,12 +1220,12 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t index_ij_kl = - fxdiv_divide_size_t(linear_index, range_kl); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_kl.quotient, range_j); - const struct fxdiv_result_size_t index_k_l = - fxdiv_divide_size_t(index_ij_kl.remainder, range_l); + const struct pthreadpool_div_result index_ij_kl = + pthreadpool_divide_with_divisor(linear_index, range_kl); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_kl.quotient, range_j); + const struct pthreadpool_div_result index_k_l = + pthreadpool_divide_with_divisor(index_ij_kl.remainder, range_l); task(argument, index_i_j.quotient, index_i_j.remainder, index_k_l.quotient, index_k_l.remainder); } @@ -1251,18 +1251,18 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_kl = + const struct pthreadpool_divisor_size_t tile_range_kl = threadpool->params.parallelize_4d_tile_1d.tile_range_kl; - const struct fxdiv_result_size_t tile_index_ij_kl = - fxdiv_divide_size_t(range_start, tile_range_kl); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result tile_index_ij_kl = + pthreadpool_divide_with_divisor(range_start, tile_range_kl); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_4d_tile_1d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_kl.quotient, range_j); - const struct fxdiv_divisor_size_t tile_range_l = + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_kl.quotient, range_j); + const struct pthreadpool_divisor_size_t tile_range_l = threadpool->params.parallelize_4d_tile_1d.tile_range_l; - const struct fxdiv_result_size_t tile_index_k_l = - fxdiv_divide_size_t(tile_index_ij_kl.remainder, tile_range_l); + const struct pthreadpool_div_result tile_index_k_l = + pthreadpool_divide_with_divisor(tile_index_ij_kl.remainder, tile_range_l); const size_t tile_l = threadpool->params.parallelize_4d_tile_1d.tile_l; size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; @@ -1297,12 +1297,12 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ij_kl = - fxdiv_divide_size_t(linear_index, tile_range_kl); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_kl.quotient, range_j); - const struct fxdiv_result_size_t tile_index_k_l = - fxdiv_divide_size_t(tile_index_ij_kl.remainder, tile_range_l); + const struct pthreadpool_div_result tile_index_ij_kl = + pthreadpool_divide_with_divisor(linear_index, tile_range_kl); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_kl.quotient, range_j); + const struct pthreadpool_div_result tile_index_k_l = + pthreadpool_divide_with_divisor(tile_index_ij_kl.remainder, tile_range_l); const size_t start_l = tile_index_k_l.remainder * tile_l; task(argument, index_i_j.quotient, index_i_j.remainder, tile_index_k_l.quotient, start_l, min(range_l - start_l, tile_l)); @@ -1329,18 +1329,18 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_kl = + const struct pthreadpool_divisor_size_t tile_range_kl = threadpool->params.parallelize_4d_tile_2d.tile_range_kl; - const struct fxdiv_result_size_t tile_index_ij_kl = - fxdiv_divide_size_t(range_start, tile_range_kl); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result tile_index_ij_kl = + pthreadpool_divide_with_divisor(range_start, tile_range_kl); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_4d_tile_2d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_kl.quotient, range_j); - const struct fxdiv_divisor_size_t tile_range_l = + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_kl.quotient, range_j); + const struct pthreadpool_divisor_size_t tile_range_l = threadpool->params.parallelize_4d_tile_2d.tile_range_l; - const struct fxdiv_result_size_t tile_index_k_l = - fxdiv_divide_size_t(tile_index_ij_kl.remainder, tile_range_l); + const struct pthreadpool_div_result tile_index_k_l = + pthreadpool_divide_with_divisor(tile_index_ij_kl.remainder, tile_range_l); const size_t tile_k = threadpool->params.parallelize_4d_tile_2d.tile_k; const size_t tile_l = threadpool->params.parallelize_4d_tile_2d.tile_l; size_t i = index_i_j.quotient; @@ -1378,12 +1378,12 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ij_kl = - fxdiv_divide_size_t(linear_index, tile_range_kl); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_kl.quotient, range_j); - const struct fxdiv_result_size_t tile_index_k_l = - fxdiv_divide_size_t(tile_index_ij_kl.remainder, tile_range_l); + const struct pthreadpool_div_result tile_index_ij_kl = + pthreadpool_divide_with_divisor(linear_index, tile_range_kl); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_kl.quotient, range_j); + const struct pthreadpool_div_result tile_index_k_l = + pthreadpool_divide_with_divisor(tile_index_ij_kl.remainder, tile_range_l); const size_t start_k = tile_index_k_l.quotient * tile_k; const size_t start_l = tile_index_k_l.remainder * tile_l; task(argument, index_i_j.quotient, index_i_j.remainder, start_k, start_l, @@ -1423,18 +1423,18 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_kl = + const struct pthreadpool_divisor_size_t tile_range_kl = threadpool->params.parallelize_4d_tile_2d_with_uarch.tile_range_kl; - const struct fxdiv_result_size_t tile_index_ij_kl = - fxdiv_divide_size_t(range_start, tile_range_kl); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result tile_index_ij_kl = + pthreadpool_divide_with_divisor(range_start, tile_range_kl); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_4d_tile_2d_with_uarch.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_kl.quotient, range_j); - const struct fxdiv_divisor_size_t tile_range_l = + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_kl.quotient, range_j); + const struct pthreadpool_divisor_size_t tile_range_l = threadpool->params.parallelize_4d_tile_2d_with_uarch.tile_range_l; - const struct fxdiv_result_size_t tile_index_k_l = - fxdiv_divide_size_t(tile_index_ij_kl.remainder, tile_range_l); + const struct pthreadpool_div_result tile_index_k_l = + pthreadpool_divide_with_divisor(tile_index_ij_kl.remainder, tile_range_l); const size_t tile_k = threadpool->params.parallelize_4d_tile_2d_with_uarch.tile_k; const size_t tile_l = @@ -1476,12 +1476,12 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ij_kl = - fxdiv_divide_size_t(linear_index, tile_range_kl); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_kl.quotient, range_j); - const struct fxdiv_result_size_t tile_index_k_l = - fxdiv_divide_size_t(tile_index_ij_kl.remainder, tile_range_l); + const struct pthreadpool_div_result tile_index_ij_kl = + pthreadpool_divide_with_divisor(linear_index, tile_range_kl); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_kl.quotient, range_j); + const struct pthreadpool_div_result tile_index_k_l = + pthreadpool_divide_with_divisor(tile_index_ij_kl.remainder, tile_range_l); const size_t start_k = tile_index_k_l.quotient * tile_k; const size_t start_l = tile_index_k_l.remainder * tile_l; task(argument, uarch_index, index_i_j.quotient, index_i_j.remainder, @@ -1509,22 +1509,22 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t range_lm = + const struct pthreadpool_divisor_size_t range_lm = threadpool->params.parallelize_5d.range_lm; - const struct fxdiv_result_size_t index_ijk_lm = - fxdiv_divide_size_t(range_start, range_lm); - const struct fxdiv_divisor_size_t range_k = + const struct pthreadpool_div_result index_ijk_lm = + pthreadpool_divide_with_divisor(range_start, range_lm); + const struct pthreadpool_divisor_size_t range_k = threadpool->params.parallelize_5d.range_k; - const struct fxdiv_result_size_t index_ij_k = - fxdiv_divide_size_t(index_ijk_lm.quotient, range_k); - const struct fxdiv_divisor_size_t range_m = + const struct pthreadpool_div_result index_ij_k = + pthreadpool_divide_with_divisor(index_ijk_lm.quotient, range_k); + const struct pthreadpool_divisor_size_t range_m = threadpool->params.parallelize_5d.range_m; - const struct fxdiv_result_size_t index_l_m = - fxdiv_divide_size_t(index_ijk_lm.remainder, range_m); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result index_l_m = + pthreadpool_divide_with_divisor(index_ijk_lm.remainder, range_m); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_5d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_k.quotient, range_j); size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; size_t k = index_ij_k.remainder; @@ -1560,14 +1560,14 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t index_ijk_lm = - fxdiv_divide_size_t(linear_index, range_lm); - const struct fxdiv_result_size_t index_ij_k = - fxdiv_divide_size_t(index_ijk_lm.quotient, range_k); - const struct fxdiv_result_size_t index_l_m = - fxdiv_divide_size_t(index_ijk_lm.remainder, range_m); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_ijk_lm = + pthreadpool_divide_with_divisor(linear_index, range_lm); + const struct pthreadpool_div_result index_ij_k = + pthreadpool_divide_with_divisor(index_ijk_lm.quotient, range_k); + const struct pthreadpool_div_result index_l_m = + pthreadpool_divide_with_divisor(index_ijk_lm.remainder, range_m); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_k.quotient, range_j); task(argument, index_i_j.quotient, index_i_j.remainder, index_ij_k.remainder, index_l_m.quotient, index_l_m.remainder); } @@ -1593,22 +1593,22 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_m = + const struct pthreadpool_divisor_size_t tile_range_m = threadpool->params.parallelize_5d_tile_1d.tile_range_m; - const struct fxdiv_result_size_t tile_index_ijkl_m = - fxdiv_divide_size_t(range_start, tile_range_m); - const struct fxdiv_divisor_size_t range_kl = + const struct pthreadpool_div_result tile_index_ijkl_m = + pthreadpool_divide_with_divisor(range_start, tile_range_m); + const struct pthreadpool_divisor_size_t range_kl = threadpool->params.parallelize_5d_tile_1d.range_kl; - const struct fxdiv_result_size_t index_ij_kl = - fxdiv_divide_size_t(tile_index_ijkl_m.quotient, range_kl); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result index_ij_kl = + pthreadpool_divide_with_divisor(tile_index_ijkl_m.quotient, range_kl); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_5d_tile_1d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_kl.quotient, range_j); - const struct fxdiv_divisor_size_t range_l = + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_kl.quotient, range_j); + const struct pthreadpool_divisor_size_t range_l = threadpool->params.parallelize_5d_tile_1d.range_l; - const struct fxdiv_result_size_t index_k_l = - fxdiv_divide_size_t(index_ij_kl.remainder, range_l); + const struct pthreadpool_div_result index_k_l = + pthreadpool_divide_with_divisor(index_ij_kl.remainder, range_l); const size_t tile_m = threadpool->params.parallelize_5d_tile_1d.tile_m; size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; @@ -1647,14 +1647,14 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ijkl_m = - fxdiv_divide_size_t(linear_index, tile_range_m); - const struct fxdiv_result_size_t index_ij_kl = - fxdiv_divide_size_t(tile_index_ijkl_m.quotient, range_kl); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_kl.quotient, range_j); - const struct fxdiv_result_size_t index_k_l = - fxdiv_divide_size_t(index_ij_kl.remainder, range_l); + const struct pthreadpool_div_result tile_index_ijkl_m = + pthreadpool_divide_with_divisor(linear_index, tile_range_m); + const struct pthreadpool_div_result index_ij_kl = + pthreadpool_divide_with_divisor(tile_index_ijkl_m.quotient, range_kl); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_kl.quotient, range_j); + const struct pthreadpool_div_result index_k_l = + pthreadpool_divide_with_divisor(index_ij_kl.remainder, range_l); size_t start_m = tile_index_ijkl_m.remainder * tile_m; task(argument, index_i_j.quotient, index_i_j.remainder, index_k_l.quotient, index_k_l.remainder, start_m, @@ -1682,22 +1682,22 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_lm = + const struct pthreadpool_divisor_size_t tile_range_lm = threadpool->params.parallelize_5d_tile_2d.tile_range_lm; - const struct fxdiv_result_size_t tile_index_ijk_lm = - fxdiv_divide_size_t(range_start, tile_range_lm); - const struct fxdiv_divisor_size_t range_k = + const struct pthreadpool_div_result tile_index_ijk_lm = + pthreadpool_divide_with_divisor(range_start, tile_range_lm); + const struct pthreadpool_divisor_size_t range_k = threadpool->params.parallelize_5d_tile_2d.range_k; - const struct fxdiv_result_size_t index_ij_k = - fxdiv_divide_size_t(tile_index_ijk_lm.quotient, range_k); - const struct fxdiv_divisor_size_t tile_range_m = + const struct pthreadpool_div_result index_ij_k = + pthreadpool_divide_with_divisor(tile_index_ijk_lm.quotient, range_k); + const struct pthreadpool_divisor_size_t tile_range_m = threadpool->params.parallelize_5d_tile_2d.tile_range_m; - const struct fxdiv_result_size_t tile_index_l_m = - fxdiv_divide_size_t(tile_index_ijk_lm.remainder, tile_range_m); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result tile_index_l_m = + pthreadpool_divide_with_divisor(tile_index_ijk_lm.remainder, tile_range_m); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_5d_tile_2d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_k.quotient, range_j); const size_t tile_l = threadpool->params.parallelize_5d_tile_2d.tile_l; const size_t tile_m = threadpool->params.parallelize_5d_tile_2d.tile_m; size_t i = index_i_j.quotient; @@ -1739,14 +1739,14 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ijk_lm = - fxdiv_divide_size_t(linear_index, tile_range_lm); - const struct fxdiv_result_size_t index_ij_k = - fxdiv_divide_size_t(tile_index_ijk_lm.quotient, range_k); - const struct fxdiv_result_size_t tile_index_l_m = - fxdiv_divide_size_t(tile_index_ijk_lm.remainder, tile_range_m); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_k.quotient, range_j); + const struct pthreadpool_div_result tile_index_ijk_lm = + pthreadpool_divide_with_divisor(linear_index, tile_range_lm); + const struct pthreadpool_div_result index_ij_k = + pthreadpool_divide_with_divisor(tile_index_ijk_lm.quotient, range_k); + const struct pthreadpool_div_result tile_index_l_m = + pthreadpool_divide_with_divisor(tile_index_ijk_lm.remainder, tile_range_m); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_k.quotient, range_j); const size_t start_l = tile_index_l_m.quotient * tile_l; const size_t start_m = tile_index_l_m.remainder * tile_m; task(argument, index_i_j.quotient, index_i_j.remainder, @@ -1774,26 +1774,26 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t range_lmn = + const struct pthreadpool_divisor_size_t range_lmn = threadpool->params.parallelize_6d.range_lmn; - const struct fxdiv_result_size_t index_ijk_lmn = - fxdiv_divide_size_t(range_start, range_lmn); - const struct fxdiv_divisor_size_t range_k = + const struct pthreadpool_div_result index_ijk_lmn = + pthreadpool_divide_with_divisor(range_start, range_lmn); + const struct pthreadpool_divisor_size_t range_k = threadpool->params.parallelize_6d.range_k; - const struct fxdiv_result_size_t index_ij_k = - fxdiv_divide_size_t(index_ijk_lmn.quotient, range_k); - const struct fxdiv_divisor_size_t range_n = + const struct pthreadpool_div_result index_ij_k = + pthreadpool_divide_with_divisor(index_ijk_lmn.quotient, range_k); + const struct pthreadpool_divisor_size_t range_n = threadpool->params.parallelize_6d.range_n; - const struct fxdiv_result_size_t index_lm_n = - fxdiv_divide_size_t(index_ijk_lmn.remainder, range_n); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result index_lm_n = + pthreadpool_divide_with_divisor(index_ijk_lmn.remainder, range_n); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_6d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_k.quotient, range_j); - const struct fxdiv_divisor_size_t range_m = + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_k.quotient, range_j); + const struct pthreadpool_divisor_size_t range_m = threadpool->params.parallelize_6d.range_m; - const struct fxdiv_result_size_t index_l_m = - fxdiv_divide_size_t(index_lm_n.quotient, range_m); + const struct pthreadpool_div_result index_l_m = + pthreadpool_divide_with_divisor(index_lm_n.quotient, range_m); size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; size_t k = index_ij_k.remainder; @@ -1833,16 +1833,16 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t index_ijk_lmn = - fxdiv_divide_size_t(linear_index, range_lmn); - const struct fxdiv_result_size_t index_ij_k = - fxdiv_divide_size_t(index_ijk_lmn.quotient, range_k); - const struct fxdiv_result_size_t index_lm_n = - fxdiv_divide_size_t(index_ijk_lmn.remainder, range_n); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_k.quotient, range_j); - const struct fxdiv_result_size_t index_l_m = - fxdiv_divide_size_t(index_lm_n.quotient, range_m); + const struct pthreadpool_div_result index_ijk_lmn = + pthreadpool_divide_with_divisor(linear_index, range_lmn); + const struct pthreadpool_div_result index_ij_k = + pthreadpool_divide_with_divisor(index_ijk_lmn.quotient, range_k); + const struct pthreadpool_div_result index_lm_n = + pthreadpool_divide_with_divisor(index_ijk_lmn.remainder, range_n); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_l_m = + pthreadpool_divide_with_divisor(index_lm_n.quotient, range_m); task(argument, index_i_j.quotient, index_i_j.remainder, index_ij_k.remainder, index_l_m.quotient, index_l_m.remainder, index_lm_n.remainder); @@ -1869,26 +1869,26 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_lmn = + const struct pthreadpool_divisor_size_t tile_range_lmn = threadpool->params.parallelize_6d_tile_1d.tile_range_lmn; - const struct fxdiv_result_size_t tile_index_ijk_lmn = - fxdiv_divide_size_t(range_start, tile_range_lmn); - const struct fxdiv_divisor_size_t range_k = + const struct pthreadpool_div_result tile_index_ijk_lmn = + pthreadpool_divide_with_divisor(range_start, tile_range_lmn); + const struct pthreadpool_divisor_size_t range_k = threadpool->params.parallelize_6d_tile_1d.range_k; - const struct fxdiv_result_size_t index_ij_k = - fxdiv_divide_size_t(tile_index_ijk_lmn.quotient, range_k); - const struct fxdiv_divisor_size_t tile_range_n = + const struct pthreadpool_div_result index_ij_k = + pthreadpool_divide_with_divisor(tile_index_ijk_lmn.quotient, range_k); + const struct pthreadpool_divisor_size_t tile_range_n = threadpool->params.parallelize_6d_tile_1d.tile_range_n; - const struct fxdiv_result_size_t tile_index_lm_n = - fxdiv_divide_size_t(tile_index_ijk_lmn.remainder, tile_range_n); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result tile_index_lm_n = + pthreadpool_divide_with_divisor(tile_index_ijk_lmn.remainder, tile_range_n); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_6d_tile_1d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_k.quotient, range_j); - const struct fxdiv_divisor_size_t range_m = + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_k.quotient, range_j); + const struct pthreadpool_divisor_size_t range_m = threadpool->params.parallelize_6d_tile_1d.range_m; - const struct fxdiv_result_size_t index_l_m = - fxdiv_divide_size_t(tile_index_lm_n.quotient, range_m); + const struct pthreadpool_div_result index_l_m = + pthreadpool_divide_with_divisor(tile_index_lm_n.quotient, range_m); const size_t tile_n = threadpool->params.parallelize_6d_tile_1d.tile_n; size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; @@ -1931,16 +1931,16 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ijk_lmn = - fxdiv_divide_size_t(linear_index, tile_range_lmn); - const struct fxdiv_result_size_t index_ij_k = - fxdiv_divide_size_t(tile_index_ijk_lmn.quotient, range_k); - const struct fxdiv_result_size_t tile_index_lm_n = - fxdiv_divide_size_t(tile_index_ijk_lmn.remainder, tile_range_n); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_k.quotient, range_j); - const struct fxdiv_result_size_t index_l_m = - fxdiv_divide_size_t(tile_index_lm_n.quotient, range_m); + const struct pthreadpool_div_result tile_index_ijk_lmn = + pthreadpool_divide_with_divisor(linear_index, tile_range_lmn); + const struct pthreadpool_div_result index_ij_k = + pthreadpool_divide_with_divisor(tile_index_ijk_lmn.quotient, range_k); + const struct pthreadpool_div_result tile_index_lm_n = + pthreadpool_divide_with_divisor(tile_index_ijk_lmn.remainder, tile_range_n); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_l_m = + pthreadpool_divide_with_divisor(tile_index_lm_n.quotient, range_m); const size_t start_n = tile_index_lm_n.remainder * tile_n; task(argument, index_i_j.quotient, index_i_j.remainder, index_ij_k.remainder, index_l_m.quotient, index_l_m.remainder, @@ -1968,26 +1968,26 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_mn = + const struct pthreadpool_divisor_size_t tile_range_mn = threadpool->params.parallelize_6d_tile_2d.tile_range_mn; - const struct fxdiv_result_size_t tile_index_ijkl_mn = - fxdiv_divide_size_t(range_start, tile_range_mn); - const struct fxdiv_divisor_size_t range_kl = + const struct pthreadpool_div_result tile_index_ijkl_mn = + pthreadpool_divide_with_divisor(range_start, tile_range_mn); + const struct pthreadpool_divisor_size_t range_kl = threadpool->params.parallelize_6d_tile_2d.range_kl; - const struct fxdiv_result_size_t index_ij_kl = - fxdiv_divide_size_t(tile_index_ijkl_mn.quotient, range_kl); - const struct fxdiv_divisor_size_t tile_range_n = + const struct pthreadpool_div_result index_ij_kl = + pthreadpool_divide_with_divisor(tile_index_ijkl_mn.quotient, range_kl); + const struct pthreadpool_divisor_size_t tile_range_n = threadpool->params.parallelize_6d_tile_2d.tile_range_n; - const struct fxdiv_result_size_t tile_index_m_n = - fxdiv_divide_size_t(tile_index_ijkl_mn.remainder, tile_range_n); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result tile_index_m_n = + pthreadpool_divide_with_divisor(tile_index_ijkl_mn.remainder, tile_range_n); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_6d_tile_2d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_kl.quotient, range_j); - const struct fxdiv_divisor_size_t range_l = + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_kl.quotient, range_j); + const struct pthreadpool_divisor_size_t range_l = threadpool->params.parallelize_6d_tile_2d.range_l; - const struct fxdiv_result_size_t index_k_l = - fxdiv_divide_size_t(index_ij_kl.remainder, range_l); + const struct pthreadpool_div_result index_k_l = + pthreadpool_divide_with_divisor(index_ij_kl.remainder, range_l); const size_t tile_m = threadpool->params.parallelize_6d_tile_2d.tile_m; const size_t tile_n = threadpool->params.parallelize_6d_tile_2d.tile_n; size_t i = index_i_j.quotient; @@ -2034,16 +2034,16 @@ PTHREADPOOL_INTERNAL PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_thread_pa &other_thread->range_length) < range_threshold) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ijkl_mn = - fxdiv_divide_size_t(linear_index, tile_range_mn); - const struct fxdiv_result_size_t index_ij_kl = - fxdiv_divide_size_t(tile_index_ijkl_mn.quotient, range_kl); - const struct fxdiv_result_size_t tile_index_m_n = - fxdiv_divide_size_t(tile_index_ijkl_mn.remainder, tile_range_n); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_kl.quotient, range_j); - const struct fxdiv_result_size_t index_k_l = - fxdiv_divide_size_t(index_ij_kl.remainder, range_l); + const struct pthreadpool_div_result tile_index_ijkl_mn = + pthreadpool_divide_with_divisor(linear_index, tile_range_mn); + const struct pthreadpool_div_result index_ij_kl = + pthreadpool_divide_with_divisor(tile_index_ijkl_mn.quotient, range_kl); + const struct pthreadpool_div_result tile_index_m_n = + pthreadpool_divide_with_divisor(tile_index_ijkl_mn.remainder, tile_range_n); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_kl.quotient, range_j); + const struct pthreadpool_div_result index_k_l = + pthreadpool_divide_with_divisor(index_ij_kl.remainder, range_l); const size_t start_m = tile_index_m_n.quotient * tile_m; const size_t start_n = tile_index_m_n.remainder * tile_n; task(argument, index_i_j.quotient, index_i_j.remainder, diff --git a/src/legacy-api.c b/src/legacy-api.c index e4ee357..40a2ae8 100644 --- a/src/legacy-api.c +++ b/src/legacy-api.c @@ -11,7 +11,7 @@ #include /* Dependencies */ -#include +#include "threadpool-utils.h" /* Public library header */ #include @@ -55,8 +55,8 @@ void pthreadpool_compute_2d_tiled(pthreadpool_t threadpool, struct compute_3d_tiled_context { pthreadpool_function_3d_tiled_t function; void* argument; - struct fxdiv_divisor_size_t tile_range_j; - struct fxdiv_divisor_size_t tile_range_k; + struct pthreadpool_divisor_size_t tile_range_j; + struct pthreadpool_divisor_size_t tile_range_k; size_t range_i; size_t range_j; size_t range_k; @@ -67,12 +67,12 @@ struct compute_3d_tiled_context { static void compute_3d_tiled(const struct compute_3d_tiled_context* context, size_t linear_index) { - const struct fxdiv_divisor_size_t tile_range_k = context->tile_range_k; - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(linear_index, tile_range_k); - const struct fxdiv_divisor_size_t tile_range_j = context->tile_range_j; - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, tile_range_j); + const struct pthreadpool_divisor_size_t tile_range_k = context->tile_range_k; + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(linear_index, tile_range_k); + const struct pthreadpool_divisor_size_t tile_range_j = context->tile_range_j; + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, tile_range_j); const size_t max_tile_i = context->tile_i; const size_t max_tile_j = context->tile_j; const size_t max_tile_k = context->tile_k; @@ -110,8 +110,8 @@ void pthreadpool_compute_3d_tiled(pthreadpool_t threadpool, struct compute_3d_tiled_context context = { .function = function, .argument = argument, - .tile_range_j = fxdiv_init_size_t(tile_range_j), - .tile_range_k = fxdiv_init_size_t(tile_range_k), + .tile_range_j = pthreadpool_init_divisor(tile_range_j), + .tile_range_k = pthreadpool_init_divisor(tile_range_k), .range_i = range_i, .range_j = range_j, .range_k = range_k, @@ -127,9 +127,9 @@ void pthreadpool_compute_3d_tiled(pthreadpool_t threadpool, struct compute_4d_tiled_context { pthreadpool_function_4d_tiled_t function; void* argument; - struct fxdiv_divisor_size_t tile_range_kl; - struct fxdiv_divisor_size_t tile_range_j; - struct fxdiv_divisor_size_t tile_range_l; + struct pthreadpool_divisor_size_t tile_range_kl; + struct pthreadpool_divisor_size_t tile_range_j; + struct pthreadpool_divisor_size_t tile_range_l; size_t range_i; size_t range_j; size_t range_k; @@ -142,15 +142,15 @@ struct compute_4d_tiled_context { static void compute_4d_tiled(const struct compute_4d_tiled_context* context, size_t linear_index) { - const struct fxdiv_divisor_size_t tile_range_kl = context->tile_range_kl; - const struct fxdiv_result_size_t tile_index_ij_kl = - fxdiv_divide_size_t(linear_index, tile_range_kl); - const struct fxdiv_divisor_size_t tile_range_j = context->tile_range_j; - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(tile_index_ij_kl.quotient, tile_range_j); - const struct fxdiv_divisor_size_t tile_range_l = context->tile_range_l; - const struct fxdiv_result_size_t tile_index_k_l = - fxdiv_divide_size_t(tile_index_ij_kl.remainder, tile_range_l); + const struct pthreadpool_divisor_size_t tile_range_kl = context->tile_range_kl; + const struct pthreadpool_div_result tile_index_ij_kl = + pthreadpool_divide_with_divisor(linear_index, tile_range_kl); + const struct pthreadpool_divisor_size_t tile_range_j = context->tile_range_j; + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_kl.quotient, tile_range_j); + const struct pthreadpool_divisor_size_t tile_range_l = context->tile_range_l; + const struct pthreadpool_div_result tile_index_k_l = + pthreadpool_divide_with_divisor(tile_index_ij_kl.remainder, tile_range_l); const size_t max_tile_i = context->tile_i; const size_t max_tile_j = context->tile_j; const size_t max_tile_k = context->tile_k; @@ -196,9 +196,9 @@ void pthreadpool_compute_4d_tiled(pthreadpool_t threadpool, struct compute_4d_tiled_context context = { .function = function, .argument = argument, - .tile_range_kl = fxdiv_init_size_t(tile_range_k * tile_range_l), - .tile_range_j = fxdiv_init_size_t(tile_range_j), - .tile_range_l = fxdiv_init_size_t(tile_range_l), + .tile_range_kl = pthreadpool_init_divisor(tile_range_k * tile_range_l), + .tile_range_j = pthreadpool_init_divisor(tile_range_j), + .tile_range_l = pthreadpool_init_divisor(tile_range_l), .range_i = range_i, .range_j = range_j, .range_k = range_k, diff --git a/src/portable-api.c b/src/portable-api.c index b136ac7..060a5a5 100644 --- a/src/portable-api.c +++ b/src/portable-api.c @@ -20,7 +20,7 @@ #endif /* Dependencies */ -#include +#include "threadpool-utils.h" /* Public library header */ #include @@ -419,10 +419,10 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_2d(struct pthrea /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_2d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(range_start, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(range_start, range_j); size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; @@ -445,8 +445,8 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_2d(struct pthrea pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(linear_index, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(linear_index, range_j); task(argument, index_i_j.quotient, index_i_j.remainder); } } @@ -468,10 +468,10 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_2d_with_thread(s /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_2d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(range_start, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(range_start, range_j); size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; @@ -494,8 +494,8 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_2d_with_thread(s pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(linear_index, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(linear_index, range_j); task(argument, thread_number, index_i_j.quotient, index_i_j.remainder); } } @@ -517,10 +517,10 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_2d_tile_1d(struc /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_j = + const struct pthreadpool_divisor_size_t tile_range_j = threadpool->params.parallelize_2d_tile_1d.tile_range_j; - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(range_start, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(range_start, tile_range_j); const size_t tile_j = threadpool->params.parallelize_2d_tile_1d.tile_j; size_t i = tile_index_i_j.quotient; size_t start_j = tile_index_i_j.remainder * tile_j; @@ -546,8 +546,8 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_2d_tile_1d(struc pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(linear_index, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(linear_index, tile_range_j); const size_t start_j = tile_index_i_j.remainder * tile_j; task(argument, tile_index_i_j.quotient, start_j, min(range_j - start_j, tile_j)); @@ -583,10 +583,10 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_2d_tile_1d_with_ /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_j = + const struct pthreadpool_divisor_size_t tile_range_j = threadpool->params.parallelize_2d_tile_1d_with_uarch.tile_range_j; - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(range_start, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(range_start, tile_range_j); const size_t tile_j = threadpool->params.parallelize_2d_tile_1d_with_uarch.tile_j; size_t i = tile_index_i_j.quotient; @@ -614,8 +614,8 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_2d_tile_1d_with_ pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(linear_index, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(linear_index, tile_range_j); const size_t start_j = tile_index_i_j.remainder * tile_j; task(argument, uarch_index, tile_index_i_j.quotient, start_j, min(range_j - start_j, tile_j)); @@ -651,10 +651,10 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_2d_tile_1d_with_ /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_j = + const struct pthreadpool_divisor_size_t tile_range_j = threadpool->params.parallelize_2d_tile_1d_with_uarch.tile_range_j; - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(range_start, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(range_start, tile_range_j); const size_t tile_j = threadpool->params.parallelize_2d_tile_1d_with_uarch.tile_j; size_t i = tile_index_i_j.quotient; @@ -683,8 +683,8 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_2d_tile_1d_with_ pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(linear_index, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(linear_index, tile_range_j); const size_t start_j = tile_index_i_j.remainder * tile_j; task(argument, uarch_index, thread_number, tile_index_i_j.quotient, start_j, min(range_j - start_j, tile_j)); @@ -928,10 +928,10 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_2d_tile_2d(struc /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_j = + const struct pthreadpool_divisor_size_t tile_range_j = threadpool->params.parallelize_2d_tile_2d.tile_range_j; - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(range_start, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(range_start, tile_range_j); const size_t tile_i = threadpool->params.parallelize_2d_tile_2d.tile_i; const size_t tile_j = threadpool->params.parallelize_2d_tile_2d.tile_j; size_t start_i = tile_index_i_j.quotient * tile_i; @@ -960,8 +960,8 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_2d_tile_2d(struc pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(linear_index, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(linear_index, tile_range_j); const size_t start_i = tile_index_i_j.quotient * tile_i; const size_t start_j = tile_index_i_j.remainder * tile_j; task(argument, start_i, start_j, min(range_i - start_i, tile_i), @@ -996,12 +996,12 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_2d_tile_2d_with_ #endif /* Process thread's own range of items */ - const struct fxdiv_divisor_size_t tile_range_j = + const struct pthreadpool_divisor_size_t tile_range_j = threadpool->params.parallelize_2d_tile_2d_with_uarch.tile_range_j; const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_result_size_t index = - fxdiv_divide_size_t(range_start, tile_range_j); + const struct pthreadpool_div_result index = + pthreadpool_divide_with_divisor(range_start, tile_range_j); const size_t range_i = threadpool->params.parallelize_2d_tile_2d_with_uarch.range_i; const size_t tile_i = @@ -1034,8 +1034,8 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_2d_tile_2d_with_ pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(linear_index, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(linear_index, tile_range_j); const size_t start_i = tile_index_i_j.quotient * tile_i; const size_t start_j = tile_index_i_j.remainder * tile_j; task(argument, uarch_index, start_i, start_j, @@ -1337,14 +1337,14 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_3d(struct pthrea /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t range_k = + const struct pthreadpool_divisor_size_t range_k = threadpool->params.parallelize_3d.range_k; - const struct fxdiv_result_size_t index_ij_k = - fxdiv_divide_size_t(range_start, range_k); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result index_ij_k = + pthreadpool_divide_with_divisor(range_start, range_k); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_3d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_k.quotient, range_j); size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; size_t k = index_ij_k.remainder; @@ -1371,10 +1371,10 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_3d(struct pthrea pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t index_ij_k = - fxdiv_divide_size_t(linear_index, range_k); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_ij_k = + pthreadpool_divide_with_divisor(linear_index, range_k); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_k.quotient, range_j); task(argument, index_i_j.quotient, index_i_j.remainder, index_ij_k.remainder); } @@ -1397,14 +1397,14 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_3d_tile_1d(struc /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_k = + const struct pthreadpool_divisor_size_t tile_range_k = threadpool->params.parallelize_3d_tile_1d.tile_range_k; - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(range_start, tile_range_k); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(range_start, tile_range_k); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_3d_tile_1d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, range_j); const size_t tile_k = threadpool->params.parallelize_3d_tile_1d.tile_k; size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; @@ -1434,10 +1434,10 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_3d_tile_1d(struc pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(linear_index, tile_range_k); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, range_j); + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(linear_index, tile_range_k); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, range_j); const size_t start_k = tile_index_ij_k.remainder * tile_k; task(argument, index_i_j.quotient, index_i_j.remainder, start_k, min(range_k - start_k, tile_k)); @@ -1461,14 +1461,14 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_3d_tile_1d_with_ /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_k = + const struct pthreadpool_divisor_size_t tile_range_k = threadpool->params.parallelize_3d_tile_1d.tile_range_k; - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(range_start, tile_range_k); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(range_start, tile_range_k); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_3d_tile_1d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, range_j); const size_t tile_k = threadpool->params.parallelize_3d_tile_1d.tile_k; size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; @@ -1499,10 +1499,10 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_3d_tile_1d_with_ pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(linear_index, tile_range_k); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, range_j); + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(linear_index, tile_range_k); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, range_j); const size_t start_k = tile_index_ij_k.remainder * tile_k; task(argument, thread_number, index_i_j.quotient, index_i_j.remainder, start_k, min(range_k - start_k, tile_k)); @@ -1538,14 +1538,14 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_3d_tile_1d_with_ /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_k = + const struct pthreadpool_divisor_size_t tile_range_k = threadpool->params.parallelize_3d_tile_1d_with_uarch.tile_range_k; - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(range_start, tile_range_k); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(range_start, tile_range_k); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_3d_tile_1d_with_uarch.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, range_j); const size_t tile_k = threadpool->params.parallelize_3d_tile_1d_with_uarch.tile_k; size_t i = index_i_j.quotient; @@ -1577,10 +1577,10 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_3d_tile_1d_with_ pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(linear_index, tile_range_k); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, range_j); + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(linear_index, tile_range_k); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, range_j); const size_t start_k = tile_index_ij_k.remainder * tile_k; task(argument, uarch_index, index_i_j.quotient, index_i_j.remainder, start_k, min(range_k - start_k, tile_k)); @@ -1616,14 +1616,14 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_3d_tile_1d_with_ /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_k = + const struct pthreadpool_divisor_size_t tile_range_k = threadpool->params.parallelize_3d_tile_1d_with_uarch.tile_range_k; - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(range_start, tile_range_k); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(range_start, tile_range_k); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_3d_tile_1d_with_uarch.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, range_j); const size_t tile_k = threadpool->params.parallelize_3d_tile_1d_with_uarch.tile_k; size_t i = index_i_j.quotient; @@ -1656,10 +1656,10 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_3d_tile_1d_with_ pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(linear_index, tile_range_k); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, range_j); + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(linear_index, tile_range_k); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, range_j); const size_t start_k = tile_index_ij_k.remainder * tile_k; task(argument, uarch_index, thread_number, index_i_j.quotient, index_i_j.remainder, start_k, min(range_k - start_k, tile_k)); @@ -1922,14 +1922,14 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_3d_tile_2d(struc /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_k = + const struct pthreadpool_divisor_size_t tile_range_k = threadpool->params.parallelize_3d_tile_2d.tile_range_k; - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(range_start, tile_range_k); - const struct fxdiv_divisor_size_t tile_range_j = + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(range_start, tile_range_k); + const struct pthreadpool_divisor_size_t tile_range_j = threadpool->params.parallelize_3d_tile_2d.tile_range_j; - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, tile_range_j); const size_t tile_j = threadpool->params.parallelize_3d_tile_2d.tile_j; const size_t tile_k = threadpool->params.parallelize_3d_tile_2d.tile_k; size_t i = tile_index_i_j.quotient; @@ -1963,10 +1963,10 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_3d_tile_2d(struc pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(linear_index, tile_range_k); - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, tile_range_j); + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(linear_index, tile_range_k); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, tile_range_j); const size_t start_j = tile_index_i_j.remainder * tile_j; const size_t start_k = tile_index_ij_k.remainder * tile_k; task(argument, tile_index_i_j.quotient, start_j, start_k, @@ -2003,14 +2003,14 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_3d_tile_2d_with_ /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_k = + const struct pthreadpool_divisor_size_t tile_range_k = threadpool->params.parallelize_3d_tile_2d_with_uarch.tile_range_k; - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(range_start, tile_range_k); - const struct fxdiv_divisor_size_t tile_range_j = + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(range_start, tile_range_k); + const struct pthreadpool_divisor_size_t tile_range_j = threadpool->params.parallelize_3d_tile_2d_with_uarch.tile_range_j; - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, tile_range_j); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, tile_range_j); const size_t tile_j = threadpool->params.parallelize_3d_tile_2d_with_uarch.tile_j; const size_t tile_k = @@ -2048,10 +2048,10 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_3d_tile_2d_with_ pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ij_k = - fxdiv_divide_size_t(linear_index, tile_range_k); - const struct fxdiv_result_size_t tile_index_i_j = - fxdiv_divide_size_t(tile_index_ij_k.quotient, tile_range_j); + const struct pthreadpool_div_result tile_index_ij_k = + pthreadpool_divide_with_divisor(linear_index, tile_range_k); + const struct pthreadpool_div_result tile_index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_k.quotient, tile_range_j); const size_t start_j = tile_index_i_j.remainder * tile_j; const size_t start_k = tile_index_ij_k.remainder * tile_k; task(argument, uarch_index, tile_index_i_j.quotient, start_j, start_k, @@ -2396,18 +2396,18 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_4d(struct pthrea /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t range_kl = + const struct pthreadpool_divisor_size_t range_kl = threadpool->params.parallelize_4d.range_kl; - const struct fxdiv_result_size_t index_ij_kl = - fxdiv_divide_size_t(range_start, range_kl); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result index_ij_kl = + pthreadpool_divide_with_divisor(range_start, range_kl); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_4d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_kl.quotient, range_j); - const struct fxdiv_divisor_size_t range_l = + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_kl.quotient, range_j); + const struct pthreadpool_divisor_size_t range_l = threadpool->params.parallelize_4d.range_l; - const struct fxdiv_result_size_t index_k_l = - fxdiv_divide_size_t(index_ij_kl.remainder, range_l); + const struct pthreadpool_div_result index_k_l = + pthreadpool_divide_with_divisor(index_ij_kl.remainder, range_l); size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; size_t k = index_k_l.quotient; @@ -2439,12 +2439,12 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_4d(struct pthrea pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t index_ij_kl = - fxdiv_divide_size_t(linear_index, range_kl); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_kl.quotient, range_j); - const struct fxdiv_result_size_t index_k_l = - fxdiv_divide_size_t(index_ij_kl.remainder, range_l); + const struct pthreadpool_div_result index_ij_kl = + pthreadpool_divide_with_divisor(linear_index, range_kl); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_kl.quotient, range_j); + const struct pthreadpool_div_result index_k_l = + pthreadpool_divide_with_divisor(index_ij_kl.remainder, range_l); task(argument, index_i_j.quotient, index_i_j.remainder, index_k_l.quotient, index_k_l.remainder); } @@ -2467,18 +2467,18 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_4d_tile_1d(struc /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_kl = + const struct pthreadpool_divisor_size_t tile_range_kl = threadpool->params.parallelize_4d_tile_1d.tile_range_kl; - const struct fxdiv_result_size_t tile_index_ij_kl = - fxdiv_divide_size_t(range_start, tile_range_kl); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result tile_index_ij_kl = + pthreadpool_divide_with_divisor(range_start, tile_range_kl); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_4d_tile_1d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_kl.quotient, range_j); - const struct fxdiv_divisor_size_t tile_range_l = + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_kl.quotient, range_j); + const struct pthreadpool_divisor_size_t tile_range_l = threadpool->params.parallelize_4d_tile_1d.tile_range_l; - const struct fxdiv_result_size_t tile_index_k_l = - fxdiv_divide_size_t(tile_index_ij_kl.remainder, tile_range_l); + const struct pthreadpool_div_result tile_index_k_l = + pthreadpool_divide_with_divisor(tile_index_ij_kl.remainder, tile_range_l); const size_t tile_l = threadpool->params.parallelize_4d_tile_1d.tile_l; size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; @@ -2513,12 +2513,12 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_4d_tile_1d(struc pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ij_kl = - fxdiv_divide_size_t(linear_index, tile_range_kl); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_kl.quotient, range_j); - const struct fxdiv_result_size_t tile_index_k_l = - fxdiv_divide_size_t(tile_index_ij_kl.remainder, tile_range_l); + const struct pthreadpool_div_result tile_index_ij_kl = + pthreadpool_divide_with_divisor(linear_index, tile_range_kl); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_kl.quotient, range_j); + const struct pthreadpool_div_result tile_index_k_l = + pthreadpool_divide_with_divisor(tile_index_ij_kl.remainder, tile_range_l); const size_t start_l = tile_index_k_l.remainder * tile_l; task(argument, index_i_j.quotient, index_i_j.remainder, tile_index_k_l.quotient, start_l, min(range_l - start_l, tile_l)); @@ -2542,18 +2542,18 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_4d_tile_2d(struc /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_kl = + const struct pthreadpool_divisor_size_t tile_range_kl = threadpool->params.parallelize_4d_tile_2d.tile_range_kl; - const struct fxdiv_result_size_t tile_index_ij_kl = - fxdiv_divide_size_t(range_start, tile_range_kl); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result tile_index_ij_kl = + pthreadpool_divide_with_divisor(range_start, tile_range_kl); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_4d_tile_2d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_kl.quotient, range_j); - const struct fxdiv_divisor_size_t tile_range_l = + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_kl.quotient, range_j); + const struct pthreadpool_divisor_size_t tile_range_l = threadpool->params.parallelize_4d_tile_2d.tile_range_l; - const struct fxdiv_result_size_t tile_index_k_l = - fxdiv_divide_size_t(tile_index_ij_kl.remainder, tile_range_l); + const struct pthreadpool_div_result tile_index_k_l = + pthreadpool_divide_with_divisor(tile_index_ij_kl.remainder, tile_range_l); const size_t tile_k = threadpool->params.parallelize_4d_tile_2d.tile_k; const size_t tile_l = threadpool->params.parallelize_4d_tile_2d.tile_l; size_t i = index_i_j.quotient; @@ -2591,12 +2591,12 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_4d_tile_2d(struc pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ij_kl = - fxdiv_divide_size_t(linear_index, tile_range_kl); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_kl.quotient, range_j); - const struct fxdiv_result_size_t tile_index_k_l = - fxdiv_divide_size_t(tile_index_ij_kl.remainder, tile_range_l); + const struct pthreadpool_div_result tile_index_ij_kl = + pthreadpool_divide_with_divisor(linear_index, tile_range_kl); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_kl.quotient, range_j); + const struct pthreadpool_div_result tile_index_k_l = + pthreadpool_divide_with_divisor(tile_index_ij_kl.remainder, tile_range_l); const size_t start_k = tile_index_k_l.quotient * tile_k; const size_t start_l = tile_index_k_l.remainder * tile_l; task(argument, index_i_j.quotient, index_i_j.remainder, start_k, start_l, @@ -2633,18 +2633,18 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_4d_tile_2d_with_ /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_kl = + const struct pthreadpool_divisor_size_t tile_range_kl = threadpool->params.parallelize_4d_tile_2d_with_uarch.tile_range_kl; - const struct fxdiv_result_size_t tile_index_ij_kl = - fxdiv_divide_size_t(range_start, tile_range_kl); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result tile_index_ij_kl = + pthreadpool_divide_with_divisor(range_start, tile_range_kl); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_4d_tile_2d_with_uarch.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_kl.quotient, range_j); - const struct fxdiv_divisor_size_t tile_range_l = + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_kl.quotient, range_j); + const struct pthreadpool_divisor_size_t tile_range_l = threadpool->params.parallelize_4d_tile_2d_with_uarch.tile_range_l; - const struct fxdiv_result_size_t tile_index_k_l = - fxdiv_divide_size_t(tile_index_ij_kl.remainder, tile_range_l); + const struct pthreadpool_div_result tile_index_k_l = + pthreadpool_divide_with_divisor(tile_index_ij_kl.remainder, tile_range_l); const size_t tile_k = threadpool->params.parallelize_4d_tile_2d_with_uarch.tile_k; const size_t tile_l = @@ -2686,12 +2686,12 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_4d_tile_2d_with_ pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ij_kl = - fxdiv_divide_size_t(linear_index, tile_range_kl); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(tile_index_ij_kl.quotient, range_j); - const struct fxdiv_result_size_t tile_index_k_l = - fxdiv_divide_size_t(tile_index_ij_kl.remainder, tile_range_l); + const struct pthreadpool_div_result tile_index_ij_kl = + pthreadpool_divide_with_divisor(linear_index, tile_range_kl); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(tile_index_ij_kl.quotient, range_j); + const struct pthreadpool_div_result tile_index_k_l = + pthreadpool_divide_with_divisor(tile_index_ij_kl.remainder, tile_range_l); const size_t start_k = tile_index_k_l.quotient * tile_k; const size_t start_l = tile_index_k_l.remainder * tile_l; task(argument, uarch_index, index_i_j.quotient, index_i_j.remainder, @@ -2955,22 +2955,22 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_5d(struct pthrea /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t range_lm = + const struct pthreadpool_divisor_size_t range_lm = threadpool->params.parallelize_5d.range_lm; - const struct fxdiv_result_size_t index_ijk_lm = - fxdiv_divide_size_t(range_start, range_lm); - const struct fxdiv_divisor_size_t range_k = + const struct pthreadpool_div_result index_ijk_lm = + pthreadpool_divide_with_divisor(range_start, range_lm); + const struct pthreadpool_divisor_size_t range_k = threadpool->params.parallelize_5d.range_k; - const struct fxdiv_result_size_t index_ij_k = - fxdiv_divide_size_t(index_ijk_lm.quotient, range_k); - const struct fxdiv_divisor_size_t range_m = + const struct pthreadpool_div_result index_ij_k = + pthreadpool_divide_with_divisor(index_ijk_lm.quotient, range_k); + const struct pthreadpool_divisor_size_t range_m = threadpool->params.parallelize_5d.range_m; - const struct fxdiv_result_size_t index_l_m = - fxdiv_divide_size_t(index_ijk_lm.remainder, range_m); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result index_l_m = + pthreadpool_divide_with_divisor(index_ijk_lm.remainder, range_m); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_5d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_k.quotient, range_j); size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; size_t k = index_ij_k.remainder; @@ -3006,14 +3006,14 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_5d(struct pthrea pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t index_ijk_lm = - fxdiv_divide_size_t(linear_index, range_lm); - const struct fxdiv_result_size_t index_ij_k = - fxdiv_divide_size_t(index_ijk_lm.quotient, range_k); - const struct fxdiv_result_size_t index_l_m = - fxdiv_divide_size_t(index_ijk_lm.remainder, range_m); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_ijk_lm = + pthreadpool_divide_with_divisor(linear_index, range_lm); + const struct pthreadpool_div_result index_ij_k = + pthreadpool_divide_with_divisor(index_ijk_lm.quotient, range_k); + const struct pthreadpool_div_result index_l_m = + pthreadpool_divide_with_divisor(index_ijk_lm.remainder, range_m); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_k.quotient, range_j); task(argument, index_i_j.quotient, index_i_j.remainder, index_ij_k.remainder, index_l_m.quotient, index_l_m.remainder); } @@ -3036,22 +3036,22 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_5d_tile_1d(struc /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_m = + const struct pthreadpool_divisor_size_t tile_range_m = threadpool->params.parallelize_5d_tile_1d.tile_range_m; - const struct fxdiv_result_size_t tile_index_ijkl_m = - fxdiv_divide_size_t(range_start, tile_range_m); - const struct fxdiv_divisor_size_t range_kl = + const struct pthreadpool_div_result tile_index_ijkl_m = + pthreadpool_divide_with_divisor(range_start, tile_range_m); + const struct pthreadpool_divisor_size_t range_kl = threadpool->params.parallelize_5d_tile_1d.range_kl; - const struct fxdiv_result_size_t index_ij_kl = - fxdiv_divide_size_t(tile_index_ijkl_m.quotient, range_kl); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result index_ij_kl = + pthreadpool_divide_with_divisor(tile_index_ijkl_m.quotient, range_kl); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_5d_tile_1d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_kl.quotient, range_j); - const struct fxdiv_divisor_size_t range_l = + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_kl.quotient, range_j); + const struct pthreadpool_divisor_size_t range_l = threadpool->params.parallelize_5d_tile_1d.range_l; - const struct fxdiv_result_size_t index_k_l = - fxdiv_divide_size_t(index_ij_kl.remainder, range_l); + const struct pthreadpool_div_result index_k_l = + pthreadpool_divide_with_divisor(index_ij_kl.remainder, range_l); const size_t tile_m = threadpool->params.parallelize_5d_tile_1d.tile_m; size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; @@ -3090,14 +3090,14 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_5d_tile_1d(struc pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ijkl_m = - fxdiv_divide_size_t(linear_index, tile_range_m); - const struct fxdiv_result_size_t index_ij_kl = - fxdiv_divide_size_t(tile_index_ijkl_m.quotient, range_kl); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_kl.quotient, range_j); - const struct fxdiv_result_size_t index_k_l = - fxdiv_divide_size_t(index_ij_kl.remainder, range_l); + const struct pthreadpool_div_result tile_index_ijkl_m = + pthreadpool_divide_with_divisor(linear_index, tile_range_m); + const struct pthreadpool_div_result index_ij_kl = + pthreadpool_divide_with_divisor(tile_index_ijkl_m.quotient, range_kl); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_kl.quotient, range_j); + const struct pthreadpool_div_result index_k_l = + pthreadpool_divide_with_divisor(index_ij_kl.remainder, range_l); size_t start_m = tile_index_ijkl_m.remainder * tile_m; task(argument, index_i_j.quotient, index_i_j.remainder, index_k_l.quotient, index_k_l.remainder, start_m, @@ -3122,22 +3122,22 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_5d_tile_2d(struc /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_lm = + const struct pthreadpool_divisor_size_t tile_range_lm = threadpool->params.parallelize_5d_tile_2d.tile_range_lm; - const struct fxdiv_result_size_t tile_index_ijk_lm = - fxdiv_divide_size_t(range_start, tile_range_lm); - const struct fxdiv_divisor_size_t range_k = + const struct pthreadpool_div_result tile_index_ijk_lm = + pthreadpool_divide_with_divisor(range_start, tile_range_lm); + const struct pthreadpool_divisor_size_t range_k = threadpool->params.parallelize_5d_tile_2d.range_k; - const struct fxdiv_result_size_t index_ij_k = - fxdiv_divide_size_t(tile_index_ijk_lm.quotient, range_k); - const struct fxdiv_divisor_size_t tile_range_m = + const struct pthreadpool_div_result index_ij_k = + pthreadpool_divide_with_divisor(tile_index_ijk_lm.quotient, range_k); + const struct pthreadpool_divisor_size_t tile_range_m = threadpool->params.parallelize_5d_tile_2d.tile_range_m; - const struct fxdiv_result_size_t tile_index_l_m = - fxdiv_divide_size_t(tile_index_ijk_lm.remainder, tile_range_m); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result tile_index_l_m = + pthreadpool_divide_with_divisor(tile_index_ijk_lm.remainder, tile_range_m); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_5d_tile_2d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_k.quotient, range_j); const size_t tile_l = threadpool->params.parallelize_5d_tile_2d.tile_l; const size_t tile_m = threadpool->params.parallelize_5d_tile_2d.tile_m; size_t i = index_i_j.quotient; @@ -3179,14 +3179,14 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_5d_tile_2d(struc pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ijk_lm = - fxdiv_divide_size_t(linear_index, tile_range_lm); - const struct fxdiv_result_size_t index_ij_k = - fxdiv_divide_size_t(tile_index_ijk_lm.quotient, range_k); - const struct fxdiv_result_size_t tile_index_l_m = - fxdiv_divide_size_t(tile_index_ijk_lm.remainder, tile_range_m); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_k.quotient, range_j); + const struct pthreadpool_div_result tile_index_ijk_lm = + pthreadpool_divide_with_divisor(linear_index, tile_range_lm); + const struct pthreadpool_div_result index_ij_k = + pthreadpool_divide_with_divisor(tile_index_ijk_lm.quotient, range_k); + const struct pthreadpool_div_result tile_index_l_m = + pthreadpool_divide_with_divisor(tile_index_ijk_lm.remainder, tile_range_m); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_k.quotient, range_j); const size_t start_l = tile_index_l_m.quotient * tile_l; const size_t start_m = tile_index_l_m.remainder * tile_m; task(argument, index_i_j.quotient, index_i_j.remainder, @@ -3211,26 +3211,26 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_6d(struct pthrea /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t range_lmn = + const struct pthreadpool_divisor_size_t range_lmn = threadpool->params.parallelize_6d.range_lmn; - const struct fxdiv_result_size_t index_ijk_lmn = - fxdiv_divide_size_t(range_start, range_lmn); - const struct fxdiv_divisor_size_t range_k = + const struct pthreadpool_div_result index_ijk_lmn = + pthreadpool_divide_with_divisor(range_start, range_lmn); + const struct pthreadpool_divisor_size_t range_k = threadpool->params.parallelize_6d.range_k; - const struct fxdiv_result_size_t index_ij_k = - fxdiv_divide_size_t(index_ijk_lmn.quotient, range_k); - const struct fxdiv_divisor_size_t range_n = + const struct pthreadpool_div_result index_ij_k = + pthreadpool_divide_with_divisor(index_ijk_lmn.quotient, range_k); + const struct pthreadpool_divisor_size_t range_n = threadpool->params.parallelize_6d.range_n; - const struct fxdiv_result_size_t index_lm_n = - fxdiv_divide_size_t(index_ijk_lmn.remainder, range_n); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result index_lm_n = + pthreadpool_divide_with_divisor(index_ijk_lmn.remainder, range_n); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_6d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_k.quotient, range_j); - const struct fxdiv_divisor_size_t range_m = + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_k.quotient, range_j); + const struct pthreadpool_divisor_size_t range_m = threadpool->params.parallelize_6d.range_m; - const struct fxdiv_result_size_t index_l_m = - fxdiv_divide_size_t(index_lm_n.quotient, range_m); + const struct pthreadpool_div_result index_l_m = + pthreadpool_divide_with_divisor(index_lm_n.quotient, range_m); size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; size_t k = index_ij_k.remainder; @@ -3270,16 +3270,16 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_6d(struct pthrea pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t index_ijk_lmn = - fxdiv_divide_size_t(linear_index, range_lmn); - const struct fxdiv_result_size_t index_ij_k = - fxdiv_divide_size_t(index_ijk_lmn.quotient, range_k); - const struct fxdiv_result_size_t index_lm_n = - fxdiv_divide_size_t(index_ijk_lmn.remainder, range_n); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_k.quotient, range_j); - const struct fxdiv_result_size_t index_l_m = - fxdiv_divide_size_t(index_lm_n.quotient, range_m); + const struct pthreadpool_div_result index_ijk_lmn = + pthreadpool_divide_with_divisor(linear_index, range_lmn); + const struct pthreadpool_div_result index_ij_k = + pthreadpool_divide_with_divisor(index_ijk_lmn.quotient, range_k); + const struct pthreadpool_div_result index_lm_n = + pthreadpool_divide_with_divisor(index_ijk_lmn.remainder, range_n); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_l_m = + pthreadpool_divide_with_divisor(index_lm_n.quotient, range_m); task(argument, index_i_j.quotient, index_i_j.remainder, index_ij_k.remainder, index_l_m.quotient, index_l_m.remainder, index_lm_n.remainder); @@ -3303,26 +3303,26 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_6d_tile_1d(struc /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_lmn = + const struct pthreadpool_divisor_size_t tile_range_lmn = threadpool->params.parallelize_6d_tile_1d.tile_range_lmn; - const struct fxdiv_result_size_t tile_index_ijk_lmn = - fxdiv_divide_size_t(range_start, tile_range_lmn); - const struct fxdiv_divisor_size_t range_k = + const struct pthreadpool_div_result tile_index_ijk_lmn = + pthreadpool_divide_with_divisor(range_start, tile_range_lmn); + const struct pthreadpool_divisor_size_t range_k = threadpool->params.parallelize_6d_tile_1d.range_k; - const struct fxdiv_result_size_t index_ij_k = - fxdiv_divide_size_t(tile_index_ijk_lmn.quotient, range_k); - const struct fxdiv_divisor_size_t tile_range_n = + const struct pthreadpool_div_result index_ij_k = + pthreadpool_divide_with_divisor(tile_index_ijk_lmn.quotient, range_k); + const struct pthreadpool_divisor_size_t tile_range_n = threadpool->params.parallelize_6d_tile_1d.tile_range_n; - const struct fxdiv_result_size_t tile_index_lm_n = - fxdiv_divide_size_t(tile_index_ijk_lmn.remainder, tile_range_n); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result tile_index_lm_n = + pthreadpool_divide_with_divisor(tile_index_ijk_lmn.remainder, tile_range_n); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_6d_tile_1d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_k.quotient, range_j); - const struct fxdiv_divisor_size_t range_m = + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_k.quotient, range_j); + const struct pthreadpool_divisor_size_t range_m = threadpool->params.parallelize_6d_tile_1d.range_m; - const struct fxdiv_result_size_t index_l_m = - fxdiv_divide_size_t(tile_index_lm_n.quotient, range_m); + const struct pthreadpool_div_result index_l_m = + pthreadpool_divide_with_divisor(tile_index_lm_n.quotient, range_m); const size_t tile_n = threadpool->params.parallelize_6d_tile_1d.tile_n; size_t i = index_i_j.quotient; size_t j = index_i_j.remainder; @@ -3365,16 +3365,16 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_6d_tile_1d(struc pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ijk_lmn = - fxdiv_divide_size_t(linear_index, tile_range_lmn); - const struct fxdiv_result_size_t index_ij_k = - fxdiv_divide_size_t(tile_index_ijk_lmn.quotient, range_k); - const struct fxdiv_result_size_t tile_index_lm_n = - fxdiv_divide_size_t(tile_index_ijk_lmn.remainder, tile_range_n); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_k.quotient, range_j); - const struct fxdiv_result_size_t index_l_m = - fxdiv_divide_size_t(tile_index_lm_n.quotient, range_m); + const struct pthreadpool_div_result tile_index_ijk_lmn = + pthreadpool_divide_with_divisor(linear_index, tile_range_lmn); + const struct pthreadpool_div_result index_ij_k = + pthreadpool_divide_with_divisor(tile_index_ijk_lmn.quotient, range_k); + const struct pthreadpool_div_result tile_index_lm_n = + pthreadpool_divide_with_divisor(tile_index_ijk_lmn.remainder, tile_range_n); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_k.quotient, range_j); + const struct pthreadpool_div_result index_l_m = + pthreadpool_divide_with_divisor(tile_index_lm_n.quotient, range_m); const size_t start_n = tile_index_lm_n.remainder * tile_n; task(argument, index_i_j.quotient, index_i_j.remainder, index_ij_k.remainder, index_l_m.quotient, index_l_m.remainder, @@ -3399,26 +3399,26 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_6d_tile_2d(struc /* Process thread's own range of items */ const size_t range_start = pthreadpool_load_relaxed_size_t(&thread->range_start); - const struct fxdiv_divisor_size_t tile_range_mn = + const struct pthreadpool_divisor_size_t tile_range_mn = threadpool->params.parallelize_6d_tile_2d.tile_range_mn; - const struct fxdiv_result_size_t tile_index_ijkl_mn = - fxdiv_divide_size_t(range_start, tile_range_mn); - const struct fxdiv_divisor_size_t range_kl = + const struct pthreadpool_div_result tile_index_ijkl_mn = + pthreadpool_divide_with_divisor(range_start, tile_range_mn); + const struct pthreadpool_divisor_size_t range_kl = threadpool->params.parallelize_6d_tile_2d.range_kl; - const struct fxdiv_result_size_t index_ij_kl = - fxdiv_divide_size_t(tile_index_ijkl_mn.quotient, range_kl); - const struct fxdiv_divisor_size_t tile_range_n = + const struct pthreadpool_div_result index_ij_kl = + pthreadpool_divide_with_divisor(tile_index_ijkl_mn.quotient, range_kl); + const struct pthreadpool_divisor_size_t tile_range_n = threadpool->params.parallelize_6d_tile_2d.tile_range_n; - const struct fxdiv_result_size_t tile_index_m_n = - fxdiv_divide_size_t(tile_index_ijkl_mn.remainder, tile_range_n); - const struct fxdiv_divisor_size_t range_j = + const struct pthreadpool_div_result tile_index_m_n = + pthreadpool_divide_with_divisor(tile_index_ijkl_mn.remainder, tile_range_n); + const struct pthreadpool_divisor_size_t range_j = threadpool->params.parallelize_6d_tile_2d.range_j; - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_kl.quotient, range_j); - const struct fxdiv_divisor_size_t range_l = + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_kl.quotient, range_j); + const struct pthreadpool_divisor_size_t range_l = threadpool->params.parallelize_6d_tile_2d.range_l; - const struct fxdiv_result_size_t index_k_l = - fxdiv_divide_size_t(index_ij_kl.remainder, range_l); + const struct pthreadpool_div_result index_k_l = + pthreadpool_divide_with_divisor(index_ij_kl.remainder, range_l); const size_t tile_m = threadpool->params.parallelize_6d_tile_2d.tile_m; const size_t tile_n = threadpool->params.parallelize_6d_tile_2d.tile_n; size_t i = index_i_j.quotient; @@ -3465,16 +3465,16 @@ static PTHREADPOOL_NO_SANITIZE_FUNCTION void thread_parallelize_6d_tile_2d(struc pthreadpool_try_decrement_relaxed_size_t(&other_thread->range_length)) { const size_t linear_index = pthreadpool_decrement_fetch_relaxed_size_t(&other_thread->range_end); - const struct fxdiv_result_size_t tile_index_ijkl_mn = - fxdiv_divide_size_t(linear_index, tile_range_mn); - const struct fxdiv_result_size_t index_ij_kl = - fxdiv_divide_size_t(tile_index_ijkl_mn.quotient, range_kl); - const struct fxdiv_result_size_t tile_index_m_n = - fxdiv_divide_size_t(tile_index_ijkl_mn.remainder, tile_range_n); - const struct fxdiv_result_size_t index_i_j = - fxdiv_divide_size_t(index_ij_kl.quotient, range_j); - const struct fxdiv_result_size_t index_k_l = - fxdiv_divide_size_t(index_ij_kl.remainder, range_l); + const struct pthreadpool_div_result tile_index_ijkl_mn = + pthreadpool_divide_with_divisor(linear_index, tile_range_mn); + const struct pthreadpool_div_result index_ij_kl = + pthreadpool_divide_with_divisor(tile_index_ijkl_mn.quotient, range_kl); + const struct pthreadpool_div_result tile_index_m_n = + pthreadpool_divide_with_divisor(tile_index_ijkl_mn.remainder, tile_range_n); + const struct pthreadpool_div_result index_i_j = + pthreadpool_divide_with_divisor(index_ij_kl.quotient, range_j); + const struct pthreadpool_div_result index_k_l = + pthreadpool_divide_with_divisor(index_ij_kl.remainder, range_l); const size_t start_m = tile_index_m_n.quotient * tile_m; const size_t start_n = tile_index_m_n.remainder * tile_n; task(argument, index_i_j.quotient, index_i_j.remainder, @@ -3761,7 +3761,7 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_2d(pthreadpool_t t } else { const size_t range = range_i * range_j; const struct pthreadpool_2d_params params = { - .range_j = fxdiv_init_size_t(range_j), + .range_j = pthreadpool_init_divisor(range_j), }; thread_function_t parallelize_2d = &thread_parallelize_2d; #if PTHREADPOOL_USE_FASTPATH @@ -3798,7 +3798,7 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_2d_with_thread( } else { const size_t range = range_i * range_j; const struct pthreadpool_2d_params params = { - .range_j = fxdiv_init_size_t(range_j), + .range_j = pthreadpool_init_divisor(range_j), }; thread_function_t parallelize_2d_with_thread = &thread_parallelize_2d_with_thread; @@ -3842,7 +3842,7 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_2d_tile_1d(pthread const struct pthreadpool_2d_tile_1d_params params = { .range_j = range_j, .tile_j = tile_j, - .tile_range_j = fxdiv_init_size_t(tile_range_j), + .tile_range_j = pthreadpool_init_divisor(tile_range_j), }; thread_function_t parallelize_2d_tile_1d = &thread_parallelize_2d_tile_1d; #if PTHREADPOOL_USE_FASTPATH @@ -3897,7 +3897,7 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_2d_tile_1d_with_ua .max_uarch_index = max_uarch_index, .range_j = range_j, .tile_j = tile_j, - .tile_range_j = fxdiv_init_size_t(tile_range_j), + .tile_range_j = pthreadpool_init_divisor(tile_range_j), }; thread_function_t parallelize_2d_tile_1d_with_uarch = &thread_parallelize_2d_tile_1d_with_uarch; @@ -3954,7 +3954,7 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_2d_tile_1d_with_ua .max_uarch_index = max_uarch_index, .range_j = range_j, .tile_j = tile_j, - .tile_range_j = fxdiv_init_size_t(tile_range_j), + .tile_range_j = pthreadpool_init_divisor(tile_range_j), }; thread_function_t parallelize_2d_tile_1d_with_uarch_with_thread = &thread_parallelize_2d_tile_1d_with_uarch_with_thread; @@ -4113,7 +4113,7 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_2d_tile_2d(pthread .tile_i = tile_i, .range_j = range_j, .tile_j = tile_j, - .tile_range_j = fxdiv_init_size_t(tile_range_j), + .tile_range_j = pthreadpool_init_divisor(tile_range_j), }; thread_function_t parallelize_2d_tile_2d = &thread_parallelize_2d_tile_2d; #if PTHREADPOOL_USE_FASTPATH @@ -4305,7 +4305,7 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_2d_tile_2d_with_ua .tile_i = tile_i, .range_j = range_j, .tile_j = tile_j, - .tile_range_j = fxdiv_init_size_t(tile_range_j), + .tile_range_j = pthreadpool_init_divisor(tile_range_j), }; thread_function_t parallelize_2d_tile_2d_with_uarch = &thread_parallelize_2d_tile_2d_with_uarch; @@ -4348,8 +4348,8 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_3d(pthreadpool_t t } else { const size_t range = range_i * range_j * range_k; const struct pthreadpool_3d_params params = { - .range_j = fxdiv_init_size_t(range_j), - .range_k = fxdiv_init_size_t(range_k), + .range_j = pthreadpool_init_divisor(range_j), + .range_k = pthreadpool_init_divisor(range_k), }; thread_function_t parallelize_3d = &thread_parallelize_3d; #if PTHREADPOOL_USE_FASTPATH @@ -4393,8 +4393,8 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_3d_tile_1d(pthread const struct pthreadpool_3d_tile_1d_params params = { .range_k = range_k, .tile_k = tile_k, - .range_j = fxdiv_init_size_t(range_j), - .tile_range_k = fxdiv_init_size_t(tile_range_k), + .range_j = pthreadpool_init_divisor(range_j), + .tile_range_k = pthreadpool_init_divisor(tile_range_k), }; thread_function_t parallelize_3d_tile_1d = &thread_parallelize_3d_tile_1d; #if PTHREADPOOL_USE_FASTPATH @@ -4440,8 +4440,8 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_3d_tile_1d_with_th const struct pthreadpool_3d_tile_1d_params params = { .range_k = range_k, .tile_k = tile_k, - .range_j = fxdiv_init_size_t(range_j), - .tile_range_k = fxdiv_init_size_t(tile_range_k), + .range_j = pthreadpool_init_divisor(range_j), + .tile_range_k = pthreadpool_init_divisor(tile_range_k), }; thread_function_t parallelize_3d_tile_1d_with_thread = &thread_parallelize_3d_tile_1d_with_thread; @@ -4500,8 +4500,8 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_3d_tile_1d_with_ua .max_uarch_index = max_uarch_index, .range_k = range_k, .tile_k = tile_k, - .range_j = fxdiv_init_size_t(range_j), - .tile_range_k = fxdiv_init_size_t(tile_range_k), + .range_j = pthreadpool_init_divisor(range_j), + .tile_range_k = pthreadpool_init_divisor(tile_range_k), }; thread_function_t parallelize_3d_tile_1d_with_uarch = &thread_parallelize_3d_tile_1d_with_uarch; @@ -4560,8 +4560,8 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_3d_tile_1d_with_ua .max_uarch_index = max_uarch_index, .range_k = range_k, .tile_k = tile_k, - .range_j = fxdiv_init_size_t(range_j), - .tile_range_k = fxdiv_init_size_t(tile_range_k), + .range_j = pthreadpool_init_divisor(range_j), + .tile_range_k = pthreadpool_init_divisor(tile_range_k), }; thread_function_t parallelize_3d_tile_1d_with_uarch_with_thread = &thread_parallelize_3d_tile_1d_with_uarch_with_thread; @@ -4735,8 +4735,8 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_3d_tile_2d(pthread .tile_j = tile_j, .range_k = range_k, .tile_k = tile_k, - .tile_range_j = fxdiv_init_size_t(tile_range_j), - .tile_range_k = fxdiv_init_size_t(tile_range_k), + .tile_range_j = pthreadpool_init_divisor(tile_range_j), + .tile_range_k = pthreadpool_init_divisor(tile_range_k), }; thread_function_t parallelize_3d_tile_2d = &thread_parallelize_3d_tile_2d; #if PTHREADPOOL_USE_FASTPATH @@ -4947,8 +4947,8 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_3d_tile_2d_with_ua .tile_j = tile_j, .range_k = range_k, .tile_k = tile_k, - .tile_range_j = fxdiv_init_size_t(tile_range_j), - .tile_range_k = fxdiv_init_size_t(tile_range_k), + .tile_range_j = pthreadpool_init_divisor(tile_range_j), + .tile_range_k = pthreadpool_init_divisor(tile_range_k), }; thread_function_t parallelize_3d_tile_2d_with_uarch = &thread_parallelize_3d_tile_2d_with_uarch; @@ -4995,9 +4995,9 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_4d(pthreadpool_t t const size_t range = range_i * range_j * range_kl; const struct pthreadpool_4d_params params = { .range_k = range_k, - .range_j = fxdiv_init_size_t(range_j), - .range_kl = fxdiv_init_size_t(range_kl), - .range_l = fxdiv_init_size_t(range_l), + .range_j = pthreadpool_init_divisor(range_j), + .range_kl = pthreadpool_init_divisor(range_kl), + .range_l = pthreadpool_init_divisor(range_l), }; thread_function_t parallelize_4d = &thread_parallelize_4d; #if PTHREADPOOL_USE_FASTPATH @@ -5046,9 +5046,9 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_4d_tile_1d(pthread .range_k = range_k, .range_l = range_l, .tile_l = tile_l, - .range_j = fxdiv_init_size_t(range_j), - .tile_range_kl = fxdiv_init_size_t(tile_range_kl), - .tile_range_l = fxdiv_init_size_t(tile_range_l), + .range_j = pthreadpool_init_divisor(range_j), + .tile_range_kl = pthreadpool_init_divisor(tile_range_kl), + .tile_range_l = pthreadpool_init_divisor(tile_range_l), }; thread_function_t parallelize_4d_tile_1d = &thread_parallelize_4d_tile_1d; #if PTHREADPOOL_USE_FASTPATH @@ -5102,9 +5102,9 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_4d_tile_2d(pthread .tile_k = tile_k, .range_l = range_l, .tile_l = tile_l, - .range_j = fxdiv_init_size_t(range_j), - .tile_range_kl = fxdiv_init_size_t(tile_range_kl), - .tile_range_l = fxdiv_init_size_t(tile_range_l), + .range_j = pthreadpool_init_divisor(range_j), + .tile_range_kl = pthreadpool_init_divisor(tile_range_kl), + .tile_range_l = pthreadpool_init_divisor(tile_range_l), }; thread_function_t parallelize_4d_tile_2d = &thread_parallelize_4d_tile_2d; #if PTHREADPOOL_USE_FASTPATH @@ -5169,9 +5169,9 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_4d_tile_2d_with_ua .tile_k = tile_k, .range_l = range_l, .tile_l = tile_l, - .range_j = fxdiv_init_size_t(range_j), - .tile_range_kl = fxdiv_init_size_t(tile_range_kl), - .tile_range_l = fxdiv_init_size_t(tile_range_l), + .range_j = pthreadpool_init_divisor(range_j), + .tile_range_kl = pthreadpool_init_divisor(tile_range_kl), + .tile_range_l = pthreadpool_init_divisor(tile_range_l), }; thread_function_t parallelize_4d_tile_2d_with_uarch = &thread_parallelize_4d_tile_2d_with_uarch; @@ -5336,10 +5336,10 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_5d(pthreadpool_t t const size_t range = range_i * range_j * range_k * range_lm; const struct pthreadpool_5d_params params = { .range_l = range_l, - .range_j = fxdiv_init_size_t(range_j), - .range_k = fxdiv_init_size_t(range_k), - .range_lm = fxdiv_init_size_t(range_lm), - .range_m = fxdiv_init_size_t(range_m), + .range_j = pthreadpool_init_divisor(range_j), + .range_k = pthreadpool_init_divisor(range_k), + .range_lm = pthreadpool_init_divisor(range_lm), + .range_m = pthreadpool_init_divisor(range_m), }; thread_function_t parallelize_5d = &thread_parallelize_5d; #if PTHREADPOOL_USE_FASTPATH @@ -5390,10 +5390,10 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_5d_tile_1d(pthread .range_k = range_k, .range_m = range_m, .tile_m = tile_m, - .range_j = fxdiv_init_size_t(range_j), - .range_kl = fxdiv_init_size_t(range_kl), - .range_l = fxdiv_init_size_t(range_l), - .tile_range_m = fxdiv_init_size_t(tile_range_m), + .range_j = pthreadpool_init_divisor(range_j), + .range_kl = pthreadpool_init_divisor(range_kl), + .range_l = pthreadpool_init_divisor(range_l), + .tile_range_m = pthreadpool_init_divisor(tile_range_m), }; thread_function_t parallelize_5d_tile_1d = &thread_parallelize_5d_tile_1d; #if PTHREADPOOL_USE_FASTPATH @@ -5451,10 +5451,10 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_5d_tile_2d(pthread .tile_l = tile_l, .range_m = range_m, .tile_m = tile_m, - .range_j = fxdiv_init_size_t(range_j), - .range_k = fxdiv_init_size_t(range_k), - .tile_range_lm = fxdiv_init_size_t(tile_range_lm), - .tile_range_m = fxdiv_init_size_t(tile_range_m), + .range_j = pthreadpool_init_divisor(range_j), + .range_k = pthreadpool_init_divisor(range_k), + .tile_range_lm = pthreadpool_init_divisor(tile_range_lm), + .tile_range_m = pthreadpool_init_divisor(tile_range_m), }; thread_function_t parallelize_5d_tile_2d = &thread_parallelize_5d_tile_2d; #if PTHREADPOOL_USE_FASTPATH @@ -5505,11 +5505,11 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_6d(pthreadpool_t t const size_t range = range_i * range_j * range_k * range_lmn; const struct pthreadpool_6d_params params = { .range_l = range_l, - .range_j = fxdiv_init_size_t(range_j), - .range_k = fxdiv_init_size_t(range_k), - .range_lmn = fxdiv_init_size_t(range_lmn), - .range_m = fxdiv_init_size_t(range_m), - .range_n = fxdiv_init_size_t(range_n), + .range_j = pthreadpool_init_divisor(range_j), + .range_k = pthreadpool_init_divisor(range_k), + .range_lmn = pthreadpool_init_divisor(range_lmn), + .range_m = pthreadpool_init_divisor(range_m), + .range_n = pthreadpool_init_divisor(range_n), }; thread_function_t parallelize_6d = &thread_parallelize_6d; #if PTHREADPOOL_USE_FASTPATH @@ -5564,11 +5564,11 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_6d_tile_1d(pthread .range_l = range_l, .range_n = range_n, .tile_n = tile_n, - .range_j = fxdiv_init_size_t(range_j), - .range_k = fxdiv_init_size_t(range_k), - .tile_range_lmn = fxdiv_init_size_t(tile_range_lmn), - .range_m = fxdiv_init_size_t(range_m), - .tile_range_n = fxdiv_init_size_t(tile_range_n), + .range_j = pthreadpool_init_divisor(range_j), + .range_k = pthreadpool_init_divisor(range_k), + .tile_range_lmn = pthreadpool_init_divisor(tile_range_lmn), + .range_m = pthreadpool_init_divisor(range_m), + .tile_range_n = pthreadpool_init_divisor(tile_range_n), }; thread_function_t parallelize_6d_tile_1d = &thread_parallelize_6d_tile_1d; #if PTHREADPOOL_USE_FASTPATH @@ -5630,11 +5630,11 @@ PTHREADPOOL_NO_SANITIZE_FUNCTION void pthreadpool_parallelize_6d_tile_2d(pthread .tile_m = tile_m, .range_n = range_n, .tile_n = tile_n, - .range_j = fxdiv_init_size_t(range_j), - .range_kl = fxdiv_init_size_t(range_kl), - .range_l = fxdiv_init_size_t(range_l), - .tile_range_mn = fxdiv_init_size_t(tile_range_mn), - .tile_range_n = fxdiv_init_size_t(tile_range_n), + .range_j = pthreadpool_init_divisor(range_j), + .range_kl = pthreadpool_init_divisor(range_kl), + .range_l = pthreadpool_init_divisor(range_l), + .tile_range_mn = pthreadpool_init_divisor(tile_range_mn), + .tile_range_n = pthreadpool_init_divisor(tile_range_n), }; thread_function_t parallelize_6d_tile_2d = &thread_parallelize_6d_tile_2d; #if PTHREADPOOL_USE_FASTPATH diff --git a/src/pthreads.c b/src/pthreads.c index 0ea30be..6944152 100644 --- a/src/pthreads.c +++ b/src/pthreads.c @@ -22,7 +22,7 @@ #include /* Configuration header */ -#include +#include "threadpool-utils.h" #include "threadpool-common.h" /* POSIX headers */ @@ -695,8 +695,8 @@ PTHREADPOOL_INTERNAL void pthreadpool_parallelize( (uint32_t)threadpool->job_id, num_threads); /* Populate a `thread_info` struct for each thread */ - const struct fxdiv_result_size_t range_params = - fxdiv_divide_size_t(linear_range, fxdiv_init_size_t(num_threads)); + const struct pthreadpool_div_result range_params = + pthreadpool_divide_with_divisor(linear_range, pthreadpool_init_divisor(num_threads)); size_t range_start = 0; for (size_t tid = 0; tid < num_threads; tid++) { struct thread_info* thread = &threadpool->threads[tid]; diff --git a/src/threadpool-object.h b/src/threadpool-object.h index da4066a..ca2c74c 100644 --- a/src/threadpool-object.h +++ b/src/threadpool-object.h @@ -27,7 +27,7 @@ #endif /* Dependencies */ -#include +#include "threadpool-utils.h" /* Library header */ #include @@ -144,7 +144,7 @@ struct pthreadpool_2d_params { * FXdiv divisor for the range_j argument passed to the * pthreadpool_parallelize_2d function. */ - struct fxdiv_divisor_size_t range_j; + struct pthreadpool_divisor_size_t range_j; }; struct pthreadpool_2d_tile_1d_params { @@ -161,7 +161,7 @@ struct pthreadpool_2d_tile_1d_params { /** * FXdiv divisor for the divide_round_up(range_j, tile_j) value. */ - struct fxdiv_divisor_size_t tile_range_j; + struct pthreadpool_divisor_size_t tile_range_j; }; struct pthreadpool_2d_tile_1d_with_uarch_params { @@ -188,7 +188,7 @@ struct pthreadpool_2d_tile_1d_with_uarch_params { /** * FXdiv divisor for the divide_round_up(range_j, tile_j) value. */ - struct fxdiv_divisor_size_t tile_range_j; + struct pthreadpool_divisor_size_t tile_range_j; }; struct pthreadpool_2d_tile_1d_dynamic_params { @@ -261,7 +261,7 @@ struct pthreadpool_2d_tile_2d_params { /** * FXdiv divisor for the divide_round_up(range_j, tile_j) value. */ - struct fxdiv_divisor_size_t tile_range_j; + struct pthreadpool_divisor_size_t tile_range_j; }; struct pthreadpool_2d_tile_2d_with_uarch_params { @@ -298,7 +298,7 @@ struct pthreadpool_2d_tile_2d_with_uarch_params { /** * FXdiv divisor for the divide_round_up(range_j, tile_j) value. */ - struct fxdiv_divisor_size_t tile_range_j; + struct pthreadpool_divisor_size_t tile_range_j; }; struct pthreadpool_2d_tile_2d_dynamic_params { @@ -362,12 +362,12 @@ struct pthreadpool_3d_params { * FXdiv divisor for the range_j argument passed to the * pthreadpool_parallelize_3d function. */ - struct fxdiv_divisor_size_t range_j; + struct pthreadpool_divisor_size_t range_j; /** * FXdiv divisor for the range_k argument passed to the * pthreadpool_parallelize_3d function. */ - struct fxdiv_divisor_size_t range_k; + struct pthreadpool_divisor_size_t range_k; }; struct pthreadpool_3d_tile_1d_params { @@ -385,11 +385,11 @@ struct pthreadpool_3d_tile_1d_params { * FXdiv divisor for the range_j argument passed to the * pthreadpool_parallelize_3d_tile_1d function. */ - struct fxdiv_divisor_size_t range_j; + struct pthreadpool_divisor_size_t range_j; /** * FXdiv divisor for the divide_round_up(range_k, tile_k) value. */ - struct fxdiv_divisor_size_t tile_range_k; + struct pthreadpool_divisor_size_t tile_range_k; }; struct pthreadpool_3d_tile_1d_with_uarch_params { @@ -417,11 +417,11 @@ struct pthreadpool_3d_tile_1d_with_uarch_params { * FXdiv divisor for the range_j argument passed to the * pthreadpool_parallelize_3d_tile_1d_with_uarch function. */ - struct fxdiv_divisor_size_t range_j; + struct pthreadpool_divisor_size_t range_j; /** * FXdiv divisor for the divide_round_up(range_k, tile_k) value. */ - struct fxdiv_divisor_size_t tile_range_k; + struct pthreadpool_divisor_size_t tile_range_k; }; struct pthreadpool_3d_tile_1d_dynamic_params { @@ -504,11 +504,11 @@ struct pthreadpool_3d_tile_2d_params { /** * FXdiv divisor for the divide_round_up(range_j, tile_j) value. */ - struct fxdiv_divisor_size_t tile_range_j; + struct pthreadpool_divisor_size_t tile_range_j; /** * FXdiv divisor for the divide_round_up(range_k, tile_k) value. */ - struct fxdiv_divisor_size_t tile_range_k; + struct pthreadpool_divisor_size_t tile_range_k; }; struct pthreadpool_3d_tile_2d_with_uarch_params { @@ -545,11 +545,11 @@ struct pthreadpool_3d_tile_2d_with_uarch_params { /** * FXdiv divisor for the divide_round_up(range_j, tile_j) value. */ - struct fxdiv_divisor_size_t tile_range_j; + struct pthreadpool_divisor_size_t tile_range_j; /** * FXdiv divisor for the divide_round_up(range_k, tile_k) value. */ - struct fxdiv_divisor_size_t tile_range_k; + struct pthreadpool_divisor_size_t tile_range_k; }; struct pthreadpool_3d_tile_2d_dynamic_params { @@ -628,16 +628,16 @@ struct pthreadpool_4d_params { * FXdiv divisor for the range_j argument passed to the * pthreadpool_parallelize_4d function. */ - struct fxdiv_divisor_size_t range_j; + struct pthreadpool_divisor_size_t range_j; /** * FXdiv divisor for the range_k * range_l value. */ - struct fxdiv_divisor_size_t range_kl; + struct pthreadpool_divisor_size_t range_kl; /** * FXdiv divisor for the range_l argument passed to the * pthreadpool_parallelize_4d function. */ - struct fxdiv_divisor_size_t range_l; + struct pthreadpool_divisor_size_t range_l; }; struct pthreadpool_4d_tile_1d_params { @@ -660,15 +660,15 @@ struct pthreadpool_4d_tile_1d_params { * FXdiv divisor for the range_j argument passed to the * pthreadpool_parallelize_4d_tile_1d function. */ - struct fxdiv_divisor_size_t range_j; + struct pthreadpool_divisor_size_t range_j; /** * FXdiv divisor for the range_k * divide_round_up(range_l, tile_l) value. */ - struct fxdiv_divisor_size_t tile_range_kl; + struct pthreadpool_divisor_size_t tile_range_kl; /** * FXdiv divisor for the divide_round_up(range_l, tile_l) value. */ - struct fxdiv_divisor_size_t tile_range_l; + struct pthreadpool_divisor_size_t tile_range_l; }; struct pthreadpool_4d_tile_2d_params { @@ -696,16 +696,16 @@ struct pthreadpool_4d_tile_2d_params { * FXdiv divisor for the range_j argument passed to the * pthreadpool_parallelize_4d_tile_2d function. */ - struct fxdiv_divisor_size_t range_j; + struct pthreadpool_divisor_size_t range_j; /** * FXdiv divisor for the divide_round_up(range_k, tile_k) * * divide_round_up(range_l, tile_l) value. */ - struct fxdiv_divisor_size_t tile_range_kl; + struct pthreadpool_divisor_size_t tile_range_kl; /** * FXdiv divisor for the divide_round_up(range_l, tile_l) value. */ - struct fxdiv_divisor_size_t tile_range_l; + struct pthreadpool_divisor_size_t tile_range_l; }; struct pthreadpool_4d_tile_2d_with_uarch_params { @@ -743,16 +743,16 @@ struct pthreadpool_4d_tile_2d_with_uarch_params { * FXdiv divisor for the range_j argument passed to the * pthreadpool_parallelize_4d_tile_2d_with_uarch function. */ - struct fxdiv_divisor_size_t range_j; + struct pthreadpool_divisor_size_t range_j; /** * FXdiv divisor for the divide_round_up(range_k, tile_k) * * divide_round_up(range_l, tile_l) value. */ - struct fxdiv_divisor_size_t tile_range_kl; + struct pthreadpool_divisor_size_t tile_range_kl; /** * FXdiv divisor for the divide_round_up(range_l, tile_l) value. */ - struct fxdiv_divisor_size_t tile_range_l; + struct pthreadpool_divisor_size_t tile_range_l; }; struct pthreadpool_4d_tile_2d_dynamic_params { @@ -841,21 +841,21 @@ struct pthreadpool_5d_params { * FXdiv divisor for the range_j argument passed to the * pthreadpool_parallelize_5d function. */ - struct fxdiv_divisor_size_t range_j; + struct pthreadpool_divisor_size_t range_j; /** * FXdiv divisor for the range_k argument passed to the * pthreadpool_parallelize_5d function. */ - struct fxdiv_divisor_size_t range_k; + struct pthreadpool_divisor_size_t range_k; /** * FXdiv divisor for the range_l * range_m value. */ - struct fxdiv_divisor_size_t range_lm; + struct pthreadpool_divisor_size_t range_lm; /** * FXdiv divisor for the range_m argument passed to the * pthreadpool_parallelize_5d function. */ - struct fxdiv_divisor_size_t range_m; + struct pthreadpool_divisor_size_t range_m; }; struct pthreadpool_5d_tile_1d_params { @@ -878,20 +878,20 @@ struct pthreadpool_5d_tile_1d_params { * FXdiv divisor for the range_j argument passed to the * pthreadpool_parallelize_5d_tile_1d function. */ - struct fxdiv_divisor_size_t range_j; + struct pthreadpool_divisor_size_t range_j; /** * FXdiv divisor for the range_k * range_l value. */ - struct fxdiv_divisor_size_t range_kl; + struct pthreadpool_divisor_size_t range_kl; /** * FXdiv divisor for the range_l argument passed to the * pthreadpool_parallelize_5d_tile_1d function. */ - struct fxdiv_divisor_size_t range_l; + struct pthreadpool_divisor_size_t range_l; /** * FXdiv divisor for the divide_round_up(range_m, tile_m) value. */ - struct fxdiv_divisor_size_t tile_range_m; + struct pthreadpool_divisor_size_t tile_range_m; }; struct pthreadpool_5d_tile_2d_params { @@ -919,21 +919,21 @@ struct pthreadpool_5d_tile_2d_params { * FXdiv divisor for the range_j argument passed to the * pthreadpool_parallelize_5d_tile_2d function. */ - struct fxdiv_divisor_size_t range_j; + struct pthreadpool_divisor_size_t range_j; /** * FXdiv divisor for the range_k argument passed to the * pthreadpool_parallelize_5d_tile_2d function. */ - struct fxdiv_divisor_size_t range_k; + struct pthreadpool_divisor_size_t range_k; /** * FXdiv divisor for the divide_round_up(range_l, tile_l) * * divide_round_up(range_m, tile_m) value. */ - struct fxdiv_divisor_size_t tile_range_lm; + struct pthreadpool_divisor_size_t tile_range_lm; /** * FXdiv divisor for the divide_round_up(range_m, tile_m) value. */ - struct fxdiv_divisor_size_t tile_range_m; + struct pthreadpool_divisor_size_t tile_range_m; }; struct pthreadpool_6d_params { @@ -946,26 +946,26 @@ struct pthreadpool_6d_params { * FXdiv divisor for the range_j argument passed to the * pthreadpool_parallelize_6d function. */ - struct fxdiv_divisor_size_t range_j; + struct pthreadpool_divisor_size_t range_j; /** * FXdiv divisor for the range_k argument passed to the * pthreadpool_parallelize_6d function. */ - struct fxdiv_divisor_size_t range_k; + struct pthreadpool_divisor_size_t range_k; /** * FXdiv divisor for the range_l * range_m * range_n value. */ - struct fxdiv_divisor_size_t range_lmn; + struct pthreadpool_divisor_size_t range_lmn; /** * FXdiv divisor for the range_m argument passed to the * pthreadpool_parallelize_6d function. */ - struct fxdiv_divisor_size_t range_m; + struct pthreadpool_divisor_size_t range_m; /** * FXdiv divisor for the range_n argument passed to the * pthreadpool_parallelize_6d function. */ - struct fxdiv_divisor_size_t range_n; + struct pthreadpool_divisor_size_t range_n; }; struct pthreadpool_6d_tile_1d_params { @@ -988,26 +988,26 @@ struct pthreadpool_6d_tile_1d_params { * FXdiv divisor for the range_j argument passed to the * pthreadpool_parallelize_6d_tile_1d function. */ - struct fxdiv_divisor_size_t range_j; + struct pthreadpool_divisor_size_t range_j; /** * FXdiv divisor for the range_k argument passed to the * pthreadpool_parallelize_6d_tile_1d function. */ - struct fxdiv_divisor_size_t range_k; + struct pthreadpool_divisor_size_t range_k; /** * FXdiv divisor for the range_l * range_m * divide_round_up(range_n, tile_n) * value. */ - struct fxdiv_divisor_size_t tile_range_lmn; + struct pthreadpool_divisor_size_t tile_range_lmn; /** * FXdiv divisor for the range_m argument passed to the * pthreadpool_parallelize_6d_tile_1d function. */ - struct fxdiv_divisor_size_t range_m; + struct pthreadpool_divisor_size_t range_m; /** * FXdiv divisor for the divide_round_up(range_n, tile_n) value. */ - struct fxdiv_divisor_size_t tile_range_n; + struct pthreadpool_divisor_size_t tile_range_n; }; struct pthreadpool_6d_tile_2d_params { @@ -1040,25 +1040,25 @@ struct pthreadpool_6d_tile_2d_params { * FXdiv divisor for the range_j argument passed to the * pthreadpool_parallelize_6d_tile_2d function. */ - struct fxdiv_divisor_size_t range_j; + struct pthreadpool_divisor_size_t range_j; /** * FXdiv divisor for the range_k * range_l value. */ - struct fxdiv_divisor_size_t range_kl; + struct pthreadpool_divisor_size_t range_kl; /** * FXdiv divisor for the range_l argument passed to the * pthreadpool_parallelize_6d_tile_2d function. */ - struct fxdiv_divisor_size_t range_l; + struct pthreadpool_divisor_size_t range_l; /** * FXdiv divisor for the divide_round_up(range_m, tile_m) * * divide_round_up(range_n, tile_n) value. */ - struct fxdiv_divisor_size_t tile_range_mn; + struct pthreadpool_divisor_size_t tile_range_mn; /** * FXdiv divisor for the divide_round_up(range_n, tile_n) value. */ - struct fxdiv_divisor_size_t tile_range_n; + struct pthreadpool_divisor_size_t tile_range_n; }; union pthreadpool_params { diff --git a/src/threadpool-utils.h b/src/threadpool-utils.h index d080c58..395b504 100644 --- a/src/threadpool-utils.h +++ b/src/threadpool-utils.h @@ -146,4 +146,263 @@ static inline size_t divide_round_up(size_t dividend, size_t divisor) { static inline size_t min(size_t a, size_t b) { return a < b ? a : b; } static inline size_t max(size_t a, size_t b) { return a > b ? a : b; } +struct pthreadpool_div_result { + size_t quotient; + size_t remainder; +}; + +static inline struct pthreadpool_div_result pthreadpool_div_size_t(size_t n, + size_t d) { + struct pthreadpool_div_result result; + result.quotient = n / d; + result.remainder = n % d; + return result; +} + +// --- Begin FXdiv-like implementation --- + +static inline uint64_t pthreadpool_mulext_uint32_t(uint32_t a, uint32_t b) { +#if defined(_MSC_VER) && defined(_M_IX86) + return (uint64_t) __emulu((unsigned int) a, (unsigned int) b); +#else + return (uint64_t) a * (uint64_t) b; +#endif +} + +static inline uint32_t pthreadpool_mulhi_uint32_t(uint32_t a, uint32_t b) { +#if defined(__OPENCL_VERSION__) + return mul_hi(a, b); +#elif defined(__CUDA_ARCH__) + return (uint32_t) __umulhi((unsigned int) a, (unsigned int) b); +#elif defined(_MSC_VER) && defined(_M_IX86) + return (uint32_t) (__emulu((unsigned int) a, (unsigned int) b) >> 32); +#elif defined(_MSC_VER) && defined(_M_ARM) + return (uint32_t) _MulUnsignedHigh((unsigned long) a, (unsigned long) b); +#else + return (uint32_t) (((uint64_t) a * (uint64_t) b) >> 32); +#endif +} + +static inline uint64_t pthreadpool_mulhi_uint64_t(uint64_t a, uint64_t b) { +#if defined(__OPENCL_VERSION__) + return mul_hi(a, b); +#elif defined(__CUDA_ARCH__) + return (uint64_t) __umul64hi((unsigned long long) a, (unsigned long long) b); +#elif defined(_MSC_VER) && defined(_M_X64) + return (uint64_t) __umulh((unsigned __int64) a, (unsigned __int64) b); +#elif defined(__GNUC__) && defined(__SIZEOF_INT128__) + return (uint64_t) (((((unsigned __int128) a) * ((unsigned __int128) b))) >> 64); +#else + const uint32_t a_lo = (uint32_t) a; + const uint32_t a_hi = (uint32_t) (a >> 32); + const uint32_t b_lo = (uint32_t) b; + const uint32_t b_hi = (uint32_t) (b >> 32); + + const uint64_t t = pthreadpool_mulext_uint32_t(a_hi, b_lo) + + (uint64_t) pthreadpool_mulhi_uint32_t(a_lo, b_lo); + return pthreadpool_mulext_uint32_t(a_hi, b_hi) + (t >> 32) + + ((pthreadpool_mulext_uint32_t(a_lo, b_hi) + (uint64_t) (uint32_t) t) >> 32); +#endif +} + +static inline size_t pthreadpool_mulhi_size_t(size_t a, size_t b) { +#if SIZE_MAX == UINT32_MAX + return (size_t) pthreadpool_mulhi_uint32_t((uint32_t) a, (uint32_t) b); +#elif SIZE_MAX == UINT64_MAX + return (size_t) pthreadpool_mulhi_uint64_t((uint64_t) a, (uint64_t) b); +#else + #error Unsupported platform +#endif +} + +struct pthreadpool_divisor_uint32_t { + uint32_t value; + uint32_t m; + uint8_t s1; + uint8_t s2; +}; + +struct pthreadpool_divisor_uint64_t { + uint64_t value; + uint64_t m; + uint8_t s1; + uint8_t s2; +}; + +struct pthreadpool_divisor_size_t { + size_t value; + size_t m; + uint8_t s1; + uint8_t s2; +}; + +static inline struct pthreadpool_divisor_uint32_t pthreadpool_init_uint32_t(uint32_t d) { + struct pthreadpool_divisor_uint32_t result = { d }; + if (d == 1) { + result.m = UINT32_C(1); + result.s1 = 0; + result.s2 = 0; + } else { + #if defined(__GNUC__) + const uint32_t l_minus_1 = 31 - __builtin_clz(d - 1); + #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64) || defined(_M_ARM) || defined(_M_ARM64)) + unsigned long l_minus_1; + _BitScanReverse(&l_minus_1, (unsigned long) (d - 1)); + #else + uint32_t l_minus_1 = 0; + uint32_t x = d - 1; + uint32_t y = x >> 16; + if (y != 0) { l_minus_1 += 16; x = y; } + y = x >> 8; + if (y != 0) { l_minus_1 += 8; x = y; } + y = x >> 4; + if (y != 0) { l_minus_1 += 4; x = y; } + y = x >> 2; + if (y != 0) { l_minus_1 += 2; x = y; } + if ((x & 2) != 0) { l_minus_1 += 1; } + #endif + uint32_t u_hi = (UINT32_C(2) << (uint32_t) l_minus_1) - d; + const uint32_t q = ((uint64_t) u_hi << 32) / d; + + result.m = q + UINT32_C(1); + result.s1 = 1; + result.s2 = (uint8_t) l_minus_1; + } + return result; +} + +static inline struct pthreadpool_divisor_uint64_t pthreadpool_init_uint64_t(uint64_t d) { + struct pthreadpool_divisor_uint64_t result = { d }; + if (d == 1) { + result.m = UINT64_C(1); + result.s1 = 0; + result.s2 = 0; + } else { + #if defined(__GNUC__) + const uint32_t l_minus_1 = 63 - __builtin_clzll(d - 1); + const uint32_t nlz_d = __builtin_clzll(d); + #elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_ARM64)) + unsigned long l_minus_1; + _BitScanReverse64(&l_minus_1, (unsigned __int64) (d - 1)); + unsigned long bsr_d; + _BitScanReverse64(&bsr_d, (unsigned __int64) d); + const uint32_t nlz_d = bsr_d ^ 0x3F; + #else + const uint64_t d_minus_1 = d - 1; + const uint32_t d_is_power_of_2 = (d & d_minus_1) == 0; + uint32_t l_minus_1 = 0; + uint32_t x = (uint32_t) d_minus_1; + uint32_t y = d_minus_1 >> 32; + if (y != 0) { l_minus_1 += 32; x = y; } + y = x >> 16; + if (y != 0) { l_minus_1 += 16; x = y; } + y = x >> 8; + if (y != 0) { l_minus_1 += 8; x = y; } + y = x >> 4; + if (y != 0) { l_minus_1 += 4; x = y; } + y = x >> 2; + if (y != 0) { l_minus_1 += 2; x = y; } + if ((x & 2) != 0) { l_minus_1 += 1; } + const uint32_t nlz_d = (l_minus_1 ^ UINT32_C(0x3F)) - d_is_power_of_2; + #endif + uint64_t u_hi = (UINT64_C(2) << (uint32_t) l_minus_1) - d; + + #if defined(__GNUC__) && defined(__x86_64__) + uint64_t q; + __asm__("DIVQ %[d]" + : "=a" (q), "+d" (u_hi) + : [d] "r" (d), "a" (UINT64_C(0)) + : "cc"); + #elif (defined(_MSC_VER) && _MSC_VER >= 1920) && !defined(__clang__) && !defined(__INTEL_COMPILER) && defined(_M_X64) + unsigned __int64 remainder; + const uint64_t q = (uint64_t) _udiv128((unsigned __int64) u_hi, 0, (unsigned __int64) d, &remainder); + #else + /* Portable implementation */ + uint64_t d_shift = d << nlz_d; + uint64_t u_hi_shift = u_hi << nlz_d; + const uint64_t d_hi = (uint32_t) (d_shift >> 32); + const uint32_t d_lo = (uint32_t) d_shift; + + uint64_t q1 = u_hi_shift / d_hi; + uint64_t r1 = u_hi_shift - q1 * d_hi; + while ((q1 >> 32) != 0 || pthreadpool_mulext_uint32_t((uint32_t) q1, d_lo) > (r1 << 32)) { + q1 -= 1; + r1 += d_hi; + if ((r1 >> 32) != 0) { break; } + } + u_hi_shift = (u_hi_shift << 32) - q1 * d_shift; + uint64_t q0 = u_hi_shift / d_hi; + uint64_t r0 = u_hi_shift - q0 * d_hi; + while ((q0 >> 32) != 0 || pthreadpool_mulext_uint32_t((uint32_t) q0, d_lo) > (r0 << 32)) { + q0 -= 1; + r0 += d_hi; + if ((r0 >> 32) != 0) { break; } + } + const uint64_t q = (q1 << 32) | (uint32_t) q0; + #endif + result.m = q + UINT64_C(1); + result.s1 = 1; + result.s2 = (uint8_t) l_minus_1; + } + return result; +} + +static inline struct pthreadpool_divisor_size_t pthreadpool_init_divisor(size_t d) { +#if SIZE_MAX == UINT32_MAX + const struct pthreadpool_divisor_uint32_t uint_result = pthreadpool_init_uint32_t((uint32_t) d); +#elif SIZE_MAX == UINT64_MAX + const struct pthreadpool_divisor_uint64_t uint_result = pthreadpool_init_uint64_t((uint64_t) d); +#else + #error Unsupported platform +#endif + struct pthreadpool_divisor_size_t size_result = { + (size_t) uint_result.value, + (size_t) uint_result.m, + uint_result.s1, + uint_result.s2 + }; + return size_result; +} + +static inline uint32_t pthreadpool_quotient_uint32_t(uint32_t n, const struct pthreadpool_divisor_uint32_t divisor) { + const uint32_t t = pthreadpool_mulhi_uint32_t(n, divisor.m); + return (t + ((n - t) >> divisor.s1)) >> divisor.s2; +} + +static inline uint64_t pthreadpool_quotient_uint64_t(uint64_t n, const struct pthreadpool_divisor_uint64_t divisor) { + const uint64_t t = pthreadpool_mulhi_uint64_t(n, divisor.m); + return (t + ((n - t) >> divisor.s1)) >> divisor.s2; +} + +static inline size_t pthreadpool_quotient_size_t(size_t n, const struct pthreadpool_divisor_size_t divisor) { +#if SIZE_MAX == UINT32_MAX + const struct pthreadpool_divisor_uint32_t uint32_divisor = { + (uint32_t) divisor.value, + (uint32_t) divisor.m, + divisor.s1, + divisor.s2 + }; + return pthreadpool_quotient_uint32_t((uint32_t) n, uint32_divisor); +#elif SIZE_MAX == UINT64_MAX + const struct pthreadpool_divisor_uint64_t uint64_divisor = { + (uint64_t) divisor.value, + (uint64_t) divisor.m, + divisor.s1, + divisor.s2 + }; + return pthreadpool_quotient_uint64_t((uint64_t) n, uint64_divisor); +#else + #error Unsupported platform +#endif +} + +static inline struct pthreadpool_div_result pthreadpool_divide_with_divisor(size_t n, const struct pthreadpool_divisor_size_t divisor) { + const size_t quotient = pthreadpool_quotient_size_t(n, divisor); + const size_t remainder = n - quotient * divisor.value; + struct pthreadpool_div_result result = { quotient, remainder }; + return result; +} + +// --- End FXdiv-like implementation --- + #endif // __PTHREADPOOL_SRC_THREADPOOL_UTILS_H_