Debian Codegraph @

debian/missing-sources/glam/templates/swizzle_impl.rs.tera

raw
1 // Generated from {{template_path}} template. Edit the template, not the generated file.
2
3 {% if not is_scalar %}
4 #![allow(clippy::useless_conversion)]
5 {% endif %}
6
7 {# component indices #}
8 {% set indices = [0, 1, 2, 3] %}
9
10 {# vector dimensions #}
11 {% set dimensions = [2, 3, 4] %}
12
13 {# element names #}
14 {% set e = ["x", "y", "z", "w"] %}
15
16 {# shuffle bits (sse2) #}
17 {% set b = ["00", "01", "10", "11"] %}
18
19 {# low index (wasm32) #}
20 {% set l = ["0", "1", "2", "3"] %}
21
22 {# high index (wasm32) #}
23 {% set h = ["4", "5", "6", "7"] %}
24
25 use crate::{
26 Vec{{ dim }}Swizzles,
27 {{vec2_t}}, {{vec3_t}}, {{vec4_t}},
28 };
29
30 {% if is_sse2 %}
31 #[cfg(target_arch = "x86")]
32 use core::arch::x86::*;
33 #[cfg(target_arch = "x86_64")]
34 use core::arch::x86_64::*;
35 {% elif is_wasm32 %}
36 use core::arch::wasm32::*;
37 {% elif is_coresimd %}
38 use core::simd::*;
39 {% endif %}
40
41 impl Vec{{ dim }}Swizzles for {{ self_t }} {
42 {% if dim != 2 %}
43 type Vec2 = {{ vec2_t }};
44 {% endif %}
45 {% if dim != 3 %}
46 type Vec3 = {{ vec3_t }};
47 {% endif %}
48 {% if dim != 4 %}
49 type Vec4 = {{ vec4_t }};
50 {% endif %}
51
52 {% for i in dimensions %}
53 {% for j0 in indices | slice(end=dim) %}
54 {% for j1 in indices | slice(end=dim) %}
55 {% if i == 2 %}
56 {% set skip = dim == 2 and j0 == 0 and j1 == 1 %}
57 {% if not skip %}
58 {% if vec2_t == self_t %}
59 {% set ret_t = "Self" %}
60 {% else %}
61 {% set ret_t = vec2_t %}
62 {% endif %}
63
64 #[inline]
65 fn {{ e[j0] }}{{ e[j1] }}(self) -> {{ ret_t }} {
66 {{ ret_t }} { x: self.{{ e[j0] }}, y: self.{{ e[j1] }} }
67 }
68 {% endif %}
69 {% set skip = dim == 2 or j0 == j1 %}
70 {% if not skip %}
71 #[inline]
72 fn with_{{ e[j0] }}{{ e[j1] }}(self, rhs: {{ vec2_t }}) -> Self {
73 Self::new(
74 {% for l in range(start = 0, end = dim) %}
75 {% if j0 == l %}
76 rhs.x,
77 {% elif j1 == l %}
78 rhs.y,
79 {% else %}
80 self.{{e[l]}},
81 {% endif %}
82 {% endfor %}
83 )
84 }
85 {% endif %}
86 {% else %}
87 {% for j2 in indices | slice(end=dim) %}
88 {% if i == 3 %}
89 {% set skip = dim == 3 and j0 == 0 and j1 == 1 and j2 == 2 %}
90 {% if not skip %}
91 {% if vec3_t == self_t %}
92 {% set ret_t = "Self" %}
93 {% else %}
94 {% set ret_t = vec3_t %}
95 {% endif %}
96 #[inline]
97 fn {{ e[j0] }}{{ e[j1] }}{{ e[j2] }}(self) -> {{ ret_t }} {
98 {% if vec3_t == "Vec3A" and is_sse2 %}
99 {{ ret_t }}((unsafe { _mm_shuffle_ps(self.0, self.0, 0b00_{{ b[j2] }}_{{ b[j1] }}_{{ b[j0] }}) }).into())
100 {% elif vec3_t == "Vec3A" and is_wasm32 %}
101 {{ ret_t }}(i32x4_shuffle::<{{ l[j0] }}, {{ l[j1] }}, {{ h[j2] }}, {{ h[0] }}>(self.0, self.0).into())
102 {% elif vec3_t == "Vec3A" and is_coresimd %}
103 {{ ret_t }}(simd_swizzle!(self.0, [{{ l[j0] }}, {{ l[j1] }}, {{ l[j2] }}, {{ l[0] }}]).into())
104 {% else %}
105 {{ ret_t }}::new(self.{{ e[j0] }}, self.{{ e[j1] }}, self.{{ e[j2] }})
106 {% endif %}
107 }
108 {% endif %}
109 {% set skip = dim == 3 or j0 == j1 or j0 == j2 or j1 == j2 %}
110 {% if not skip %}
111 #[inline]
112 fn with_{{ e[j0] }}{{ e[j1] }}{{ e[j2] }}(self, rhs: {{ vec3_t }}) -> Self {
113 Self::new(
114 {% for l in range(start = 0, end = dim) %}
115 {% if j0 == l %}
116 rhs.x,
117 {% elif j1 == l %}
118 rhs.y,
119 {% elif j2 == l %}
120 rhs.z,
121 {% else %}
122 self.{{e[l]}},
123 {% endif %}
124 {% endfor %}
125 )
126 }
127 {% endif %}
128 {% else %}
129 {% for j3 in indices | slice(end=dim) %}
130 {% set skip = dim == 4 and j0 == 0 and j1 == 1 and j2 == 2 and j3 == 3 %}
131 {% if not skip %}
132 {% if vec4_t == self_t %}
133 {% set ret_t = "Self" %}
134 {% else %}
135 {% set ret_t = vec4_t %}
136 {% endif %}
137 #[inline]
138 fn {{ e[j0] }}{{ e[j1] }}{{ e[j2] }}{{ e[j3] }}(self) -> {{ ret_t }} {
139 {% if is_sse2 %}
140 {{ ret_t }}(unsafe { _mm_shuffle_ps(self.0, self.0, 0b{{ b[j3] }}_{{ b[j2] }}_{{ b[j1] }}_{{ b[j0] }}) })
141 {% elif is_wasm32 %}
142 {{ ret_t }}(i32x4_shuffle::<{{ l[j0] }}, {{ l[j1] }}, {{ h[j2] }}, {{ h[j3] }}>(self.0, self.0))
143 {% elif is_coresimd %}
144 {{ ret_t }}(simd_swizzle!(self.0, [{{ l[j0] }}, {{ l[j1] }}, {{ l[j2] }}, {{ l[j3] }}]))
145 {% else %}
146 {{ ret_t }}::new(self.{{ e[j0] }}, self.{{ e[j1] }}, self.{{ e[j2] }}, self.{{ e[j3] }})
147 {% endif %}
148 }
149 {% endif %}
150 {% endfor %}
151 {% endif %}
152 {% endfor %}
153 {% endif %}
154 {% endfor %}
155 {% endfor %}
156 {% endfor %}
157 }
158