Removed: Duplicate code in V5 experimental inline

This commit is contained in:
Yashar Alan Zenker
2026-07-04 21:18:08 +02:00
parent cc54d0282c
commit 614766ecc2
+18 -21
View File
@@ -2,12 +2,14 @@
// Argument structs passed to the threads for the caluclations // Argument structs passed to the threads for the caluclations
typedef struct{ typedef struct{
unsigned n; unsigned n;
unsigned bytes_per_color;
_Bool color; _Bool color;
_Bool flipped; _Bool flipped;
float res; float res;
size_t width; size_t width;
unsigned char* img; unsigned char* img;
} const_args; } const_args;
typedef struct { typedef struct {
float start_r; float start_r;
@@ -20,6 +22,7 @@ typedef struct {
static void* compute(void * args); static void* compute(void * args);
static unsigned converge(float c_real, float c_imag, unsigned n); static unsigned converge(float c_real, float c_imag, unsigned n);
static inline void simd_converge(unsigned int (*value_array)[] ,__m128 c_real_vector,__m128 c_imag_vector,__m128 four,__m128 minus_two,const_args* c); static inline void simd_converge(unsigned int (*value_array)[] ,__m128 c_real_vector,__m128 c_imag_vector,__m128 four,__m128 minus_two,const_args* c);
static inline void set_color(const_args* c,unsigned int value,size_t position);
static size_t get_thread_count(); static size_t get_thread_count();
/** /**
@@ -59,6 +62,7 @@ void tricorn_V5(float complex start, size_t width, ssize_t height, float res, un
consts->res = res; consts->res = res;
consts->img = img; consts->img = img;
consts->n = n; consts->n = n;
consts->bytes_per_color = color ? 3 : 1;
pthread_t threads[thread_count]; pthread_t threads[thread_count];
for(size_t i = 0; i < thread_count; i++){ for(size_t i = 0; i < thread_count; i++){
@@ -89,8 +93,6 @@ static void* compute(void * vargs){
const_args *c = args->consts; const_args *c = args->consts;
vargs = NULL; vargs = NULL;
const int bytes_per_color = c->color ? 3 : 1;
// Absolute height for iteration purposes // Absolute height for iteration purposes
const size_t simd_width = (c->width / 4) * 4; const size_t simd_width = (c->width / 4) * 4;
@@ -115,16 +117,9 @@ static void* compute(void * vargs){
for(unsigned i = 0 ; i < 4;i++) { for(unsigned i = 0 ; i < 4;i++) {
unsigned int value = value_array[i]; unsigned int value = value_array[i];
size_t position = (y*c->width + (x+i)) * bytes_per_color; size_t position = (y*c->width + (x+i)) * c->bytes_per_color;
if(!c->color) { set_color(c,value,position);
c->img[position] = value;
}
else {
c->img[position] = ((value*3) % 255);
c->img[position + 1] = ((value*2) % 255);
c->img[position + 2] = ((value*5) % 255);
}
} }
c_real_vector = _mm_add_ps(c_real_vector,_mm_set1_ps(four_res)); c_real_vector = _mm_add_ps(c_real_vector,_mm_set1_ps(four_res));
} }
@@ -132,17 +127,9 @@ static void* compute(void * vargs){
for(;x < c->width; x++) { for(;x < c->width; x++) {
float c_real = c_start_real + (x*c->res); float c_real = c_start_real + (x*c->res);
unsigned int value = converge(c_real,c_imag,c->n); unsigned int value = converge(c_real,c_imag,c->n);
size_t position = (y*c->width + x) * c->bytes_per_color;
size_t position = (y*c->width + x) * bytes_per_color; set_color(c,value,position);
if(!c->color) {
c->img[position] = value;
}
else {
c->img[position] = ((value*3) % 255);
c->img[position + 1] = ((value*2) % 255);
c->img[position + 2] = ((value*5) % 255);
}
} }
c_imag -= vertical_step; c_imag -= vertical_step;
c_imag_vector = _mm_sub_ps(c_imag_vector,vertical_step_vector); c_imag_vector = _mm_sub_ps(c_imag_vector,vertical_step_vector);
@@ -204,6 +191,16 @@ static unsigned converge(float c_real, float c_imag, unsigned n) {
} }
return 0; return 0;
} }
static inline void set_color(const_args* c,unsigned int value,size_t position){
if(!c->color) {
c->img[position] = value;
}
else {
c->img[position] = ((value*3) % 255);
c->img[position + 1] = ((value*2) % 255);
c->img[position + 2] = ((value*5) % 255);
}
}
// Platform independent function returning the amount of threads available on the systems cpu // Platform independent function returning the amount of threads available on the systems cpu
static inline size_t get_thread_count(){ static inline size_t get_thread_count(){
#ifdef WIN32 #ifdef WIN32