@@ -197,32 +197,29 @@ end
197
197
return tupexpr (i -> :(rand (V)), N)
198
198
end
199
199
200
+ @generated function scale_tuple (tup:: NTuple{N} , x) where N
201
+ return tupexpr (i -> :(tup[$ i] * x), N)
202
+ end
203
+
204
+ @generated function div_tuple_by_scalar (tup:: NTuple{N} , x) where N
205
+ return tupexpr (i -> :(tup[$ i] / x), N)
206
+ end
207
+
208
+ @generated function add_tuples (a:: NTuple{N} , b:: NTuple{N} ) where N
209
+ return tupexpr (i -> :(a[$ i] + b[$ i]), N)
210
+ end
200
211
201
- const SIMDFloat = Union{Float64, Float32}
202
- const SIMDInt = Union{
203
- Int128, Int64, Int32, Int16, Int8,
204
- UInt128, UInt64, UInt32, UInt16, UInt8,
205
- }
206
- const SIMDType = Union{SIMDFloat, SIMDInt}
207
- const NT{N,T} = NTuple{N,T}
208
- using SIMD
209
-
210
- # SIMD implementation
211
- add_tuples (a:: NT{N,T} , b:: NT{N,T} ) where {N, T<: SIMDType } = Tuple (Vec (a) + Vec (b))
212
- sub_tuples (a:: NT{N,T} , b:: NT{N,T} ) where {N, T<: SIMDType } = Tuple (Vec (a) - Vec (b))
213
- scale_tuple (tup:: NT{N,T} , x:: T ) where {N, T<: SIMDType } = Tuple (Vec (tup) * x)
214
- div_tuple_by_scalar (tup:: NT{N,T} , x:: T ) where {N, T<: SIMDFloat } = Tuple (Vec (tup) / x)
215
- minus_tuple (tup:: NT{N,T} ) where {N, T<: SIMDType } = Tuple (- Vec (tup))
216
- mul_tuples (a:: NT{N,T} , b:: NT{N,T} , af:: T , bf:: T ) where {N, T<: SIMDType } = Tuple (muladd (Vec {N,T} (af), Vec (a), Vec {N,T} (bf) * Vec (b)))
217
-
218
-
219
- # Fallback implementations
220
- @generated add_tuples (a:: NT{N} , b:: NT{N} ) where N = tupexpr (i -> :(a[$ i] + b[$ i]), N)
221
- @generated sub_tuples (a:: NT{N} , b:: NT{N} ) where N = tupexpr (i -> :(a[$ i] - b[$ i]), N)
222
- @generated scale_tuple (tup:: NT{N} , x) where N = tupexpr (i -> :(tup[$ i] * x), N)
223
- @generated div_tuple_by_scalar (tup:: NT{N} , x) where N = tupexpr (i -> :(tup[$ i] / x), N)
224
- @generated minus_tuple (tup:: NT{N} ) where N = tupexpr (i -> :(- tup[$ i]), N)
225
- @generated mul_tuples (a:: NT{N} , b:: NT{N} , af, bf) where N = tupexpr (i -> :((af * a[$ i]) + (bf * b[$ i])), N)
212
+ @generated function sub_tuples (a:: NTuple{N} , b:: NTuple{N} ) where N
213
+ return tupexpr (i -> :(a[$ i] - b[$ i]), N)
214
+ end
215
+
216
+ @generated function minus_tuple (tup:: NTuple{N} ) where N
217
+ return tupexpr (i -> :(- tup[$ i]), N)
218
+ end
219
+
220
+ @generated function mul_tuples (a:: NTuple{N} , b:: NTuple{N} , afactor, bfactor) where N
221
+ return tupexpr (i -> :((afactor * a[$ i]) + (bfactor * b[$ i])), N)
222
+ end
226
223
227
224
# ##################
228
225
# Pretty Printing #
0 commit comments