Let's say I have an if-statement with an unfortunate amount of || checks. Does the CPU go through all the checks before summing it up to an either false or true bool, or does it terminate and return true as soon as it finds a true bool?
I am wondering because of the 3d object frustum culling of boxes requiring 6 different checks, that you can either do as consecutive if statements, or as a single if statement with multiple || in it, wherein if it goes through all the checks even though as early as the first check returns true, then it's better in the long run for the program to use multiple if statements instead of a single one, as it leads to less calculations during runtime.
Here's the part of the frustum culling code for a "generic cube object with any side length" wherein this is of interest. I'll post both versions, first is using only if statements, the second using a single if:
for (int i = 0; i < 6; i++)
{
if (DirectX::XMVectorGetX(DirectX::XMPlaneDotCoord(DirectX::XMLoadFloat4(&frustumPlanes[i]), {xC-r, yC-r, zC-r})) >= 0.0f) continue;
if (DirectX::XMVectorGetX(DirectX::XMPlaneDotCoord(DirectX::XMLoadFloat4(&frustumPlanes[i]), {xC-r, yC-r, zC+r})) >= 0.0f) continue;
if (DirectX::XMVectorGetX(DirectX::XMPlaneDotCoord(DirectX::XMLoadFloat4(&frustumPlanes[i]), {xC-r, yC+r, zC-r})) >= 0.0f) continue;
if (DirectX::XMVectorGetX(DirectX::XMPlaneDotCoord(DirectX::XMLoadFloat4(&frustumPlanes[i]), {xC-r, yC+r, zC+r})) >= 0.0f) continue;
if (DirectX::XMVectorGetX(DirectX::XMPlaneDotCoord(DirectX::XMLoadFloat4(&frustumPlanes[i]), {xC+r, yC-r, zC-r})) >= 0.0f) continue;
if (DirectX::XMVectorGetX(DirectX::XMPlaneDotCoord(DirectX::XMLoadFloat4(&frustumPlanes[i]), {xC+r, yC-r, zC+r})) >= 0.0f) continue;
if (DirectX::XMVectorGetX(DirectX::XMPlaneDotCoord(DirectX::XMLoadFloat4(&frustumPlanes[i]), {xC+r, yC+r, zC-r})) >= 0.0f) continue;
if (DirectX::XMVectorGetX(DirectX::XMPlaneDotCoord(DirectX::XMLoadFloat4(&frustumPlanes[i]), {xC+r, yC+r, zC+r})) >= 0.0f) continue;
return false;
}
for (int i = 0; i < 6; i++)
{
if ((DirectX::XMVectorGetX(DirectX::XMPlaneDotCoord(DirectX::XMLoadFloat4(&frustumPlanes[i]), {xC-rX, yC-rY, zC-rZ})) >= 0.0f) ||
(DirectX::XMVectorGetX(DirectX::XMPlaneDotCoord(DirectX::XMLoadFloat4(&frustumPlanes[i]), {xC-rX, yC-rY, zC+rZ})) >= 0.0f) ||
(DirectX::XMVectorGetX(DirectX::XMPlaneDotCoord(DirectX::XMLoadFloat4(&frustumPlanes[i]), {xC-rX, yC+rY, zC-rZ})) >= 0.0f) ||
(DirectX::XMVectorGetX(DirectX::XMPlaneDotCoord(DirectX::XMLoadFloat4(&frustumPlanes[i]), {xC-rX, yC+rY, zC+rZ})) >= 0.0f) ||
(DirectX::XMVectorGetX(DirectX::XMPlaneDotCoord(DirectX::XMLoadFloat4(&frustumPlanes[i]), {xC+rX, yC-rY, zC-rZ})) >= 0.0f) ||
(DirectX::XMVectorGetX(DirectX::XMPlaneDotCoord(DirectX::XMLoadFloat4(&frustumPlanes[i]), {xC+rX, yC-rY, zC+rZ})) >= 0.0f) ||
(DirectX::XMVectorGetX(DirectX::XMPlaneDotCoord(DirectX::XMLoadFloat4(&frustumPlanes[i]), {xC+rX, yC+rY, zC-rZ})) >= 0.0f) ||
(DirectX::XMVectorGetX(DirectX::XMPlaneDotCoord(DirectX::XMLoadFloat4(&frustumPlanes[i]), {xC+rX, yC+rY, zC+rZ})) >= 0.0f)) continue;
return false;
}```