ams: support building unit test programs on windows/linux/macos

This commit is contained in:
Michael Scire 2022-03-06 12:08:20 -08:00 committed by SciresM
parent 9a38be201a
commit 64a97576d0
756 changed files with 33359 additions and 9372 deletions

View file

@ -45,7 +45,7 @@ namespace ams::crypto::impl {
return static_cast<BigNum::Word>(half) << BITSIZEOF(BigNum::HalfWord);
}
constexpr ALWAYS_INLINE BigNum::Word ToLowerHalf(BigNum::HalfWord half) {
[[maybe_unused]] constexpr ALWAYS_INLINE BigNum::Word ToLowerHalf(BigNum::HalfWord half) {
static_assert(sizeof(BigNum::Word) == sizeof(BigNum::HalfWord) * 2);
return static_cast<BigNum::Word>(half);
}
@ -422,4 +422,69 @@ namespace ams::crypto::impl {
return true;
}
#if !defined(ATMOSPHERE_ARCH_ARM64)
BigNum::Word BigNum::Add(Word *dst, const Word *lhs, const Word *rhs, size_t num_words) {
Word carry = 0;
for (size_t i = 0; i < num_words; ++i) {
Word v;
if ((v = lhs[i] + carry) < carry) {
v = rhs[i];
} else if ((v += rhs[i]) < rhs[i]) {
carry = 1;
} else {
carry = 0;
}
dst[i] = v;
}
return carry;
}
BigNum::Word BigNum::Sub(Word *dst, const Word *lhs, const Word *rhs, size_t num_words) {
Word borrow = 0;
for (size_t i = 0; i < num_words; ++i) {
Word v;
if ((v = lhs[i] - borrow) > (BigNum::MaxWord - borrow)) {
v = BigNum::MaxWord - rhs[i];
} else if ((v -= rhs[i]) > (BigNum::MaxWord - rhs[i])) {
borrow = 1;
} else {
borrow = 0;
}
dst[i] = v;
}
return borrow;
}
BigNum::Word BigNum::MultAdd(Word *dst, const Word *w, size_t num_words, Word mult) {
/* If multiplying by zero, nothing to do. */
if (mult == 0) {
return 0;
}
Word carry = 0, work[2];
for (size_t i = 0; i < num_words; i++) {
/* Multiply, calculate carry for next. */
MultWord(work, mult, w[i]);
if ((dst[i] += carry) < carry) {
carry = 1;
} else {
carry = 0;
}
if ((dst[i] += work[0]) < work[0]) {
carry++;
}
carry += work[1];
}
return carry;
}
#endif
}