Krita Source Code Documentation
Loading...
Searching...
No Matches
OptiRound< _impl, result_type > Struct Template Reference

#include <KoStreamedMath.h>

Static Public Member Functions

static ALWAYS_INLINE result_type roundScalar (const float value)
 

Detailed Description

template<typename _impl, typename result_type>
struct OptiRound< _impl, result_type >

Definition at line 33 of file KoStreamedMath.h.

Member Function Documentation

◆ roundScalar()

template<typename _impl , typename result_type >
static ALWAYS_INLINE result_type OptiRound< _impl, result_type >::roundScalar ( const float value)
inlinestatic

Definition at line 34 of file KoStreamedMath.h.

35 {
36#ifdef __SSE__
37 // SSE/AVX instructions use round-to-even rounding rule so we
38 // should reuse it when possible
39 return _mm_cvtss_si32(_mm_set_ss(value));
40#elif XSIMD_WITH_NEON64
41 return vgetq_lane_s32(vcvtnq_s32_f32(vrndiq_f32(vdupq_n_f32(value))),
42 0);
43#elif XSIMD_WITH_NEON
44 /* origin:
45 * https://github.com/DLTcollab/sse2neon/blob/cad518a93b326f0f644b7972d488d04eaa2b0475/sse2neon.h#L4028-L4047
46 */
47 // Contributors to this work are:
48 // John W. Ratcliff <jratcliffscarab@gmail.com>
49 // Brandon Rowlett <browlett@nvidia.com>
50 // Ken Fast <kfast@gdeb.com>
51 // Eric van Beurden <evanbeurden@nvidia.com>
52 // Alexander Potylitsin <apotylitsin@nvidia.com>
53 // Hasindu Gamaarachchi <hasindu2008@gmail.com>
54 // Jim Huang <jserv@biilabs.io>
55 // Mark Cheng <marktwtn@biilabs.io>
56 // Malcolm James MacLeod <malcolm@gulden.com>
57 // Devin Hussey (easyaspi314) <husseydevin@gmail.com>
58 // Sebastian Pop <spop@amazon.com>
59 // Developer Ecosystem Engineering
60 // <DeveloperEcosystemEngineering@apple.com> Danila Kutenin
61 // <danilak@google.com> François Turban (JishinMaster)
62 // <francois.turban@gmail.com> Pei-Hsuan Hung <afcidk@gmail.com>
63 // Yang-Hao Yuan <yanghau@biilabs.io>
64 // Syoyo Fujita <syoyo@lighttransport.com>
65 // Brecht Van Lommel <brecht@blender.org>
66
67 /*
68 * sse2neon is freely redistributable under the MIT License.
69 *
70 * Permission is hereby granted, free of charge, to any person obtaining
71 * a copy of this software and associated documentation files (the
72 * "Software"), to deal in the Software without restriction, including
73 * without limitation the rights to use, copy, modify, merge, publish,
74 * distribute, sublicense, and/or sell copies of the Software, and to
75 * permit persons to whom the Software is furnished to do so, subject to
76 * the following conditions:
77 *
78 * The above copyright notice and this permission notice shall be
79 * included in all copies or substantial portions of the Software.
80 *
81 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
82 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
83 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
84 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
85 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
86 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
87 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
88 * SOFTWARE.
89 */
90 const auto nearbyint_as_int = [](const float v) {
91 const auto a = vdupq_n_f32(v);
92 const auto signmask = vdupq_n_u32(0x80000000);
93 const auto half =
94 vbslq_f32(signmask, a, vdupq_n_f32(0.5f)); /* +/- 0.5 */
95 const auto r_normal = vcvtq_s32_f32(
96 vaddq_f32(a, half)); /* round to integer: [a + 0.5]*/
97 const auto r_trunc =
98 vcvtq_s32_f32(a); /* truncate to integer: [a] */
99 const auto plusone = vreinterpretq_s32_u32(
100 vshrq_n_u32(vreinterpretq_u32_s32(vnegq_s32(r_trunc)),
101 31)); /* 1 or 0 */
102 const auto r_even =
103 vbicq_s32(vaddq_s32(r_trunc, plusone),
104 vdupq_n_s32(1)); /* ([a] + {0,1}) & ~1 */
105 const auto delta = vsubq_f32(
106 a,
107 vcvtq_f32_s32(r_trunc)); /* compute delta: delta = (a - [a]) */
108 const auto is_delta_half =
109 vceqq_f32(delta, half); /* delta == +/- 0.5 */
110 return vbslq_s32(is_delta_half, r_even, r_normal);
111 };
112 return vgetq_lane_s32(nearbyint_as_int(value), 0);
113#else
114 return std::lroundf(value);
115#endif
116 }
float value(const T *src, size_t ch)
qreal v

References v, and value().


The documentation for this struct was generated from the following file: