Code: Select all
for(auto& object : objects)
{
object.update();
}
Here is a link to the repository containing all of these implementations. Each implementation will have its own branch clearly labeled. You can try it out yourself to see how well they go. Be sure to run them using command prompt. Otherwise, the application would start up, print the results, then exit immediately. Also, your CPU needs to able to do AVX and FMA operations for the vectorized operations benchmarks to be meaningful.
tl;dr This
Code: Select all
struct vector3
{
float x;
float y;
float z;
};
struct object
{
vector3 position;
vector3 velocity;
vector3 acceleration;
};
Code: Select all
auto position_x = array<float>{};
auto position_y = array<float>{};
auto position_z = array<float>{};
auto velocity_x = array<float>{};
auto velocity_y = array<float>{};
auto velocity_z = array<float>{};
auto acceleration_x = array<float>{};
auto acceleration_y = array<float>{};
auto acceleration_z = array<float>{};
Code: Select all
struct simd_vector
{
using underlying_type = __m256;
using element_type = float;
static constexpr auto size = sizeof(underlying_type) / sizeof(element_type);
alignas(sizeof(underlying_type)) element_type elements[size];
};
struct vector3
{
simd_vector x;
simd_vector y;
simd_vector z;
};
struct object
{
vector3 acceleration;
vector3 velocity;
vector3 position;
};
Code: Select all
float* acceleration_x = static_cast<float*>(_aligned_malloc(total_gameobjects * sizeof(float), sizeof(simd_vector)));
float* acceleration_y = static_cast<float*>(_aligned_malloc(total_gameobjects * sizeof(float), sizeof(simd_vector)));
float* acceleration_z = static_cast<float*>(_aligned_malloc(total_gameobjects * sizeof(float), sizeof(simd_vector)));
float* velocity_x = static_cast<float*>(_aligned_malloc(total_gameobjects * sizeof(float), sizeof(simd_vector)));
float* velocity_y = static_cast<float*>(_aligned_malloc(total_gameobjects * sizeof(float), sizeof(simd_vector)));
float* velocity_z = static_cast<float*>(_aligned_malloc(total_gameobjects * sizeof(float), sizeof(simd_vector)));
float* position_x = static_cast<float*>(_aligned_malloc(total_gameobjects * sizeof(float), sizeof(simd_vector)));
float* position_y = static_cast<float*>(_aligned_malloc(total_gameobjects * sizeof(float), sizeof(simd_vector)));
float* position_z = static_cast<float*>(_aligned_malloc(total_gameobjects * sizeof(float), sizeof(simd_vector)));