-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig.hpp
98 lines (91 loc) · 2.82 KB
/
config.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef APA_CONFIG_HPP
#define APA_CONFIG_HPP
#include <cstdint>
#include <stddef.h>
#ifndef _APA_TESTING_PHASE
#if defined(_FORCE_BASE2_64)
#define _BASE2_64
#elif defined(_FORCE_BASE2_32)
#define _BASE2_32
#elif defined(_FORCE_BASE2_16)
#define _BASE2_16
#elif defined(__SIZEOF_INT128__) || defined(UINT128MAX)
#define _BASE2_64
#elif defined(UINT64_MAX) || defined(UINT64_WIDTH)
#define _BASE2_32
#elif defined(UINT32_MAX) || defined(UINT32_WIDTH)
#define _BASE2_16
#else
#error "ubint is not supported in this system."
#endif
#endif
#ifdef _BASE2_64
#if (__MINGW64__ || __MINGW64)
#define PRINT_LIMBHEX_NOPAD "%llx"
#define PRINT_LIMBHEX "%016llx"
#define PRINT_LIMBHEX_SPACED " %016llx"
#elif (__clang__ || __GNUC__ || __GNUG__)
#define PRINT_LIMBHEX_NOPAD "%lx"
#define PRINT_LIMBHEX "%016lx"
#define PRINT_LIMBHEX_SPACED " %016lx"
#else
#error not supported
#endif
#elif defined(_BASE2_32)
#if (__MINGW64__ || __MINGW64)
#define PRINT_LIMBHEX_NOPAD "%x"
#define PRINT_LIMBHEX "%08x"
#define PRINT_LIMBHEX_SPACED " %08x"
#elif (__clang__ || __GNUC__ || __GNUG__)
#define PRINT_LIMBHEX_NOPAD "%x"
#define PRINT_LIMBHEX "%08x"
#define PRINT_LIMBHEX_SPACED " %08x"
#else
#error not supported
#endif
#elif defined(_BASE2_16)
#if (__MINGW64__ || __MINGW64)
#define PRINT_LIMBHEX_NOPAD "%x"
#define PRINT_LIMBHEX "%04x"
#define PRINT_LIMBHEX_SPACED " %04x"
#elif (__clang__ || __GNUC__ || __GNUG__)
#define PRINT_LIMBHEX_NOPAD "%x"
#define PRINT_LIMBHEX "%04x"
#define PRINT_LIMBHEX_SPACED " %04x"
#else
#error not supported in this system
#endif
#endif
namespace apa {
#ifdef _APA_TESTING_PHASE
static const size_t KARATSUBA_SIZE = 4;
#else
// most efficient limb size where karatsuba should activate.
static const size_t KARATSUBA_SIZE = 62;
#endif
// 'cast_t' should always be double the size of 'limb_t', this is to avoid
// overflows.
#ifdef _BASE2_64
#ifndef _APA_TESTING_PHASE
#pragma message("compiling with base2^64 types - fastest performance")
#endif
typedef int64_t bint_arg_t;
typedef uint64_t limb_t;
typedef __uint128_t cast_t;
#elif defined(_BASE2_32)
#ifndef _APA_TESTING_PHASE
#pragma message("compiling with base2^32 - average performance")
#endif
typedef int32_t bint_arg_t;
typedef uint32_t limb_t;
typedef uint64_t cast_t;
#elif defined(_BASE2_16)
#ifndef _APA_TESTING_PHASE
#pragma message("compiling with base2^16 - slowest performance")
#endif
typedef int16_t bint_arg_t;
typedef uint16_t limb_t;
typedef uint32_t cast_t;
#endif
} // namespace apa
#endif