Продолжение переименования типов и функций
This commit is contained in:
parent
605afabd94
commit
3b6efaafa9
25 changed files with 768 additions and 916 deletions
|
@ -10,19 +10,19 @@
|
|||
#endif // _WINDOWS_
|
||||
|
||||
typedef struct {
|
||||
// fp32_versor_t versor1, versor2, result;
|
||||
fp32_matrix3x3_t matrix;
|
||||
fp32_vector3_t vector1, vector2;
|
||||
} fp32_structure_t;
|
||||
versor_fp32_t versor1, versor2, result;
|
||||
matrix3x3_fp32_t matrix;
|
||||
vector3_fp32_t vector1, vector2;
|
||||
} structure_fp32_t;
|
||||
|
||||
fp32_structure_t* allocate_structures(const unsigned int amount)
|
||||
structure_fp32_t* allocate_structures(const unsigned int amount)
|
||||
{
|
||||
return calloc(amount, sizeof(fp32_structure_t));
|
||||
return calloc(amount, sizeof(structure_fp32_t));
|
||||
}
|
||||
|
||||
fp32_structure_t* make_structures(const unsigned int amount)
|
||||
structure_fp32_t* make_structures(const unsigned int amount)
|
||||
{
|
||||
fp32_structure_t* list = allocate_structures(amount);
|
||||
structure_fp32_t* list = allocate_structures(amount);
|
||||
|
||||
if (list == 0) {
|
||||
return 0;
|
||||
|
@ -31,8 +31,7 @@ fp32_structure_t* make_structures(const unsigned int amount)
|
|||
const float multiplier = 2.0f / RAND_MAX;
|
||||
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
/*
|
||||
fp32_versor_set_values(
|
||||
versor_fp32_set_values(
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
|
@ -40,7 +39,7 @@ fp32_structure_t* make_structures(const unsigned int amount)
|
|||
&list[i].versor1
|
||||
);
|
||||
|
||||
fp32_versor_set_values(
|
||||
versor_fp32_set_values(
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
|
@ -48,54 +47,54 @@ fp32_structure_t* make_structures(const unsigned int amount)
|
|||
&list[i].versor2
|
||||
);
|
||||
|
||||
fp32_versor_reset(&list[i].result);
|
||||
*/
|
||||
fp32_matrix3x3_set_to_identity(&list[i].matrix);
|
||||
versor_reset_fp32(&list[i].result);
|
||||
|
||||
fp32_vector3_set_values(
|
||||
matrix3x3_fp32_set_to_identity(&list[i].matrix);
|
||||
|
||||
vector3_set_fp32(
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
&list[i].vector1
|
||||
);
|
||||
|
||||
fp32_vector3_reset(&list[i].vector2);
|
||||
vector3_reset_fp32(&list[i].vector2);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void print_versor(const fp32_versor_t* versor)
|
||||
void print_versor_fp32(const versor_fp32_t* versor)
|
||||
{
|
||||
printf("Versor (%f, %f, %f, %f)\n", versor->s0, versor->x1, versor->x2, versor->x3);
|
||||
}
|
||||
|
||||
void print_vector(const fp32_vector3_t* vector)
|
||||
void print_versor_fp64(const versor_fp64_t* versor)
|
||||
{
|
||||
printf("(%f, %f, %f) / %f\n", vector->x1, vector->x2, vector->x3, fp32_vector3_get_modulus(vector));
|
||||
printf("Versor (%lf, %lf, %lf, %lf)\n", versor->s0, versor->x1, versor->x2, versor->x3);
|
||||
}
|
||||
|
||||
void item_work(fp32_structure_t* item)
|
||||
void print_vector_fp32(const vector3_fp32_t* vector)
|
||||
{
|
||||
//fp32_versor_combine(&item->versor1, &item->versor1, &item->result);
|
||||
//fp32_versor_make_rotation_matrix(&item->result, &item->matrix);
|
||||
fp32_matrix3x3_right_product(&item->matrix, &item->vector1, &item->vector2);
|
||||
printf("(%f, %f, %f) / %f\n", vector->x1, vector->x2, vector->x3, vector3_get_modulus_fp32(vector));
|
||||
}
|
||||
|
||||
void circle_work(const unsigned int amount, fp32_structure_t* list)
|
||||
void print_vector_fp64(const vector3_fp64_t* vector)
|
||||
{
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
//fp32_versor_combine(&list[i].versor1, &list[i].versor1, &list[i].result);
|
||||
//fp32_versor_make_rotation_matrix(&list[i].result, &list[i].matrix);
|
||||
fp32_matrix3x3_right_product(&list[i].matrix, &list[i].vector1, &list[i].vector2);
|
||||
//fp32_versor_turn(&list[i].result, &list[i].vector1, &list[i].vector2);
|
||||
}
|
||||
printf("(%lf, %lf, %lf) / %lf\n", vector->x1, vector->x2, vector->x3, vector3_get_modulus_fp64(vector));
|
||||
}
|
||||
|
||||
void item_work(structure_fp32_t* item)
|
||||
{
|
||||
versor_fp32_combine(&item->versor1, &item->versor1, &item->result);
|
||||
versor_fp32_make_rotation_matrix(&item->result, &item->matrix);
|
||||
matrix3x3_fp32_right_product(&item->matrix, &item->vector1, &item->vector2);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const unsigned int amount = 1000000;
|
||||
fp32_structure_t* list;
|
||||
structure_fp32_t* list;
|
||||
|
||||
#ifdef _WIN64
|
||||
ULONGLONG now, start, end;
|
||||
|
@ -121,14 +120,13 @@ int main()
|
|||
clock_gettime(CLOCK_REALTIME, &start);
|
||||
#endif // _WIN64
|
||||
|
||||
for (int j = 0; j < 1000; j++) {
|
||||
//circle(amount, list);
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
for (int j = 0; j < 1000; j++) {
|
||||
//item_work(list + i);
|
||||
//fp32_versor_combine(&list[i].versor1, &list[i].versor1, &list[i].result);
|
||||
//fp32_versor_make_rotation_matrix(&list[i].result, &list[i].matrix);
|
||||
fp32_matrix3x3_right_product(&list[i].matrix, &list[i].vector1, &list[i].vector2);
|
||||
//fp32_versor_turn(&list[i].result, &list[i].vector1, &list[i].vector2);
|
||||
versor_fp32_combine(&list[i].versor1, &list[i].versor2, &list[i].result);
|
||||
versor_fp32_make_rotation_matrix(&list[i].result, &list[i].matrix);
|
||||
matrix3x3_fp32_right_product(&list[i].matrix, &list[i].vector1, &list[i].vector2);
|
||||
//versor_fp32_turn(&list[i].result, &list[i].vector1, &list[i].vector2);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,196 +140,11 @@ int main()
|
|||
printf("Time: %lf\n", (end.tv_sec - start.tv_sec) * 1000.0 + (end.tv_nsec - start.tv_nsec) * 0.000001);
|
||||
#endif // _WIN64
|
||||
|
||||
//print_versor(&list[10].versor1);
|
||||
//print_versor(&list[10].versor2);
|
||||
//print_versor(&list[10].result);
|
||||
//print_versor_fp32(&list[10].versor1);
|
||||
//print_versor_fp32(&list[10].versor2);
|
||||
//print_versor_fp32(&list[10].result);
|
||||
|
||||
free(list);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
fp32_vector3_t* allocate_vectors3(const unsigned int amount)
|
||||
{
|
||||
return calloc(amount, sizeof(fp32_vector3_t));
|
||||
}
|
||||
|
||||
fp32_vector3_t* make_zero_vectors3(const unsigned int amount)
|
||||
{
|
||||
fp32_vector3_t* list = allocate_vectors3(amount);
|
||||
|
||||
if (list == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
fp32_vector3_reset(&list[i]);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
fp32_vector3_t* make_random_vectors3(const unsigned int amount)
|
||||
{
|
||||
fp32_vector3_t* list = allocate_vectors3(amount);
|
||||
|
||||
if (list == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float multiplier = 2.0f / RAND_MAX;
|
||||
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
list[i].x1 = rand() * multiplier - 1.0f;
|
||||
list[i].x2 = rand() * multiplier - 1.0f;
|
||||
list[i].x3 = rand() * multiplier - 1.0f;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
fp32_versor_t* allocate_versors(const unsigned int amount)
|
||||
{
|
||||
return calloc(amount, sizeof(fp32_versor_t));
|
||||
}
|
||||
|
||||
fp32_versor_t * make_zero_versors(const unsigned int amount)
|
||||
{
|
||||
fp32_versor_t * list = allocate_versors(amount);
|
||||
|
||||
if (list == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
fp32_versor_reset(&list[i]);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
fp32_versor_t * make_random_versors(const unsigned int amount)
|
||||
{
|
||||
fp32_versor_t * list = allocate_versors(amount);
|
||||
|
||||
if (list == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const float multiplier = 2.0f / RAND_MAX;
|
||||
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
fp32_versor_set_values(
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
&list[i]
|
||||
);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const unsigned int amount = 1000000;
|
||||
|
||||
#ifdef _WIN64
|
||||
ULONGLONG now, start, end;
|
||||
now = GetTickCount64();
|
||||
srand((unsigned int)(now & 0xfffffff));
|
||||
#else
|
||||
struct timespec now, start, end;
|
||||
clock_gettime(0, &now);
|
||||
srand((unsigned int)(now.tv_nsec & 0xfffffff));
|
||||
#endif // _WIN64
|
||||
|
||||
fp32_versor_t * versors1 = make_random_versors(amount);
|
||||
|
||||
if (versors1 == 0) {
|
||||
printf("Cannot allocate memory for versors1");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fp32_versor_t * versors2 = make_random_versors(amount);
|
||||
|
||||
if (versors2 == 0) {
|
||||
printf("Cannot allocate memory for versors2");
|
||||
free(versors1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
fp32_versor_t * results = make_zero_versors(amount);
|
||||
|
||||
if (results == 0) {
|
||||
printf("Cannot allocate memory for results");
|
||||
free(versors2);
|
||||
free(versors1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
fp32_matrix3x3_t* matrixes =malloc(amount * sizeof(fp32_matrix3x3_t));
|
||||
|
||||
if (matrixes == 0) {
|
||||
printf("Cannot allocate memory for matrixes");
|
||||
free(results);
|
||||
free(versors2);
|
||||
free(versors1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
fp32_vector3_t* vectors = make_random_vectors3(amount);
|
||||
|
||||
if (results == 0) {
|
||||
printf("Cannot allocate memory for result vectors");
|
||||
free(matrixes);
|
||||
free(results);
|
||||
free(versors2);
|
||||
free(versors1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef _WIN64
|
||||
end = GetTickCount64();
|
||||
printf("Setup time: %lld\n", end - now);
|
||||
|
||||
start = GetTickCount64();
|
||||
#else
|
||||
clock_gettime(CLOCK_REALTIME, &end);
|
||||
printf("Time: %lf\n", (end.tv_sec - now.tv_sec) * 1000.0 + (end.tv_nsec - now.tv_nsec) * 0.000001);
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &start);
|
||||
#endif // _WIN64
|
||||
for (int j = 0; j < 1000; j++) {
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
fp32_versor_combine(&versors1[i], &versors2[i], &results[i]);
|
||||
fp32_versor_make_rotation_matrix(&versors1[i], &matrixes[i]);
|
||||
fp32_matrix3x3_right_product(&matrixes[i], &vectors[i], &vectors[i]);
|
||||
//fp32_versor_turn(&results[i], &vectors[i], &vectors[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN64
|
||||
end = GetTickCount64();
|
||||
|
||||
printf("Time: %lld\n", end - start);
|
||||
#else
|
||||
clock_gettime(CLOCK_REALTIME, &end);
|
||||
|
||||
printf("Time: %lf\n", (end.tv_sec - start.tv_sec) * 1000.0 + (end.tv_nsec - start.tv_nsec) * 0.000001);
|
||||
#endif // _WIN64
|
||||
|
||||
print_versor(versors1 + 10);
|
||||
print_versor(versors2 + 10);
|
||||
print_versor(results + 10);
|
||||
|
||||
free(vectors);
|
||||
free(matrixes);
|
||||
free(results);
|
||||
free(versors2);
|
||||
free(versors1);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue