mlucas.in 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #!/bin/sh
  2. #
  3. # mlucas - shell wrapper for Mlucas
  4. # Copyright (C) 2015-2021 Alex Vong <alexvong1995 AT protonmail DOT com>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software Foundation,
  18. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. # use error
  20. set -e
  21. # substitute variables
  22. HOST_CPU='@host_cpu@'
  23. PKGLIBEXECDIR='@pkglibexecdir@'
  24. # Obtain DIRNAME by tranforming `foo/bar' to `foo'
  25. # Otherwise, set it to $PKGLIBEXECDIR
  26. case "$0" in
  27. */*)
  28. DIRNAME=`expr "x$0" : 'x\(.*\)/[^/]*'`
  29. ;;
  30. *)
  31. DIRNAME="$PKGLIBEXECDIR"
  32. ;;
  33. esac
  34. # try invoking different variants of mlucas
  35. # FIXME: should be generated
  36. case "$HOST_CPU" in
  37. i?86)
  38. if test -x "$DIRNAME/mlucas-sse2" && \
  39. "$DIRNAME/mlucas-sse2" \
  40. -fftlen 192 -iters 100 -radset 0 \
  41. >/dev/null 2>&1
  42. then
  43. exec "$DIRNAME/mlucas-sse2" "$@"
  44. elif test -x "$DIRNAME/mlucas-generic-c"
  45. then
  46. exec "$DIRNAME/mlucas-generic-c" "$@"
  47. elif test -x "$PKGLIBEXECDIR/mlucas-sse2" && \
  48. "$PKGLIBEXECDIR/mlucas-sse2" \
  49. -fftlen 192 -iters 100 -radset 0 \
  50. >/dev/null 2>&1
  51. then
  52. exec "$PKGLIBEXECDIR/mlucas-sse2" "$@"
  53. elif test -x "$PKGLIBEXECDIR/mlucas-generic-c"
  54. then
  55. exec "$PKGLIBEXECDIR/mlucas-generic-c" "$@"
  56. fi
  57. ;;
  58. x86_64)
  59. if test -x "$DIRNAME/mlucas-avx512" && \
  60. "$DIRNAME/mlucas-avx512" \
  61. -fftlen 192 -iters 100 -radset 0 \
  62. >/dev/null 2>&1
  63. then
  64. exec "$DIRNAME/mlucas-avx512" "$@"
  65. elif test -x "$DIRNAME/mlucas-avx2" && \
  66. "$DIRNAME/mlucas-avx2" \
  67. -fftlen 192 -iters 100 -radset 0 \
  68. >/dev/null 2>&1
  69. then
  70. exec "$DIRNAME/mlucas-avx2" "$@"
  71. elif test -x "$DIRNAME/mlucas-avx" && \
  72. "$DIRNAME/mlucas-avx" \
  73. -fftlen 192 -iters 100 -radset 0 \
  74. >/dev/null 2>&1
  75. then
  76. exec "$DIRNAME/mlucas-avx" "$@"
  77. elif test -x "$DIRNAME/mlucas-sse2" && \
  78. "$DIRNAME/mlucas-sse2" \
  79. -fftlen 192 -iters 100 -radset 0 \
  80. >/dev/null 2>&1
  81. then
  82. exec "$DIRNAME/mlucas-sse2" "$@"
  83. elif test -x "$DIRNAME/mlucas-generic-c"
  84. then
  85. exec "$DIRNAME/mlucas-generic-c" "$@"
  86. elif test -x "$PKGLIBEXECDIR/mlucas-avx512" && \
  87. "$PKGLIBEXECDIR/mlucas-avx512" \
  88. -fftlen 192 -iters 100 -radset 0 \
  89. >/dev/null 2>&1
  90. then
  91. exec "$PKGLIBEXECDIR/mlucas-avx512" "$@"
  92. elif test -x "$PKGLIBEXECDIR/mlucas-avx2" && \
  93. "$PKGLIBEXECDIR/mlucas-avx2" \
  94. -fftlen 192 -iters 100 -radset 0 \
  95. >/dev/null 2>&1
  96. then
  97. exec "$PKGLIBEXECDIR/mlucas-avx2" "$@"
  98. elif test -x "$PKGLIBEXECDIR/mlucas-avx" && \
  99. "$PKGLIBEXECDIR/mlucas-avx" \
  100. -fftlen 192 -iters 100 -radset 0 \
  101. >/dev/null 2>&1
  102. then
  103. exec "$PKGLIBEXECDIR/mlucas-avx" "$@"
  104. elif test -x "$PKGLIBEXECDIR/mlucas-sse2" && \
  105. "$PKGLIBEXECDIR/mlucas-sse2" \
  106. -fftlen 192 -iters 100 -radset 0 \
  107. >/dev/null 2>&1
  108. then
  109. exec "$PKGLIBEXECDIR/mlucas-sse2" "$@"
  110. elif test -x "$PKGLIBEXECDIR/mlucas-generic-c"
  111. then
  112. exec "$PKGLIBEXECDIR/mlucas-generic-c" "$@"
  113. fi
  114. ;;
  115. aarch64)
  116. if test -x "$DIRNAME/mlucas-arm-v8-simd" && \
  117. "$DIRNAME/mlucas-arm-v8-simd" \
  118. -fftlen 192 -iters 100 -radset 0 \
  119. >/dev/null 2>&1
  120. then
  121. exec "$DIRNAME/mlucas-arm-v8-simd" "$@"
  122. elif test -x "$DIRNAME/mlucas-generic-c"
  123. then
  124. exec "$DIRNAME/mlucas-generic-c" "$@"
  125. elif test -x "$PKGLIBEXECDIR/mlucas-arm-v8-simd" && \
  126. "$PKGLIBEXECDIR/mlucas-arm-v8-simd" \
  127. -fftlen 192 -iters 100 -radset 0 \
  128. >/dev/null 2>&1
  129. then
  130. exec "$PKGLIBEXECDIR/mlucas-arm-v8-simd" "$@"
  131. elif test -x "$PKGLIBEXECDIR/mlucas-generic-c"
  132. then
  133. exec "$PKGLIBEXECDIR/mlucas-generic-c" "$@"
  134. fi
  135. ;;
  136. *)
  137. if test -x "$DIRNAME/mlucas-generic-c"
  138. then
  139. exec "$DIRNAME/mlucas-generic-c" "$@"
  140. elif test -x "$PKGLIBEXECDIR/mlucas-generic-c"
  141. then
  142. exec "$PKGLIBEXECDIR/mlucas-generic-c" "$@"
  143. fi
  144. ;;
  145. esac
  146. # report error and die
  147. printf '%s\n%s\n%s\n' \
  148. 'None of the mlucas executables works.' \
  149. 'See BUGS section in mlucas(1) on how to report bugs about' \
  150. 'installation problems.' \
  151. >&2
  152. exit 1