Added: Pregenerated lookup table

This commit is contained in:
Yashar Alan Zenker
2026-07-17 11:53:16 +02:00
parent 1ead5be671
commit dc4b8bfaef
6 changed files with 287 additions and 38 deletions
+279
View File
@@ -0,0 +1,279 @@
#ifndef COLOR_TABLE_H
#define COLOR_TABLE_H
/*
* Generated file. Do not edit manually.
*
* Factors:
* red: 3
* green: 2
* blue: 5
*
* Formula:
* red = (i * 3) % 255
* green = (i * 2) % 255
* blue = (i * 5) % 255
*/
#include <stdint.h>
static const uint8_t color_lookup_table[256][3] = {
{ 0, 0, 0 },
{ 3, 2, 5 },
{ 6, 4, 10 },
{ 9, 6, 15 },
{ 12, 8, 20 },
{ 15, 10, 25 },
{ 18, 12, 30 },
{ 21, 14, 35 },
{ 24, 16, 40 },
{ 27, 18, 45 },
{ 30, 20, 50 },
{ 33, 22, 55 },
{ 36, 24, 60 },
{ 39, 26, 65 },
{ 42, 28, 70 },
{ 45, 30, 75 },
{ 48, 32, 80 },
{ 51, 34, 85 },
{ 54, 36, 90 },
{ 57, 38, 95 },
{ 60, 40, 100 },
{ 63, 42, 105 },
{ 66, 44, 110 },
{ 69, 46, 115 },
{ 72, 48, 120 },
{ 75, 50, 125 },
{ 78, 52, 130 },
{ 81, 54, 135 },
{ 84, 56, 140 },
{ 87, 58, 145 },
{ 90, 60, 150 },
{ 93, 62, 155 },
{ 96, 64, 160 },
{ 99, 66, 165 },
{ 102, 68, 170 },
{ 105, 70, 175 },
{ 108, 72, 180 },
{ 111, 74, 185 },
{ 114, 76, 190 },
{ 117, 78, 195 },
{ 120, 80, 200 },
{ 123, 82, 205 },
{ 126, 84, 210 },
{ 129, 86, 215 },
{ 132, 88, 220 },
{ 135, 90, 225 },
{ 138, 92, 230 },
{ 141, 94, 235 },
{ 144, 96, 240 },
{ 147, 98, 245 },
{ 150, 100, 250 },
{ 153, 102, 0 },
{ 156, 104, 5 },
{ 159, 106, 10 },
{ 162, 108, 15 },
{ 165, 110, 20 },
{ 168, 112, 25 },
{ 171, 114, 30 },
{ 174, 116, 35 },
{ 177, 118, 40 },
{ 180, 120, 45 },
{ 183, 122, 50 },
{ 186, 124, 55 },
{ 189, 126, 60 },
{ 192, 128, 65 },
{ 195, 130, 70 },
{ 198, 132, 75 },
{ 201, 134, 80 },
{ 204, 136, 85 },
{ 207, 138, 90 },
{ 210, 140, 95 },
{ 213, 142, 100 },
{ 216, 144, 105 },
{ 219, 146, 110 },
{ 222, 148, 115 },
{ 225, 150, 120 },
{ 228, 152, 125 },
{ 231, 154, 130 },
{ 234, 156, 135 },
{ 237, 158, 140 },
{ 240, 160, 145 },
{ 243, 162, 150 },
{ 246, 164, 155 },
{ 249, 166, 160 },
{ 252, 168, 165 },
{ 0, 170, 170 },
{ 3, 172, 175 },
{ 6, 174, 180 },
{ 9, 176, 185 },
{ 12, 178, 190 },
{ 15, 180, 195 },
{ 18, 182, 200 },
{ 21, 184, 205 },
{ 24, 186, 210 },
{ 27, 188, 215 },
{ 30, 190, 220 },
{ 33, 192, 225 },
{ 36, 194, 230 },
{ 39, 196, 235 },
{ 42, 198, 240 },
{ 45, 200, 245 },
{ 48, 202, 250 },
{ 51, 204, 0 },
{ 54, 206, 5 },
{ 57, 208, 10 },
{ 60, 210, 15 },
{ 63, 212, 20 },
{ 66, 214, 25 },
{ 69, 216, 30 },
{ 72, 218, 35 },
{ 75, 220, 40 },
{ 78, 222, 45 },
{ 81, 224, 50 },
{ 84, 226, 55 },
{ 87, 228, 60 },
{ 90, 230, 65 },
{ 93, 232, 70 },
{ 96, 234, 75 },
{ 99, 236, 80 },
{ 102, 238, 85 },
{ 105, 240, 90 },
{ 108, 242, 95 },
{ 111, 244, 100 },
{ 114, 246, 105 },
{ 117, 248, 110 },
{ 120, 250, 115 },
{ 123, 252, 120 },
{ 126, 254, 125 },
{ 129, 1, 130 },
{ 132, 3, 135 },
{ 135, 5, 140 },
{ 138, 7, 145 },
{ 141, 9, 150 },
{ 144, 11, 155 },
{ 147, 13, 160 },
{ 150, 15, 165 },
{ 153, 17, 170 },
{ 156, 19, 175 },
{ 159, 21, 180 },
{ 162, 23, 185 },
{ 165, 25, 190 },
{ 168, 27, 195 },
{ 171, 29, 200 },
{ 174, 31, 205 },
{ 177, 33, 210 },
{ 180, 35, 215 },
{ 183, 37, 220 },
{ 186, 39, 225 },
{ 189, 41, 230 },
{ 192, 43, 235 },
{ 195, 45, 240 },
{ 198, 47, 245 },
{ 201, 49, 250 },
{ 204, 51, 0 },
{ 207, 53, 5 },
{ 210, 55, 10 },
{ 213, 57, 15 },
{ 216, 59, 20 },
{ 219, 61, 25 },
{ 222, 63, 30 },
{ 225, 65, 35 },
{ 228, 67, 40 },
{ 231, 69, 45 },
{ 234, 71, 50 },
{ 237, 73, 55 },
{ 240, 75, 60 },
{ 243, 77, 65 },
{ 246, 79, 70 },
{ 249, 81, 75 },
{ 252, 83, 80 },
{ 0, 85, 85 },
{ 3, 87, 90 },
{ 6, 89, 95 },
{ 9, 91, 100 },
{ 12, 93, 105 },
{ 15, 95, 110 },
{ 18, 97, 115 },
{ 21, 99, 120 },
{ 24, 101, 125 },
{ 27, 103, 130 },
{ 30, 105, 135 },
{ 33, 107, 140 },
{ 36, 109, 145 },
{ 39, 111, 150 },
{ 42, 113, 155 },
{ 45, 115, 160 },
{ 48, 117, 165 },
{ 51, 119, 170 },
{ 54, 121, 175 },
{ 57, 123, 180 },
{ 60, 125, 185 },
{ 63, 127, 190 },
{ 66, 129, 195 },
{ 69, 131, 200 },
{ 72, 133, 205 },
{ 75, 135, 210 },
{ 78, 137, 215 },
{ 81, 139, 220 },
{ 84, 141, 225 },
{ 87, 143, 230 },
{ 90, 145, 235 },
{ 93, 147, 240 },
{ 96, 149, 245 },
{ 99, 151, 250 },
{ 102, 153, 0 },
{ 105, 155, 5 },
{ 108, 157, 10 },
{ 111, 159, 15 },
{ 114, 161, 20 },
{ 117, 163, 25 },
{ 120, 165, 30 },
{ 123, 167, 35 },
{ 126, 169, 40 },
{ 129, 171, 45 },
{ 132, 173, 50 },
{ 135, 175, 55 },
{ 138, 177, 60 },
{ 141, 179, 65 },
{ 144, 181, 70 },
{ 147, 183, 75 },
{ 150, 185, 80 },
{ 153, 187, 85 },
{ 156, 189, 90 },
{ 159, 191, 95 },
{ 162, 193, 100 },
{ 165, 195, 105 },
{ 168, 197, 110 },
{ 171, 199, 115 },
{ 174, 201, 120 },
{ 177, 203, 125 },
{ 180, 205, 130 },
{ 183, 207, 135 },
{ 186, 209, 140 },
{ 189, 211, 145 },
{ 192, 213, 150 },
{ 195, 215, 155 },
{ 198, 217, 160 },
{ 201, 219, 165 },
{ 204, 221, 170 },
{ 207, 223, 175 },
{ 210, 225, 180 },
{ 213, 227, 185 },
{ 216, 229, 190 },
{ 219, 231, 195 },
{ 222, 233, 200 },
{ 225, 235, 205 },
{ 228, 237, 210 },
{ 231, 239, 215 },
{ 234, 241, 220 },
{ 237, 243, 225 },
{ 240, 245, 230 },
{ 243, 247, 235 },
{ 246, 249, 240 },
{ 249, 251, 245 },
{ 252, 253, 250 },
{ 0, 0, 0 },
};
#endif /* COLOR_TABLE_H */
+1 -9
View File
@@ -1,6 +1,6 @@
#include "tricorn.h" #include "tricorn.h"
#include <immintrin.h>
#include "color_table.h"
static unsigned converge(float c_real, float c_imag, unsigned n); static unsigned converge(float c_real, float c_imag, unsigned n);
@@ -16,14 +16,6 @@ static unsigned converge(float c_real, float c_imag, unsigned n);
*/ */
void tricorn(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){ void tricorn(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){
int bytesPerColor = color ? 3 : 1; int bytesPerColor = color ? 3 : 1;
unsigned char color_lookup_table[256][3];
if(color) {
for (int i = 0; i < 256; i++) {
color_lookup_table[i][0] = (unsigned char)((i * 3) % 255);
color_lookup_table[i][1] = (unsigned char)((i * 2) % 255);
color_lookup_table[i][2] = (unsigned char)((i * 5) % 255);
}
}
// Absolute height for iteration purposes // Absolute height for iteration purposes
+1 -10
View File
@@ -1,4 +1,5 @@
#include "tricorn_V1.h" #include "tricorn_V1.h"
#include "color_table.h"
static unsigned converge(float c_real, float c_imag, unsigned n); static unsigned converge(float c_real, float c_imag, unsigned n);
@@ -15,16 +16,6 @@ static unsigned converge(float c_real, float c_imag, unsigned n);
*/ */
void tricorn_V1(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){ void tricorn_V1(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){
int bytesPerColor = color ? 3 : 1; int bytesPerColor = color ? 3 : 1;
unsigned char color_lookup_table[256][3];
if(color) {
for (int i = 0; i < 256; i++) {
color_lookup_table[i][0] = (unsigned char)((i * 3) % 255);
color_lookup_table[i][1] = (unsigned char)((i * 2) % 255);
color_lookup_table[i][2] = (unsigned char)((i * 5) % 255);
}
}
// Absolute height for iteration purposes // Absolute height for iteration purposes
ssize_t actual_height = height > 0 ? height : (ssize_t)(-height); ssize_t actual_height = height > 0 ? height : (ssize_t)(-height);
+1 -9
View File
@@ -1,5 +1,6 @@
#include "tricorn_V2.h" #include "tricorn_V2.h"
#include <immintrin.h> #include <immintrin.h>
#include "color_table.h"
static unsigned converge(float c_rea, float c_imag, unsigned n); static unsigned converge(float c_rea, float c_imag, unsigned n);
@@ -16,16 +17,7 @@ static unsigned converge(float c_rea, float c_imag, unsigned n);
*/ */
void tricorn_V2(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){ void tricorn_V2(float complex start, size_t width, ssize_t height, float res, unsigned n, _Bool color, unsigned char* img){
int bytesPerColor = color ? 3 : 1; int bytesPerColor = color ? 3 : 1;
unsigned char color_lookup_table[256][3];
if(color) {
for (int i = 0; i < 256; i++) {
color_lookup_table[i][0] = (unsigned char)((i * 3) % 255);
color_lookup_table[i][1] = (unsigned char)((i * 2) % 255);
color_lookup_table[i][2] = (unsigned char)((i * 5) % 255);
}
}
// Absolute height for iteration purposes // Absolute height for iteration purposes
ssize_t actual_height = height < 0 ? (ssize_t)(-height) : height; ssize_t actual_height = height < 0 ? (ssize_t)(-height) : height;
size_t simd_width = (width / 4) * 4; size_t simd_width = (width / 4) * 4;
+1 -10
View File
@@ -1,4 +1,5 @@
#include "tricorn_V3.h" #include "tricorn_V3.h"
#include "color_table.h"
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);
@@ -22,7 +23,6 @@ typedef struct {
const_args* consts; const_args* consts;
} compute_args; } compute_args;
unsigned char color_lookup_table[256][3];
@@ -37,13 +37,6 @@ unsigned char color_lookup_table[256][3];
* @param img Pointer to the pre-allocated memory buffer where the bitmap data will be stored. * @param img Pointer to the pre-allocated memory buffer where the bitmap data will be stored.
*/ */
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){
if(color) {
for (int i = 0; i < 256; i++) {
color_lookup_table[i][0] = (unsigned char)((i * 3) % 255);
color_lookup_table[i][1] = (unsigned char)((i * 2) % 255);
color_lookup_table[i][2] = (unsigned char)((i * 5) % 255);
}
}
const ssize_t min_rows_per_thread = 10; const ssize_t min_rows_per_thread = 10;
const _Bool flipped = height < 0; const _Bool flipped = height < 0;
@@ -56,8 +49,6 @@ void tricorn_V3(float complex start, size_t width, ssize_t height, float res, un
while((abs_height/thread_count) < min_rows_per_thread) thread_count--; while((abs_height/thread_count) < min_rows_per_thread) thread_count--;
else thread_count = 1; else thread_count = 1;
const size_t y_step = (abs_height+thread_count-1)/thread_count; const size_t y_step = (abs_height+thread_count-1)/thread_count;
const float start_r = crealf(start); const float start_r = crealf(start);
const float directional_res = (flipped ? -1.0f: 1.0f)*res; const float directional_res = (flipped ? -1.0f: 1.0f)*res;
+4
View File
@@ -90,6 +90,10 @@ Insgesamt zeigt das Projekt die schrittweise Optimierung von einer skalaren Impl
## 5. Individuelle Beiträge ## 5. Individuelle Beiträge
**Yashar Alan Zenker:** **Yashar Alan Zenker:**
- Konzeptionierung der grundlegenden Algorithmusstruktur
- SISD und Threading Implementationen
- Integration von SIMD und Threading
- Cleanups und Refactoring
**Nikola Granitsky:** **Nikola Granitsky:**
- Implementierung von SIMD- und Skalar-Optimierungen - Implementierung von SIMD- und Skalar-Optimierungen