* fix error in divergence test, now it is even faster

* add comments in render() in case anyone ever reads that :P
This commit is contained in:
Benoit Jacob 2008-07-01 14:23:01 +00:00
parent a356ebd47d
commit 95549007b3

View File

@ -51,10 +51,12 @@ template<typename Real> void MandelbrotThread::render(int img_width, int img_hei
Packet pcr, pci = pci_start, pzr, pzi = pzi_start, pzr_buf; Packet pcr, pci = pci_start, pzr, pzi = pzi_start, pzr_buf;
for(int i = 0; i < packetSize; i++) pzr[i] = pcr[i] = start.x() + (x+i) * step.x(); for(int i = 0; i < packetSize; i++) pzr[i] = pcr[i] = start.x() + (x+i) * step.x();
// do the iterations. Every 4 iterations we check for divergence, in which case we can stop iterating. // do the iterations. Every iters_before_test iterations we check for divergence,
// in which case we can stop iterating.
int j = 0; int j = 0;
typedef Eigen::Matrix<int, packetSize, 1> Packeti; typedef Eigen::Matrix<int, packetSize, 1> Packeti;
Packeti pix_iter = Packeti::zero(), pix_dont_diverge; Packeti pix_iter = Packeti::zero(), // number of iteration per pixel in the packet
pix_dont_diverge; // whether or not each pixel has already diverged
do do
{ {
for(int i = 0; i < iters_before_test/4; i++) // peel the inner loop by 4 for(int i = 0; i < iters_before_test/4; i++) // peel the inner loop by 4
@ -67,7 +69,9 @@ template<typename Real> void MandelbrotThread::render(int img_width, int img_hei
} }
pix_dont_diverge = (pzr.cwiseAbs2() + pzi.cwiseAbs2()) pix_dont_diverge = (pzr.cwiseAbs2() + pzi.cwiseAbs2())
.eval() // temporary fix as what follows is not yet vectorized by Eigen .eval() // temporary fix as what follows is not yet vectorized by Eigen
.cwiseLessThan(Packet::constant(iters_before_test)) .cwiseLessThan(Packet::constant(4))
// the 4 here is not a magic value, it's a math fact that if
// the square modulus is >4 then divergence is inevitable.
.template cast<int>(); .template cast<int>();
pix_iter += iters_before_test * pix_dont_diverge; pix_iter += iters_before_test * pix_dont_diverge;
j++; j++;