Removed: Duplicate code in V5 experimental inline
This commit is contained in:
@@ -2,12 +2,14 @@
|
||||
// Argument structs passed to the threads for the caluclations
|
||||
typedef struct{
|
||||
unsigned n;
|
||||
unsigned bytes_per_color;
|
||||
_Bool color;
|
||||
_Bool flipped;
|
||||
float res;
|
||||
size_t width;
|
||||
unsigned char* img;
|
||||
|
||||
|
||||
} const_args;
|
||||
typedef struct {
|
||||
float start_r;
|
||||
@@ -20,6 +22,7 @@ typedef struct {
|
||||
static void* compute(void * args);
|
||||
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 set_color(const_args* c,unsigned int value,size_t position);
|
||||
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->img = img;
|
||||
consts->n = n;
|
||||
consts->bytes_per_color = color ? 3 : 1;
|
||||
|
||||
pthread_t threads[thread_count];
|
||||
for(size_t i = 0; i < thread_count; i++){
|
||||
@@ -89,8 +93,6 @@ static void* compute(void * vargs){
|
||||
const_args *c = args->consts;
|
||||
vargs = NULL;
|
||||
|
||||
|
||||
const int bytes_per_color = c->color ? 3 : 1;
|
||||
// Absolute height for iteration purposes
|
||||
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++) {
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
set_color(c,value,position);
|
||||
}
|
||||
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++) {
|
||||
float c_real = c_start_real + (x*c->res);
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
set_color(c,value,position);
|
||||
}
|
||||
c_imag -= vertical_step;
|
||||
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;
|
||||
}
|
||||
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
|
||||
static inline size_t get_thread_count(){
|
||||
#ifdef WIN32
|
||||
|
||||
Reference in New Issue
Block a user