Prior art matters for patents, not copyrights. Carmack's code is still protected by copyright even if he didn't invent the algorithm.
And copyright doesn't prevent someone else from implementing the same algorithm, only from copying the code. If Microsoft had been able to copyright the fast inverse square root function, Carmack could still have written his own version and even copyrighted that version himself.