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 29 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 30 of file KoStreamedMath.h.

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