14. constexpr auto max_iter = 50U;
auto mandelbrot (double cx, double cy) {
auto x = cx ;
auto y = cy ;
auto iter = max_iter;
for (; iter > 0; --iter) {
auto x2 = x*x;
auto y2 = y*y;
if (x2 + y2 > 4) return iter;
y = 2*x*y + cy ;
x = x2 - y2 + cx ;
}
return iter;
}
r2 = x2 + y2
y
x
r
(x,y)2 = (x2 - y2,2xy)
Zn+1 = Zn
2 + C
20. constexpr auto max_iter = 50U;
auto mandelbrot (double cx, double cy) {
auto x = cx ;
auto y = cy ;
auto iter = max_iter;
for (; iter > 0; --iter) {
auto x2 = x*x;
auto y2 = y*y;
if (x2 + y2 > 4) return iter;
y = 2*x*y + cy ;
x = x2 - y2 + cx ;
}
return iter;
}
21. auto mandelbrot (__m256 cx, __m256 cy) {
auto x = cx;
auto y = cy;
int cmp_mask = 0 ;
for (auto iter = max_iter; iter > 0; --iter) {
auto x2 = x*x;
auto y2 = y*y;
auto r2 = x2 + y2;
auto _4 = float8 (4.0F);
cmp_mask = r2 <= _4;
if (!cmp_mask) return 0;
auto xy = x*y;
y = xy + xy + cy;
x = x2 - y2 + cx;
}
return cmp_mask;
}
25. auto mandelbrot (__m256 cx, __m256 cy) {
auto x = cx;
auto y = cy;
int cmp_mask = 0 ;
for (auto iter = max_iter; iter > 0; --iter) {
auto x2 = x*x;
auto y2 = y*y;
auto r2 = x2 + y2;
auto _4 = float8 (4.0F);
cmp_mask = r2 <= _4;
if (!cmp_mask) return 0;
auto xy = x*y;
y = xy + xy + cy;
x = x2 - y2 + cx;
}
return cmp_mask;
}
30. constexpr auto max_iter = 50U;
auto mandelbrot (double cx, double cy) {
auto x = cx ;
auto y = cy ;
auto iter = max_iter;
for (; iter > 0; --iter) {
auto x2 = x*x;
auto y2 = y*y;
if (x2 + y2 > 4) return iter;
y = 2*x*y + cy ;
x = x2 - y2 + cx ;
}
return iter;
}
31. auto mandelbrot (__m256 cx, __m256 cy) {
auto x = cx;
auto y = cy;
int cmp_mask = 0 ;
for (auto iter = max_iter; iter > 0; --iter) {
auto x2 = x*x;
auto y2 = y*y;
auto r2 = x2 + y2;
auto _4 = float8 (4.0F);
cmp_mask = r2 <= _4;
if (!cmp_mask) return 0;
auto xy = x*y;
y = xy + xy + cy;
x = x2 - y2 + cx;
}
return cmp_mask;
}
Uses the mathematical properties of mandelbrot
Uses knowledge that inf and NaN <= 4 is false
33. constexpr auto max_iter = 50U;
auto mandelbrot (double cx, double cy) {
auto x = cx ;
auto y = cy ;
auto iter = max_iter;
for (; iter > 0; --iter) {
auto x2 = x*x;
auto y2 = y*y;
if (x2 + y2 > 4) return iter;
y = 2*x*y + cy ;
x = x2 - y2 + cx ;
}
return iter;
}