mirror of
https://github.com/opencv/opencv.git
synced 2026-12-06 06:55:35 -06:00
* experimental new arithmetics; work-in-progress * continue working on new-gen arithmetic expressions * * improved performance of the new add on small arrays * added sub * extended tests * fixed potential bug when adding multi-channel array and a single-channel scalar * improved const handling * * added copyMask * added mul/dev (without scale so far) * * accelerated mul * addedd scale to mul and div * * done substantial refactoring; however a few more rounds of refactoring are ahead. * added min, max, absdiff, addweighted. * improved performance of the new arithmetic functions, but some of them are still slow, e.g. operations with mask have some bugs (that affect speed, not accuracy). * * further (significantly) accelerated several functions, especially on small arrays: mul, binary ops with mask * further polished the new arithmetic engine * started integration of the new element-wise arithmetic engine into core * big step forward. We now use the new engine inside cv::add, subtract, multiply, divide, absdiff, min and max. * big progress: * added bitwise operations * fixed and accelerated compare * ported regression tests to test new broadcasting behaviour of arithmetic functions * lot's of improvements in compare, divide, addWeighted! * lot's of small and big performance improvements in the new arithmetics * * some more optimizations; parsing texpr-expressions is now faster as well * port new_arithm to Linux/x86: dispatch guards, scalar-Mat compat fallback, dnn shape-contract fixes Core: - arithm.simd.hpp: CV_CPU_OPTIMIZATION_DECLARATIONS_ONLY guards (the file is included once per dispatched mode on x86), vx_load_expand instead of the 128-bit v_load_expand, VTraits::vlanes() instead of ::nlanes - arithm.cpp/precomp.hpp: compat fallback for scalar-like Mat operands (1x1, 1xcn/cnx1, 4x1 CV_64F - java/python tuples, operator-(Mat, Matx)): treated as a per-channel scalar ONLY when the shapes are not broadcast-compatible, so every valid numpy-style broadcast keeps its meaning and calls that would otherwise throw get the 4.x semantics DNN (fallout of the stricter shape semantics, found by the new engine): - dict.hpp: DictValue relied on fresh AutoBuffer having size()==fixed_size; allocate explicitly - batch_norm: weights_/bias_ are 1-D [n] now; 0/1-D forward runs on exact-shape 1-D views - net_impl2: extend the post-forward sanity check to non-temp outputs - a layer that reallocates its preallocated output tensor now fails loudly instead of silently detaching the result from the graph - LSTM/LSTM2 batchwise (layout=1): getMemoryShapes now matches what forward() writes (ONNX: Y=(batch,seq,dirs,hid), Yh/Yc=(batch,dirs,hid)); forward assembles seq-major results in a local buffer and transposes INTO the preallocated outputs in place Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * u8/s8 multiply: exact integer SIMD path on non-FP16 builds (3-10x vs 5.x) The unit-scale branch of vecBinaryKernel already supported a separate work-vector type Wvec1 (used by the ARM f16 build and by u16/s16 everywhere), but on x86 the u8/s8 same-type multiply still went through the f32 hub. Route it through v_uint16/v_int16: products of 8-bit values fit exactly (255^2 < 2^16), the saturating pack on store gives bit-exact results at half the vector traffic. Also fix a latent kernel bug this exposed: the unit-scale branch stepped by Wvec's lane count while loading/storing Wvec1 vectors. All previous Wvec1 instantiations had equal lane counts, but u8's v_uint16 has 2x the lanes of v_float32 - the pairs overlapped (50% redundant work) and the tail backoff could write VECSZ bytes past the row end. The branch now derives its step, offsets and tail condition from Wvec1 itself. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * vecBinaryKernel: constexpr Op::useScalar instead of a runtime-only scale check Every binary op functor now declares whether it consumes the scale scalar (params[0]): true only for mul and the two div variants. Ops that ignore it (add/sub/min/max/absdiff) take the fast 2-arg branch unconditionally - the 'scalar == 1' check used to fail for them (their params[0] is 0), sending them through the preproc branch, and the condition now folds at compile time. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * restore cv::hal::mul8u as a wrapper over the element-wise engine The symbol is still declared in core/hal/hal.hpp and called directly by external code (the G-API fluid backend in opencv_contrib), but its implementation went away with the old arithm kernels. Forward it to getMulFunc(CV_8U, CV_8U) - with scale==1 it lands on the new exact integer SIMD path. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * silence every new-arithm warning reported by CI (ARM64/Mac) and gcc 15 - arithm.cpp: bitwise_op_ocl and the actualScalarDepth/coerceTypes helpers are consumed only by the OpenCL paths - guard them with HAVE_OPENCL; haveScalar in cv::compare is read only inside CV_OCL_RUN - CV_UNUSED for OpenCL-less builds - arithm_expr.hpp: declare getBitwiseFunc/getNotFunc/getAddWeightedFunc next to the other per-op entry points (-Wmissing-prototypes in arithm.dispatch.cpp) - arithm.simd.hpp: define CV_SIMD_16F to 0 when FP16 SIMD is absent (-Wundef); {}-init the expandScalar staging buffers (-Wmaybe-uninitialized: they are fully written before use, but the compiler cannot prove it with runtime vector widths); rename the compare kernel's lambda parameter (-Wshadow) - arithm_expr.cpp: rename the exec tile-lambda's hot-field locals that shadowed TExpr members and outer locals (-Wshadow) - test_new_arithm_extensive.cpp: rename the name-generator lambdas' parameter shadowing the INSTANTIATE macro's own (-Wshadow), drop an unused variable Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * restore 4.x scalar semantics for the bindings' 4x1 CV_64F Scalar columns The python/java bindings materialize numbers and tuples as a 2-D 4x1 CV_64F Mat - or UMat, when the call carries UMat arguments. Three CI-reported python failures came from those pseudo-scalars reaching the engine as arrays: - absdiff(int_arr, 0): the (4,1) column is broadcast-COMPATIBLE with a 1-D array, so numpy semantics silently won - an outer-product f64 result instead of the int per-channel-scalar one; - subtract(u8 4x8x4, (40,)): same, by the rows==4 coincidence; - multiply(UMat, 2., dst=UMat): the scalar arrives as a UMAT, which the scalar detection did not recognize at all. isScalarArg now treats the exact bindings shape - 2-D 4x1 CV_64F single-channel Mat/UMat against a <=4-channel array - as a scalar UNCONDITIONALLY (a 1-D [4] array has dims==1 and still broadcasts). One exception, decided in arithm_op: when the partner is itself a tiny scalar-shaped array, both are honest data and ride the broadcast (compare(Mat 4x1, Mat 1x1) - issue #8999 - stays elementwise). Small-array discipline, this all runs per engine call: the probes read Mat/UMat fields directly (rows == 4 alone rejects almost everything, no _InputArray getter dispatch), and a UMAT scalar's 32 bytes are copied into a caller-stack buffer - no heap, no getMat mapping. Measured: no latency change on 4x4/16x16 element-wise calls. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * cv::texpr: std::string_view -> const std::string& in the public API string_view in an exported signature breaks some CUDA toolchain builds, and for short expression strings the difference is immaterial (SSO, parsed once). The parser internals keep string_view - the argument converts implicitly. Also drop the now-unused <string_view> include from cvstd.hpp, so the header does not reach every nvcc TU. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * compare boundary-rewrite: fixed 4-slot kind/bound arrays instead of AutoBuffers A CONST operand is capped at 4 channels (addConst), so the per-channel kind/bound staging needs no dynamic buffers - plain int[4]/double[4], with a CV_Assert on the contract. This is also what gcc's -Wmaybe-uninitialized was flagging (it could not see the AutoBuffer's inline storage get filled). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * element-wise engine: unary math kernels (sqrt/exp/log/sin/cos/tanh/erf/relu) + select New dispatched pair math.simd.hpp / math.dispatch.cpp - the unary/ternary sibling of arithm.simd.hpp: - vecUnaryKernel: T -> T over f16/bf16/f32/f64 on top of the intrin_math primitives (v_exp/v_log/v_sin/v_cos/v_sqrt/v_erf/v_max). f32/f64 compute natively, f16/bf16 ride the f32 hub inside the kernel (vx_load_pair_as / v_store_pair_as) - no materialized casts. Continuity collapse + the halide right-edge backoff, suppressed in-place (it would re-apply Op to already-written values). tanh = (e^2x-1)/(e^2x+1) with the input clamped to +/-10 (f32) / +/-20 (f64) - unclamped saturation hits inf/inf = NaN. erf has no f64 SIMD primitive: std::erf per lane. - selectKernel(mask, x, y): 1-byte mask expanded to lane width and tested against zero in the INTEGER domain (immune to DAZ/FTZ), branches of any depth by element size, broadcast branches supported. - emitUnary: math over a float input is T -> T now (f16 in -> f16 out, native kernel when input and result depths match); integer inputs still compute in the float domain and land in f32. - emitTernary/select: literal branches are typed via typedConstFrom (an OP_CAST of a depth-less flex const crashed); a non-1-byte mask is normalized by an explicit "mask != 0" compare, never a value cast. texpr already parsed the function names - they now execute. Tests: per-depth accuracy of all 8 ops against the double std:: reference, integer input, in-place, select over 4 depths / const branch / float mask. Perf vs the classic kernels (1920x1080 f32, 16 threads, AVX2): exp 3.7x, log 2.6x, sqrt 5.7x faster; polarToCart expressed as (r*cos(a), r*sin(a)) 4.0x. Accuracy improves too (max rel err vs f64 reference): exp 8.1e-8 vs 2.1e-7, log 8.0e-8 vs 1.5e-7. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * engine: OP_COPY_MASK folded into OP_SELECT; selectKernel moved to arithm.simd.hpp copyMask(dst, mask, src) is select(mask, src, dst) - one masking primitive instead of two. The compiler emits the masked-op tail as addInsn(OP_SELECT, mask, r, out, out): the output slot rides as both arg2 and the result, so unmasked elements are preserved by reading them back through the b-branch. OP_COPY_MASK, copyMaskKernel and getCopyMaskFunc are gone. selectKernel (moved from math.simd.hpp to arithm.simd.hpp) inherits every copyMaskKernel optimization: - the interleaved multichannel fast path (2..4 channels under a per-pixel mask: expand the mask once per VECSZ rows, v_store_interleave across lanes); - the per-row scalar path with the row-skip when the selected source row IS dst (the "leave the output untouched" half of copyMask); - plus the select-specific ones: branch broadcasts (stepx == 0) and the right-edge tail backoff under dst-aliases-a-branch - safe because re-running select over already-blended elements is idempotent; only dst == mask keeps the backoff off (the store would rewrite mask bytes before the re-read). Masked-add perf is on par with the old copyMask (1280x720, 1 thread: 8UC3 204 -> 198 us, 32FC3 1395 -> 1344, 8UC1/32FC1 within noise). Full core suite 24117 green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * engine: dedicated vectorized pow kernel (moved from arithm to math.simd.hpp) pow was the last scalar-only binary op (scalarBinaryKernel + std::pow, f32/f64 only). The new powKernel keeps exact std::pow semantics and is T x T -> T over all four float depths (f16/bf16 via the f32 hub): - scalar exponent (the dominant call shape - texpr literals ride as 0-dim broadcast consts) is dispatched PER ROW to the special cases: y==2 -> x*x, y==3 -> x*x*x, y==0.5 -> v_sqrt, y==1 -> copy, y==0 -> fill 1; - everything else - including a per-element exponent array - runs the general vectorized exp(y * log(x)) path, valid for x > 0; a vector pair containing any x <= 0 lane falls back to scalar std::pow for that pair (v_check_any), which preserves every std::pow subtlety: signed results for integer y on negative bases, NaN for fractional y, the x == 0 family; - no right-edge tail backoff: pow is not idempotent, in-place calls finish rows in the scalar tail. Perf vs the classic cv::pow (1920x1080 f32, 16 threads, AVX2): p=2 1.4x (classic special-cases it too), p=3 6.1x, p=0.5 6.3x, fractional p 4.5x with slightly better accuracy (6.1e-7 vs 7.4e-7 max rel err). Tests: exponent sweep 2/3/0.5/1/0/2.5/-1.5 vs the double std::pow reference on f32/f64, negative bases (exact signed cubes, NaN for fractional), array exponent. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * powKernel: halide right-edge tail backoff in every SIMD loop Same shape as vecBinaryKernel: the final partial vector re-processes [width - VECSZ*2, width) instead of finishing scalar, suppressed when dst aliases an input (pow is not idempotent - the overlap region must be recomputed from an untouched source, which the no-alias case guarantees). Modest measured win (~2% on ROI rows for the special-cased exponents; the general path tail was already cheap - modern libm powf is fast), no regressions; mainly aligns the kernel with the house style, where every SIMD loop ends vector-wide. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix MSVC 2019 C2975: function-local constexpr as a template argument inside a lambda MSVC 2019 loses the constexpr-ness of function-local constants (LOCAL_OPS, MAX_DIMS, ...) when they are used as template arguments inside a lambda body (AutoBuffer<Slice, LOCAL_OPS> / std::array<int, MAX_DIMS> in the parallel bodies of BroadcastOp::run and TExpr::exec). Hoist them to namespace scope - no behavior change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * ocl_arithm_op: route 16U multiply to the CPU engine on Apple OpenCL The Apple OpenCL driver miscompiles the 16U multiply kernel: products near the top of the u16 range come back wrapped instead of saturated (CPU vs GPU NORM_INF up to 65535 in OCL_Arithm/Mul.Mat CV_16U cases). The same arithm.cl kernel is correct on Intel NEO and NVIDIA drivers - verified not to reproduce on Linux/Intel iGPU - so gate the decline to __APPLE__ only; the CPU engine computes 16u multiply exactly (integer SIMD path). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * engine: neg/abs as compositions, clamp kernel, ** and ?: operators, abs(a-b) peephole - OP_NEG and OP_ABS need no kernels: neg = sub(0, a), abs = absdiff(a, 0) - including the engine absdiff auto-type rule (signed |a| lands in the UNSIGNED type of the same width: |SHRT_MIN| fits u16 exactly instead of saturating; NB the public cv::absdiff auto depth keeps the source type for 4.x compatibility - values agree, the depth rule is the engine own). - peephole: abs(x - y) rewrites to absdiff(x, y) ALWAYS. On integers the literal semantics differ (the subtract saturates first: u8 gives max(x-y, 0)), but whoever writes abs(a - b) means absdiff - we deliberately hand out the useful semantics instead of the saturation artifact. The just- emitted OP_SUB is retired via the moveToOutput manoeuvre, so the program shrinks to the single absdiff instruction. abs(x), abs(x - 0) and absdiff(x, 0) all give one result. - OP_CLAMP kernel (arithm.simd.hpp): v_min(v_max(x, lo), hi) over u8/s8/u16/s16/u32/s32/f32 (+f64 with 64-bit SIMD), scalar f16/bf16/64-bit ints; lo/hi may broadcast (the common clamp(img, a, b) shape) or be full arrays; the tail backoff stays on under dst-aliases-x (clamp is idempotent). emitTernary types literal bounds via typedConstFrom (same flex-const crash select had) and keeps the auto result type pinned to x. - parser: "a ** b" == pow(a, b), precedence above * /, RIGHT-associative (a ** 2 ** 3 == a ** 8); "cond ? a : b" == select(cond, a, b), precedence below everything, right-associative chains (f1 ? a : f2 ? b : c) work without parentheses. parseTernary() is the expression entry point now. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * cv::exp/log/sqrt on the engine via math_op; hal functions wrapped as engine kernels math_op is the master function of the unary math family (the arithm_op analogue): same-shape same-type output over f16/bf16/f32/f64 (classic exp/log accepted f32/f64 only - the half floats are new), two tiers: - small (<= 100000 elements) and continuous: call the kernel DIRECTLY over the flattened data - no TExpr, no broadcastOp, no parallel_for setup; - everything else: the usual single-instruction program via compile()/exec() (parallelism for large arrays, real steps for ROIs). getMathFunc routes OP_EXP/OP_LOG at f32/f64 through the full cv::hal stack - an external vendor HAL (CALL_HAL), IPP, or the built-in table kernels, whichever is installed - by wrapping hal::exp32f/exp64f/log32f/log64f as engine kernels with the function pointer in TKernel::userdata, the same mechanism castKernel uses for core BinaryFuncs. The engine adds tiling and parallelism on top, so every tier gets the best available scalar-span implementation. v_exp/v_log remain for f16/bf16 (the f32 hub) and the ops hal has no entry points for. v_log_default_32f: the degree-8 polynomial is evaluated by Estrin pairing (4 dependent levels) instead of an 8-FMA Horner chain (~5% on the f16 hub path). An exp64 Taylor-without-division rewrite was tried and benched SLOWER than the Cephes Pade scheme (the evaluation is FMA-throughput-bound, and vdivpd pipelines well enough) - reverted; a table-based reduction is the only way further there. cv::exp f32 (16 threads, AVX2+IPP build), old -> new: 640 elements 0.16 -> 0.15 us, 16k 2.79 -> 2.49, 640x480 47 -> 20, 1920x1080 452 -> 60 us (the old CPU loops were single-threaded); f64 exp 1080p 1295 -> 161 us. No size regresses; small arrays now run at installed-HAL speed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * getMathFunc: IPP tier + raw-HAL probing; the exp/log table kernels are deleted The raw cv_hal_* entry points return int for a reason: without an installed HAL they are stubs returning CV_HAL_ERROR_NOT_IMPLEMENTED. getMathFunc now selects the exp/log implementation in three tiers: 1. HAVE_IPP && ipp::useIPP(): ippsExp/ippsLn through thin int adapters (IPP is not routed through the cv_hal_ hooks, so it needs its own tier); 2. the raw cv_hal_exp32f/... hook, PROBED once with a 1-element call on the safe input 1.0 (cached in magic statics): implemented -> wrapped as an engine kernel with the function pointer in TKernel::userdata; 3. the engine own v_exp/v_log kernels. Whichever wins, the engine adds tiling and parallelism on top. The EXPTAB/LOGTAB table kernels and their tables (~790 lines in mathfuncs_core.simd.hpp + mathfuncs.cpp) are DELETED: they benched within ~15% of v_exp/v_log, not worth a second implementation. The public cv::hal::exp32f/exp64f/log32f/log64f keep their contract - CALL_HAL, then IPP, then the built-in implementation - but the built-in is now the engine vector kernel via ew::mathSpanEngine (one contiguous span, exported from math.dispatch.cpp). All unary math kernels (vec/scalar/hal wrappers, pow) also handle the vertical-broadcast tile (s0y == 0, a row expanded into a matrix): the first row is computed, the rest are memcpy of it - transcendentals cost far more than a row copy. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * texpr: hypot(x, y) binary op (alias: mag) hypot = sqrt(x^2 + y^2), NAIVE like cv::magnitude (not the overflow-safe std::hypot), computed in the float work type; kernels for the four float depths only (T x T -> T; integer inputs ride the usual f32-compute + cast). A 10-line EwHypot functor on top of vecBinaryKernel in arithm.simd.hpp - broadcast branches, continuity collapse and the tail backoff come for free. Registered in the parser as both "hypot" (the C/numpy name) and "mag" (the cv::magnitude-flavored alias). A building block for the future cartToPolar. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * texpr: atan2(y, x) binary op - radians, standard C range v_atan2 (arithm.simd.hpp, generic over the universal-intrinsic float vector): the fastAtan2 minimax polynomial from mathfuncs_core v_atan_f32 reworked to plain radians - the 180/pi factor dropped from the coefficients and the C quadrant logic instead of the [0, 360) wrap, so the result matches std::atan2 over (-pi, pi]. Measured absolute accuracy ~1.6e-4 rad. (v_atan_f32 itself is untouched - cv::phase/fastAtan2 keep their degree semantics.) EwAtan2 rides vecBinaryKernel: f16/bf16/f32 through v_atan2 (the f32 hub), f64 through exact scalar std::atan2. arg0 = y, arg1 = x, like std::atan2; float depths only, same emitBinary policy as pow/hypot. Parser name "atan2". Together with hypot this completes the cartToPolar building blocks. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix the RISC-V RVV build and two ARM64 warnings The new f64 kernel registrations (hypot, pow, the unary math family) gate on CV_SIMD_64F || CV_SIMD_SCALABLE_64F, but the vx_setall_as(const double*, v_float64&) helper family in arithm.simd.hpp was still CV_SIMD_64F-only - scalable platforms (RVV) have v_float64 with CV_SIMD_64F == 0, so vecBinaryKernel<double, ...> failed to instantiate there. Widen the helper gate to match (verified with a riscv64 rv64gcv cross-build of opencv_core - the engine f64 paths now vectorize on RVV instead of not compiling). cv::exp/cv::log: the depth local is consumed by CV_OCL_RUN only - CV_UNUSED for OpenCL-less builds (ARM64 -Wunused-variable). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * silence the remaining ARM64 gcc warnings - compare boundary-rewrite: {}-init the fixed kind/bound arrays (filled for every channel used below, but gcc cannot prove it across the cn <= 4 loop); - cv::exp/log: [[maybe_unused]] on the depth local (consumed by CV_OCL_RUN only), instead of the CV_UNUSED idiom; - AutoBuffer::reserve: a targeted -Wmaybe-uninitialized suppression around the live-element copy loop - only [0, sz) is read, all written before, but gcc inlining a grow-from-inline-storage chain cannot see that. An annotation for the analyzer, no behavior change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * saturating 32-bit add/sub kernels; cv::texpr python binding; two CI warnings - v_add_sat/v_sub_sat for v_int32/v_uint32, local to arithm.simd.hpp for now (the plan is to grow them into proper universal intrinsics later): NEON single-instruction vqadd/vqsub, elsewhere the Hacker Delight bit tricks over universal intrinsics (u32 add is 2 ops: or with the wrapped-compare mask). EwAdd/EwSub overload vec() for the 32-bit lanes and getAddSubFunc routes 32S/32U T->T through vecBinaryKernel instead of the former pure scalar kernel. Semantics unchanged - the scalar int64 tail already saturated; directed boundary tests added (both rails, 0 - INT_MIN, u32 cases, a full-range random block vs an exact int64 reference). 640x480 32S add: 0.48x of 5.x -> parity (memory-bound); 1080p: 6-8x. - cv::texpr becomes CV_EXPORTS_W: python gets cv.texpr(expr, [inputs]) -> tuple of ndarrays, so `res, = cv.texpr(...)` and `mag, ang = cv.texpr(...)` unpacking both work. modules/python/test/test_expr.py covers arithmetic, the fused abs(a-b), casts, broadcasting, ?: and ** operators, math functions vs numpy, clamp, named temporaries, tuple outputs, the one-line cartToPolar and the int32 saturation cases. - warnings: {}-init the parser args array (gcc -Wmaybe-uninitialized on Ubuntu 20/22); the compare short-row block gates sizeof(T) <= 4 as constexpr so the f64 instantiation does not leave set-but-unused locals (gcc 9 -Wunused-but-set-variable). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * arithm_op: direct-kernel fast path for small continuous arrays Building and compiling the 1-instruction program plus the BroadcastOp setup costs ~40-250ns per call - negligible on big images, dominant at 127x61-class sizes where the classic 5.x functions were 1.3-2x faster. Mirror math_op two tiers in arithm_op: two same-type same-shape continuous arrays, no mask, no scalar, result depth == input depth, <= 100k elements -> call the T x T -> T kernel directly over the flattened elements (checks ordered cheapest-first). Applies to add/subtract/min/max/absdiff/multiply/addWeighted/and/or/xor; compare and divide lower to more than a single kernel (boundary rewrites, int guards) and keep the ordinary path. addWeighted falls through automatically for the 32/64-bit int types whose lowering is wide-compute + cast (getElemwiseFunc returns no direct kernel there). 127x61 vs 5.x, was -> now: add/subtract 8UC1 0.76x -> 1.3x, min/max u8 0.6x -> ~1x, addWeighted 1.0x -> 1.1-1.4x (32SC1 stays 4.5x); the one remaining laggard is add/sub 32SC1 (0.74-0.82x) - the price of the new SATURATING semantics (7-instruction AVX2 emulation vs the wrapping single add of 5.x; single-instruction on NEON). The 127x61 size is ADDED PERMANENTLY to the arithmetic/addWeighted/compare perf grids: per-call overhead regressions in these base functions must be caught by CI, not discovered by users. dst creation goes through createSameSize (whole-shape transfer including layout and future metadata, not piecemeal dims+sizes) here and in math_op. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * cv::pow rebuilt on the engine; integer-exponent and 1/sqrt(x) kernel branches Routing: p = 0/1/2 keep their early special cases (fill/copy/multiply); an INTEGER array with an INTEGER power keeps the classic iPow multiply chain - bit-exact compatibility, including its wrap-around quirks (iPow squares in int, so e.g. pow(255,4) on u8 wraps negative and saturates to 0 - somebody may rely on that). Everything else goes through the engine with the math_op two-tier scheme: small continuous arrays call powKernel directly (the exponent rides as a broadcast T scalar), the rest run the tiled parallel program. Integer arrays with fractional powers compute in the float domain and saturate back; the 32U/64-bit depths (classic iPow asserted on them) and f16/bf16 (the classic float path misread them) now just work. powKernel gets two new per-row exponent branches: - p == -0.5: 1/v_sqrt(x) (the classic path used IPP ippsInvSqrt_A21, a 21-bit approximation; ours is exact - slightly slower on small arrays, 4.5x faster at 1080p via parallelism); - any other INTEGER p (|p| <= 65536): LSB-first binary exponentiation, the same multiply chain and order as iPow, fully vectorized - a few ulp accurate vs ~2e-7 of exp(p*log x), and exact on non-positive bases (the sign falls out of the multiplies, 0^negative divides to inf) - no scalar patching. cv::pow f32 vs 5.x: p=0.5 365 -> 61 us at 1080p (6x), p=3 7.7x, p=5 7x AND faster at every size (the old scalar chain: 0.81 -> 0.47 us at 127x61), p=2.5 5.3x. The s16^5 iPow path is untouched (118.7 == 118.5 us). pow_exponents accuracy tests extended to 11 exponents x f32/f64 against the double std::pow reference. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * perf: SANITY_CHECK_NOTHING for the tests whose grids got the 127x61 size The 127x61 entry added to guard per-call overhead has no regression data in opencv_extra, so the legacy SANITY_CHECK in addWeighted/compare failed on CI (locally it passes silently without the test-data path). Accuracy of both functions is covered by the accuracy suite; the perf tests should measure time. PatchNaNs/finiteMask keep their SANITY_CHECK - their grids are untouched. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix a temp-buffer double release in the liveness pass ("d*d" crash) When the same temp is passed as SEVERAL arguments of its last-use instruction (e.g. the named-intermediate expression "d = {0} - {1}; d*d", where the MUL consumes slot d twice), the buffer-reuse scan pushed the temp's physical buffer onto the free list once per argument. That overflows the ntemps-sized freeBufs array (caught by the AutoBuffer range check in Debug: python test_expr.py::test_named_temporary) and, in larger programs, would hand the same physical buffer to two live temps. Release the buffer once by retiring lastUse[t] after the first hit. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * executor: recalibrate opCost to vectorized cycles + clamp the stripe count The per-element op costs fed into the parallel_for_ stripe hint were scalar-era estimates (~20x above the vectorized reality: the atan2/exp polynomials run at ~1.5 cycles/element, not 30). The hint therefore split transcendental/divide work into hundreds of ~1 us jobs, which the macOS/GCD backend dispatches poorly under sustained load, on top of the P/E-core equal-share straggler effect. Measured on M4 Max (12P+4E), sustained medians @1920x1080 f32: texpr atan2 320 -> 133 us, cv::exp 280 -> 141 us, cv::log 301 -> ~200 us, cv::pow(x,2.5) 388 -> 376 us; the PR tables' math rows improved ~1.5-2x across the board. - opCost is now in units of ~1/4 cycle/element of the SIMD kernels: cheap ops 1 (unchanged), div/sqrt/hypot/convert_scale 10 -> 3, transcendentals 30 -> 6. - the stripe hint is clamped by min(4*nthreads, max(32, 3*nthreads)): ~4 stripes/thread is plenty of granularity for element-wise work, and the ceiling is 32 pieces except on machines with many (heterogeneous) cores, where anything coarser than ~3 pieces/worker turns the slow cores into equal-share bottlenecks (measured: 32 stripes on 16 threads is the worst point of the curve - 193 us vs 137 us at 48 for atan2). getNumThreads() is clamped from below (WINRT/plugin backends may report 0). Not addressed here (needs cross-machine data, M2/M3 Ultra): streaming memory-bound ops saturate the M4 Max fabric at ~8 fat stripes and E-core participation only adds contention - a cost model cannot express that; candidate follow-up is a bytes-aware clamp or a GCD-backend-level fix. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * multiply: v_mul_sat integer kernels (full product clamped to the type) v_mul_sat(V, V) -> V for u8/s8/u16/s16/u32/s32 - the full-precision product clamped to the lane type, which is exactly cv::multiply's integer semantics at scale == 1. Local to arithm.simd.hpp for now, next to v_add_sat/v_sub_sat, to be promoted into proper universal intrinsics later. NEON: widening vmull + saturating narrow (vqmovn); other backends: the portable v_mul_expand + saturating v_pack composition for 8/16-bit lanes. 32-bit lanes have no universal widening multiply (no v_mul_expand for s32), so the 32-bit integer fast path is NEON-only for now and the other backends keep the previous f64 work-vector kernels (which measure well on x86 with IPP-free AVX2). EwMul::vec() now routes the integer lane types through v_mul_sat, and getMulFunc_ passes the NATIVE lane vector as the scale==1 fast-path type: whole-register loads/stores, the widening happens inside the multiply. Replaces both the half-register widening loads (u8/s8/u16/s16) and the scalar-equivalent f64 path for 32S/32U on NEON. M4 Max, 640x480 (the sizes where the old kernels lost to carotene): 8U 22.0 -> 13.6 us, 8S 15.0 -> 11.1, 16S 21.2 -> 17.4, 32S 84.8 -> 30.5 (parity with the classic path everywhere, 32S was 0.38x). 1920x1080: 8S 1.30x -> 1.78x, 16S 2.57x -> 2.98x, 32S 2.20x -> 4.02x vs 5.x. Correctness: exhaustive 8-bit (all 65536 pairs per sign), directed saturation corners for 16/32-bit (46341^2, INT_MIN*-1, 65536*65536, all sign combinations) against an exact int64 reference. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * NEON: make v_cvt_f64(v_int32) exact (was via f32, losing bits > 2^24) The NEON implementations of v_cvt_f64/v_cvt_f64_high for v_int32 did s32 -> f32 -> f64 (vcvt_f32_s32 + vcvt_f64_f32), silently rounding any |x| > 2^24. Every vectorized f64 work path with int32 inputs on AArch64 was affected: the engine's addWeighted/divide 32S kernels, convertTo 32S -> 64F, etc. Found via addWeighted 32SC1 on values ~1e9: max error was 32 vs the exact double reference (the classic carotene path is worse still - it computes in f32 end-to-end with f32-truncated weights, max error 96 on the same data). The exact sequence sxtl + scvtf (vmovl_s32 + vcvtq_f64_s64) is the same 2 instructions, so there is no cost. addWeighted 32SC1 on the engine now matches the exact-double reference bit-for-bit and stays at parity/1.4x vs the classic path (640x480/1920x1080). Pre-existing upstream bug (same code in 4.x) - worth a standalone backport with directed large-value tests. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * math_op: drop the temporary direct-IPP tier for exp/log Upstream moved the IPP math wrappers into the hal/ipp HAL module (cv_hal_exp32f/ log32f & co now resolve to ipp_hal_* which honor cv::ipp::useIPP via CV_HAL_CHECK_USE_IPP). The engine's single probeHalUnary(cv_hal_*) probe already picks that up uniformly, so the stopgap #ifdef HAVE_IPP ippExp/ippLog tier and its ipp::useIPP() branch in getMathFunc are now redundant - removed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * arithm: restore cv::hal::and8u/or8u/xor8u/not8u as engine wrappers These public CV_EXPORTS entry points (core/hal/hal.hpp) lost their definitions when the bitwise ops moved to the element-wise engine, but they are still declared and called by other modules (opencv_objdetect's aruco) and external code - the link broke with undefined references to cv::hal::and8u/xor8u. Restore them as thin forwarders over the engine's byte-wise bitwise kernels (getBitwiseFunc / getNotFunc), mirroring the existing mul8u wrapper. CV_Assert guards the kernel lookup. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * blobdetector: guard empty contour when computing blob radius The new AutoBuffer leaves its tail uninitialized for trivial types, which surfaced a -Wmaybe-uninitialized in findBlobs where the median of per-point distances is read. Use a std::vector, default the radius to 0, and compute the median only for a non-empty contour - no unproven size invariant. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
828 lines
32 KiB
C++
828 lines
32 KiB
C++
// This file is part of OpenCV project.
|
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
|
// of this distribution and at http://opencv.org/license.html
|
|
|
|
#include "precomp.hpp"
|
|
#include "convert.hpp"
|
|
|
|
#if !defined(OPENCV_SUPRESS_WARNING_AVX2_WITHOUT_FP16C) && \
|
|
(defined(__GNUC__) && defined(__AVX2__) && !defined(__F16C__))
|
|
#warning "Non-optimal compiler flags: AVX2 without FP16. Generated code is very slow. Consider adding '-mf16c' compiler option."
|
|
#endif
|
|
|
|
namespace cv {
|
|
namespace hal {
|
|
CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN
|
|
|
|
void cvt16f32f(const hfloat* src, float* dst, int len);
|
|
void cvt32f16f(const float* src, hfloat* dst, int len);
|
|
void cvt16bf32f(const bfloat* src, float* dst, int len);
|
|
void cvt32f16bf(const float* src, bfloat* dst, int len);
|
|
void addRNGBias32f(float* arr, const float* scaleBiasPairs, int len, int cn);
|
|
void addRNGBias64f(double* arr, const double* scaleBiasPairs, int len, int cn);
|
|
|
|
CV_CPU_OPTIMIZATION_NAMESPACE_END
|
|
} // namespace cv::hal
|
|
|
|
CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN
|
|
|
|
BinaryFunc getConvertFunc(int sdepth, int ddepth);
|
|
|
|
CV_CPU_OPTIMIZATION_NAMESPACE_END
|
|
|
|
#ifndef CV_CPU_OPTIMIZATION_DECLARATIONS_ONLY
|
|
|
|
namespace hal {
|
|
CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN
|
|
|
|
BinaryFunc getConvertFunc(int sdepth, int ddepth);
|
|
|
|
void cvt16f32f( const hfloat* src, float* dst, int len )
|
|
{
|
|
CV_INSTRUMENT_REGION();
|
|
int j = 0;
|
|
#if (CV_SIMD || CV_SIMD_SCALABLE)
|
|
const int VECSZ = VTraits<v_float32>::vlanes();
|
|
for( ; j < len; j += VECSZ )
|
|
{
|
|
if( j > len - VECSZ )
|
|
{
|
|
if( j == 0 )
|
|
break;
|
|
j = len - VECSZ;
|
|
}
|
|
v_store(dst + j, vx_load_expand(src + j));
|
|
}
|
|
#endif
|
|
for( ; j < len; j++ )
|
|
dst[j] = (float)src[j];
|
|
}
|
|
|
|
void cvt32f16f( const float* src, hfloat* dst, int len )
|
|
{
|
|
CV_INSTRUMENT_REGION();
|
|
int j = 0;
|
|
#if (CV_SIMD || CV_SIMD_SCALABLE)
|
|
const int VECSZ = VTraits<v_float32>::vlanes();
|
|
for( ; j < len; j += VECSZ )
|
|
{
|
|
if( j > len - VECSZ )
|
|
{
|
|
if( j == 0 )
|
|
break;
|
|
j = len - VECSZ;
|
|
}
|
|
v_pack_store(dst + j, vx_load(src + j));
|
|
}
|
|
#endif
|
|
for( ; j < len; j++ )
|
|
dst[j] = hfloat(src[j]);
|
|
}
|
|
|
|
void cvt32f16bf( const float* src, bfloat* dst, int len )
|
|
{
|
|
CV_INSTRUMENT_REGION();
|
|
int j = 0;
|
|
#if (CV_SIMD || CV_SIMD_SCALABLE)
|
|
const int VECSZ = VTraits<v_float32>::vlanes();
|
|
for( ; j < len; j += VECSZ )
|
|
{
|
|
if( j > len - VECSZ )
|
|
{
|
|
if( j == 0 )
|
|
break;
|
|
j = len - VECSZ;
|
|
}
|
|
v_pack_store(dst + j, vx_load(src + j));
|
|
}
|
|
#endif
|
|
for( ; j < len; j++ )
|
|
dst[j] = bfloat(src[j]);
|
|
}
|
|
|
|
void addRNGBias32f( float* arr, const float* scaleBiasPairs, int len, int cn )
|
|
{
|
|
CV_INSTRUMENT_REGION();
|
|
if (cn == 1) {
|
|
float bias = scaleBiasPairs[1];
|
|
for( int i = 0; i < len; i++ ) {
|
|
arr[i] += bias;
|
|
}
|
|
} else {
|
|
int k = 0;
|
|
len *= cn;
|
|
cn--;
|
|
for( int i = 0; i < len; i++ ) {
|
|
arr[i] += scaleBiasPairs[k*2 + 1];
|
|
k = (k + 1) & ((k >= cn) - 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
void addRNGBias64f( double* arr, const double* scaleBiasPairs, int len, int cn )
|
|
{
|
|
CV_INSTRUMENT_REGION();
|
|
if (cn == 1) {
|
|
double bias = scaleBiasPairs[1];
|
|
for( int i = 0; i < len; i++ ) {
|
|
arr[i] += bias;
|
|
}
|
|
} else {
|
|
int k = 0;
|
|
len *= cn;
|
|
cn--;
|
|
for( int i = 0; i < len; i++ ) {
|
|
arr[i] += scaleBiasPairs[k*2 + 1];
|
|
k = (k + 1) & ((k >= cn) - 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
CV_CPU_OPTIMIZATION_NAMESPACE_END
|
|
} // namespace cv::hal
|
|
|
|
// cv::
|
|
CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN
|
|
|
|
template<typename _Ts, typename _Td, typename _Twvec> static inline void
|
|
cvt_( const _Ts* src, size_t sstep, _Td* dst, size_t dstep, Size size )
|
|
{
|
|
sstep /= sizeof(src[0]);
|
|
dstep /= sizeof(dst[0]);
|
|
|
|
for( int i = 0; i < size.height; i++, src += sstep, dst += dstep )
|
|
{
|
|
int j = 0;
|
|
// Excluding GNU in CV_SIMD_SCALABLE because of "opencv/issues/26936"
|
|
#if (CV_SIMD || (CV_SIMD_SCALABLE && !(defined(__GNUC__) && !defined(__clang__))) )
|
|
const int VECSZ = VTraits<_Twvec>::vlanes()*2;
|
|
for( ; j < size.width; j += VECSZ )
|
|
{
|
|
if( j > size.width - VECSZ )
|
|
{
|
|
if( j == 0 || src == (_Ts*)dst )
|
|
break;
|
|
j = size.width - VECSZ;
|
|
}
|
|
_Twvec v0, v1;
|
|
vx_load_pair_as(src + j, v0, v1);
|
|
v_store_pair_as(dst + j, v0, v1);
|
|
}
|
|
#endif
|
|
for( ; j < size.width; j++ )
|
|
dst[j] = saturate_cast<_Td>(src[j]);
|
|
}
|
|
}
|
|
|
|
template<typename _Ts, typename _Td, typename dummy> static inline void
|
|
cvt_64f( const _Ts* src, size_t sstep, _Td* dst, size_t dstep, Size size )
|
|
{
|
|
sstep /= sizeof(src[0]);
|
|
dstep /= sizeof(dst[0]);
|
|
|
|
for( int i = 0; i < size.height; i++, src += sstep, dst += dstep )
|
|
{
|
|
int j = 0;
|
|
#if (CV_SIMD_64F || CV_SIMD_SCALABLE_64F)
|
|
const int VECSZ = VTraits<v_float64>::vlanes()*2;
|
|
for( ; j < size.width; j += VECSZ )
|
|
{
|
|
if( j > size.width - VECSZ )
|
|
{
|
|
if( j == 0 || src == (_Ts*)dst )
|
|
break;
|
|
j = size.width - VECSZ;
|
|
}
|
|
v_float64 v0, v1;
|
|
vx_load_pair_as(src + j, v0, v1);
|
|
v_store_pair_as(dst + j, v0, v1);
|
|
}
|
|
#endif
|
|
for( ; j < size.width; j++ )
|
|
dst[j] = saturate_cast<_Td>(src[j]);
|
|
}
|
|
}
|
|
|
|
// in order to reduce the code size, for (16f <-> ...) conversions
|
|
// we add a conversion function without loop unrolling
|
|
template<typename _Ts, typename _Td, typename _Twvec> static inline void
|
|
cvt1_( const _Ts* src, size_t sstep, _Td* dst, size_t dstep, Size size )
|
|
{
|
|
sstep /= sizeof(src[0]);
|
|
dstep /= sizeof(dst[0]);
|
|
|
|
for( int i = 0; i < size.height; i++, src += sstep, dst += dstep )
|
|
{
|
|
int j = 0;
|
|
#if (CV_SIMD || CV_SIMD_SCALABLE)
|
|
const int VECSZ = VTraits<_Twvec>::vlanes();
|
|
for( ; j < size.width; j += VECSZ )
|
|
{
|
|
if( j > size.width - VECSZ )
|
|
{
|
|
if( j == 0 || src == (_Ts*)dst )
|
|
break;
|
|
j = size.width - VECSZ;
|
|
}
|
|
_Twvec v;
|
|
vx_load_as(src + j, v);
|
|
v_store_as(dst + j, v);
|
|
}
|
|
vx_cleanup();
|
|
#endif
|
|
for( ; j < size.width; j++ )
|
|
dst[j] = saturate_cast<_Td>(src[j]);
|
|
}
|
|
}
|
|
|
|
static void cvtCopy( const uchar* src, size_t sstep,
|
|
uchar* dst, size_t dstep, Size size, size_t elemsize)
|
|
{
|
|
size_t len = size.width*elemsize;
|
|
for( int i = 0; i < size.height; i++, src += sstep, dst += dstep )
|
|
{
|
|
memcpy( dst, src, len );
|
|
}
|
|
}
|
|
|
|
#define DEF_CVT_FUNC(suffix, cvtfunc, _Ts, _Td, _Twvec) \
|
|
static void cvt##suffix(const uchar* src_, size_t sstep, const uchar*, size_t, \
|
|
uchar* dst_, size_t dstep, Size size, void*) \
|
|
{ \
|
|
CV_INSTRUMENT_REGION(); \
|
|
const _Ts* src = (const _Ts*)src_; \
|
|
_Td* dst = (_Td*)dst_; \
|
|
cvtfunc<_Ts, _Td, _Twvec>(src, sstep, dst, dstep, size); \
|
|
}
|
|
|
|
#define DEF_CVT2BOOL_FUNC(suffix, _Ts, shift) \
|
|
static void cvt##suffix(const uchar* src_, size_t sstep, const uchar*, size_t, \
|
|
uchar* dst, size_t dstep, Size size, void*) \
|
|
{ \
|
|
CV_INSTRUMENT_REGION(); \
|
|
const _Ts* src = (const _Ts*)src_; \
|
|
sstep /= sizeof(src[0]); \
|
|
\
|
|
for( int i = 0; i < size.height; i++, src += sstep, dst += dstep ) { \
|
|
for ( int j = 0; j < size.width; j++ ) \
|
|
dst[j] = (src[j]<<shift) != 0; \
|
|
} \
|
|
}
|
|
|
|
#define DEF_CVTBOOL2_FUNC(suffix, _Td, scale) \
|
|
static void cvt##suffix(const uchar* src, size_t sstep, const uchar*, size_t, \
|
|
uchar* dst_, size_t dstep, Size size, void*) \
|
|
{ \
|
|
CV_INSTRUMENT_REGION(); \
|
|
_Td* dst = (_Td*)dst_; \
|
|
dstep /= sizeof(dst[0]); \
|
|
\
|
|
for( int i = 0; i < size.height; i++, src += sstep, dst += dstep ) { \
|
|
for ( int j = 0; j < size.width; j++ ) \
|
|
dst[j] = (_Td)((src[j] != 0)*scale); \
|
|
} \
|
|
}
|
|
|
|
#define DEF_CVT_SCALAR_FUNC(suffix, _Ts, _Td) \
|
|
static void cvt##suffix(const uchar* src_, size_t sstep, const uchar*, size_t, \
|
|
uchar* dst_, size_t dstep, Size size, void*) \
|
|
{ \
|
|
CV_INSTRUMENT_REGION(); \
|
|
const _Ts* src = (const _Ts*)src_; \
|
|
_Td* dst = (_Td*)dst_; \
|
|
sstep /= sizeof(src[0]); \
|
|
dstep /= sizeof(dst[0]); \
|
|
\
|
|
for( int i = 0; i < size.height; i++, src += sstep, dst += dstep ) { \
|
|
for ( int j = 0; j < size.width; j++ ) \
|
|
dst[j] = saturate_cast<_Td>(src[j]); \
|
|
} \
|
|
}
|
|
|
|
#define DEF_CVT_SCALAR_FUNC_S2U(suffix, _Ts, _Td, _Tw) \
|
|
static void cvt##suffix(const uchar* src_, size_t sstep, const uchar*, size_t, \
|
|
uchar* dst_, size_t dstep, Size size, void*) \
|
|
{ \
|
|
CV_INSTRUMENT_REGION(); \
|
|
const _Ts* src = (const _Ts*)src_; \
|
|
_Td* dst = (_Td*)dst_; \
|
|
sstep /= sizeof(src[0]); \
|
|
dstep /= sizeof(dst[0]); \
|
|
\
|
|
for( int i = 0; i < size.height; i++, src += sstep, dst += dstep ) { \
|
|
for ( int j = 0; j < size.width; j++ ) \
|
|
dst[j] = saturate_cast<_Td>(std::max((_Tw)src[j], (_Tw)0)); \
|
|
} \
|
|
}
|
|
|
|
////////////////////// 8u -> ... ////////////////////////
|
|
|
|
DEF_CVT_FUNC(8u8s, cvt_, uchar, schar, v_int16)
|
|
DEF_CVT_FUNC(8u16s, cvt_, uchar, short, v_int16)
|
|
DEF_CVT_FUNC(8u32s, cvt_, uchar, int, v_int32)
|
|
DEF_CVT_FUNC(8u32f, cvt_, uchar, float, v_float32)
|
|
DEF_CVT_FUNC(8u64f, cvt_, uchar, double, v_int32)
|
|
DEF_CVT_SCALAR_FUNC(8u64s, uchar, int64_t)
|
|
DEF_CVT_FUNC(8u16f, cvt1_, uchar, hfloat, v_float32)
|
|
DEF_CVT_FUNC(8u16bf, cvt1_, uchar, bfloat, v_float32)
|
|
DEF_CVT2BOOL_FUNC(8u8b, uchar, 0)
|
|
|
|
////////////////////// 8s -> ... ////////////////////////
|
|
|
|
DEF_CVT_FUNC(8s8u, cvt_, schar, uchar, v_int16)
|
|
DEF_CVT_FUNC(8s16u, cvt_, schar, ushort, v_uint16)
|
|
DEF_CVT_FUNC(8s16s, cvt_, schar, short, v_int16)
|
|
DEF_CVT_FUNC(8s32u, cvt_, schar, unsigned, v_uint32)
|
|
DEF_CVT_FUNC(8s32s, cvt_, schar, int, v_int32)
|
|
DEF_CVT_FUNC(8s32f, cvt_, schar, float, v_float32)
|
|
DEF_CVT_FUNC(8s64f, cvt_, schar, double, v_int32)
|
|
DEF_CVT_FUNC(8s64u, cvt_, schar, uint64_t, v_uint32)
|
|
DEF_CVT_FUNC(8s64s, cvt_, schar, int64_t, v_int32)
|
|
DEF_CVT_FUNC(8s16f, cvt1_, schar, hfloat, v_float32)
|
|
DEF_CVT_FUNC(8s16bf, cvt1_, schar, bfloat, v_float32)
|
|
|
|
////////////////////// 8b -> ... ////////////////////////
|
|
|
|
DEF_CVTBOOL2_FUNC(8b8u, uchar, 1)
|
|
DEF_CVTBOOL2_FUNC(8b16s, short, 1)
|
|
DEF_CVTBOOL2_FUNC(8b32s, int, 1)
|
|
DEF_CVTBOOL2_FUNC(8b32f, float, 1)
|
|
DEF_CVTBOOL2_FUNC(8b64f, double, 1)
|
|
DEF_CVTBOOL2_FUNC(8b64s, int64_t, 1)
|
|
DEF_CVTBOOL2_FUNC(8b16f, uint16_t, 0x3c00) // hfloat(1.0f)
|
|
DEF_CVTBOOL2_FUNC(8b16bf, uint16_t, 0x3f80) // bfloat(1.0f)
|
|
|
|
////////////////////// 16u -> ... ////////////////////////
|
|
|
|
DEF_CVT_FUNC(16u8u, cvt_, ushort, uchar, v_uint16)
|
|
DEF_CVT_FUNC(16u8s, cvt_, ushort, schar, v_uint16)
|
|
DEF_CVT_FUNC(16u16s, cvt_, ushort, short, v_int32)
|
|
DEF_CVT_FUNC(16u32s, cvt_, ushort, int, v_int32)
|
|
DEF_CVT_FUNC(16u32f, cvt_, ushort, float, v_float32)
|
|
DEF_CVT_FUNC(16u64f, cvt_, ushort, double, v_int32)
|
|
DEF_CVT_SCALAR_FUNC(16u64s, ushort, int64_t)
|
|
DEF_CVT_FUNC(16u16f, cvt1_,ushort, hfloat, v_float32)
|
|
DEF_CVT_FUNC(16u16bf, cvt1_, ushort, bfloat, v_float32)
|
|
|
|
////////////////////// 16s -> ... ////////////////////////
|
|
|
|
DEF_CVT_FUNC(16s8u, cvt_, short, uchar, v_int16)
|
|
DEF_CVT_FUNC(16s8s, cvt_, short, schar, v_int16)
|
|
DEF_CVT_FUNC(16s16u, cvt_, short, ushort, v_int32)
|
|
DEF_CVT_FUNC(16s32u, cvt_, short, unsigned, v_uint32)
|
|
DEF_CVT_FUNC(16s32s, cvt_, short, int, v_int32)
|
|
DEF_CVT_FUNC(16s32f, cvt_, short, float, v_float32)
|
|
DEF_CVT_FUNC(16s64f, cvt_, short, double, v_int32)
|
|
DEF_CVT_FUNC(16s64u, cvt_, short, uint64_t, v_uint32)
|
|
DEF_CVT_FUNC(16s64s, cvt_, short, int64_t, v_int32)
|
|
DEF_CVT_FUNC(16s16f, cvt1_,short, hfloat, v_float32)
|
|
DEF_CVT_FUNC(16s16bf, cvt1_, short, bfloat, v_float32)
|
|
DEF_CVT2BOOL_FUNC(16s8b, short, 0)
|
|
|
|
////////////////////// 32u -> ... ////////////////////////
|
|
|
|
DEF_CVT_FUNC(32u8u, cvt_, unsigned, uchar, v_uint32)
|
|
DEF_CVT_FUNC(32u8s, cvt_, unsigned, schar, v_int32)
|
|
DEF_CVT_FUNC(32u16u, cvt_, unsigned, ushort, v_uint32)
|
|
DEF_CVT_FUNC(32u16s, cvt_, unsigned, short, v_int32)
|
|
DEF_CVT_SCALAR_FUNC(32u32s, unsigned, int)
|
|
DEF_CVT_FUNC(32u32f, cvt_, unsigned, float, v_float32)
|
|
DEF_CVT_FUNC(32u64f, cvt_, unsigned, double, v_float32)
|
|
DEF_CVT_SCALAR_FUNC(32u64s, unsigned, int64_t)
|
|
DEF_CVT_FUNC(32u16f, cvt1_, unsigned, hfloat, v_float32)
|
|
DEF_CVT_FUNC(32u16bf, cvt1_, int, bfloat, v_float32)
|
|
|
|
////////////////////// 32s -> ... ////////////////////////
|
|
|
|
DEF_CVT_FUNC(32s8u, cvt_, int, uchar, v_int32)
|
|
DEF_CVT_FUNC(32s8s, cvt_, int, schar, v_int32)
|
|
DEF_CVT_FUNC(32s16u, cvt_, int, ushort, v_int32)
|
|
DEF_CVT_FUNC(32s16s, cvt_, int, short, v_int32)
|
|
DEF_CVT_FUNC(32s32u, cvt_, int, unsigned, v_uint32)
|
|
DEF_CVT_FUNC(32s32f, cvt_, int, float, v_float32)
|
|
DEF_CVT_FUNC(32s64f, cvt_, int, double, v_int32)
|
|
DEF_CVT_FUNC(32s64u, cvt_, int, uint64_t, v_uint32)
|
|
DEF_CVT_FUNC(32s64s, cvt_, int, int64_t, v_int32)
|
|
DEF_CVT_FUNC(32s16f, cvt1_,int, hfloat, v_float32)
|
|
DEF_CVT_FUNC(32s16bf, cvt1_, int, bfloat, v_float32)
|
|
DEF_CVT2BOOL_FUNC(32s8b, int, 0)
|
|
|
|
////////////////////// 32f -> ... ////////////////////////
|
|
|
|
DEF_CVT_FUNC(32f8u, cvt_, float, uchar, v_float32)
|
|
DEF_CVT_FUNC(32f8s, cvt_, float, schar, v_float32)
|
|
DEF_CVT_FUNC(32f16u, cvt_, float, ushort, v_float32)
|
|
DEF_CVT_FUNC(32f16s, cvt_, float, short, v_float32)
|
|
DEF_CVT_FUNC(32f32u, cvt_, float, unsigned, v_float32)
|
|
DEF_CVT_FUNC(32f32s, cvt_, float, int, v_float32)
|
|
DEF_CVT_FUNC(32f64f, cvt_, float, double, v_float32)
|
|
DEF_CVT_FUNC(32f64u, cvt_64f, float, uint64_t, v_float64)
|
|
DEF_CVT_FUNC(32f64s, cvt_64f, float, int64_t, v_float64)
|
|
DEF_CVT_FUNC(32f16f, cvt1_,float, hfloat, v_float32)
|
|
DEF_CVT_FUNC(32f16bf, cvt1_,float, bfloat, v_float32)
|
|
DEF_CVT2BOOL_FUNC(32f8b, int, 1)
|
|
|
|
////////////////////// 64f -> ... ////////////////////////
|
|
|
|
DEF_CVT_FUNC(64f8u, cvt_, double, uchar, v_int32)
|
|
DEF_CVT_FUNC(64f8s, cvt_, double, schar, v_int32)
|
|
DEF_CVT_FUNC(64f16u, cvt_, double, ushort, v_int32)
|
|
DEF_CVT_FUNC(64f16s, cvt_, double, short, v_int32)
|
|
DEF_CVT_FUNC(64f32u, cvt_64f, double, unsigned, v_float32)
|
|
DEF_CVT_FUNC(64f32s, cvt_, double, int, v_int32)
|
|
DEF_CVT_FUNC(64f32f, cvt_, double, float, v_float32)
|
|
DEF_CVT_FUNC(64f64u, cvt_64f, double, uint64_t, v_float64)
|
|
DEF_CVT_FUNC(64f64s, cvt_64f, double, int64_t, v_float64)
|
|
DEF_CVT_FUNC(64f16f, cvt1_,double, hfloat, v_float32)
|
|
DEF_CVT_FUNC(64f16bf, cvt1_,double, bfloat, v_float32)
|
|
DEF_CVT2BOOL_FUNC(64f8b, int64_t, 1)
|
|
|
|
////////////////////// 16f -> ... ////////////////////////
|
|
|
|
DEF_CVT_FUNC(16f8u, cvt_, hfloat, uchar, v_float32)
|
|
DEF_CVT_FUNC(16f8s, cvt_, hfloat, schar, v_float32)
|
|
DEF_CVT_FUNC(16f16u, cvt1_, hfloat, ushort, v_float32)
|
|
DEF_CVT_FUNC(16f16s, cvt1_, hfloat, short, v_float32)
|
|
DEF_CVT_FUNC(16f32u, cvt1_, hfloat, unsigned, v_float32)
|
|
DEF_CVT_FUNC(16f32s, cvt1_, hfloat, int, v_float32)
|
|
DEF_CVT_FUNC(16f32f, cvt1_, hfloat, float, v_float32)
|
|
DEF_CVT_FUNC(16f64f, cvt1_, hfloat, double, v_float32)
|
|
DEF_CVT_FUNC(16f64u, cvt1_, hfloat, uint64_t, v_float32)
|
|
DEF_CVT_FUNC(16f64s, cvt1_, hfloat, int64_t, v_float32)
|
|
DEF_CVT_FUNC(16f16bf, cvt1_, hfloat, bfloat, v_float32)
|
|
DEF_CVT2BOOL_FUNC(16f8b, short, 1)
|
|
|
|
////////////////////// 16bf -> ... ////////////////////////
|
|
|
|
DEF_CVT_FUNC(16bf8u, cvt_, bfloat, uchar, v_float32)
|
|
DEF_CVT_FUNC(16bf8s, cvt_, bfloat, schar, v_float32)
|
|
DEF_CVT_FUNC(16bf16u, cvt1_, bfloat, ushort, v_float32)
|
|
DEF_CVT_FUNC(16bf16s, cvt1_, bfloat, short, v_float32)
|
|
DEF_CVT_FUNC(16bf32u, cvt1_, bfloat, unsigned, v_float32)
|
|
DEF_CVT_FUNC(16bf32s, cvt1_, bfloat, int, v_float32)
|
|
DEF_CVT_FUNC(16bf32f, cvt1_, bfloat, float, v_float32)
|
|
DEF_CVT_FUNC(16bf64f, cvt1_, bfloat, double, v_float32)
|
|
DEF_CVT_FUNC(16bf64u, cvt1_, bfloat, uint64_t, v_float32)
|
|
DEF_CVT_FUNC(16bf64s, cvt1_, bfloat, int64_t, v_float32)
|
|
DEF_CVT_FUNC(16bf16f, cvt1_, bfloat, hfloat, v_float32)
|
|
|
|
////////////////////// 64s -> ... ////////////////////////
|
|
|
|
DEF_CVT_FUNC(64s8u, cvt_, int64_t, uchar, v_int32)
|
|
DEF_CVT_FUNC(64s8s, cvt_, int64_t, schar, v_int32)
|
|
DEF_CVT_FUNC(64s16u, cvt_, int64_t, ushort, v_int32)
|
|
DEF_CVT_FUNC(64s16s, cvt_, int64_t, short, v_int32)
|
|
DEF_CVT_FUNC(64s32u, cvt_, int64_t, unsigned, v_uint32)
|
|
DEF_CVT_FUNC(64s32s, cvt_, int64_t, int, v_int32)
|
|
DEF_CVT_FUNC(64s32f, cvt_64f, int64_t, float, v_float32)
|
|
DEF_CVT_FUNC(64s64f, cvt_64f, int64_t, double, v_float64)
|
|
DEF_CVT_FUNC(64s64u, cvt_, int64_t, uint64_t, v_uint64)
|
|
DEF_CVT_FUNC(64s16f, cvt1_,int64_t, hfloat, v_float32)
|
|
DEF_CVT_FUNC(64s16bf, cvt1_, int64_t, bfloat, v_float32)
|
|
DEF_CVT2BOOL_FUNC(64s8b, int64_t, 0)
|
|
|
|
////////////////////// 64u -> ... ////////////////////////
|
|
|
|
DEF_CVT_FUNC(64u8u, cvt_, uint64_t, uchar, v_int32)
|
|
DEF_CVT_FUNC(64u8s, cvt_, uint64_t, schar, v_int32)
|
|
DEF_CVT_FUNC(64u16u, cvt_, uint64_t, ushort, v_int32)
|
|
DEF_CVT_FUNC(64u16s, cvt_, uint64_t, short, v_int32)
|
|
DEF_CVT_FUNC(64u32u, cvt_, uint64_t, unsigned, v_uint32)
|
|
DEF_CVT_FUNC(64u32s, cvt_, uint64_t, int, v_int32)
|
|
DEF_CVT_FUNC(64u32f, cvt_64f, uint64_t, float, v_float64)
|
|
DEF_CVT_FUNC(64u64f, cvt_64f, uint64_t, double, v_float64)
|
|
DEF_CVT_FUNC(64u16f, cvt1_,uint64_t, hfloat, v_float32)
|
|
DEF_CVT_FUNC(64u16bf, cvt1_, uint64_t, bfloat, v_float32)
|
|
|
|
///////////// "conversion" w/o conversion ///////////////
|
|
|
|
static void cvt8u(const uchar* src, size_t sstep, const uchar*, size_t, uchar* dst, size_t dstep, Size size, void*)
|
|
{ CV_INSTRUMENT_REGION(); cvtCopy(src, sstep, dst, dstep, size, 1); }
|
|
|
|
static void cvt16u(const uchar* src, size_t sstep, const uchar*, size_t, uchar* dst, size_t dstep, Size size, void*)
|
|
{ CV_INSTRUMENT_REGION(); cvtCopy((const uchar*)src, sstep, (uchar*)dst, dstep, size, 2); }
|
|
|
|
static void cvt32s(const uchar* src, size_t sstep, const uchar*, size_t, uchar* dst, size_t dstep, Size size, void*)
|
|
{ CV_INSTRUMENT_REGION(); cvtCopy((const uchar*)src, sstep, (uchar*)dst, dstep, size, 4); }
|
|
|
|
static void cvt64s(const uchar* src, size_t sstep, const uchar*, size_t, uchar* dst, size_t dstep, Size size, void*)
|
|
{ CV_INSTRUMENT_REGION(); cvtCopy((const uchar*)src, sstep, (uchar*)dst, dstep, size, 8); }
|
|
|
|
//////////////////// FP8 (1-byte float) conversions — scalar via saturate_cast ////////////////////
|
|
// Suffixes: 8fe4m3 (E4M3FN), 8fe4m3u (E4M3FNUZ).
|
|
#define DEF_CVT_FP8(S, T) \
|
|
DEF_CVT_SCALAR_FUNC(S##8u, T, uchar) DEF_CVT_SCALAR_FUNC(8u##S, uchar, T) \
|
|
DEF_CVT_SCALAR_FUNC(S##8s, T, schar) DEF_CVT_SCALAR_FUNC(8s##S, schar, T) \
|
|
DEF_CVT_SCALAR_FUNC(S##16u, T, ushort) DEF_CVT_SCALAR_FUNC(16u##S, ushort, T) \
|
|
DEF_CVT_SCALAR_FUNC(S##16s, T, short) DEF_CVT_SCALAR_FUNC(16s##S, short, T) \
|
|
DEF_CVT_SCALAR_FUNC(S##32u, T, unsigned) DEF_CVT_SCALAR_FUNC(32u##S, unsigned, T) \
|
|
DEF_CVT_SCALAR_FUNC(S##32s, T, int) DEF_CVT_SCALAR_FUNC(32s##S, int, T) \
|
|
DEF_CVT_SCALAR_FUNC(32f##S, float, T) \
|
|
DEF_CVT_SCALAR_FUNC(S##64f, T, double) DEF_CVT_SCALAR_FUNC(64f##S, double, T) \
|
|
DEF_CVT_SCALAR_FUNC(S##16f, T, hfloat) DEF_CVT_SCALAR_FUNC(16f##S, hfloat, T) \
|
|
DEF_CVT_SCALAR_FUNC(S##16bf, T, bfloat) DEF_CVT_SCALAR_FUNC(16bf##S, bfloat, T) \
|
|
DEF_CVT_SCALAR_FUNC(S##64u, T, uint64_t) DEF_CVT_SCALAR_FUNC(64u##S, uint64_t, T) \
|
|
DEF_CVT_SCALAR_FUNC(S##64s, T, int64_t) DEF_CVT_SCALAR_FUNC(64s##S, int64_t, T) \
|
|
DEF_CVT_SCALAR_FUNC(S##8b, T, bool)
|
|
|
|
DEF_CVT_FP8(8fe4m3, fp8_t)
|
|
DEF_CVT_FP8(8fe4m3u, fp8a_t)
|
|
|
|
// FP8 -> FP8, cross-format only (identity uses the 1-byte copy cvt8u, like 16f->16f uses cvt16u)
|
|
DEF_CVT_SCALAR_FUNC(8fe4m38fe4m3u, fp8_t, fp8a_t)
|
|
DEF_CVT_SCALAR_FUNC(8fe4m3u8fe4m3, fp8a_t, fp8_t)
|
|
|
|
// FP8 -> float32: 256-entry decode table gathered via universal intrinsics (same table as scalar)
|
|
template<typename FP8>
|
|
static void cvtFp8ToF32(const uchar* src, size_t sstep, const uchar*, size_t,
|
|
uchar* dst_, size_t dstep, Size size, void*)
|
|
{
|
|
CV_INSTRUMENT_REGION();
|
|
float* dst = (float*)dst_;
|
|
const float* tab = FP8::decodeLUT();
|
|
dstep /= sizeof(dst[0]);
|
|
for (int i = 0; i < size.height; i++, src += sstep, dst += dstep)
|
|
{
|
|
int j = 0;
|
|
#if (CV_SIMD || CV_SIMD_SCALABLE)
|
|
const int VECSZ = VTraits<v_float32>::vlanes();
|
|
for (; j <= size.width - VECSZ; j += VECSZ)
|
|
v_store(dst + j, v_lut(tab, v_reinterpret_as_s32(vx_load_expand_q(src + j))));
|
|
#endif
|
|
for (; j < size.width; j++) dst[j] = tab[src[j]];
|
|
}
|
|
}
|
|
static void cvt8fe4m332f(const uchar* s, size_t ss, const uchar* p, size_t ps, uchar* d, size_t ds, Size sz, void* x)
|
|
{ cvtFp8ToF32<fp8_t>(s, ss, p, ps, d, ds, sz, x); }
|
|
static void cvt8fe4m3u32f(const uchar* s, size_t ss, const uchar* p, size_t ps, uchar* d, size_t ds, Size sz, void* x)
|
|
{ cvtFp8ToF32<fp8a_t>(s, ss, p, ps, d, ds, sz, x); }
|
|
|
|
BinaryFunc getConvertFunc(int sdepth_, int ddepth_)
|
|
{
|
|
int sdepth = CV_MAT_DEPTH(sdepth_);
|
|
int ddepth = CV_MAT_DEPTH(ddepth_);
|
|
BinaryFunc func =
|
|
ddepth == CV_8U ? (
|
|
sdepth == CV_8U ? cvt8u :
|
|
sdepth == CV_8S ? cvt8s8u :
|
|
sdepth == CV_16U ? cvt16u8u :
|
|
sdepth == CV_16S ? cvt16s8u :
|
|
sdepth == CV_32U ? cvt32u8u :
|
|
sdepth == CV_32S ? cvt32s8u :
|
|
sdepth == CV_32F ? cvt32f8u :
|
|
sdepth == CV_64F ? cvt64f8u :
|
|
sdepth == CV_16F ? cvt16f8u :
|
|
sdepth == CV_16BF ? cvt16bf8u :
|
|
sdepth == CV_Bool ? cvt8b8u :
|
|
sdepth == CV_64U ? cvt64u8u :
|
|
sdepth == CV_64S ? cvt64s8u :
|
|
sdepth == CV_8F_E4M3FN ? cvt8fe4m38u :
|
|
sdepth == CV_8F_E4M3FNUZ ? cvt8fe4m3u8u :
|
|
0) :
|
|
ddepth == CV_8S ? (
|
|
sdepth == CV_8U ? cvt8u8s :
|
|
sdepth == CV_8S ? cvt8u :
|
|
sdepth == CV_16U ? cvt16u8s :
|
|
sdepth == CV_16S ? cvt16s8s :
|
|
sdepth == CV_32U ? cvt32u8s :
|
|
sdepth == CV_32S ? cvt32s8s :
|
|
sdepth == CV_32F ? cvt32f8s :
|
|
sdepth == CV_64F ? cvt64f8s :
|
|
sdepth == CV_16F ? cvt16f8s :
|
|
sdepth == CV_16BF ? cvt16bf8s :
|
|
sdepth == CV_Bool ? cvt8b8u :
|
|
sdepth == CV_64U ? cvt64u8s :
|
|
sdepth == CV_64S ? cvt64s8s :
|
|
sdepth == CV_8F_E4M3FN ? cvt8fe4m38s :
|
|
sdepth == CV_8F_E4M3FNUZ ? cvt8fe4m3u8s :
|
|
0) :
|
|
ddepth == CV_16U ? (
|
|
sdepth == CV_8U ? cvt8u16s : // same as cvt8u16u
|
|
sdepth == CV_8S ? cvt8s16u :
|
|
sdepth == CV_16U ? cvt16u :
|
|
sdepth == CV_16S ? cvt16s16u :
|
|
sdepth == CV_32U ? cvt32u16u :
|
|
sdepth == CV_32S ? cvt32s16u :
|
|
sdepth == CV_32F ? cvt32f16u :
|
|
sdepth == CV_64F ? cvt64f16u :
|
|
sdepth == CV_16F ? cvt16f16u :
|
|
sdepth == CV_16BF ? cvt16bf16u :
|
|
sdepth == CV_Bool ? cvt8b16s :
|
|
sdepth == CV_64U ? cvt64u16u :
|
|
sdepth == CV_64S ? cvt64s16u :
|
|
sdepth == CV_8F_E4M3FN ? cvt8fe4m316u :
|
|
sdepth == CV_8F_E4M3FNUZ ? cvt8fe4m3u16u :
|
|
0) :
|
|
ddepth == CV_16S ? (
|
|
sdepth == CV_8U ? cvt8u16s :
|
|
sdepth == CV_8S ? cvt8s16s :
|
|
sdepth == CV_16U ? cvt16u16s :
|
|
sdepth == CV_16S ? cvt16u :
|
|
sdepth == CV_32U ? cvt32u16s :
|
|
sdepth == CV_32S ? cvt32s16s :
|
|
sdepth == CV_32F ? cvt32f16s :
|
|
sdepth == CV_64F ? cvt64f16s :
|
|
sdepth == CV_16F ? cvt16f16s :
|
|
sdepth == CV_16BF ? cvt16bf16s :
|
|
sdepth == CV_Bool ? cvt8b16s :
|
|
sdepth == CV_64U ? cvt64u16s :
|
|
sdepth == CV_64S ? cvt64s16s :
|
|
sdepth == CV_8F_E4M3FN ? cvt8fe4m316s :
|
|
sdepth == CV_8F_E4M3FNUZ ? cvt8fe4m3u16s :
|
|
0) :
|
|
ddepth == CV_32U ? (
|
|
sdepth == CV_8U ? cvt8u32s : // same as cvt8u32u
|
|
sdepth == CV_8S ? cvt8s32u :
|
|
sdepth == CV_16U ? cvt16u32s : // same as cvt16u32u
|
|
sdepth == CV_16S ? cvt16s32u :
|
|
sdepth == CV_32U ? cvt32s :
|
|
sdepth == CV_32S ? cvt32s32u :
|
|
sdepth == CV_32F ? cvt32f32u :
|
|
sdepth == CV_64F ? cvt64f32u :
|
|
sdepth == CV_16F ? cvt16f32u :
|
|
sdepth == CV_16BF ? cvt16bf32u :
|
|
sdepth == CV_Bool ? cvt8b32s :
|
|
sdepth == CV_64U ? cvt64u32u :
|
|
sdepth == CV_64S ? cvt64s32u :
|
|
sdepth == CV_8F_E4M3FN ? cvt8fe4m332u :
|
|
sdepth == CV_8F_E4M3FNUZ ? cvt8fe4m3u32u :
|
|
0) :
|
|
ddepth == CV_32S ? (
|
|
sdepth == CV_8U ? cvt8u32s :
|
|
sdepth == CV_8S ? cvt8s32s :
|
|
sdepth == CV_16U ? cvt16u32s :
|
|
sdepth == CV_16S ? cvt16s32s :
|
|
sdepth == CV_32U ? cvt32u32s :
|
|
sdepth == CV_32S ? cvt32s :
|
|
sdepth == CV_32F ? cvt32f32s :
|
|
sdepth == CV_64F ? cvt64f32s :
|
|
sdepth == CV_16F ? cvt16f32s :
|
|
sdepth == CV_16BF ? cvt16bf32s :
|
|
sdepth == CV_Bool ? cvt8b32s :
|
|
sdepth == CV_64U ? cvt64u32s :
|
|
sdepth == CV_64S ? cvt64s32s :
|
|
sdepth == CV_8F_E4M3FN ? cvt8fe4m332s :
|
|
sdepth == CV_8F_E4M3FNUZ ? cvt8fe4m3u32s :
|
|
0) :
|
|
ddepth == CV_32F ? (
|
|
sdepth == CV_8U ? cvt8u32f :
|
|
sdepth == CV_8S ? cvt8s32f :
|
|
sdepth == CV_16U ? cvt16u32f :
|
|
sdepth == CV_16S ? cvt16s32f :
|
|
sdepth == CV_32U ? cvt32u32f :
|
|
sdepth == CV_32S ? cvt32s32f :
|
|
sdepth == CV_32F ? cvt32s :
|
|
sdepth == CV_64F ? cvt64f32f :
|
|
sdepth == CV_16F ? cvt16f32f :
|
|
sdepth == CV_16BF ? cvt16bf32f :
|
|
sdepth == CV_Bool ? cvt8b32f :
|
|
sdepth == CV_64U ? cvt64u32f :
|
|
sdepth == CV_64S ? cvt64s32f :
|
|
sdepth == CV_8F_E4M3FN ? cvt8fe4m332f :
|
|
sdepth == CV_8F_E4M3FNUZ ? cvt8fe4m3u32f :
|
|
0) :
|
|
ddepth == CV_64F ? (
|
|
sdepth == CV_8U ? cvt8u64f :
|
|
sdepth == CV_8S ? cvt8s64f :
|
|
sdepth == CV_16U ? cvt16u64f :
|
|
sdepth == CV_16S ? cvt16s64f :
|
|
sdepth == CV_32U ? cvt32u64f :
|
|
sdepth == CV_32S ? cvt32s64f :
|
|
sdepth == CV_32F ? cvt32f64f :
|
|
sdepth == CV_64F ? cvt64s :
|
|
sdepth == CV_16F ? cvt16f64f :
|
|
sdepth == CV_16BF ? cvt16bf64f :
|
|
sdepth == CV_Bool ? cvt8b64f :
|
|
sdepth == CV_64U ? cvt64u64f :
|
|
sdepth == CV_64S ? cvt64s64f :
|
|
sdepth == CV_8F_E4M3FN ? cvt8fe4m364f :
|
|
sdepth == CV_8F_E4M3FNUZ ? cvt8fe4m3u64f :
|
|
0) :
|
|
ddepth == CV_16F ? (
|
|
sdepth == CV_8U ? cvt8u16f :
|
|
sdepth == CV_8S ? cvt8s16f :
|
|
sdepth == CV_16U ? cvt16u16f :
|
|
sdepth == CV_16S ? cvt16s16f :
|
|
sdepth == CV_32U ? cvt32u16f :
|
|
sdepth == CV_32S ? cvt32s16f :
|
|
sdepth == CV_32F ? cvt32f16f :
|
|
sdepth == CV_64F ? cvt64f16f :
|
|
sdepth == CV_16F ? cvt16u :
|
|
sdepth == CV_16BF ? cvt16bf16f :
|
|
sdepth == CV_Bool ? cvt8b16f :
|
|
sdepth == CV_64U ? cvt64u16f :
|
|
sdepth == CV_64S ? cvt64s16f :
|
|
sdepth == CV_8F_E4M3FN ? cvt8fe4m316f :
|
|
sdepth == CV_8F_E4M3FNUZ ? cvt8fe4m3u16f :
|
|
0) :
|
|
ddepth == CV_16BF ? (
|
|
sdepth == CV_8U ? cvt8u16bf :
|
|
sdepth == CV_8S ? cvt8s16bf :
|
|
sdepth == CV_16U ? cvt16u16bf :
|
|
sdepth == CV_16S ? cvt16s16bf :
|
|
sdepth == CV_32U ? cvt32u16bf :
|
|
sdepth == CV_32S ? cvt32s16bf :
|
|
sdepth == CV_32F ? cvt32f16bf :
|
|
sdepth == CV_64F ? cvt64f16bf :
|
|
sdepth == CV_16F ? cvt16f16bf :
|
|
sdepth == CV_16BF ? cvt16u :
|
|
sdepth == CV_Bool ? cvt8b16bf :
|
|
sdepth == CV_64U ? cvt64u16bf :
|
|
sdepth == CV_64S ? cvt64s16bf :
|
|
sdepth == CV_8F_E4M3FN ? cvt8fe4m316bf :
|
|
sdepth == CV_8F_E4M3FNUZ ? cvt8fe4m3u16bf :
|
|
0) :
|
|
ddepth == CV_Bool ? (
|
|
sdepth == CV_8U ? cvt8u8b :
|
|
sdepth == CV_8S ? cvt8u8b :
|
|
sdepth == CV_16U ? cvt16s8b :
|
|
sdepth == CV_16S ? cvt16s8b :
|
|
sdepth == CV_32U ? cvt32s8b :
|
|
sdepth == CV_32S ? cvt32s8b :
|
|
sdepth == CV_32F ? cvt32f8b :
|
|
sdepth == CV_64F ? cvt64f8b :
|
|
sdepth == CV_16F ? cvt16f8b :
|
|
sdepth == CV_16BF ? cvt16f8b : // same as cvt16f8b
|
|
sdepth == CV_Bool ? cvt8u :
|
|
sdepth == CV_64U ? cvt64s8b :
|
|
sdepth == CV_64S ? cvt64s8b :
|
|
sdepth == CV_8F_E4M3FN ? cvt8fe4m38b :
|
|
sdepth == CV_8F_E4M3FNUZ ? cvt8fe4m3u8b :
|
|
0) :
|
|
ddepth == CV_64U ? (
|
|
sdepth == CV_8U ? cvt8u64s : // same as cvt8u64u
|
|
sdepth == CV_8S ? cvt8s64u :
|
|
sdepth == CV_16U ? cvt16u64s : // same as cvt16u64u
|
|
sdepth == CV_16S ? cvt16s64u :
|
|
sdepth == CV_32U ? cvt32u64s : // same as cvt32u64u
|
|
sdepth == CV_32S ? cvt32s64u :
|
|
sdepth == CV_32F ? cvt32f64u :
|
|
sdepth == CV_64F ? cvt64f64u :
|
|
sdepth == CV_16F ? cvt16f64u :
|
|
sdepth == CV_16BF ? cvt16bf64u :
|
|
sdepth == CV_Bool ? cvt8b64s :
|
|
sdepth == CV_64U ? cvt64s :
|
|
sdepth == CV_64S ? cvt64s64u :
|
|
sdepth == CV_8F_E4M3FN ? cvt8fe4m364u :
|
|
sdepth == CV_8F_E4M3FNUZ ? cvt8fe4m3u64u :
|
|
0) :
|
|
ddepth == CV_64S ? (
|
|
sdepth == CV_8U ? cvt8u64s :
|
|
sdepth == CV_8S ? cvt8s64s :
|
|
sdepth == CV_16U ? cvt16u64s :
|
|
sdepth == CV_16S ? cvt16s64s :
|
|
sdepth == CV_32U ? cvt32u64s :
|
|
sdepth == CV_32S ? cvt32s64s :
|
|
sdepth == CV_32F ? cvt32f64s :
|
|
sdepth == CV_64F ? cvt64f64s :
|
|
sdepth == CV_16F ? cvt16f64s :
|
|
sdepth == CV_16BF ? cvt16bf64s :
|
|
sdepth == CV_Bool ? cvt8b64s :
|
|
sdepth == CV_64U ? cvt64s :
|
|
sdepth == CV_64S ? cvt64s :
|
|
sdepth == CV_8F_E4M3FN ? cvt8fe4m364s :
|
|
sdepth == CV_8F_E4M3FNUZ ? cvt8fe4m3u64s :
|
|
0) :
|
|
ddepth == CV_8F_E4M3FN ? (
|
|
sdepth == CV_8U ? cvt8u8fe4m3 :
|
|
sdepth == CV_8S ? cvt8s8fe4m3 :
|
|
sdepth == CV_16U ? cvt16u8fe4m3 :
|
|
sdepth == CV_16S ? cvt16s8fe4m3 :
|
|
sdepth == CV_32U ? cvt32u8fe4m3 :
|
|
sdepth == CV_32S ? cvt32s8fe4m3 :
|
|
sdepth == CV_32F ? cvt32f8fe4m3 :
|
|
sdepth == CV_64F ? cvt64f8fe4m3 :
|
|
sdepth == CV_16F ? cvt16f8fe4m3 :
|
|
sdepth == CV_16BF ? cvt16bf8fe4m3 :
|
|
sdepth == CV_Bool ? cvt8u8fe4m3 : // bool stored as 0/1 byte -> reuse uchar path
|
|
sdepth == CV_64U ? cvt64u8fe4m3 :
|
|
sdepth == CV_64S ? cvt64s8fe4m3 :
|
|
sdepth == CV_8F_E4M3FN ? cvt8u : // identity: 1-byte copy
|
|
sdepth == CV_8F_E4M3FNUZ ? cvt8fe4m3u8fe4m3 :
|
|
0) :
|
|
ddepth == CV_8F_E4M3FNUZ ? (
|
|
sdepth == CV_8U ? cvt8u8fe4m3u :
|
|
sdepth == CV_8S ? cvt8s8fe4m3u :
|
|
sdepth == CV_16U ? cvt16u8fe4m3u :
|
|
sdepth == CV_16S ? cvt16s8fe4m3u :
|
|
sdepth == CV_32U ? cvt32u8fe4m3u :
|
|
sdepth == CV_32S ? cvt32s8fe4m3u :
|
|
sdepth == CV_32F ? cvt32f8fe4m3u :
|
|
sdepth == CV_64F ? cvt64f8fe4m3u :
|
|
sdepth == CV_16F ? cvt16f8fe4m3u :
|
|
sdepth == CV_16BF ? cvt16bf8fe4m3u :
|
|
sdepth == CV_Bool ? cvt8u8fe4m3u : // bool stored as 0/1 byte -> reuse uchar path
|
|
sdepth == CV_64U ? cvt64u8fe4m3u :
|
|
sdepth == CV_64S ? cvt64s8fe4m3u :
|
|
sdepth == CV_8F_E4M3FN ? cvt8fe4m38fe4m3u :
|
|
sdepth == CV_8F_E4M3FNUZ ? cvt8u : // identity: 1-byte copy
|
|
0) :
|
|
0;
|
|
CV_Assert(func != 0);
|
|
return func;
|
|
}
|
|
|
|
CV_CPU_OPTIMIZATION_NAMESPACE_END
|
|
#endif
|
|
} // namespace
|