Skip to content

Commit 1d733da

Browse files
Jeffrey HurchallaJeffrey Hurchalla
authored andcommitted
add minor improvements to unit-tests build script for macOS ARM support
1 parent 8efe255 commit 1d733da

File tree

5 files changed

+51
-24
lines changed

5 files changed

+51
-24
lines changed

benchmark/benchmark.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
66
*/
77

8+
#include "hurchalla/util/compiler_macros.h"
89
#include "hurchalla/util/traits/extensible_make_unsigned.h"
910
#include "hurchalla/util/traits/ut_numeric_limits.h"
1011
#include "hurchalla/factoring/factorize.h"
1112
#include <iostream>
1213
#include <chrono>
13-
#if defined(__GNUC__)
14+
#if defined(__GNUC__) && (defined(HURCHALLA_TARGET_ISA_X86_64) \
15+
|| defined(HURCHALLA_TARGET_ISA_X86_32))
1416
# include <cpuid.h>
1517
# include <string>
1618
# include <cstring>
@@ -25,7 +27,8 @@
2527
#define STRINGIFYMACRO(y) STRINGIFY(y)
2628

2729

28-
#if defined(__GNUC__)
30+
#if defined(__GNUC__) && (defined(HURCHALLA_TARGET_ISA_X86_64) \
31+
|| defined(HURCHALLA_TARGET_ISA_X86_32))
2932
std::string displayCPU()
3033
{
3134
// this code is copied from https://stackoverflow.com/a/50021699
@@ -109,7 +112,8 @@ void print_int_type()
109112

110113
int main()
111114
{
112-
#if defined(__GNUC__)
115+
#if defined(__GNUC__) && (defined(HURCHALLA_TARGET_ISA_X86_64) \
116+
|| defined(HURCHALLA_TARGET_ISA_X86_32))
113117
std::cout << displayCPU() << "\n";
114118
#endif
115119

build_tests.sh

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

3-
# Copyright (c) 2020-2022 Jeffrey Hurchalla.
3+
# Copyright (c) 2020-2024 Jeffrey Hurchalla.
44
# This Source Code Form is subject to the terms of the Mozilla Public
55
# License, v. 2.0. If a copy of the MPL was not distributed with this
66
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
77

8+
#TODO
9+
# test_factoring with gcc in debug 5:46 to compile. Using the standard MontgomeryForm
810

911
# Description of this script -----------
1012
# This is a working convenience script for invoking the testing builds and then
1113
# running the tests.
1214
# The syntax is
13-
# ./build_tests [-c<compiler_name>] [-r] [-a] [-u] [-t] [-m<Release|Debug|Profile>] [-l<standard_library_name>]
15+
# ./build_tests [-c<compiler_name>] [-j<num_jobs>] [-r] [-a] [-u] [-t] [-m<Release|Debug|Profile>] [-l<standard_library_name>]
1416
#
1517
# -c allows you to select the compiler, rather than using the default.
18+
# -j specifies the number of jobs (typically threads) that you want the compiler
19+
# to use when building. If you omit this option, the compiler's default
20+
# number of jobs will be used.
1621
# -r specifies to run all tests after the build. Without -r, no tests will run.
1722
# -a specifies you want to compile the code using typically helpful (how much it
1823
# helps depends on your compiler) inline asm optimizations, which makes for
@@ -167,18 +172,26 @@
167172
# update-alternatives for both icc and icpc. ]
168173

169174

175+
if [ "${BASH_VERSINFO:-0}" -lt 4 ]; then
176+
>&2 echo "This script requires some verion of bash >= 4.0. Bash 3.2.57 is known to fail, but the minimum required version is unknown"
177+
exit 1
178+
fi
179+
170180

171-
while getopts ":m:l:c:h-:raut" opt; do
181+
while getopts ":m:l:c:j:h-:raut" opt; do
172182
case $opt in
173183
h)
174184
;&
175185
-)
176-
echo "Usage: build_tests [-c<compiler_name>] [-r] [-a] [-u] [-t] [-m<Release|Debug|Profile>] [-l<standard_library_name>]" >&2
186+
echo "Usage: build_tests [-c<compiler_name>] [-j<num_jobs>] [-r] [-a] [-u] [-t] [-m<Release|Debug|Profile>] [-l<standard_library_name>]" >&2
177187
exit 1
178188
;;
179189
c)
180190
compiler=$OPTARG
181191
;;
192+
j)
193+
num_jobs="-j$OPTARG"
194+
;;
182195
m)
183196
mode=$OPTARG
184197
;;
@@ -395,9 +408,18 @@ fi
395408
# "[The] UndefinedBehaviorSanitizer ... test suite is integrated into the CMake
396409
# build and can be run with check-ubsan command."
397410
if [ "$compiler_name" = "gcc" ]; then
398-
gcc_ubsan="-fsanitize=undefined -fno-sanitize-recover \
399-
-fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow"
400-
411+
if [[ $(uname -m) == 'arm64' ]]; then
412+
# At the time of this writing, gcc does not seem to have implemented sanitizers
413+
# (at least not ubsan) for Silicon MacOS. I get link errors if compiling
414+
# with them on mac. See https://github.com/orgs/Homebrew/discussions/3384
415+
# https://github.com/orgs/Homebrew/discussions/3260
416+
# https://stackoverflow.com/questions/65259300/detect-apple-silicon-from-command-line
417+
418+
: # do nothing, at least for now
419+
else
420+
gcc_ubsan="-fsanitize=undefined -fno-sanitize-recover \
421+
-fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow"
422+
fi
401423
elif [ "$compiler_name" = "clang" ] && [[ $compiler_version -ge 6 ]]; then
402424
# clang6 doesn't support -fsanitize=implicit-conversion. Clang10 does support
403425
# it. I don't know if clang7,8,9 support it.

