1 /* This file is part of the gf2x library. 2 3 Copyright 2007, 2008, 2009, 2010, 2013, 2015 4 Richard Brent, Pierrick Gaudry, Emmanuel Thome', Paul Zimmermann 5 6 This program is free software; you can redistribute it and/or modify it 7 under the terms of either: 8 - If the archive contains a file named toom-gpl.c (not a trivial 9 placeholder), the GNU General Public License as published by the Free 10 Software Foundation; either version 3 of the License, or (at your 11 option) any later version. 12 - If the archive contains a file named toom-gpl.c which is a trivial 13 placeholder, the GNU Lesser General Public License as published by 14 the Free Software Foundation; either version 2.1 of the License, or 15 (at your option) any later version. 16 17 This program is distributed in the hope that it will be useful, but WITHOUT 18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 FITNESS FOR A PARTICULAR PURPOSE. See the license text for more details. 20 21 You should have received a copy of the GNU General Public License as 22 well as the GNU Lesser General Public License along with this program; 23 see the files COPYING and COPYING.LIB. If not, write to the Free 24 Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 25 02110-1301, USA. 26 */ 27 28 #ifndef GF2X_IMPL_H_ 29 #define GF2X_IMPL_H_ 30 31 #include "gf2x.h" 32 /* first include the stuff that even users of the library have access to */ 33 #include "gf2x/gf2x-impl-export.h" 34 35 /* then proceed to the really internal stuff */ 36 #include "gf2x/gf2x-config.h" 37 #include "gf2x/gf2x-thresholds.h" 38 39 /* These flags are for internal use. When a new routine is added, don't 40 change the flags, otherwise the tuning in the already_tuned directory 41 will become invalid. */ 42 #define GF2X_SELECT_KARA 0 /* do not change ! */ 43 #define GF2X_SELECT_TC3 1 44 #define GF2X_SELECT_TC3W 2 45 #define GF2X_SELECT_TC4 3 46 #define GF2X_SELECT_KARAX 4 47 #define GF2X_SELECT_TC3X 5 48 49 #define GF2X_SELECT_UNB_DFLT 0 50 #define GF2X_SELECT_UNB_TC3U 1 /* do not change ! */ 51 52 #include <assert.h> 53 #ifndef ASSERT 54 #define ASSERT(x) assert(x) 55 #endif 56 57 /* We use it for internal checking of the proper propagation of errors. 58 */ 59 #ifndef GF2X_ATTRIBUTE_WARN_UNUSED_RESULT 60 /* https://gcc.gnu.org/onlinedocs/gcc-3.3.6/gcc/Function-Attributes.html#Function-Attributes 61 * https://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Function-Attributes.html#Function-Attributes 62 */ 63 #ifndef GF2X_GNUC_VERSION_ATLEAST 64 #define GF2X_LEXGE2(X,Y,A,B) (X>A || (X == A && Y >= B)) 65 #define GF2X_LEXGE3(X,Y,Z,A,B,C) (X>A || (X == A && GF2X_LEXGE2(Y,Z,B,C))) 66 #define GF2X_LEXLE2(X,Y,A,B) GF2X_LEXGE2(A,B,X,Y) 67 #define GF2X_LEXLE3(X,Y,Z,A,B,C) GF2X_LEXGE3(A,B,C,X,Y,Z) 68 #ifndef GF2X_GNUC_VERSION_ATLEAST 69 #ifndef __GNUC__ 70 #define GF2X_GNUC_VERSION_ATLEAST(X,Y,Z) 0 71 #else 72 #define GF2X_GNUC_VERSION_ATLEAST(X,Y,Z) \ 73 GF2X_LEXGE3(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__,X,Y,Z) 74 #endif 75 #endif 76 #endif 77 #if GF2X_GNUC_VERSION_ATLEAST(3,4,0) 78 #define GF2X_ATTRIBUTE_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) 79 #else 80 #define GF2X_ATTRIBUTE_WARN_UNUSED_RESULT 81 #endif 82 #endif 83 #ifndef MAX 84 #define MAX(a,b) ((a)<(b) ? (b) : (a)) 85 #endif 86 87 88 #ifdef __cplusplus 89 extern "C" { 90 #endif 91 92 extern long gf2x_toomspace(long n); 93 extern long gf2x_toomuspace(long n); 94 95 extern void gf2x_mul_basecase_inner(unsigned long * c, const unsigned long * a, 96 long na, const unsigned long * b, long nb); 97 #if GF2X_GNUC_VERSION_ATLEAST(3, 4, 0) 98 #define gf2x_is_static_true(x) (__builtin_constant_p((x)) && (x)) 99 #define gf2x_static_assert(name, x) char name[gf2x_is_static_true(x)] GF2X_MAYBE_UNUSED 100 #else 101 #define gf2x_static_assert(name, x) /**/ 102 #endif 103 #define gf2x_mul_basecase(c,a,na,b,nb) do { \ 104 gf2x_static_assert(dummy, MAX(na, nb) < GF2X_MUL_KARA_THRESHOLD); \ 105 gf2x_mul_basecase_inner(c, a, na, b, nb); \ 106 } while (0) 107 108 extern void gf2x_mul_toom(unsigned long *c, const unsigned long *a, 109 const unsigned long *b, long n, unsigned long *stk); 110 extern void gf2x_mul_kara(unsigned long *c, const unsigned long *a, const unsigned long *b, 111 long n, unsigned long *stk); 112 #if GF2X_HAVE_SSE2_SUPPORT && (GF2X_WORDSIZE == 64) 113 #define HAVE_KARAX 114 extern void gf2x_mul_karax(unsigned long *c, const unsigned long *a, const unsigned long *b, 115 long n, unsigned long *stk); 116 extern void gf2x_mul_tc3x(unsigned long *c, const unsigned long *a, const unsigned long *b, 117 long n, unsigned long *stk); 118 #endif 119 #if GPL_CODE_PRESENT 120 extern void gf2x_mul_tc3(unsigned long *c, const unsigned long *a, const unsigned long *b, 121 long n, unsigned long *stk); 122 extern void gf2x_mul_tc3w(unsigned long *c, const unsigned long *a, const unsigned long *b, 123 long n, unsigned long *stk); 124 extern void gf2x_mul_tc4(unsigned long *c, const unsigned long *a, const unsigned long *b, 125 long n, unsigned long *stk); 126 extern void gf2x_mul_tc3u(unsigned long * c, const unsigned long * a, long sa, 127 const unsigned long * b, unsigned long * stk); 128 #endif /* GPL_CODE_PRESENT */ 129 130 extern short gf2x_best_toom(unsigned long); 131 extern long gf2x_toomspace(long); 132 133 extern short gf2x_best_utoom(unsigned long); 134 extern long gf2x_toomuspace(long); 135 136 137 /* gf2x_mul_fft returns 0 on success, and a negative error 138 * code among the GF2X_ERROR_* constants defined in gf2x.h. 139 */ 140 141 #include "gf2x-ternary-fft.h" 142 143 #define GF2X_MUL_FFT_MINIMUM_SIZE GF2X_TERNARY_FFT_MINIMUM_SIZE 144 145 extern int gf2x_mul_fft(unsigned long *c, const unsigned long *a, size_t an, 146 const unsigned long *b, size_t bn, long K) 147 GF2X_ATTRIBUTE_WARN_UNUSED_RESULT; 148 149 150 /* tunetoom.c need to poke into toom.c's tables ; that's very ugly. So 151 * please don't use for anything else. 152 * */ 153 extern short best_tab[GF2X_TOOM_TUNING_LIMIT]; 154 extern short best_utab[GF2X_TOOM_TUNING_LIMIT]; 155 156 #ifdef __cplusplus 157 } 158 #endif 159 160 #endif /* GF2X_IMPL_H_ */ 161