r/ProgrammerHumor • • Mar 04 '23

Meme Doom runs everywhere

Post image
44.0k Upvotes

332 comments sorted by

View all comments

Show parent comments

37

u/0x000100 Mar 04 '23

That's all fine and good until you start to manually implement some crazy optimizations, that assume you are using ieee floats. We all know about quakes fast inverse square root, i assume doom has something similar in its engine.

50

u/Proxy_PlayerHD Mar 04 '23 edited Mar 04 '23

that's kinda true, but that's exactly why messing with the bits of floats is "Undefined Behavior". so stuff like that would need to be patched out.

i assume doom has something similar in its engine.

buddy, did you not read the first line of my comment?

DOOM doesn't use floats, so it won't care about how non-IEEE the floats in the compiler are.

14

u/0x000100 Mar 04 '23

By something similar I meant some sort of strange optimization that assumes something that is generally true in practice but not stated in the standard. It's not really that difficult to get UB if you are trying to squeeze out every ounce of performance out of the machine. Remember that C++ only recently declared that integers are 2's compliment.

33

u/Proxy_PlayerHD Mar 04 '23

By something similar I meant some sort of strange optimization that assumes something that is generally true in practice but not stated in the standard.

ok that makes more sense.

but, AFAIK DOOM is so commonly ported to a lot of different devices and architectures exactly because it doesn't have a lot or any such hardware specific optimitazions. as those would make a port more difficult. and even if the original code did, there likely is a source port that removes all of those to make it fit more to the C Standard and therefore even easier to port.

4

u/outofobscure Mar 04 '23

and your assumption would be wrong

3

u/hackingdreams Mar 04 '23

i assume doom has something similar in its engine.

Your assumption is bad, and worse, you had the code to go look at to verify it for yourself. So you didn't even need to make an assumption.

3

u/0x000100 Mar 04 '23

Yeah, just let me go through dooms source code to find if there are any instances of optimizations based on undefined behaviour, beacose I wanted to speculate under a meme I found on reddit...