From a3d829533cabb564606e98e58f8dc1fe4575b7d1 Mon Sep 17 00:00:00 2001 From: go38coz Date: Sun, 28 Jun 2026 20:49:00 +0200 Subject: [PATCH] Added implementation switching based on -V parameter --- Implementierung/main.c | 10 ++++++++-- Implementierung/tricorn_simd.c | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Implementierung/main.c b/Implementierung/main.c index 94d06d7..46ae555 100644 --- a/Implementierung/main.c +++ b/Implementierung/main.c @@ -199,13 +199,19 @@ int main(int argc, char** argv) bytesPerColour = 1; } - unsigned char *tempArr = malloc(width*abs(height)*bytesPerColour);// allocate image array on the heap to support large images as the stack is usually only 8 MB big + ssize_t absolute_height = height >= 0 ? height : height * - 1; + unsigned char *tempArr = malloc(width*absolute_height*bytesPerColour);// allocate image array on the heap to support large images as the stack is usually only 8 MB big if(tempArr == NULL) { exit(EXIT_FAILURE); } printf("yashar\n"); - tricorn_simd(complexA,width,height,resolution,n,colored,tempArr); + if(version_to_use == 0) { + tricorn_simd(complexA,width,height,resolution,n,colored,tempArr); + } + else { + tricorn(complexA,width,height,resolution,n,colored,tempArr); + } printf("yashar\n"); save_bmp(output_data,tempArr,width,height,colored); diff --git a/Implementierung/tricorn_simd.c b/Implementierung/tricorn_simd.c index fc4accc..de6cea7 100644 --- a/Implementierung/tricorn_simd.c +++ b/Implementierung/tricorn_simd.c @@ -22,7 +22,7 @@ void tricorn_simd(float complex start, size_t width, ssize_t height, float res, __m128 c_imag_vector = _mm_set1_ps(c_imag); size_t x = 0; - for(; x < simd_width;x += 4) { //Simd + for(; x < simd_width;x += 4) { //SIMD Loop 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); @@ -35,7 +35,7 @@ void tricorn_simd(float complex start, size_t width, ssize_t height, float res, __m128 real2 = _mm_mul_ps(real,real); __m128 imag2 = _mm_mul_ps(imag,imag); - __m128 unbounded = _mm_cmplt_ps(_mm_add_ps(real2,imag2),four); + __m128 unbounded = _mm_cmple_ps(_mm_add_ps(real2,imag2),four); __m128i unbounded_i = _mm_castps_si128(unbounded); active_mask = _mm_and_si128(active_mask,unbounded_i);