In many official Apple samples and Xcode templates, two float4x4
matrices are multiplied using simd_mul
, like:
simd_mul(viewMatrix, modelMatrix)
Now, simd.h provides a *
operator for it's types, so the above line could have been written as
viewMatrix * modelMatrix
Is there any difference, either in usage or performance between the above two methods? I can only look into simd.h
so I have no idea how is the method actually implemented, but I guess it's just a call to simd_mul
.
There is no difference. Swift is open source, and in simd.swift.gyb you'll find
% for k in [2,3,4]:
/// Matrix multiplication (the "usual" matrix product, not the elementwise
/// product).
% restype = ctype[type] + str(k) + 'x' + str(rows)
% rhstype = ctype[type] + str(k) + 'x' + str(cols)
@_transparent
public static func *(lhs: ${mattype}, rhs: ${rhstype}) -> ${restype} {
return simd_mul(lhs, rhs)
}
% end # for k in [2,3,4]
.gyb files (“Generate Your Boilerplate“) are pre-processed by a special Swift preprocessor (compare https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20151207/000226.html). The above code is nested inside loops
%for type in floating_types:
% for rows in [2,3,4]:
% for cols in [2,3,4]:
% mattype = 'simd_' + ctype[type] + str(cols) + 'x' + str(rows)
// ....
% end # for cols in [2,3,4]
% end # for rows in [2,3,4]
%end # for type in floating_types
so that it ultimately expands to *
operator definitions for all
possible matrix operand combinations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With