Skip to content

Commit

Permalink
Some SSE math tests #387
Browse files Browse the repository at this point in the history
  • Loading branch information
kremius committed Mar 29, 2017
1 parent 2b28b8f commit 084e262
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
15 changes: 10 additions & 5 deletions sources/core/atmos/AtmosConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ const int NYTROGEN_FREEDOM = 5;
const int NYTROGEN_WEIGHT = 14 * 3;
const char* const NYTROGEN_NAME = "Nytrogen";

const int GASES_NUM = 3;
const int TEST_GAS = 3;
const int TEST_GAS_FREEDOM = 1;
const int TEST_GAS_WEIGHT = 1;
const char* const TEST_GAS_NAME = "Test gas";

const int GASES_WEIGHT[GASES_NUM] = {OXYGEN_WEIGHT, CO2_WEIGHT, NYTROGEN_WEIGHT};
const int GASES_FREEDOM[GASES_NUM] = {OXYGEN_FREEDOM, CO2_FREEDOM, NYTROGEN_FREEDOM};
const char* const GASES_NAME[GASES_NUM] = {OXYGEN_NAME, CO2_NAME, NYTROGEN_NAME};
const int GASES_NUM = 4;

const int GASES_WEIGHT[GASES_NUM] = {OXYGEN_WEIGHT, CO2_WEIGHT, NYTROGEN_WEIGHT, TEST_GAS_WEIGHT};
const int GASES_FREEDOM[GASES_NUM] = {OXYGEN_FREEDOM, CO2_FREEDOM, NYTROGEN_FREEDOM, TEST_GAS_FREEDOM};
const char* const GASES_NAME[GASES_NUM] = {OXYGEN_NAME, CO2_NAME, NYTROGEN_NAME, TEST_GAS_NAME};

const int MAX_GAS_LEVEL = 1000;

Expand All @@ -34,7 +39,7 @@ const int ENERGY_CONST = 100;

struct AtmosData
{
int gases[GASES_NUM];
int gases[GASES_NUM] alignas(16);
int energy;
int pressure;
int volume;
Expand Down
37 changes: 18 additions & 19 deletions sources/core/atmos/AtmosGrid.cpp
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
#include "AtmosGrid.h"

#include "emmintrin.h"

void AtmosGrid::Process()
{
Prepare(0);
Prepare(1);
Prepare(2);
Prepare(3);
Prepare(4);
//Prepare(1);
//Prepare(2);
//Prepare(3);
//Prepare(4);

Finalize();
}

inline void ProcessFiveCells(AtmosGrid::Cell* near_cells[])
{
int near_size = 0;
int gases_sums[GASES_NUM];
for (int i = 0; i < GASES_NUM; ++i)
{
gases_sums[i] = 0;
}
int gases_sums[GASES_NUM] alignas(16);
__m128i* gases_sums_sse = reinterpret_cast<__m128i*>(gases_sums);
*gases_sums_sse = _mm_setzero_si128();
int energy_sum = 0;

for (int dir = 0; dir < atmos::DIRS_SIZE + 1; ++dir)
{
if (AtmosGrid::Cell* nearby = near_cells[dir])
{
for (int i = 0; i < GASES_NUM; ++i)
{
gases_sums[i] += nearby->data.gases[i];
}
__m128i* nearby_gases_sse = reinterpret_cast<__m128i*>(nearby->data.gases);
*gases_sums_sse = _mm_add_epi32(*nearby_gases_sse, *gases_sums_sse);
energy_sum += nearby->data.energy;
++near_size;
}
}

int gases_average[GASES_NUM];
int gases_remains[GASES_NUM];
int gases_average[GASES_NUM] alignas(16);
__m128i* gases_average_sse = reinterpret_cast<__m128i*>(gases_average);
int gases_remains[GASES_NUM] alignas(16);
for (int i = 0; i < GASES_NUM; ++i)
{
gases_average[i] = gases_sums[i] / near_size;
Expand Down Expand Up @@ -99,10 +98,10 @@ void AtmosGrid::Prepare(int stage)
continue;
}

if (((column + (line * 2)) % 5) != ((MAIN_TICK + stage) % 5))
{
continue;
}
//if (((column + (line * 2)) % 5) != ((MAIN_TICK + stage) % 5))
//{
// continue;
//}

Cell* near_cells[atmos::DIRS_SIZE + 1];

Expand Down
10 changes: 5 additions & 5 deletions sources/core/atmos/AtmosGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ class AtmosGrid
public:
struct Cell
{
AtmosData data;
AtmosData data alignas(16);

int flows[atmos::DIRS_SIZE];
int flows[atmos::DIRS_SIZE] alignas(16);

IAtmosphere::Flags flags;
IAtmosphere::Flags flags alignas(16);
Cell()
{
for (int i = 0; i < GASES_NUM; ++i)
Expand Down Expand Up @@ -105,8 +105,8 @@ class AtmosGrid
{
case atmos::DOWN: return cells_[pos + 1];
case atmos::UP: return cells_[pos - 1];
case atmos::RIGHT: return cells_[pos + width_];
case atmos::LEFT: return cells_[pos - width_];
case atmos::RIGHT: return cells_[pos + 32];
case atmos::LEFT: return cells_[pos - 32];
default: break;
}

Expand Down

0 comments on commit 084e262

Please sign in to comment.