loading… 0 of 8 answered
01 why
Why does `float4 c = a + b;` (Unity.Mathematics) give you SIMD more reliably than writing a scalar loop and hoping it auto-vectorizes?
a float4 uses less memory than four floatsb The float4 add IS four-wide arithmetic by construction — it compiles to one vector instruction with nothing for the compiler to infer, whereas a loop must be proven vectorizablec float4 runs on a separate coprocessord Loops can't be vectorized at all in Burstcheck 02 why
Unity.Mathematics deliberately mirrors HLSL/shader conventions (lower-case float4, math.dot, swizzles). What's the practical payoff?
a It makes the code shorter to typeb Gameplay and graphics math become the same vocabulary, so a team carries fewer translation errors between CPU simulation and GPU rendering and reasons about both with one modelc It lets C# code run on the GPU automaticallyd It's required by the Burst compilercheck 03 how
Using v.xz (a swizzle) instead of manually reading v.x and v.z into a new float2 is preferred because:
a Swizzles are just shorter to write; performance is identicalb A swizzle is a lane operation the hardware does directly, where manual .x/.z recombination is scalar copying that's often slower and less clearc Manual access doesn't compile under Burstd Swizzles automatically normalize the vectorcheck 04 how
Mixing Mathf.Sqrt / System.Math into hot Burst numeric code (instead of math.sqrt) tends to hurt because:
a Those functions are deprecatedb They're scalar and sometimes double-based, so they're not the vector idiom and can force width-halving float↔double conversionsc They throw exceptions under Burstd They only work on the main threadcheck 05 how
In the Burst Inspector, you see `vmulss` and `vaddss` in a loop you expected to be vectorized. What does the `ss` suffix tell you?
a Scalar single — one value per instruction; the loop did NOT vectorize, so hunt for the branch/dependency/opaque call that stopped itb SIMD single — it vectorized perfectlyc Signed short — an integer conversion happenedd Nothing meaningful; suffixes are cosmeticcheck 06 why
Your Burst micro-benchmark of a million multiplies reports a speed implying billions of ops in nanoseconds. Most likely explanation?
a Burst genuinely achieved that throughputb The loop's result was never used, so dead-code elimination deleted the loop entirely — you timed an empty loop and measured nothingc The CPU overclocked during the testd The timer has nanosecond precision errorscheck 07 how
The correct defense against DCE deleting your benchmark loop is to:
a Add more iterationsb Make the result observable — write it to a NativeArray, return it, or accumulate into an output the caller reads — so the compiler can't prove the work is deadc Disable Burst for the benchmarkd Use double instead of floatcheck 08 why
Why should a benchmark that decides an architecture choice run several untimed iterations first, then report a median from a release build rather than a single Editor sample?
a To make the test take longer and seem more rigorousb The first runs pay one-time costs (compilation, cold caches, page faults) and Editor safety checks inflate numbers — warmup plus release build plus a stable central value measure steady state, not startup or debug overheadc Medians are always larger than means, giving a safety margind Release builds disable the CPU cachecheck
your notes stored in this browser · syncs when you sign in
← m03.l06 m03.l08 →