Moved converge to its own file to reduce REDUNDANCY
This commit is contained in:
@@ -8,10 +8,13 @@ SRCS = $(wildcard *.c)
|
|||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
DEPS = $(SRCS:.c=.d)
|
DEPS = $(SRCS:.c=.d)
|
||||||
|
|
||||||
.PHONY: all clean
|
.PHONY: all clean run
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
|
run: all
|
||||||
|
./project -s -2.0,-1.5 -d 1200,900 -r 0.003 -n 256 -o tricorn.bmp -C
|
||||||
|
|
||||||
$(TARGET): $(OBJS)
|
$(TARGET): $(OBJS)
|
||||||
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
#ifndef CONVERGE_HELPER_H
|
||||||
|
#define CONVERGE_HELPER_H
|
||||||
|
|
||||||
|
static inline unsigned converge(float c_real, float c_imag, unsigned n) {
|
||||||
|
float real = 0.0f;
|
||||||
|
float imag = 0.0f;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < n; i++) {
|
||||||
|
float real2 = real * real;
|
||||||
|
float imag2 = imag * imag;
|
||||||
|
|
||||||
|
// If the pixel has diverged calculate the value and return it
|
||||||
|
if (real2 + imag2 > 4.0f) {
|
||||||
|
return 255 - 4 * (i % 64);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate imaginary and real parts separately
|
||||||
|
imag = -2.0f * real * imag + c_imag;
|
||||||
|
real = real2 - imag2 + c_real;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
#include "tricorn.h"
|
#include "tricorn.h"
|
||||||
|
|
||||||
#include "color_table.h"
|
#include "color_table.h"
|
||||||
static unsigned converge(float c_real, float c_imag, unsigned n);
|
#include "converge_helper.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Generates a Tricorn fractal image using an optimized SIMD algorithm
|
* @brief Generates a Tricorn fractal image using an optimized SIMD algorithm
|
||||||
@@ -132,24 +130,3 @@ void tricorn(float complex start, size_t width, ssize_t height, float res, unsig
|
|||||||
c_imag_vector = _mm_add_ps(c_imag_vector,vertical_step_vector);
|
c_imag_vector = _mm_add_ps(c_imag_vector,vertical_step_vector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterative application of the equation given by the assignment
|
|
||||||
static unsigned converge(float c_real, float c_imag, unsigned n) {
|
|
||||||
float real = 0.0f;
|
|
||||||
float imag = 0.0f;
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < n; i++) {
|
|
||||||
float real2 = real * real;
|
|
||||||
float imag2 = imag * imag;
|
|
||||||
|
|
||||||
// If the pixel has diverged calculate the value and return it
|
|
||||||
if (real2 + imag2 > 4.0f) {
|
|
||||||
return 255 - 4 * (i % 64);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate imaginary and real parts separately
|
|
||||||
imag = -2.0f * real * imag + c_imag;
|
|
||||||
real = real2 - imag2 + c_real;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "tricorn_V1.h"
|
#include "tricorn_V1.h"
|
||||||
#include "color_table.h"
|
#include "color_table.h"
|
||||||
|
#include "converge_helper.h"
|
||||||
static unsigned converge(float c_real, float c_imag, unsigned n);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,24 +51,3 @@ void tricorn_V1(float complex start, size_t width, ssize_t height, float res, un
|
|||||||
c_imag += vertical_step; // For reach row calculate the next value for the imaginary part by accumulation
|
c_imag += vertical_step; // For reach row calculate the next value for the imaginary part by accumulation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterative application of the equation given by the assignment
|
|
||||||
static inline unsigned converge(float c_real, float c_imag, unsigned n) {
|
|
||||||
float real = 0.0f;
|
|
||||||
float imag = 0.0f;
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < n; i++) {
|
|
||||||
float real2 = real * real;
|
|
||||||
float imag2 = imag * imag;
|
|
||||||
|
|
||||||
// If the pixel has diverged calculate the value and return it
|
|
||||||
if (real2 + imag2 > 4.0f) {
|
|
||||||
return 255 - 4 * (i % 64);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate imaginary and real parts separately
|
|
||||||
imag = -2.0f * real * imag + c_imag;
|
|
||||||
real = real2 - imag2 + c_real;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
#include "tricorn_V2.h"
|
#include "tricorn_V2.h"
|
||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
#include "color_table.h"
|
#include "color_table.h"
|
||||||
|
#include "converge_helper.h"
|
||||||
static unsigned converge(float c_rea, float c_imag, unsigned n);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -129,24 +128,3 @@ void tricorn_V2(float complex start, size_t width, ssize_t height, float res, un
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterative application of the equation given by the assignment
|
|
||||||
static unsigned converge(float c_real, float c_imag, unsigned n) {
|
|
||||||
float real = 0.0f;
|
|
||||||
float imag = 0.0f;
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < n; i++) {
|
|
||||||
float real2 = real * real;
|
|
||||||
float imag2 = imag * imag;
|
|
||||||
|
|
||||||
// If the pixel has diverged calculate the value and return it
|
|
||||||
if (real2 + imag2 > 4.0f) {
|
|
||||||
return 255 - 4 * (i % 64);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate imaginary and real parts separately
|
|
||||||
imag = -2.0f * real * imag + c_imag;
|
|
||||||
real = real2 - imag2 + c_real;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#include "tricorn_V3.h"
|
#include "tricorn_V3.h"
|
||||||
#include "color_table.h"
|
#include "color_table.h"
|
||||||
|
#include "converge_helper.h"
|
||||||
|
|
||||||
static void* compute(void * args);
|
static void* compute(void * args);
|
||||||
static unsigned converge(float c_real, float c_imag, unsigned n);
|
|
||||||
static size_t get_thread_count();
|
static size_t get_thread_count();
|
||||||
|
|
||||||
// Argument structs passed to the threads for the caluclations
|
// Argument structs passed to the threads for the caluclations
|
||||||
@@ -38,7 +38,7 @@ typedef struct {
|
|||||||
*/
|
*/
|
||||||
void tricorn_V3(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){
|
void tricorn_V3(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){
|
||||||
|
|
||||||
const ssize_t min_rows_per_thread = 10;
|
const size_t min_rows_per_thread = 10;
|
||||||
const _Bool flipped = height < 0;
|
const _Bool flipped = height < 0;
|
||||||
const size_t abs_height = flipped ? -height : height;
|
const size_t abs_height = flipped ? -height : height;
|
||||||
|
|
||||||
@@ -203,26 +203,7 @@ static void* compute(void * vargs){
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterative application of the equation given by the assignment
|
|
||||||
static unsigned converge(float c_real, float c_imag, unsigned n) {
|
|
||||||
float real = 0.0f;
|
|
||||||
float imag = 0.0f;
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < n; i++) {
|
|
||||||
float real2 = real * real;
|
|
||||||
float imag2 = imag * imag;
|
|
||||||
|
|
||||||
// If the pixel has diverged calculate the value and return it
|
|
||||||
if (real2 + imag2 > 4.0f) {
|
|
||||||
return 255 - 4 * (i % 64);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate imaginary and real parts separately
|
|
||||||
imag = -2.0f * real * imag + c_imag;
|
|
||||||
real = real2 - imag2 + c_real;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
static inline size_t get_thread_count(){
|
static inline size_t get_thread_count(){
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
SYSTEM_INFO sysinfo;
|
SYSTEM_INFO sysinfo;
|
||||||
|
|||||||
Reference in New Issue
Block a user