Debian Codegraph @

debian/missing-sources/moxcms/src/conversions/neon/interpolator_q0_15.rs

raw
1 /*
2 * // Copyright (c) Radzivon Bartoshyk 3/2025. All rights reserved.
3 * //
4 * // Redistribution and use in source and binary forms, with or without modification,
5 * // are permitted provided that the following conditions are met:
6 * //
7 * // 1. Redistributions of source code must retain the above copyright notice, this
8 * // list of conditions and the following disclaimer.
9 * //
10 * // 2. Redistributions in binary form must reproduce the above copyright notice,
11 * // this list of conditions and the following disclaimer in the documentation
12 * // and/or other materials provided with the distribution.
13 * //
14 * // 3. Neither the name of the copyright holder nor the names of its
15 * // contributors may be used to endorse or promote products derived from
16 * // this software without specific prior written permission.
17 * //
18 * // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 * // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 * // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29 #![cfg(feature = "neon_luts")]
30 use crate::conversions::interpolator::BarycentricWeight;
31 use crate::math::FusedMultiplyAdd;
32 use std::arch::aarch64::*;
33 use std::ops::{Add, Mul, Sub};
34
35 #[repr(align(8), C)]
36 pub(crate) struct NeonAlignedI16x4(pub(crate) [i16; 4]);
37
38 #[cfg(feature = "options")]
39 pub(crate) struct TetrahedralNeonQ0_15<const GRID_SIZE: usize> {}
40
41 #[cfg(feature = "options")]
42 pub(crate) struct PyramidalNeonQ0_15<const GRID_SIZE: usize> {}
43
44 pub(crate) struct TrilinearNeonQ0_15<const GRID_SIZE: usize> {}
45
46 #[cfg(feature = "options")]
47 pub(crate) struct PrismaticNeonQ0_15<const GRID_SIZE: usize> {}
48
49 #[cfg(feature = "options")]
50 pub(crate) struct PyramidalNeonQ0_15Double<const GRID_SIZE: usize> {}
51
52 #[cfg(feature = "options")]
53 pub(crate) struct PrismaticNeonQ0_15Double<const GRID_SIZE: usize> {}
54
55 pub(crate) struct TrilinearNeonQ0_15Double<const GRID_SIZE: usize> {}
56
57 #[cfg(feature = "options")]
58 pub(crate) struct TetrahedralNeonQ0_15Double<const GRID_SIZE: usize> {}
59
60 trait Fetcher<T> {
61 fn fetch(&self, x: i32, y: i32, z: i32) -> T;
62 }
63
64 struct TetrahedralNeonQ0_15FetchVector<'a, const GRID_SIZE: usize> {
65 cube: &'a [NeonAlignedI16x4],
66 }
67
68 struct TetrahedralNeonQ0_15FetchVectorDouble<'a, const GRID_SIZE: usize> {
69 cube0: &'a [NeonAlignedI16x4],
70 cube1: &'a [NeonAlignedI16x4],
71 }
72
73 #[derive(Copy, Clone)]
74 pub(crate) struct NeonVectorQ0_15 {
75 pub(crate) v: int16x4_t,
76 }
77
78 #[derive(Copy, Clone)]
79 pub(crate) struct NeonVectorQ0_15Double {
80 pub(crate) v: int16x8_t,
81 }
82
83 impl From<i16> for NeonVectorQ0_15 {
84 #[inline(always)]
85 fn from(v: i16) -> Self {
86 NeonVectorQ0_15 {
87 v: unsafe { vdup_n_s16(v) },
88 }
89 }
90 }
91
92 impl From<i16> for NeonVectorQ0_15Double {
93 #[inline(always)]
94 fn from(v: i16) -> Self {
95 NeonVectorQ0_15Double {
96 v: unsafe { vdupq_n_s16(v) },
97 }
98 }
99 }
100
101 impl Sub<NeonVectorQ0_15> for NeonVectorQ0_15 {
102 type Output = Self;
103 #[inline(always)]
104 fn sub(self, rhs: NeonVectorQ0_15) -> Self::Output {
105 NeonVectorQ0_15 {
106 v: unsafe { vsub_s16(self.v, rhs.v) },
107 }
108 }
109 }
110
111 impl Mul<NeonVectorQ0_15> for NeonVectorQ0_15 {
112 type Output = Self;
113 #[inline(always)]
114 fn mul(self, rhs: NeonVectorQ0_15) -> Self::Output {
115 NeonVectorQ0_15 {
116 v: unsafe { vqrdmulh_s16(self.v, rhs.v) },
117 }
118 }
119 }
120
121 impl Sub<NeonVectorQ0_15Double> for NeonVectorQ0_15Double {
122 type Output = Self;
123 #[inline(always)]
124 fn sub(self, rhs: NeonVectorQ0_15Double) -> Self::Output {
125 NeonVectorQ0_15Double {
126 v: unsafe { vsubq_s16(self.v, rhs.v) },
127 }
128 }
129 }
130
131 impl Mul<NeonVectorQ0_15Double> for NeonVectorQ0_15Double {
132 type Output = Self;
133 #[inline(always)]
134 fn mul(self, rhs: NeonVectorQ0_15Double) -> Self::Output {
135 NeonVectorQ0_15Double {
136 v: unsafe { vqrdmulhq_s16(self.v, rhs.v) },
137 }
138 }
139 }
140
141 impl Add<NeonVectorQ0_15> for NeonVectorQ0_15 {
142 type Output = Self;
143 #[inline(always)]
144 fn add(self, rhs: NeonVectorQ0_15) -> Self::Output {
145 NeonVectorQ0_15 {
146 v: unsafe { vadd_s16(self.v, rhs.v) },
147 }
148 }
149 }
150
151 impl Add<NeonVectorQ0_15Double> for NeonVectorQ0_15Double {
152 type Output = Self;
153 #[inline(always)]
154 fn add(self, rhs: NeonVectorQ0_15Double) -> Self::Output {
155 NeonVectorQ0_15Double {
156 v: unsafe { vaddq_s16(self.v, rhs.v) },
157 }
158 }
159 }
160
161 impl FusedMultiplyAdd<NeonVectorQ0_15> for NeonVectorQ0_15 {
162 #[inline(always)]
163 fn mla(&self, b: NeonVectorQ0_15, c: NeonVectorQ0_15) -> NeonVectorQ0_15 {
164 NeonVectorQ0_15 {
165 v: unsafe { vqrdmlah_s16(self.v, b.v, c.v) },
166 }
167 }
168 }
169
170 impl NeonVectorQ0_15 {
171 #[inline(always)]
172 fn neg_mla(&self, b: NeonVectorQ0_15, c: NeonVectorQ0_15) -> NeonVectorQ0_15 {
173 NeonVectorQ0_15 {
174 v: unsafe { vqrdmlsh_s16(self.v, b.v, c.v) },
175 }
176 }
177 }
178
179 impl NeonVectorQ0_15Double {
180 #[inline(always)]
181 fn neg_mla(&self, b: NeonVectorQ0_15Double, c: NeonVectorQ0_15Double) -> NeonVectorQ0_15Double {
182 NeonVectorQ0_15Double {
183 v: unsafe { vqrdmlshq_s16(self.v, b.v, c.v) },
184 }
185 }
186 }
187
188 impl NeonVectorQ0_15Double {
189 #[inline(always)]
190 fn mla(&self, b: NeonVectorQ0_15Double, c: NeonVectorQ0_15) -> NeonVectorQ0_15Double {
191 NeonVectorQ0_15Double {
192 v: unsafe { vqrdmlahq_s16(self.v, b.v, vcombine_s16(c.v, c.v)) },
193 }
194 }
195
196 #[inline(always)]
197 pub(crate) fn split(self) -> (NeonVectorQ0_15, NeonVectorQ0_15) {
198 unsafe {
199 (
200 NeonVectorQ0_15 {
201 v: vget_low_s16(self.v),
202 },
203 NeonVectorQ0_15 {
204 v: vget_high_s16(self.v),
205 },
206 )
207 }
208 }
209 }
210
211 /// LUT size here is always fixed size (GRID_SIZE^3) and its use
212 /// is hardened at [crate::conversions::neon::assert_barycentric_lut_size_precondition].
213 impl<const GRID_SIZE: usize> Fetcher<NeonVectorQ0_15>
214 for TetrahedralNeonQ0_15FetchVector<'_, GRID_SIZE>
215 {
216 fn fetch(&self, x: i32, y: i32, z: i32) -> NeonVectorQ0_15 {
217 let offset = (x as u32 * (GRID_SIZE as u32 * GRID_SIZE as u32)
218 + y as u32 * GRID_SIZE as u32
219 + z as u32) as usize;
220 let jx = unsafe { self.cube.get_unchecked(offset..) };
221 NeonVectorQ0_15 {
222 v: unsafe { vld1_s16(jx.as_ptr() as *const i16) },
223 }
224 }
225 }
226
227 /// LUT size here is always fixed size (GRID_SIZE^3) and its use
228 /// is hardened at [crate::conversions::neon::assert_barycentric_lut_size_precondition].
229 impl<const GRID_SIZE: usize> Fetcher<NeonVectorQ0_15Double>
230 for TetrahedralNeonQ0_15FetchVectorDouble<'_, GRID_SIZE>
231 {
232 fn fetch(&self, x: i32, y: i32, z: i32) -> NeonVectorQ0_15Double {
233 let offset = (x as u32 * (GRID_SIZE as u32 * GRID_SIZE as u32)
234 + y as u32 * GRID_SIZE as u32
235 + z as u32) as usize;
236 let jx0 = unsafe { self.cube0.get_unchecked(offset..) };
237 let jx1 = unsafe { self.cube1.get_unchecked(offset..) };
238 NeonVectorQ0_15Double {
239 v: unsafe {
240 vcombine_s16(
241 vld1_s16(jx0.as_ptr() as *const i16),
242 vld1_s16(jx1.as_ptr() as *const i16),
243 )
244 },
245 }
246 }
247 }
248
249 pub(crate) trait NeonMdInterpolationQ0_15 {
250 fn inter3_neon(
251 &self,
252 cube: &[NeonAlignedI16x4],
253 in_r: usize,
254 in_g: usize,
255 in_b: usize,
256 lut: &[BarycentricWeight<i16>],
257 ) -> NeonVectorQ0_15;
258 }
259
260 pub(crate) trait NeonMdInterpolationQ0_15Double {
261 fn inter3_neon(
262 &self,
263 table0: &[NeonAlignedI16x4],
264 table1: &[NeonAlignedI16x4],
265 in_r: usize,
266 in_g: usize,
267 in_b: usize,
268 lut: &[BarycentricWeight<i16>],
269 ) -> (NeonVectorQ0_15, NeonVectorQ0_15);
270 }
271
272 #[cfg(feature = "options")]
273 impl<const GRID_SIZE: usize> TetrahedralNeonQ0_15<GRID_SIZE> {
274 #[target_feature(enable = "rdm")]
275 unsafe fn interpolate(
276 &self,
277 in_r: usize,
278 in_g: usize,
279 in_b: usize,
280 lut: &[BarycentricWeight<i16>],
281 r: impl Fetcher<NeonVectorQ0_15>,
282 ) -> NeonVectorQ0_15 {
283 let lut_r = unsafe { *lut.get_unchecked(in_r) };
284 let lut_g = unsafe { *lut.get_unchecked(in_g) };
285 let lut_b = unsafe { *lut.get_unchecked(in_b) };
286
287 let x: i32 = lut_r.x;
288 let y: i32 = lut_g.x;
289 let z: i32 = lut_b.x;
290
291 let x_n: i32 = lut_r.x_n;
292 let y_n: i32 = lut_g.x_n;
293 let z_n: i32 = lut_b.x_n;
294
295 let rx = lut_r.w;
296 let ry = lut_g.w;
297 let rz = lut_b.w;
298
299 let c0 = r.fetch(x, y, z);
300
301 let c2;
302 let c1;
303 let c3;
304 if rx >= ry {
305 if ry >= rz {
306 //rx >= ry && ry >= rz
307 c1 = r.fetch(x_n, y, z) - c0;
308 c2 = r.fetch(x_n, y_n, z) - r.fetch(x_n, y, z);
309 c3 = r.fetch(x_n, y_n, z_n) - r.fetch(x_n, y_n, z);
310 } else if rx >= rz {
311 //rx >= rz && rz >= ry
312 c1 = r.fetch(x_n, y, z) - c0;
313 c2 = r.fetch(x_n, y_n, z_n) - r.fetch(x_n, y, z_n);
314 c3 = r.fetch(x_n, y, z_n) - r.fetch(x_n, y, z);
315 } else {
316 //rz > rx && rx >= ry
317 c1 = r.fetch(x_n, y, z_n) - r.fetch(x, y, z_n);
318 c2 = r.fetch(x_n, y_n, z_n) - r.fetch(x_n, y, z_n);
319 c3 = r.fetch(x, y, z_n) - c0;
320 }
321 } else if rx >= rz {
322 //ry > rx && rx >= rz
323 c1 = r.fetch(x_n, y_n, z) - r.fetch(x, y_n, z);
324 c2 = r.fetch(x, y_n, z) - c0;
325 c3 = r.fetch(x_n, y_n, z_n) - r.fetch(x_n, y_n, z);
326 } else if ry >= rz {
327 //ry >= rz && rz > rx
328 c1 = r.fetch(x_n, y_n, z_n) - r.fetch(x, y_n, z_n);
329 c2 = r.fetch(x, y_n, z) - c0;
330 c3 = r.fetch(x, y_n, z_n) - r.fetch(x, y_n, z);
331 } else {
332 //rz > ry && ry > rx
333 c1 = r.fetch(x_n, y_n, z_n) - r.fetch(x, y_n, z_n);
334 c2 = r.fetch(x, y_n, z_n) - r.fetch(x, y, z_n);
335 c3 = r.fetch(x, y, z_n) - c0;
336 }
337 let s0 = c0.mla(c1, NeonVectorQ0_15::from(rx));
338 let s1 = s0.mla(c2, NeonVectorQ0_15::from(ry));
339 s1.mla(c3, NeonVectorQ0_15::from(rz))
340 }
341 }
342
343 #[cfg(feature = "options")]
344 impl<const GRID_SIZE: usize> TetrahedralNeonQ0_15Double<GRID_SIZE> {
345 #[target_feature(enable = "rdm")]
346 unsafe fn interpolate(
347 &self,
348 in_r: usize,
349 in_g: usize,
350 in_b: usize,
351 lut: &[BarycentricWeight<i16>],
352 r: impl Fetcher<NeonVectorQ0_15Double>,
353 ) -> (NeonVectorQ0_15, NeonVectorQ0_15) {
354 let lut_r = unsafe { *lut.get_unchecked(in_r) };
355 let lut_g = unsafe { *lut.get_unchecked(in_g) };
356 let lut_b = unsafe { *lut.get_unchecked(in_b) };
357
358 let x: i32 = lut_r.x;
359 let y: i32 = lut_g.x;
360 let z: i32 = lut_b.x;
361
362 let x_n: i32 = lut_r.x_n;
363 let y_n: i32 = lut_g.x_n;
364 let z_n: i32 = lut_b.x_n;
365
366 let rx = lut_r.w;
367 let ry = lut_g.w;
368 let rz = lut_b.w;
369
370 let c0 = r.fetch(x, y, z);
371
372 let c2;
373 let c1;
374 let c3;
375 if rx >= ry {
376 if ry >= rz {
377 //rx >= ry && ry >= rz
378 c1 = r.fetch(x_n, y, z) - c0;
379 c2 = r.fetch(x_n, y_n, z) - r.fetch(x_n, y, z);
380 c3 = r.fetch(x_n, y_n, z_n) - r.fetch(x_n, y_n, z);
381 } else if rx >= rz {
382 //rx >= rz && rz >= ry
383 c1 = r.fetch(x_n, y, z) - c0;
384 c2 = r.fetch(x_n, y_n, z_n) - r.fetch(x_n, y, z_n);
385 c3 = r.fetch(x_n, y, z_n) - r.fetch(x_n, y, z);
386 } else {
387 //rz > rx && rx >= ry
388 c1 = r.fetch(x_n, y, z_n) - r.fetch(x, y, z_n);
389 c2 = r.fetch(x_n, y_n, z_n) - r.fetch(x_n, y, z_n);
390 c3 = r.fetch(x, y, z_n) - c0;
391 }
392 } else if rx >= rz {
393 //ry > rx && rx >= rz
394 c1 = r.fetch(x_n, y_n, z) - r.fetch(x, y_n, z);
395 c2 = r.fetch(x, y_n, z) - c0;
396 c3 = r.fetch(x_n, y_n, z_n) - r.fetch(x_n, y_n, z);
397 } else if ry >= rz {
398 //ry >= rz && rz > rx
399 c1 = r.fetch(x_n, y_n, z_n) - r.fetch(x, y_n, z_n);
400 c2 = r.fetch(x, y_n, z) - c0;
401 c3 = r.fetch(x, y_n, z_n) - r.fetch(x, y_n, z);
402 } else {
403 //rz > ry && ry > rx
404 c1 = r.fetch(x_n, y_n, z_n) - r.fetch(x, y_n, z_n);
405 c2 = r.fetch(x, y_n, z_n) - r.fetch(x, y, z_n);
406 c3 = r.fetch(x, y, z_n) - c0;
407 }
408 let s0 = c0.mla(c1, NeonVectorQ0_15::from(rx));
409 let s1 = s0.mla(c2, NeonVectorQ0_15::from(ry));
410 s1.mla(c3, NeonVectorQ0_15::from(rz)).split()
411 }
412 }
413
414 macro_rules! define_md_inter_neon {
415 ($interpolator: ident) => {
416 impl<const GRID_SIZE: usize> NeonMdInterpolationQ0_15 for $interpolator<GRID_SIZE> {
417 fn inter3_neon(
418 &self,
419 cube: &[NeonAlignedI16x4],
420 in_r: usize,
421 in_g: usize,
422 in_b: usize,
423 lut: &[BarycentricWeight<i16>],
424 ) -> NeonVectorQ0_15 {
425 unsafe {
426 self.interpolate(
427 in_r,
428 in_g,
429 in_b,
430 lut,
431 TetrahedralNeonQ0_15FetchVector::<GRID_SIZE> { cube },
432 )
433 }
434 }
435 }
436 };
437 }
438
439 macro_rules! define_md_inter_neon_d {
440 ($interpolator: ident) => {
441 impl<const GRID_SIZE: usize> NeonMdInterpolationQ0_15Double for $interpolator<GRID_SIZE> {
442 fn inter3_neon(
443 &self,
444 table0: &[NeonAlignedI16x4],
445 table1: &[NeonAlignedI16x4],
446 in_r: usize,
447 in_g: usize,
448 in_b: usize,
449 lut: &[BarycentricWeight<i16>],
450 ) -> (NeonVectorQ0_15, NeonVectorQ0_15) {
451 unsafe {
452 self.interpolate(
453 in_r,
454 in_g,
455 in_b,
456 lut,
457 TetrahedralNeonQ0_15FetchVectorDouble::<GRID_SIZE> {
458 cube0: table0,
459 cube1: table1,
460 },
461 )
462 }
463 }
464 }
465 };
466 }
467
468 #[cfg(feature = "options")]
469 define_md_inter_neon!(TetrahedralNeonQ0_15);
470 #[cfg(feature = "options")]
471 define_md_inter_neon!(PyramidalNeonQ0_15);
472 #[cfg(feature = "options")]
473 define_md_inter_neon!(PrismaticNeonQ0_15);
474 define_md_inter_neon!(TrilinearNeonQ0_15);
475 #[cfg(feature = "options")]
476 define_md_inter_neon_d!(PrismaticNeonQ0_15Double);
477 #[cfg(feature = "options")]
478 define_md_inter_neon_d!(PyramidalNeonQ0_15Double);
479 #[cfg(feature = "options")]
480 define_md_inter_neon_d!(TetrahedralNeonQ0_15Double);
481 define_md_inter_neon_d!(TrilinearNeonQ0_15Double);
482
483 #[cfg(feature = "options")]
484 impl<const GRID_SIZE: usize> PyramidalNeonQ0_15<GRID_SIZE> {
485 #[target_feature(enable = "rdm")]
486 unsafe fn interpolate(
487 &self,
488 in_r: usize,
489 in_g: usize,
490 in_b: usize,
491 lut: &[BarycentricWeight<i16>],
492 r: impl Fetcher<NeonVectorQ0_15>,
493 ) -> NeonVectorQ0_15 {
494 let lut_r = unsafe { *lut.get_unchecked(in_r) };
495 let lut_g = unsafe { *lut.get_unchecked(in_g) };
496 let lut_b = unsafe { *lut.get_unchecked(in_b) };
497
498 let x: i32 = lut_r.x;
499 let y: i32 = lut_g.x;
500 let z: i32 = lut_b.x;
501
502 let x_n: i32 = lut_r.x_n;
503 let y_n: i32 = lut_g.x_n;
504 let z_n: i32 = lut_b.x_n;
505
506 let dr = lut_r.w;
507 let dg = lut_g.w;
508 let db = lut_b.w;
509
510 let c0 = r.fetch(x, y, z);
511
512 let w0 = NeonVectorQ0_15::from(db);
513 let w1 = NeonVectorQ0_15::from(dr);
514 let w2 = NeonVectorQ0_15::from(dg);
515
516 if dr > db && dg > db {
517 let x0 = r.fetch(x_n, y_n, z_n);
518 let x1 = r.fetch(x_n, y_n, z);
519 let x2 = r.fetch(x_n, y, z);
520 let x3 = r.fetch(x, y_n, z);
521
522 let w3 = w1 * w2;
523
524 let c1 = x0 - x1;
525 let c2 = x2 - c0;
526 let c3 = x3 - c0;
527 let c4 = c0 - x3 - x2 + x1;
528
529 let s0 = c0.mla(c1, w0);
530 let s1 = s0.mla(c2, w1);
531 let s2 = s1.mla(c3, w2);
532 s2.mla(c4, w3)
533 } else if db > dr && dg > dr {
534 let x0 = r.fetch(x, y, z_n);
535 let x1 = r.fetch(x_n, y_n, z_n);
536 let x2 = r.fetch(x, y_n, z_n);
537 let x3 = r.fetch(x, y_n, z);
538
539 let w3 = w2 * w0;
540
541 let c1 = x0 - c0;
542 let c2 = x1 - x2;
543 let c3 = x3 - c0;
544 let c4 = c0 - x3 - x0 + x2;
545
546 let s0 = c0.mla(c1, w0);
547 let s1 = s0.mla(c2, w1);
548 let s2 = s1.mla(c3, w2);
549 s2.mla(c4, w3)
550 } else {
551 let x0 = r.fetch(x, y, z_n);
552 let x1 = r.fetch(x_n, y, z);
553 let x2 = r.fetch(x_n, y, z_n);
554 let x3 = r.fetch(x_n, y_n, z_n);
555
556 let w3 = w0 * w1;
557
558 let c1 = x0 - c0;
559 let c2 = x1 - c0;
560 let c3 = x3 - x2;
561 let c4 = c0 - x1 - x0 + x2;
562
563 let s0 = c0.mla(c1, w0);
564 let s1 = s0.mla(c2, w1);
565 let s2 = s1.mla(c3, w2);
566 s2.mla(c4, w3)
567 }
568 }
569 }
570
571 #[cfg(feature = "options")]
572 impl<const GRID_SIZE: usize> PyramidalNeonQ0_15Double<GRID_SIZE> {
573 #[target_feature(enable = "rdm")]
574 unsafe fn interpolate(
575 &self,
576 in_r: usize,
577 in_g: usize,
578 in_b: usize,
579 lut: &[BarycentricWeight<i16>],
580 r: impl Fetcher<NeonVectorQ0_15Double>,
581 ) -> (NeonVectorQ0_15, NeonVectorQ0_15) {
582 let lut_r = unsafe { *lut.get_unchecked(in_r) };
583 let lut_g = unsafe { *lut.get_unchecked(in_g) };
584 let lut_b = unsafe { *lut.get_unchecked(in_b) };
585
586 let x: i32 = lut_r.x;
587 let y: i32 = lut_g.x;
588 let z: i32 = lut_b.x;
589
590 let x_n: i32 = lut_r.x_n;
591 let y_n: i32 = lut_g.x_n;
592 let z_n: i32 = lut_b.x_n;
593
594 let dr = lut_r.w;
595 let dg = lut_g.w;
596 let db = lut_b.w;
597
598 let c0 = r.fetch(x, y, z);
599
600 let w0 = NeonVectorQ0_15::from(db);
601 let w1 = NeonVectorQ0_15::from(dr);
602 let w2 = NeonVectorQ0_15::from(dg);
603
604 if dr > db && dg > db {
605 let w3 = NeonVectorQ0_15::from(dr) * NeonVectorQ0_15::from(dg);
606 let x0 = r.fetch(x_n, y_n, z_n);
607 let x1 = r.fetch(x_n, y_n, z);
608 let x2 = r.fetch(x_n, y, z);
609 let x3 = r.fetch(x, y_n, z);
610
611 let c1 = x0 - x1;
612 let c2 = x2 - c0;
613 let c3 = x3 - c0;
614 let c4 = c0 - x3 - x2 + x1;
615
616 let s0 = c0.mla(c1, w0);
617 let s1 = s0.mla(c2, w1);
618 let s2 = s1.mla(c3, w2);
619 s2.mla(c4, w3).split()
620 } else if db > dr && dg > dr {
621 let w3 = NeonVectorQ0_15::from(dg) * NeonVectorQ0_15::from(db);
622 let x0 = r.fetch(x, y, z_n);
623 let x1 = r.fetch(x_n, y_n, z_n);
624 let x2 = r.fetch(x, y_n, z_n);
625 let x3 = r.fetch(x, y_n, z);
626
627 let c1 = x0 - c0;
628 let c2 = x1 - x2;
629 let c3 = x3 - c0;
630 let c4 = c0 - x3 - x0 + x2;
631
632 let s0 = c0.mla(c1, w0);
633 let s1 = s0.mla(c2, w1);
634 let s2 = s1.mla(c3, w2);
635 s2.mla(c4, w3).split()
636 } else {
637 let w3 = NeonVectorQ0_15::from(db) * NeonVectorQ0_15::from(dr);
638 let x0 = r.fetch(x, y, z_n);
639 let x1 = r.fetch(x_n, y, z);
640 let x2 = r.fetch(x_n, y, z_n);
641 let x3 = r.fetch(x_n, y_n, z_n);
642
643 let c1 = x0 - c0;
644 let c2 = x1 - c0;
645 let c3 = x3 - x2;
646 let c4 = c0 - x1 - x0 + x2;
647
648 let s0 = c0.mla(c1, w0);
649 let s1 = s0.mla(c2, w1);
650 let s2 = s1.mla(c3, w2);
651 s2.mla(c4, w3).split()
652 }
653 }
654 }
655
656 #[cfg(feature = "options")]
657 impl<const GRID_SIZE: usize> PrismaticNeonQ0_15<GRID_SIZE> {
658 #[target_feature(enable = "rdm")]
659 unsafe fn interpolate(
660 &self,
661 in_r: usize,
662 in_g: usize,
663 in_b: usize,
664 lut: &[BarycentricWeight<i16>],
665 r: impl Fetcher<NeonVectorQ0_15>,
666 ) -> NeonVectorQ0_15 {
667 let lut_r = unsafe { *lut.get_unchecked(in_r) };
668 let lut_g = unsafe { *lut.get_unchecked(in_g) };
669 let lut_b = unsafe { *lut.get_unchecked(in_b) };
670
671 let x: i32 = lut_r.x;
672 let y: i32 = lut_g.x;
673 let z: i32 = lut_b.x;
674
675 let x_n: i32 = lut_r.x_n;
676 let y_n: i32 = lut_g.x_n;
677 let z_n: i32 = lut_b.x_n;
678
679 let dr = lut_r.w;
680 let dg = lut_g.w;
681 let db = lut_b.w;
682
683 let c0 = r.fetch(x, y, z);
684
685 let w0 = NeonVectorQ0_15::from(db);
686 let w1 = NeonVectorQ0_15::from(dr);
687 let w2 = NeonVectorQ0_15::from(dg);
688
689 if db > dr {
690 let w3 = w2 * w0;
691 let w4 = w1 * w2;
692 let x0 = r.fetch(x, y, z_n);
693 let x1 = r.fetch(x_n, y, z_n);
694 let x2 = r.fetch(x, y_n, z);
695 let x3 = r.fetch(x, y_n, z_n);
696 let x4 = r.fetch(x_n, y_n, z_n);
697
698 let c1 = x0 - c0;
699 let c2 = x1 - x0;
700 let c3 = x2 - c0;
701 let c4 = c0 - x2 - x0 + x3;
702 let c5 = x0 - x3 - x1 + x4;
703
704 let s0 = c0.mla(c1, w0);
705 let s1 = s0.mla(c2, w1);
706 let s2 = s1.mla(c3, w2);
707 let s3 = s2.mla(c4, w3);
708 s3.mla(c5, w4)
709 } else {
710 let w3 = w2 * w0;
711 let w4 = w1 * w2;
712 let x0 = r.fetch(x_n, y, z);
713 let x1 = r.fetch(x_n, y, z_n);
714 let x2 = r.fetch(x, y_n, z);
715 let x3 = r.fetch(x_n, y_n, z);
716 let x4 = r.fetch(x_n, y_n, z_n);
717
718 let c1 = x1 - x0;
719 let c2 = x0 - c0;
720 let c3 = x2 - c0;
721 let c4 = x0 - x3 - x1 + x4;
722 let c5 = c0 - x2 - x0 + x3;
723
724 let s0 = c0.mla(c1, w0);
725 let s1 = s0.mla(c2, w1);
726 let s2 = s1.mla(c3, w2);
727 let s3 = s2.mla(c4, w3);
728 s3.mla(c5, w4)
729 }
730 }
731 }
732
733 #[cfg(feature = "options")]
734 impl<const GRID_SIZE: usize> PrismaticNeonQ0_15Double<GRID_SIZE> {
735 #[target_feature(enable = "rdm")]
736 unsafe fn interpolate(
737 &self,
738 in_r: usize,
739 in_g: usize,
740 in_b: usize,
741 lut: &[BarycentricWeight<i16>],
742 rv: impl Fetcher<NeonVectorQ0_15Double>,
743 ) -> (NeonVectorQ0_15, NeonVectorQ0_15) {
744 let lut_r = unsafe { *lut.get_unchecked(in_r) };
745 let lut_g = unsafe { *lut.get_unchecked(in_g) };
746 let lut_b = unsafe { *lut.get_unchecked(in_b) };
747
748 let x: i32 = lut_r.x;
749 let y: i32 = lut_g.x;
750 let z: i32 = lut_b.x;
751
752 let x_n: i32 = lut_r.x_n;
753 let y_n: i32 = lut_g.x_n;
754 let z_n: i32 = lut_b.x_n;
755
756 let dr = lut_r.w;
757 let dg = lut_g.w;
758 let db = lut_b.w;
759
760 let c0 = rv.fetch(x, y, z);
761
762 let w0 = NeonVectorQ0_15::from(db);
763 let w1 = NeonVectorQ0_15::from(dr);
764 let w2 = NeonVectorQ0_15::from(dg);
765 let w3 = NeonVectorQ0_15::from(dg) * NeonVectorQ0_15::from(db);
766 let w4 = NeonVectorQ0_15::from(dr) * NeonVectorQ0_15::from(dg);
767
768 if db > dr {
769 let x0 = rv.fetch(x, y, z_n);
770 let x1 = rv.fetch(x_n, y, z_n);
771 let x2 = rv.fetch(x, y_n, z);
772 let x3 = rv.fetch(x, y_n, z_n);
773 let x4 = rv.fetch(x_n, y_n, z_n);
774
775 let c1 = x0 - c0;
776 let c2 = x1 - x0;
777 let c3 = x2 - c0;
778 let c4 = c0 - x2 - x0 + x3;
779 let c5 = x0 - x3 - x1 + x4;
780
781 let s0 = c0.mla(c1, w0);
782 let s1 = s0.mla(c2, w1);
783 let s2 = s1.mla(c3, w2);
784 let s3 = s2.mla(c4, w3);
785 s3.mla(c5, w4).split()
786 } else {
787 let x0 = rv.fetch(x_n, y, z);
788 let x1 = rv.fetch(x_n, y, z_n);
789 let x2 = rv.fetch(x, y_n, z);
790 let x3 = rv.fetch(x_n, y_n, z);
791 let x4 = rv.fetch(x_n, y_n, z_n);
792
793 let c1 = x1 - x0;
794 let c2 = x0 - c0;
795 let c3 = x2 - c0;
796 let c4 = x0 - x3 - x1 + x4;
797 let c5 = c0 - x2 - x0 + x3;
798
799 let s0 = c0.mla(c1, w0);
800 let s1 = s0.mla(c2, w1);
801 let s2 = s1.mla(c3, w2);
802 let s3 = s2.mla(c4, w3);
803 s3.mla(c5, w4).split()
804 }
805 }
806 }
807
808 impl<const GRID_SIZE: usize> TrilinearNeonQ0_15Double<GRID_SIZE> {
809 #[target_feature(enable = "rdm")]
810 unsafe fn interpolate(
811 &self,
812 in_r: usize,
813 in_g: usize,
814 in_b: usize,
815 lut: &[BarycentricWeight<i16>],
816 r: impl Fetcher<NeonVectorQ0_15Double>,
817 ) -> (NeonVectorQ0_15, NeonVectorQ0_15) {
818 let lut_r = unsafe { *lut.get_unchecked(in_r) };
819 let lut_g = unsafe { *lut.get_unchecked(in_g) };
820 let lut_b = unsafe { *lut.get_unchecked(in_b) };
821
822 let x: i32 = lut_r.x;
823 let y: i32 = lut_g.x;
824 let z: i32 = lut_b.x;
825
826 let x_n: i32 = lut_r.x_n;
827 let y_n: i32 = lut_g.x_n;
828 let z_n: i32 = lut_b.x_n;
829
830 let dr = lut_r.w;
831 let dg = lut_g.w;
832 let db = lut_b.w;
833
834 let w0 = NeonVectorQ0_15::from(dr);
835 let w1 = NeonVectorQ0_15::from(dg);
836 let w2 = NeonVectorQ0_15::from(db);
837
838 let c000 = r.fetch(x, y, z);
839 let c100 = r.fetch(x_n, y, z);
840 let c010 = r.fetch(x, y_n, z);
841 let c110 = r.fetch(x_n, y_n, z);
842 let c001 = r.fetch(x, y, z_n);
843 let c101 = r.fetch(x_n, y, z_n);
844 let c011 = r.fetch(x, y_n, z_n);
845 let c111 = r.fetch(x_n, y_n, z_n);
846
847 let dx = NeonVectorQ0_15Double::from(dr);
848
849 let c00 = c000.neg_mla(c000, dx).mla(c100, w0);
850 let c10 = c010.neg_mla(c010, dx).mla(c110, w0);
851 let c01 = c001.neg_mla(c001, dx).mla(c101, w0);
852 let c11 = c011.neg_mla(c011, dx).mla(c111, w0);
853
854 let dy = NeonVectorQ0_15Double::from(dg);
855
856 let c0 = c00.neg_mla(c00, dy).mla(c10, w1);
857 let c1 = c01.neg_mla(c01, dy).mla(c11, w1);
858
859 let dz = NeonVectorQ0_15Double::from(db);
860
861 c0.neg_mla(c0, dz).mla(c1, w2).split()
862 }
863 }
864
865 impl<const GRID_SIZE: usize> TrilinearNeonQ0_15<GRID_SIZE> {
866 #[target_feature(enable = "rdm")]
867 unsafe fn interpolate(
868 &self,
869 in_r: usize,
870 in_g: usize,
871 in_b: usize,
872 lut: &[BarycentricWeight<i16>],
873 r: impl Fetcher<NeonVectorQ0_15>,
874 ) -> NeonVectorQ0_15 {
875 let lut_r = unsafe { *lut.get_unchecked(in_r) };
876 let lut_g = unsafe { *lut.get_unchecked(in_g) };
877 let lut_b = unsafe { *lut.get_unchecked(in_b) };
878
879 let x: i32 = lut_r.x;
880 let y: i32 = lut_g.x;
881 let z: i32 = lut_b.x;
882
883 let x_n: i32 = lut_r.x_n;
884 let y_n: i32 = lut_g.x_n;
885 let z_n: i32 = lut_b.x_n;
886
887 let dr = lut_r.w;
888 let dg = lut_g.w;
889 let db = lut_b.w;
890
891 let w0 = NeonVectorQ0_15::from(dr);
892 let w1 = NeonVectorQ0_15::from(dg);
893 let w2 = NeonVectorQ0_15::from(db);
894
895 let c000 = r.fetch(x, y, z);
896 let c100 = r.fetch(x_n, y, z);
897 let c010 = r.fetch(x, y_n, z);
898 let c110 = r.fetch(x_n, y_n, z);
899 let c001 = r.fetch(x, y, z_n);
900 let c101 = r.fetch(x_n, y, z_n);
901 let c011 = r.fetch(x, y_n, z_n);
902 let c111 = r.fetch(x_n, y_n, z_n);
903
904 let dx = NeonVectorQ0_15::from(dr);
905
906 let c00 = c000.neg_mla(c000, dx).mla(c100, w0);
907 let c10 = c010.neg_mla(c010, dx).mla(c110, w0);
908 let c01 = c001.neg_mla(c001, dx).mla(c101, w0);
909 let c11 = c011.neg_mla(c011, dx).mla(c111, w0);
910
911 let dy = NeonVectorQ0_15::from(dg);
912
913 let c0 = c00.neg_mla(c00, dy).mla(c10, w1);
914 let c1 = c01.neg_mla(c01, dy).mla(c11, w1);
915
916 let dz = NeonVectorQ0_15::from(db);
917
918 c0.neg_mla(c0, dz).mla(c1, w2)
919 }
920 }