Fixed the math in SIMD and normal version to be compliant with the assignment
Checking for convergence before calculating next value and z0 = 0
This commit is contained in:
@@ -13,7 +13,7 @@ void tricorn(float complex start, size_t width, ssize_t height, float res, unsig
|
|||||||
for(size_t i = 0; i < width; i++){
|
for(size_t i = 0; i < width; i++){
|
||||||
for(ssize_t j = 0; j < height; j++){
|
for(ssize_t j = 0; j < height; j++){
|
||||||
|
|
||||||
unsigned value = converge(start + (i*res - I*j*res),n);
|
unsigned value = converge(start + (i*res - I*j*res),n+1);
|
||||||
|
|
||||||
// Pixel value position in the output array
|
// Pixel value position in the output array
|
||||||
size_t position = (j*width +i) * bytesPerColor;
|
size_t position = (j*width +i) * bytesPerColor;
|
||||||
@@ -37,14 +37,15 @@ static unsigned converge(float complex position,unsigned n){
|
|||||||
|
|
||||||
complex float result = 0;
|
complex float result = 0;
|
||||||
for(unsigned i = 0; i < n; i++){
|
for(unsigned i = 0; i < n; i++){
|
||||||
// Application of the given complex equation with m = 2
|
// Detection of unbounded behaviour
|
||||||
result = cpowf(conjf(result),2) + position;
|
|
||||||
|
|
||||||
// Detection of unbounded behaviour
|
|
||||||
// If the magnitude of the result vector is greater than the convergence limit, we know that the function will grow unbounded
|
// If the magnitude of the result vector is greater than the convergence limit, we know that the function will grow unbounded
|
||||||
// Current convergence limit taken from mandelbrot set
|
// Current convergence limit taken from mandelbrot set
|
||||||
if(sqrtf(powf (crealf(result),2)+powf(cimagf(result),2)) > convergenceLimit)
|
if(sqrtf(powf (crealf(result),2)+powf(cimagf(result),2)) > convergenceLimit)
|
||||||
return 255-4*(i % 64);
|
return 255-4*(i % 64);
|
||||||
|
|
||||||
|
// Application of the given complex equation with m = 2
|
||||||
|
result = cpowf(conjf(result),2) + position;
|
||||||
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -26,8 +26,8 @@ void tricorn_simd(float complex start, size_t width, ssize_t height, float res,
|
|||||||
float c_real = c_start_real + (x*res);
|
float c_real = c_start_real + (x*res);
|
||||||
__m128 c_real_vector = _mm_setr_ps(c_real,c_real+1.0f*res,c_real+2.0f*res,c_real+3.0f*res);
|
__m128 c_real_vector = _mm_setr_ps(c_real,c_real+1.0f*res,c_real+2.0f*res,c_real+3.0f*res);
|
||||||
|
|
||||||
__m128 real = c_real_vector;
|
__m128 real = _mm_setzero_ps();
|
||||||
__m128 imag = c_imag_vector;
|
__m128 imag = _mm_setzero_ps();
|
||||||
__m128i iterations = _mm_setzero_si128();
|
__m128i iterations = _mm_setzero_si128();
|
||||||
__m128i active_mask = _mm_set1_epi32(-1);
|
__m128i active_mask = _mm_set1_epi32(-1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user