From 8546217cf3fb419cf8598596ed29a138ffaa901a Mon Sep 17 00:00:00 2001 From: Nikola Date: Fri, 3 Jul 2026 15:03:55 +0200 Subject: [PATCH] Changed ALL function and file names to comply with assignment and added additional (Doxygen and normal) comments to mark which version is which Doxygen comments are shown when hovering over function in the IDE --- Implementierung/main.c | 25 ++++++++++++++++----- Implementierung/tricorn.h | 5 ----- Implementierung/tricorn_V0.c | 12 ++++++++-- Implementierung/tricorn_V1.c | 12 ++++++++-- Implementierung/{tricorn.c => tricorn_V2.c} | 14 ++++++++++-- Implementierung/tricorn_V2.h | 5 +++++ 6 files changed, 56 insertions(+), 17 deletions(-) delete mode 100644 Implementierung/tricorn.h rename Implementierung/{tricorn.c => tricorn_V2.c} (65%) create mode 100644 Implementierung/tricorn_V2.h diff --git a/Implementierung/main.c b/Implementierung/main.c index 5274c5b..515aec1 100644 --- a/Implementierung/main.c +++ b/Implementierung/main.c @@ -5,8 +5,9 @@ #include // for getopt #include // for getopt_long #include // for strcpy -#include "tricorn.h" #include "tricorn_V0.h" +#include "tricorn_V1.h" +#include "tricorn_V2.h" void save_bmp(const char *filename, unsigned char *img, size_t width, ssize_t height,_Bool color); @@ -200,11 +201,23 @@ int main(int argc, char** argv) } printf("yashar\n"); - if(version_to_use == 0) { // -V0 uses optimized SIMD-Version - tricorn_V0(complexA,width,height,resolution,n,colored,tempArr); - } - else if (version_to_use == 1){ // -V1 uses unoptimized version - tricorn(complexA,width,height,resolution,n,colored,tempArr); + switch (version_to_use) + { + case 0: + //Uses highly optimized SIMD version + tricorn_V0(complexA,width,height,resolution,n,colored,tempArr); + break; + case 1: + //Uses optimized SISD version + tricorn_V1(complexA,width,height,resolution,n,colored,tempArr); + break; + case 2: + //Uses unoptimised SISD comparison implementation + tricorn_V2(complexA,width,height,resolution,n,colored,tempArr); + break; + + default: + break; } printf("yashar\n"); save_bmp(output_data,tempArr,width,height,colored); diff --git a/Implementierung/tricorn.h b/Implementierung/tricorn.h deleted file mode 100644 index d415628..0000000 --- a/Implementierung/tricorn.h +++ /dev/null @@ -1,5 +0,0 @@ -#include -#include -#include -#include -void tricorn(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img); \ No newline at end of file diff --git a/Implementierung/tricorn_V0.c b/Implementierung/tricorn_V0.c index 6df52c7..9a1d762 100644 --- a/Implementierung/tricorn_V0.c +++ b/Implementierung/tricorn_V0.c @@ -4,8 +4,16 @@ static unsigned converge(float c_rea, float c_imag, unsigned n); -// HIGHLY OPTIMIZED SIMD VERSION - +/** + * @brief Generates a Tricorn fractal image using highly optimized SSE/SIMD instructions. + * @param start The starting complex coordinate (bottom-left or top-left depending on height sign). + * @param width The width of the target image in pixels. + * @param height The height of the target image. A negative height reverses the Y-axis calculation. + * @param res The step size (resolution) per pixel in the complex plane. + * @param n The maximum number of mathematical iterations per pixel. + * @param color If true, generates a 24-bit RGB image. If false, writes a grayscale image. + * @param img Pointer to the pre-allocated memory buffer where the bitmap data will be stored. + */ void tricorn_V0(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){ int bytesPerColor = color ? 3 : 1; diff --git a/Implementierung/tricorn_V1.c b/Implementierung/tricorn_V1.c index 512fe60..bab8184 100644 --- a/Implementierung/tricorn_V1.c +++ b/Implementierung/tricorn_V1.c @@ -4,8 +4,16 @@ static const float convergenceLimit = 2.0f; // Mandelbrot set limit static unsigned converge(float complex position,unsigned n); -// OPTIMIZED SISD VERSION - +/** + * @brief Generates a Tricorn fractal image using an optimized SISD implementation. + * @param start The starting complex coordinate (bottom-left or top-left depending on height sign). + * @param width The width of the target image in pixels. + * @param height The height of the target image. A negative height reverses the Y-axis calculation. + * @param res The step size (resolution) per pixel in the complex plane. + * @param n The maximum number of mathematical iterations per pixel. + * @param color If true, generates a 24-bit RGB image. If false, writes a grayscale image. + * @param img Pointer to the pre-allocated memory buffer where the bitmap data will be stored. + */ void tricorn_V1(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){ // Absolute height for iteration purposes diff --git a/Implementierung/tricorn.c b/Implementierung/tricorn_V2.c similarity index 65% rename from Implementierung/tricorn.c rename to Implementierung/tricorn_V2.c index eacf159..6017093 100644 --- a/Implementierung/tricorn.c +++ b/Implementierung/tricorn_V2.c @@ -1,9 +1,19 @@ -#include "tricorn.h" +#include "tricorn_V2.h" static const float convergenceLimit = 2.0f; // Mandelbrot set limit static unsigned converge(float complex position,unsigned n); -void tricorn(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){ +/** + * @brief Generates a Tricorn fractal image using the standard, unoptimized scalar implementation for benchmarking comparison (Version 2). + * @param start The starting complex coordinate (bottom-left or top-left depending on height sign). + * @param width The width of the target image in pixels. + * @param height The height of the target image. A negative height reverses the Y-axis calculation. + * @param res The step size (resolution) per pixel in the complex plane. + * @param n The maximum number of mathematical iterations per pixel. + * @param color If true, generates a 24-bit RGB image. If false, writes a grayscale image. + * @param img Pointer to the pre-allocated memory buffer where the bitmap data will be stored. + */ +void tricorn_V2(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){ // Absolute height for iteration purposes height = height < 0 ? height*-1 : height; diff --git a/Implementierung/tricorn_V2.h b/Implementierung/tricorn_V2.h new file mode 100644 index 0000000..c8e1e4a --- /dev/null +++ b/Implementierung/tricorn_V2.h @@ -0,0 +1,5 @@ +#include +#include +#include +#include +void tricorn_V2(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img);