1 /**
2 * Low Level MPI Types
3 * 
4 * Copyright:
5 * (C) 1999-2007 Jack Lloyd
6 * (C) 2014-2015 Etienne Cimon
7 *
8 * License:
9 * Botan is released under the Simplified BSD License (see LICENSE.md)
10 */
11 module botan_math.mp_types;
12 
13 public import botan_math.mem_ops;
14 
15 version(X86) { enum BOTAN_HAS_X86_ARCH = true; enum BOTAN_HAS_X86_64_ARCH = false; enum BOTAN_HAS_ARM_ARCH = false; enum BOTAN_HAS_ARM64_ARCH = false; }
16 version(X86_64) { enum BOTAN_HAS_X86_ARCH = false; enum BOTAN_HAS_X86_64_ARCH = true; enum BOTAN_HAS_ARM_ARCH = false; enum BOTAN_HAS_ARM64_ARCH = false; }
17 version(ARM) { enum BOTAN_HAS_X86_ARCH = false; enum BOTAN_HAS_X86_64_ARCH = false; enum BOTAN_HAS_ARM_ARCH = true; enum BOTAN_HAS_ARM64_ARCH = false; }
18 version(AArch64) { enum BOTAN_HAS_X86_ARCH = false; enum BOTAN_HAS_X86_64_ARCH = false; enum BOTAN_HAS_ARM_ARCH = false; enum BOTAN_HAS_ARM64_ARCH = true; }
19 enum ERR_ARCH = "Cannot compile the selected module on this processor architecture.";
20 
21 static if (BOTAN_HAS_X86_ARCH)
22 	enum BOTAN_MP_WORD_BITS = 32; 
23 else static if (BOTAN_HAS_X86_64_ARCH)
24 	enum BOTAN_MP_WORD_BITS = 64;
25 else static if (BOTAN_HAS_ARM_ARCH)
26 	enum BOTAN_MP_WORD_BITS = 32;
27 else static if (BOTAN_HAS_ARM64_ARCH)
28 	enum BOTAN_MP_WORD_BITS=64;
29 // todo: else static if (BOTAN_HAS_PPC_ARCH)
30 
31 version(D_SIMD) enum BOTAN_HAS_SIMD = true;
32 else version(LDC) enum BOTAN_HAS_SIMD = true;
33 else            enum BOTAN_HAS_SIMD = false;
34 
35 static if (BOTAN_MP_WORD_BITS == 8) {
36     alias word = ubyte;
37     alias dword = ushort;
38     enum BOTAN_HAS_MP_DWORD = 1;
39 }
40 else static if (BOTAN_MP_WORD_BITS == 16) {
41     alias word = ushort;
42     alias dword = uint;
43     enum BOTAN_HAS_MP_DWORD = 1;
44 }
45 else static if (BOTAN_MP_WORD_BITS == 32) {
46     alias word = uint;
47     alias dword = ulong;
48     enum BOTAN_HAS_MP_DWORD = 1;
49 }
50 else static if (BOTAN_MP_WORD_BITS == 64) {
51     alias word = ulong;
52 
53     enum BOTAN_HAS_MP_DWORD = 0;
54 
55 } else
56     static assert(false, "BOTAN_MP_WORD_BITS must be 8, 16, 32, or 64");
57 
58 
59 __gshared immutable word MP_WORD_MASK = ~cast(word)(0);
60 __gshared immutable word MP_WORD_TOP_BIT = (cast(word) 1) << (8*(word).sizeof - 1);
61 __gshared immutable word MP_WORD_MAX = MP_WORD_MASK;