aarch64_semihosting_port.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #ifndef AARCH64_BAREMETAL_PORT_HPP
  5. #define AARCH64_BAREMETAL_PORT_HPP
  6. #include <malloc.h> // Needed for `memalign`.
  7. #include <sys/errno.h> // Needed for `ENOMEM`.
  8. // -std=c++11 is missing the following definitions when targeting
  9. // semihosting on aarch64.
  10. #if __cplusplus == 201103L
  11. #include <cmath>
  12. #define M_PI 3.14159265358979323846
  13. #define M_SQRT2 1.41421356237309504880
  14. namespace std {
  15. inline double cbrt(double x) {
  16. return ::cbrt(x);
  17. }
  18. inline double copysign(double mag, double sgn) {
  19. return ::copysign(mag, sgn);
  20. }
  21. } //namespace std
  22. #endif // __cplusplus == 201103L
  23. extern "C" {
  24. // Redirect the implementation of `posix_memalign` to `memalign`
  25. // as the former is
  26. // missing at link time. https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_memalign.html
  27. __attribute__((weak)) int posix_memalign(void **memptr, size_t alignment, size_t size) {
  28. void * ptr = memalign(alignment, size);
  29. if (ptr != NULL) {
  30. *memptr = ptr;
  31. return 0;
  32. }
  33. return ENOMEM;
  34. }
  35. } // extern "C"
  36. #endif