diff --git a/src/CKKSTypes.cpp b/src/CKKSTypes.cpp index c59a4f3..b5d0763 100644 --- a/src/CKKSTypes.cpp +++ b/src/CKKSTypes.cpp @@ -17,8 +17,30 @@ #include "CKKSTypes.hpp" #include +#if defined(__MINGW32__) +#include +#endif + namespace deb { +#if DEB_ALINAS_LEN != 0 +inline void *deb_aligned_alloc(size_t alignment, size_t size) { +#if defined(__MINGW32__) + return _aligned_malloc(size, alignment); +#else + return std::aligned_alloc(alignment, size); +#endif +} + +inline void deb_aligned_free(void *ptr) { +#if defined(__MINGW32__) + _aligned_free(ptr); +#else + std::free(ptr); +#endif +} +#endif + //// --------------------------------------------------------------------- //// Implementation of Message //// --------------------------------------------------------------------- @@ -72,11 +94,9 @@ PolyUnitT::PolyUnitT(const Preset preset, const Size level, const bool alloc) data_ptr_ = std::shared_ptr(new U[degree_], std::default_delete()); #else - auto *buf = static_cast(::operator new[]( - sizeof(U) * degree_, std::align_val_t(DEB_ALINAS_LEN))); - data_ptr_ = std::shared_ptr(buf, [](U *p) { - ::operator delete[](p, std::align_val_t(DEB_ALINAS_LEN)); - }); + auto *buf = static_cast( + deb_aligned_alloc(DEB_ALINAS_LEN, sizeof(U) * degree_)); + data_ptr_ = std::shared_ptr(buf, [](U *p) { deb_aligned_free(p); }); #endif } @@ -92,11 +112,9 @@ PolyUnitT::PolyUnitT(u64 prime, Size degree, const bool alloc) data_ptr_ = std::shared_ptr(new U[degree_], std::default_delete()); #else - auto *buf = static_cast(::operator new[]( - sizeof(U) * degree_, std::align_val_t(DEB_ALINAS_LEN))); - data_ptr_ = std::shared_ptr(buf, [](U *p) { - ::operator delete[](p, std::align_val_t(DEB_ALINAS_LEN)); - }); + auto *buf = static_cast( + deb_aligned_alloc(DEB_ALINAS_LEN, sizeof(U) * degree_)); + data_ptr_ = std::shared_ptr(buf, [](U *p) { deb_aligned_free(p); }); #endif } @@ -150,8 +168,8 @@ PolynomialT::PolynomialT(const Preset preset, const bool full_level) { std::default_delete()); #else auto *buf = static_cast( - std::aligned_alloc(DEB_ALINAS_LEN, sizeof(U) * num_poly * degree)); - dealloc_ptr_ = std::shared_ptr(buf, [](U *p) { std::free(p); }); + deb_aligned_alloc(DEB_ALINAS_LEN, sizeof(U) * num_poly * degree)); + dealloc_ptr_ = std::shared_ptr(buf, [](U *p) { deb_aligned_free(p); }); #endif for (Size l = 0; l < num_poly; ++l) { polyunits_.emplace_back(preset, l, false); @@ -167,8 +185,8 @@ PolynomialT::PolynomialT(const Preset preset, const Size custom_size) { std::default_delete()); #else auto *buf = static_cast( - std::aligned_alloc(DEB_ALINAS_LEN, sizeof(U) * custom_size * degree)); - dealloc_ptr_ = std::shared_ptr(buf, [](U *p) { std::free(p); }); + deb_aligned_alloc(DEB_ALINAS_LEN, sizeof(U) * custom_size * degree)); + dealloc_ptr_ = std::shared_ptr(buf, [](U *p) { deb_aligned_free(p); }); #endif for (Size l = 0; l < custom_size; ++l) { polyunits_.emplace_back(preset, l, false); @@ -198,12 +216,11 @@ PolynomialT::deepCopy(std::optional num_polyunit) const { new U[num_polyunit_val * polyunits_[0].degree()], std::default_delete()); #else - auto *buf = static_cast(::operator new[]( - sizeof(U) * num_polyunit_val * polyunits_[0].degree(), - std::align_val_t(DEB_ALINAS_LEN))); - copy.dealloc_ptr_ = std::shared_ptr(buf, [buf](U *p) { - ::operator delete[](buf, std::align_val_t(DEB_ALINAS_LEN)); - }); + auto *buf = static_cast( + deb_aligned_alloc(DEB_ALINAS_LEN, sizeof(U) * num_polyunit_val * + polyunits_[0].degree())); + copy.dealloc_ptr_ = + std::shared_ptr(buf, [](U *p) { deb_aligned_free(p); }); #endif for (Size i = 0; i < num_polyunit_val; ++i) { copy.polyunits_.emplace_back(polyunits_[i].prime(),