My fluid sim can push rigid bodies around now.
On CPU Physics and CPU Cycles
https://6it.dev/blog/on-cpu-physics-and-cpu-cycles-80730
#HackerNews #CPU #Physics #CPU #Cycles #Technology #Performance #Computing
My VR physics engine is slowly coming together
clang and gcc are surprisingly bad at dividing by seven:
https://godbolt.org/z/vPqfeMeYe
Having upper bounds makes the problem a lot simpler, and there's a great 2011 post improving the general case: https://ridiculousfish.com/blog/posts/labor-of-division-episode-iii.html
But both compilers mostly just use the exact method from Hacker's Delight, regardless of the register size. It's not a big deal, but not somewhere I expected to see room for improvement.
// u8 uint32_t div_7_u8(uint8_t v) { return v / 7; } uint32_t div_7_u8_optimised(uint8_t v) { return (v * 0x125) >> 11; } uint32_t div_7_u8_optimised_mulh(uint8_t v) { // MULH is fast on Apple CPUs, but slow on some low-end Arm-designed CPUs return ((unsigned __int128)v * (0x125ull << (64-11))) >> 64; } // u16 uint32_t div_7_u16(uint16_t v) { return v / 7; } uint32_t div_7_u16_optimised(uint16_t v) { return ((uint64_t)v * 0x12493) >> 19; } // u32 uint32_t div_7_u32(uint32_t v) { return v / 7; } uint32_t div_7_u32_optimised(uint32_t v) { // MULH is fast on Apple CPUs, but slow on some low-end Arm-designed CPUs return ((__int128)v * 0x24924924a0000000) >> 64; } uint32_t div_7_u32_optimised_fish(uint32_t v) { // https://ridiculousfish.com/blog/posts/labor-of-division-episode-iii.html return ((v * (uint64_t)1227133513) + 1227133513) >> 33; } // u64 uint64_t div_7_u64(uint64_t v) { return v/7; } uint64_t div_7_u64_optimised(uint64_t v) { // https://ridiculousfish.com/blog/posts/labor-of-division-episode-iii.html if (v + 1) v += 1; // saturating add return ((unsigned __int128)v * 0x9249249249249249) >> (64+2); }
Added some stabilization to my rigid body sim.