diff --git a/include/llama/Simd.hpp b/include/llama/Simd.hpp index 9c436fb3d5..f7a1cec737 100644 --- a/include/llama/Simd.hpp +++ b/include/llama/Simd.hpp @@ -311,8 +311,11 @@ namespace llama // structured dstSimd type and record reference if constexpr(isRecordRef && isRecordRef) { - forEachLeafCoord([&](auto rc) LLAMA_LAMBDA_INLINE - { internal::loadSimdFromField(srcRef, dstSimd, rc); }); + if constexpr(simdLanes == simdLanes) // fast path mainly for scalar SimdN + dstSimd = srcRef; + else + forEachLeafCoord( + [&](auto rc) LLAMA_LAMBDA_INLINE { internal::loadSimdFromField(srcRef, dstSimd, rc); }); } // unstructured dstSimd and reference type else if constexpr(!isRecordRef && !isRecordRef) @@ -339,6 +342,9 @@ namespace llama // structured Simd type and record reference if constexpr(isRecordRef && isRecordRef) { + if constexpr(simdLanes == simdLanes) // fast path mainly for scalar SimdN + dstRef = srcSimd; + else forEachLeafCoord([&](auto rc) LLAMA_LAMBDA_INLINE { internal::storeSimdToField(srcSimd, dstRef, rc); }); }