Переименование типов в соответствии со стилем POSIX, отказ от префикса bg_
This commit is contained in:
parent
d2a25823a5
commit
605afabd94
25 changed files with 1109 additions and 1035 deletions
|
@ -9,29 +9,172 @@
|
|||
#include <time.h>
|
||||
#endif // _WINDOWS_
|
||||
|
||||
BgFP32Vector3* allocate_vectors3(const unsigned int amount)
|
||||
typedef struct {
|
||||
// fp32_versor_t versor1, versor2, result;
|
||||
fp32_matrix3x3_t matrix;
|
||||
fp32_vector3_t vector1, vector2;
|
||||
} fp32_structure_t;
|
||||
|
||||
fp32_structure_t* allocate_structures(const unsigned int amount)
|
||||
{
|
||||
return calloc(amount, sizeof(BgFP32Vector3));
|
||||
return calloc(amount, sizeof(fp32_structure_t));
|
||||
}
|
||||
|
||||
BgFP32Vector3* make_zero_vectors3(const unsigned int amount)
|
||||
fp32_structure_t* make_structures(const unsigned int amount)
|
||||
{
|
||||
BgFP32Vector3* list = allocate_vectors3(amount);
|
||||
fp32_structure_t* list = allocate_structures(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].versor1
|
||||
);
|
||||
|
||||
fp32_versor_set_values(
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
&list[i].versor2
|
||||
);
|
||||
|
||||
fp32_versor_reset(&list[i].result);
|
||||
*/
|
||||
fp32_matrix3x3_set_to_identity(&list[i].matrix);
|
||||
|
||||
fp32_vector3_set_values(
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
&list[i].vector1
|
||||
);
|
||||
|
||||
fp32_vector3_reset(&list[i].vector2);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void print_versor(const fp32_versor_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)
|
||||
{
|
||||
printf("(%f, %f, %f) / %f\n", vector->x1, vector->x2, vector->x3, fp32_vector3_get_modulus(vector));
|
||||
}
|
||||
|
||||
void item_work(fp32_structure_t* item)
|
||||
{
|
||||
//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);
|
||||
}
|
||||
|
||||
void circle_work(const unsigned int amount, fp32_structure_t* list)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const unsigned int amount = 1000000;
|
||||
fp32_structure_t* list;
|
||||
|
||||
#ifdef _WIN64
|
||||
ULONGLONG now, start, end;
|
||||
now = GetTickCount64();
|
||||
srand((unsigned int)(now & 0xfffffff));
|
||||
#else
|
||||
struct timespec start, end;
|
||||
clock_gettime(0, &start);
|
||||
srand((unsigned int)(start.tv_nsec & 0xfffffff));
|
||||
#endif // _WIN64
|
||||
|
||||
list = make_structures(amount);
|
||||
|
||||
#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 - start.tv_sec) * 1000.0 + (end.tv_nsec - start.tv_nsec) * 0.000001);
|
||||
|
||||
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++) {
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
#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(&list[10].versor1);
|
||||
//print_versor(&list[10].versor2);
|
||||
//print_versor(&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++) {
|
||||
bg_fp32_vector3_reset(&list[i]);
|
||||
fp32_vector3_reset(&list[i]);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
BgFP32Vector3* make_random_vectors3(const unsigned int amount)
|
||||
fp32_vector3_t* make_random_vectors3(const unsigned int amount)
|
||||
{
|
||||
BgFP32Vector3* list = allocate_vectors3(amount);
|
||||
fp32_vector3_t* list = allocate_vectors3(amount);
|
||||
|
||||
if (list == 0) {
|
||||
return 0;
|
||||
|
@ -48,29 +191,29 @@ BgFP32Vector3* make_random_vectors3(const unsigned int amount)
|
|||
return list;
|
||||
}
|
||||
|
||||
BgFP32Versor* allocate_versors(const unsigned int amount)
|
||||
fp32_versor_t* allocate_versors(const unsigned int amount)
|
||||
{
|
||||
return calloc(amount, sizeof(BgFP32Versor));
|
||||
return calloc(amount, sizeof(fp32_versor_t));
|
||||
}
|
||||
|
||||
BgFP32Versor * make_zero_versors(const unsigned int amount)
|
||||
fp32_versor_t * make_zero_versors(const unsigned int amount)
|
||||
{
|
||||
BgFP32Versor * list = allocate_versors(amount);
|
||||
fp32_versor_t * list = allocate_versors(amount);
|
||||
|
||||
if (list == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
bg_fp32_versor_reset(&list[i]);
|
||||
fp32_versor_reset(&list[i]);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
BgFP32Versor * make_random_versors(const unsigned int amount)
|
||||
fp32_versor_t * make_random_versors(const unsigned int amount)
|
||||
{
|
||||
BgFP32Versor * list = allocate_versors(amount);
|
||||
fp32_versor_t * list = allocate_versors(amount);
|
||||
|
||||
if (list == 0) {
|
||||
return 0;
|
||||
|
@ -79,7 +222,7 @@ BgFP32Versor * make_random_versors(const unsigned int amount)
|
|||
const float multiplier = 2.0f / RAND_MAX;
|
||||
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
bg_fp32_versor_set_values(
|
||||
fp32_versor_set_values(
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
rand() * multiplier - 1.0f,
|
||||
|
@ -91,76 +234,6 @@ BgFP32Versor * make_random_versors(const unsigned int amount)
|
|||
return list;
|
||||
}
|
||||
|
||||
void print_versor(const BgFP32Versor* versor)
|
||||
{
|
||||
printf("Versor (%f, %f, %f, %f)\n", versor->s0, versor->x1, versor->x2, versor->x3);
|
||||
}
|
||||
|
||||
void print_vector(const BgFP32Vector3* vector)
|
||||
{
|
||||
printf("(%f, %f, %f) / %f\n", vector->x1, vector->x2, vector->x3, bg_fp32_vector3_get_modulus(vector));
|
||||
}
|
||||
/*
|
||||
int main()
|
||||
{
|
||||
const unsigned int amount = 1000000;
|
||||
|
||||
#ifdef _WIN64
|
||||
ULONGLONG now;
|
||||
now = GetTickCount64();
|
||||
srand((unsigned int)(now & 0xfffffff));
|
||||
#else
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_REALTIME, &now);
|
||||
srand((unsigned int)(now.tv_nsec & 0xfffffff));
|
||||
#endif // _WIN64
|
||||
|
||||
BgFP32Versor * versors = make_random_versors(amount);
|
||||
|
||||
if (versors == 0) {
|
||||
printf("Cannot allocate memory for versors");
|
||||
return 0;
|
||||
}
|
||||
|
||||
BgFP32Vector3 initial, result;
|
||||
|
||||
bg_fp32_vector3_set_values(1, 2, 3, &initial);
|
||||
bg_fp32_vector3_copy(&initial, &result);
|
||||
|
||||
#ifdef _WIN64
|
||||
ULONGLONG start, end;
|
||||
start = GetTickCount64();
|
||||
#else
|
||||
struct timespec start, end;
|
||||
clock_gettime(CLOCK_REALTIME, &start);
|
||||
#endif // _WIN64
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
bg_fp32_versor_turn2(&versors[i], &result, &result);
|
||||
}
|
||||
|
||||
for (unsigned int i = amount; i > 0; i--) {
|
||||
bg_fp32_versor_turn_back2(&versors[i - 1], &result, &result);
|
||||
}
|
||||
|
||||
#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_vector(&initial);
|
||||
print_vector(&result);
|
||||
|
||||
free(versors);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
int main()
|
||||
{
|
||||
const unsigned int amount = 1000000;
|
||||
|
@ -175,14 +248,14 @@ int main()
|
|||
srand((unsigned int)(now.tv_nsec & 0xfffffff));
|
||||
#endif // _WIN64
|
||||
|
||||
BgFP32Versor * versors1 = make_random_versors(amount);
|
||||
fp32_versor_t * versors1 = make_random_versors(amount);
|
||||
|
||||
if (versors1 == 0) {
|
||||
printf("Cannot allocate memory for versors1");
|
||||
return 0;
|
||||
}
|
||||
|
||||
BgFP32Versor * versors2 = make_random_versors(amount);
|
||||
fp32_versor_t * versors2 = make_random_versors(amount);
|
||||
|
||||
if (versors2 == 0) {
|
||||
printf("Cannot allocate memory for versors2");
|
||||
|
@ -190,7 +263,7 @@ int main()
|
|||
return 0;
|
||||
}
|
||||
|
||||
BgFP32Versor * results = make_zero_versors(amount);
|
||||
fp32_versor_t * results = make_zero_versors(amount);
|
||||
|
||||
if (results == 0) {
|
||||
printf("Cannot allocate memory for results");
|
||||
|
@ -199,7 +272,7 @@ int main()
|
|||
return 0;
|
||||
}
|
||||
|
||||
BgFP32Matrix3x3* matrixes =malloc(amount * sizeof(BgFP32Matrix3x3));
|
||||
fp32_matrix3x3_t* matrixes =malloc(amount * sizeof(fp32_matrix3x3_t));
|
||||
|
||||
if (matrixes == 0) {
|
||||
printf("Cannot allocate memory for matrixes");
|
||||
|
@ -209,7 +282,7 @@ int main()
|
|||
return 0;
|
||||
}
|
||||
|
||||
BgFP32Vector3* vectors = make_random_vectors3(amount);
|
||||
fp32_vector3_t* vectors = make_random_vectors3(amount);
|
||||
|
||||
if (results == 0) {
|
||||
printf("Cannot allocate memory for result vectors");
|
||||
|
@ -233,10 +306,10 @@ int main()
|
|||
#endif // _WIN64
|
||||
for (int j = 0; j < 1000; j++) {
|
||||
for (unsigned int i = 0; i < amount; i++) {
|
||||
bg_fp32_versor_combine(&versors1[i], &versors2[i], &results[i]);
|
||||
bg_fp32_versor_make_rotation_matrix(&versors1[i], &matrixes[i]);
|
||||
bg_fp32_matrix3x3_right_product(&matrixes[i], &vectors[i], &vectors[i]);
|
||||
//bg_fp32_versor_turn(&results[i], &vectors[i], &vectors[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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -261,3 +334,4 @@ int main()
|
|||
free(versors1);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue