Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test,benchmark to assume that arm has the Neon extension #110

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 34 additions & 27 deletions benchmarks/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,23 @@ void call_sm2_montjadd(void) repeat(sm2_montjadd(b1,b2,b3))
void call_sm2_montjdouble(void) repeat(sm2_montjdouble(b1,b2))
void call_sm2_montjmixadd(void) repeat(sm2_montjmixadd(b1,b2,b3))

#ifdef __ARM_NEON
#ifdef __x86_64__

void call_bignum_copy_row_from_table_8n_neon__32_16(void) {}
void call_bignum_copy_row_from_table_8n_neon__32_32(void) {}
void call_bignum_copy_row_from_table_16_neon__32(void) {}
void call_bignum_copy_row_from_table_32_neon__32(void) {}

void call_bignum_emontredc_8n_neon__32(void) {}
void call_bignum_kmul_16_32_neon(void) {}
void call_bignum_ksqr_16_32_neon(void) {}
void call_bignum_kmul_32_64_neon(void) {}
void call_bignum_ksqr_32_64_neon(void) {}
void call_bignum_mul_8_16_neon(void) {}
void call_bignum_sqr_8_16_neon(void) {}

#else

void call_bignum_copy_row_from_table_8n_neon__32_16(void) \
repeat(bignum_copy_row_from_table_8n_neon(b0,b1,32,16,0))
void call_bignum_copy_row_from_table_8n_neon__32_32(void) \
Expand All @@ -785,27 +801,13 @@ void call_bignum_ksqr_32_64_neon(void) repeat(bignum_ksqr_32_64_neon(b0,b1,b2))
void call_bignum_mul_8_16_neon(void) repeat(bignum_mul_8_16_neon(b0,b1,b2))
void call_bignum_sqr_8_16_neon(void) repeat(bignum_sqr_8_16_neon(b0,b1))

#else
void call_bignum_copy_row_from_table_8n_neon__32_16(void) {}
void call_bignum_copy_row_from_table_8n_neon__32_32(void) {}
void call_bignum_copy_row_from_table_16_neon__32(void) {}
void call_bignum_copy_row_from_table_32_neon__32(void) {}

void call_bignum_emontredc_8n_neon__32(void) {}
void call_bignum_kmul_16_32_neon(void) {}
void call_bignum_ksqr_16_32_neon(void) {}
void call_bignum_kmul_32_64_neon(void) {}
void call_bignum_ksqr_32_64_neon(void) {}
void call_bignum_mul_8_16_neon(void) {}
void call_bignum_sqr_8_16_neon(void) {}

#endif

int main(int argc, char *argv[])
{
int bmi = get_arch_name() == ARCH_AARCH64 || supports_bmi2_and_adx();
int all = 1;
int neon = supports_neon();
int arm = get_arch_name() == ARCH_AARCH64;
char *argending;
long negreps;
function_to_test = "";
Expand Down Expand Up @@ -910,10 +912,14 @@ int main(int argc, char *argv[])
timingtest(all,"bignum_copy (32 -> 32)" ,call_bignum_copy__32_32);
timingtest(all,"bignum_copy_row_from_table (h=32,w=16)",call_bignum_copy_row_from_table__32_16);
timingtest(all,"bignum_copy_row_from_table (h=32,w=32)",call_bignum_copy_row_from_table__32_32);
timingtest(neon,"bignum_copy_row_from_table_8n_neon (h=32,w=16)",call_bignum_copy_row_from_table_8n_neon__32_16);
timingtest(neon,"bignum_copy_row_from_table_8n_neon (h=32,w=32)",call_bignum_copy_row_from_table_8n_neon__32_32);
timingtest(neon,"bignum_copy_row_from_table_16_neon (h=32)",call_bignum_copy_row_from_table_16_neon__32);
timingtest(neon,"bignum_copy_row_from_table_32_neon (h=32)",call_bignum_copy_row_from_table_32_neon__32);
timingtest(arm, "bignum_copy_row_from_table_8n_neon (h=32,w=16)",
call_bignum_copy_row_from_table_8n_neon__32_16);
timingtest(arm, "bignum_copy_row_from_table_8n_neon (h=32,w=32)",
call_bignum_copy_row_from_table_8n_neon__32_32);
timingtest(arm, "bignum_copy_row_from_table_16_neon (h=32)",
call_bignum_copy_row_from_table_16_neon__32);
timingtest(arm, "bignum_copy_row_from_table_32_neon (h=32)",
call_bignum_copy_row_from_table_32_neon__32);
timingtest(all,"bignum_ctd (32)" ,call_bignum_ctd__32);
timingtest(all,"bignum_ctz (32)" ,call_bignum_ctz__32);
timingtest(bmi,"bignum_deamont_p256",call_bignum_deamont_p256);
Expand Down Expand Up @@ -944,7 +950,8 @@ int main(int argc, char *argv[])
timingtest(all,"bignum_emontredc (12 -> 6)",call_bignum_emontredc__6);
timingtest(all,"bignum_emontredc (64 -> 32)",call_bignum_emontredc__32);
timingtest(bmi,"bignum_emontredc_8n (64 -> 32)",call_bignum_emontredc_8n__32);
timingtest(neon,"bignum_emontredc_8n_neon (64 -> 32)",call_bignum_emontredc_8n_neon__32);
timingtest(arm, "bignum_emontredc_8n_neon (64 -> 32)",
call_bignum_emontredc_8n_neon__32);
timingtest(all,"bignum_eq (32x32)" ,call_bignum_eq__32_32);
timingtest(all,"bignum_even (32)" ,call_bignum_even__32);
timingtest(all,"bignum_frombebytes_4",call_bignum_frombebytes_4);
Expand All @@ -964,13 +971,13 @@ int main(int argc, char *argv[])
timingtest(all,"bignum_invsqrt_p25519_alt",call_bignum_invsqrt_p25519_alt);
timingtest(all,"bignum_iszero (32)" ,call_bignum_iszero__32);
timingtest(bmi,"bignum_kmul_16_32",call_bignum_kmul_16_32);
timingtest(neon,"bignum_kmul_16_32_neon",call_bignum_kmul_16_32_neon);
timingtest(arm, "bignum_kmul_16_32_neon", call_bignum_kmul_16_32_neon);
timingtest(bmi,"bignum_kmul_32_64",call_bignum_kmul_32_64);
timingtest(neon,"bignum_kmul_32_64_neon",call_bignum_kmul_32_64_neon);
timingtest(arm, "bignum_kmul_32_64_neon", call_bignum_kmul_32_64_neon);
timingtest(bmi,"bignum_ksqr_16_32",call_bignum_ksqr_16_32);
timingtest(neon,"bignum_ksqr_16_32_neon",call_bignum_ksqr_16_32_neon);
timingtest(arm, "bignum_ksqr_16_32_neon", call_bignum_ksqr_16_32_neon);
timingtest(bmi,"bignum_ksqr_32_64",call_bignum_ksqr_32_64);
timingtest(neon,"bignum_ksqr_32_64_neon",call_bignum_ksqr_32_64_neon);
timingtest(arm, "bignum_ksqr_32_64_neon", call_bignum_ksqr_32_64_neon);
timingtest(all,"bignum_le (32x32)" ,call_bignum_le__32_32);
timingtest(all,"bignum_littleendian_4",call_bignum_littleendian_4);
timingtest(all,"bignum_littleendian_6",call_bignum_littleendian_6);
Expand Down Expand Up @@ -1055,7 +1062,7 @@ int main(int argc, char *argv[])
timingtest(all,"bignum_mul_6_12_alt",call_bignum_mul_6_12_alt);
timingtest(bmi,"bignum_mul_8_16",call_bignum_mul_8_16);
timingtest(all,"bignum_mul_8_16_alt",call_bignum_mul_8_16_alt);
timingtest(neon,"bignum_mul_8_16_neon",call_bignum_mul_8_16_neon);
timingtest(arm, "bignum_mul_8_16_neon", call_bignum_mul_8_16_neon);
timingtest(bmi,"bignum_mul_p25519",call_bignum_mul_p25519);
timingtest(all,"bignum_mul_p25519_alt",call_bignum_mul_p25519_alt);
timingtest(bmi,"bignum_mul_p256k1",call_bignum_mul_p256k1);
Expand Down Expand Up @@ -1105,7 +1112,7 @@ int main(int argc, char *argv[])
timingtest(all,"bignum_sqr_6_12_alt",call_bignum_sqr_6_12_alt);
timingtest(bmi,"bignum_sqr_8_16",call_bignum_sqr_8_16);
timingtest(all,"bignum_sqr_8_16_alt",call_bignum_sqr_8_16_alt);
timingtest(neon,"bignum_sqr_8_16_neon",call_bignum_sqr_8_16_neon);
timingtest(arm, "bignum_sqr_8_16_neon", call_bignum_sqr_8_16_neon);
timingtest(bmi,"bignum_sqr_p25519",call_bignum_sqr_p25519);
timingtest(all,"bignum_sqr_p25519_alt",call_bignum_sqr_p25519_alt);
timingtest(bmi,"bignum_sqr_p256k1",call_bignum_sqr_p256k1);
Expand Down
14 changes: 0 additions & 14 deletions tests/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ int supports_bmi2_and_adx(void)
return (c & (1ul<<8)) && (c & (1ul<<19));
}

int supports_neon(void)
{ // X86_64 does not support NEON.
return 0;
}

enum arch_name get_arch_name()
{ return ARCH_X86_64;
}
Expand All @@ -34,15 +29,6 @@ int supports_bmi2_and_adx(void)
return 0;
}

int supports_neon(void)
{
#ifdef __ARM_NEON
return 1;
#else
return 0;
#endif
}

enum arch_name get_arch_name()
{ return ARCH_AARCH64;
}
Expand Down
117 changes: 61 additions & 56 deletions tests/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2846,18 +2846,25 @@ int test_bignum_copy_row_from_table(void)

int test_bignum_copy_row_from_table_8n_neon(void)
{
#ifdef __ARM_NEON
return test_bignum_copy_row_from_table_specific("bignum_copy_row_from_table_8n_neon",
0, 1, bignum_copy_row_from_table_8n_neon);
#else
#ifdef __x86_64__
return 1;
#else
return test_bignum_copy_row_from_table_specific(
"bignum_copy_row_from_table_8n_neon", 0, 1,
bignum_copy_row_from_table_8n_neon);
#endif
}

#ifdef __ARM_NEON
#ifdef __x86_64__
int test_bignum_copy_row_from_table_16_neon(void)
{ return 1;
}
#else
void _bignum_copy_row_from_table_16_neon_wrapper(uint64_t *z, uint64_t *table,
uint64_t height, uint64_t width, uint64_t index)
{ assert(width == 16);
uint64_t height,
uint64_t width,
uint64_t index) {
assert(width == 16);
bignum_copy_row_from_table_16_neon(z, table, height, index);
}

Expand All @@ -2866,16 +2873,18 @@ int test_bignum_copy_row_from_table_16_neon(void)
"bignum_copy_row_from_table_16_neon", 16, 0,
_bignum_copy_row_from_table_16_neon_wrapper);
}
#else
int test_bignum_copy_row_from_table_16_neon(void)
{ return 1;
}
#endif

#ifdef __ARM_NEON
#ifdef __x86_64__
int test_bignum_copy_row_from_table_32_neon(void)
{ return 1;
}
#else
void _bignum_copy_row_from_table_32_neon_wrapper(uint64_t *z, uint64_t *table,
uint64_t height, uint64_t width, uint64_t index)
{ assert(width == 32);
uint64_t height,
uint64_t width,
uint64_t index) {
assert(width == 32);
bignum_copy_row_from_table_32_neon(z, table, height, index);
}

Expand All @@ -2884,10 +2893,6 @@ int test_bignum_copy_row_from_table_32_neon(void)
"bignum_copy_row_from_table_32_neon", 32, 0,
_bignum_copy_row_from_table_32_neon_wrapper);
}
#else
int test_bignum_copy_row_from_table_32_neon(void)
{ return 1;
}
#endif

int test_bignum_ctd(void)
Expand Down Expand Up @@ -3762,12 +3767,12 @@ int test_bignum_emontredc_8n(void)

int test_bignum_emontredc_8n_neon(void)
{
#ifdef __ARM_NEON
return test_bignum_emontredc_specific("bignum_emontredc_8n_neon", 1,
bignum_emontredc_8n_neon);
#else
#ifdef __x86_64__
// Do not call the neon function to avoid a linking failure error.
return 1;
#else
return test_bignum_emontredc_specific("bignum_emontredc_8n_neon", 1,
bignum_emontredc_8n_neon);
#endif
}

Expand Down Expand Up @@ -4451,12 +4456,12 @@ int test_bignum_kmul_16_32(void)

int test_bignum_kmul_16_32_neon(void)
{
#ifdef __ARM_NEON
return test_bignum_kmul_specific(32,16,16,"bignum_kmul_16_32_neon",
bignum_kmul_16_32_neon);
#else
#ifdef __x86_64__
// Do not call the neon function to avoid a linking failure error.
return 1;
#else
return test_bignum_kmul_specific(32, 16, 16, "bignum_kmul_16_32_neon",
bignum_kmul_16_32_neon);
#endif
}

Expand All @@ -4466,12 +4471,12 @@ int test_bignum_kmul_32_64(void)

int test_bignum_kmul_32_64_neon(void)
{
#ifdef __ARM_NEON
return test_bignum_kmul_specific(64,32,32,"bignum_kmul_32_64_neon",
bignum_kmul_32_64_neon);
#else
#ifdef __x86_64__
// Do not call the neon function to avoid a linking failure error.
return 1;
#else
return test_bignum_kmul_specific(64, 32, 32, "bignum_kmul_32_64_neon",
bignum_kmul_32_64_neon);
#endif
}

Expand Down Expand Up @@ -4511,12 +4516,12 @@ int test_bignum_ksqr_16_32(void)

int test_bignum_ksqr_16_32_neon(void)
{
#ifdef __ARM_NEON
return test_bignum_ksqr_specific(32,16,"bignum_ksqr_16_32_neon",
bignum_ksqr_16_32_neon);
#else
#ifdef __x86_64__
// Do not call the neon function to avoid a linking failure error.
return 1;
#else
return test_bignum_ksqr_specific(32, 16, "bignum_ksqr_16_32_neon",
bignum_ksqr_16_32_neon);
#endif
}

Expand All @@ -4526,12 +4531,12 @@ int test_bignum_ksqr_32_64(void)

int test_bignum_ksqr_32_64_neon(void)
{
#ifdef __ARM_NEON
return test_bignum_ksqr_specific(64,32,"bignum_ksqr_32_64_neon",
bignum_ksqr_32_64_neon);
#else
#ifdef __x86_64__
// Do not call the neon function to avoid a linking failure error.
return 1;
#else
return test_bignum_ksqr_specific(64, 32, "bignum_ksqr_32_64_neon",
bignum_ksqr_32_64_neon);
#endif
}

Expand Down Expand Up @@ -6698,12 +6703,12 @@ int test_bignum_mul_8_16_alt(void)

int test_bignum_mul_8_16_neon(void)
{
#ifdef __ARM_NEON
return test_bignum_mul_specific(16, 8, 8, "bignum_mul_8_16_neon",
bignum_mul_8_16_neon);
#else
#ifdef __x86_64__
// Do not call the neon function to avoid a linking failure error.
return 1;
#else
return test_bignum_mul_specific(16, 8, 8, "bignum_mul_8_16_neon",
bignum_mul_8_16_neon);
#endif
}

Expand Down Expand Up @@ -8024,11 +8029,12 @@ int test_bignum_sqr_8_16_alt(void)

int test_bignum_sqr_8_16_neon(void)
{
#ifdef __ARM_NEON
return test_bignum_sqr_specific(16,8,"bignum_sqr_8_16_neon",bignum_sqr_8_16_neon);
#else
#ifdef __x86_64__
// Do not call the neon function to avoid a linking failure error.
return 1;
#else
return test_bignum_sqr_specific(16, 8, "bignum_sqr_8_16_neon",
bignum_sqr_8_16_neon);
#endif
}

Expand Down Expand Up @@ -11987,17 +11993,16 @@ int main(int argc, char *argv[])
functionaltest(all,"word_recip",test_word_recip);

if (get_arch_name() == ARCH_AARCH64) {
int neon = supports_neon();
functionaltest(neon,"bignum_copy_row_from_table_8n_neon",test_bignum_copy_row_from_table_8n_neon);
functionaltest(neon,"bignum_copy_row_from_table_16_neon",test_bignum_copy_row_from_table_16_neon);
functionaltest(neon,"bignum_copy_row_from_table_32_neon",test_bignum_copy_row_from_table_32_neon);
functionaltest(neon,"bignum_emontredc_8n_neon",test_bignum_emontredc_8n_neon);
functionaltest(neon,"bignum_kmul_16_32_neon", test_bignum_kmul_16_32_neon);
functionaltest(neon,"bignum_kmul_32_64_neon", test_bignum_kmul_32_64_neon);
functionaltest(neon,"bignum_ksqr_16_32_neon",test_bignum_ksqr_16_32_neon);
functionaltest(neon,"bignum_ksqr_32_64_neon",test_bignum_ksqr_32_64_neon);
functionaltest(neon,"bignum_mul_8_16_neon",test_bignum_mul_8_16_neon);
functionaltest(neon,"bignum_sqr_8_16_neon",test_bignum_sqr_8_16_neon);
functionaltest(all,"bignum_copy_row_from_table_8n_neon",test_bignum_copy_row_from_table_8n_neon);
functionaltest(all,"bignum_copy_row_from_table_16_neon",test_bignum_copy_row_from_table_16_neon);
functionaltest(all,"bignum_copy_row_from_table_32_neon",test_bignum_copy_row_from_table_32_neon);
functionaltest(all,"bignum_emontredc_8n_neon",test_bignum_emontredc_8n_neon);
functionaltest(all,"bignum_kmul_16_32_neon", test_bignum_kmul_16_32_neon);
functionaltest(all,"bignum_kmul_32_64_neon", test_bignum_kmul_32_64_neon);
functionaltest(all,"bignum_ksqr_16_32_neon",test_bignum_ksqr_16_32_neon);
functionaltest(all,"bignum_ksqr_32_64_neon",test_bignum_ksqr_32_64_neon);
functionaltest(all,"bignum_mul_8_16_neon",test_bignum_mul_8_16_neon);
functionaltest(all,"bignum_sqr_8_16_neon",test_bignum_sqr_8_16_neon);
}

if (extrastrigger) function_to_test = "_";
Expand Down