Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make it compile on linux #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions PixelGameEngine/SmallerProjects/OneLoneCoder_PGE_Mandelbrot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

Author
~~~~~~
David Barr, aka javidx9, �OneLoneCoder 2018, 2019, 2020
David Barr, aka javidx9, �OneLoneCoder 2018, 2019, 2020
*/

#define OLC_PGE_APPLICATION
Expand Down Expand Up @@ -81,11 +81,14 @@ class olcFractalExplorer : public olc::PixelGameEngine
public:
bool OnUserCreate() override
{
//pFractal = new int[ScreenWidth() * ScreenHeight()]{ 0 };

#ifdef _WIN32
// Using Vector extensions, align memory (not as necessary as it used to be)
// MS Specific - see std::aligned_alloc for others
pFractal = (int*)_aligned_malloc(size_t(ScreenWidth()) * size_t(ScreenHeight()) * sizeof(int), 64);
#else
// pFractal = new int[ScreenWidth() * ScreenHeight()]{0};
pFractal = (int *)aligned_alloc(size_t(ScreenWidth()) * size_t(ScreenHeight()) * sizeof(int), 64);
#endif

InitialiseThreadPool();
return true;
Expand All @@ -104,8 +107,13 @@ class olcFractalExplorer : public olc::PixelGameEngine
for (int i = 0; i < nMaxThreads; i++)
workers[i].thread.join();

// Clean up memory
// Clean up memory
#ifdef _WIN32
_aligned_free(pFractal);
#else
// delete[] pFractal;
free(pFractal);
#endif
return true;
}

Expand Down Expand Up @@ -288,10 +296,18 @@ class olcFractalExplorer : public olc::PixelGameEngine
if (_mm256_movemask_pd(_mm256_castsi256_pd(_mask2)) > 0)
goto repeat;

#ifdef _WIN32
pFractal[y_offset + x + 0] = int(_n.m256i_i64[3]);
pFractal[y_offset + x + 1] = int(_n.m256i_i64[2]);
pFractal[y_offset + x + 2] = int(_n.m256i_i64[1]);
pFractal[y_offset + x + 3] = int(_n.m256i_i64[0]);
#else
// * compile with option "-march=native" on Linux
pFractal[y_offset + x + 0] = int(_n[3]);
pFractal[y_offset + x + 1] = int(_n[2]);
pFractal[y_offset + x + 2] = int(_n[1]);
pFractal[y_offset + x + 3] = int(_n[0]);
#endif
_x_pos = _mm256_add_pd(_x_pos, _x_jump);
}

Expand Down Expand Up @@ -415,10 +431,18 @@ class olcFractalExplorer : public olc::PixelGameEngine
if (_mm256_movemask_pd(_mm256_castsi256_pd(_mask2)) > 0)
goto repeat;

#ifdef _WIN32
fractal[y_offset + x + 0] = int(_n.m256i_i64[3]);
fractal[y_offset + x + 1] = int(_n.m256i_i64[2]);
fractal[y_offset + x + 2] = int(_n.m256i_i64[1]);
fractal[y_offset + x + 3] = int(_n.m256i_i64[0]);
#else
// * compile with option "-march=native" on Linux
fractal[y_offset + x + 0] = int(_n[3]);
fractal[y_offset + x + 1] = int(_n[2]);
fractal[y_offset + x + 2] = int(_n[1]);
fractal[y_offset + x + 3] = int(_n[0]);
#endif
_x_pos = _mm256_add_pd(_x_pos, _x_jump);
}

Expand Down