include/hurchalla/factoring/detail/is_prime_miller_rabin.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ struct IPMR_internal {
201201

202202
template <std::size_t TRIAL_SIZE, std::size_t TOTAL_BASES,
203203
typename B, typename MontType>
204-
static HURCHALLA_FORCE_INLINE bool miller_rabin_trials(const MontType& mf,
204+
static bool miller_rabin_trials(const MontType& mf,
205205
const std::array<B,TOTAL_BASES>& bases)
206206
{
207207
using T = typename MontType::IntegerType;
@@ -244,7 +244,7 @@ struct IPMR_internal {
244244

245245
template <std::size_t TRIAL_SIZE, std::size_t TOTAL_BASES,
246246
typename B, typename MontType>
247-
static HURCHALLA_FORCE_INLINE bool miller_rabin_trials128(const MontType& mf,
247+
static bool miller_rabin_trials128(const MontType& mf,
248248
const std::array<B,TOTAL_BASES>& bases)
249249
{
250250
using T = typename MontType::IntegerType;

include/hurchalla/factoring/factorize.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ namespace hurchalla {
4444
// disivion stage. It then uses either ECM or Pollard-Rho to find all remaining
4545
// factors, depending on the size of the number. Prior to trying to extract
4646
// any factor with ECM or Pollard-Rho, it tests for primality by using the
47-
// deterministic Miller-Rabin algorithm - we usually speed up this algorithm by
48-
// using one of the very small hash tables (~100 bytes for example) in
49-
// factoring/include/hurchalla/factoring/detail/miller_rabin_bases/
47+
// deterministic Miller-Rabin algorithm - internally this algorithm is usually
48+
// sped up by using one of the very small hash tables (~100 bytes for example)
49+
// in factoring/include/hurchalla/factoring/detail/miller_rabin_bases/
5050
//
5151
// For numbers below ~40 bits, factorize() uses the Pollard-Rho factorization
5252
// algorithm, with Brent's improvements (see https://en.wikipedia.org/wiki/Pollard%27s_rho_algorithm)
@@ -59,8 +59,8 @@ namespace hurchalla {
5959
// ------------------------------------
6060
// Performance:
6161
// ------------------------------------
62-
// For 64 bit numbers, the resulting factorization functions below are likely
63-
// the fastest you will currently be able to find, both for factoring arbitrary
62+
// For 64 bit numbers, the factorization functions above are likely the fastest
63+
// available anywhere at the time of this writing, both for factoring arbitrary
6464
// values and for factoring semiprimes with two large factors.
6565
//
6666
// For 128 bit numbers, this code needs to be performance tested against other
@@ -70,8 +70,8 @@ namespace hurchalla {
7070
//
7171
// For 32 bit numbers, a very well-optimized implementation of Hart's One Line
7272
// Factoring algorithm and/or Lehman's method might potentially be faster than
73-
// the functions here. The functions here should nonetheless be fairly close to
74-
// the fastest currently available at 32 bits.
73+
// the functions in this file. Nevertheless the functions here should be fairly
74+
// close to the fastest currently available at 32 bits.
7575
//
7676
// For 256 bit or larger numbers - which this library does not support - you may
7777
// wish to seek out ECM for smaller bit depths, and then Quadratic Sieve and

include/hurchalla/factoring/resource_intensive_api/FactorByTable32.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ class FactorByTable
4747
// table in memory from scratch.
4848
FactorByTable() : impl() {}
4949

50-
// If you call this next constructor with an argument of false for
51-
// createTableIfCantOpen, then the constructor will throw if it is unable
52-
// to open table_filepath. Otherwise (and by default), it will create the
53-
// table, which will very likely take a few minutes to complete.
50+
// If the constructor is unable to open table_filepath, and you specify
51+
// false for createTableIfCantOpen then the constructor will throw. If the
52+
// constructor is unable to open table_filepath, and you specify true for
53+
// createTableIfCantOpen, then the constructor will create the table
54+
// from scratch which will likely take a few minutes to complete.
5455
//
5556
// Can throw from a file open failure, a read failure, or mismatch in
5657
// file values read vs values expected.

0 commit comments

Comments
 (0)