4 ms·
Yes, you really don't want SIMD types for your vec4, that's a classic mistake, you want to chop vegetables. https://deplinenoise.files.wordpress.com/2015/03/gd
by Jasper_ 5y ago
Yes, you really don't want SIMD types for your vec4, that's a classic mistake, you want to chop vegetables.
https://deplinenoise.files.wordpress.com/2015/03/gdc2015_afredriksson_simd.pdf https://deplinenoise.files.wordpress.com/2015/03/gdc2015_afr...
- pcwalton 5y agoI generally agree that vertical SIMD is more efficient than horizontal SIMD when both are options, but the dot product is kind of an unfair example: that's literally the worst case for horizontal SIMD. A fairer example would be something like 4x4 matrix times vector transformation, where horizontal SIMD is pretty efficient with AVX2 broadcast instructions.
- dnautics 5y agoDoes SSE not have a one-cycle dot product between two vector registers? I'd be surprised if it didn't.... Though not sure if zig compiles to that assembly via llvm
- Tuna-Fish 5y ago... no. And your mental model of what operations cost is a little out of whack. On the newest Intel cpus, a vector double precision multiply is 4 cycles. A horizontal add is 6 cycles. There is a single instruction dot product, which is 9 cycles. Something like a dot product for fp can only ever be 1 cycle in a cpu that has a very low clockspeed. (Or is a barrel processor or something.) There is simply too much to do.
- dnautics 5y agoSorry I should have been precise and said dispatch able one per clock cycle, not latency one clock cycle. Amortized over pipelined operations with no dependencies, the net cost of such an operation is one clock cycle. Anyways I checked it, it's DPPS, and it is a 25 clock cycle latency operation, with a throughput that yields an amortized 6 clock cycle cost.
- Jasper_ 5y agoSure, but often do you do 4x4 matrix times vector? In most cases I imagine, you're going to be using a 3x4 matrix times a vec3 with implicit w=1, or a 3x3 matrix times a vec3 with implicit w=0, making the wins a lot less clear. If you want to implement 3x3 * vec3 with SIMD, then go for it, but I don't quite think that should influence your core data structure design.
- pcwalton 5y agoWell, I generally think that CPU SIMD is best used for little one-off things that you don't want to bother uploading to the GPU or other accelerators, not large-scale batch data processing. Like, if your game logic is running on CPU, then you're probably running the logic for one entity at a time anyway, in which case you probably just don't have enough batch data to make good use of vertical SIMD. So horizontal SIMD is useful there. This is why Pathfinder uses horizontal SIMD, incidentally: most of the heavy number crunching is in super branchy code (e.g. clipping, or recursive de Casteljau subdivision) where there just isn't enough batch data available to make good use of vertical SIMD. Compute shader is going to be faster for any heavy-duty batch processing that is non-branchy. The game code I've written is similar. I guess I can imagine things like physics simulations where you could have a lot of batch data processing on CPU, but even then, running that on GPU is attractive…
- AndyKelley 5y agoI clicked hoping for pictures of vegetables chopped in silly ways, was slightly disappointed tbh, but then stayed for the rest of the excellent presentation. 10/10