Handmade Hero » Forums » Code » Floats are 2 Times Faster than Doubles
Blu342
4 posts
#15582 Floats are 2 Times Faster than Doubles
3 months ago Edited by Blu342 on June 19, 2018, 7:23 a.m.

https://hero.handmade.network/episode/code/day049/#5201

In the above Q&A Casey says that floats are two times faster than doubles, because we can do double the amount of operations on them in the same # of cycles. On Day 49, when this question was asked, he hadn't yet used SIMD instrinsics, but is this what he was referring to by the 2x gain in speed? In other words, at the time of this statement simply using a float instead of a double did not actually garner double the speed, rather Casey is saying that he prefers to use floats as a default because they allow for this optimization to happen. Is that right?
mmozeiko
Mārtiņš Možeiko
1791 posts / 1 project
#15583 Floats are 2 Times Faster than Doubles
3 months ago Edited by Mārtiņš Možeiko on June 19, 2018, 8:15 a.m.

Yes, he is referring to SIMD when he said they are 2x faster. With approximately same amount of instructions you can process 2x more of data. Sure there are some differences in speed for float and double SIMD operations. But most simple ops run with exactly same throughput - like min/max/add/sub/cmp/mul.

If I remember correctly this question came up multiple times, maybe in later episodes or could be in prestream. Next time he answered it, he mentioned SIMD.
Blu342
4 posts
#15584 Floats are 2 Times Faster than Doubles
3 months ago

yeah that makes sense. i just wanted to clarify that he wasn't saying regular float ops are 2x as fast as doubles without use of SIMD intrinsics, because that seemed a little farfetched. i understand now though.