Skip to content

Instantly share code, notes, and snippets.

@heatblazer
Created October 9, 2018 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heatblazer/ce84676cf675dd03978bb348ce3bc942 to your computer and use it in GitHub Desktop.
Save heatblazer/ce84676cf675dd03978bb348ce3bc942 to your computer and use it in GitHub Desktop.
intirnsicstest
// ConsoleApplication4.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include "pch.h"
#include <intrin.h>
#include <iostream>
class Vec3D
{
float x;
float y;
float z;
float w;
public:
Vec3D() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) {}
Vec3D(float X, float Y, float Z, float W) : x(X), y(Y), z(Z), w(W) {}
Vec3D(const volatile Vec3D& ref)
{
x = ref.x;
y = ref.y;
z = ref.z;
}
Vec3D operator=(const Vec3D& ref)
{
return ref;
}
Vec3D& operator* (const Vec3D& ref)
{
__m128 vec1 = _mm_set_ps(ref.x, ref.y, ref.z, ref.w);
__m128 vec2 = _mm_set_ps(x, y, z, w);
__m128 result = _mm_mul_ps(vec1, vec2);
x = result.m128_f32[0];
y = result.m128_f32[1];
z = result.m128_f32[2];
w = result.m128_f32[3];
return *this;
}
virtual ~Vec3D() {};
void print(void)
{
std::cout << x << ":" << y << ":" << z << ":" << w << "\r\n";
}
};
int main()
{
Vec3D v1(1.0, 2.0, 3.0, 0.0);
Vec3D v2(3.0, 2.0, 1.0, 0.0);
v1 = v1 * v2;
v1.print();
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
#if 0
__m256 result_vec[TEST_SIZE] = { 0 };
__m256* arr1 = new __m256[TEST_SIZE];
__m256* arr2 = new __m256[TEST_SIZE];
__m256* arr3 = new __m256[TEST_SIZE];
for (int i = 0; i < TEST_SIZE; ++i)
{
result_vec[i] = multiply_and_add(arr1[i], arr2[i], arr3[i]);
}
float* res = (float*)&result_vec;
for (int i = 0; i < TEST_SIZE; ++i)
{
std::cout << res[i] << "\r\n";
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment