├── AUTHORS ├── NEWS ├── ChangeLog ├── include ├── cump │ ├── mpn │ │ ├── generic │ │ │ ├── copyd.impl │ │ │ ├── copyi.impl │ │ │ ├── neg.impl │ │ │ ├── cmp.impl │ │ │ ├── add_1.impl │ │ │ ├── sub_1.impl │ │ │ ├── add.impl │ │ │ ├── sub.impl │ │ │ ├── add_n.impl │ │ │ ├── mul_1.impl │ │ │ ├── sub_n.impl │ │ │ ├── mul.impl │ │ │ ├── addmul_1.impl │ │ │ ├── rshift.impl │ │ │ ├── lshift.impl │ │ │ ├── lshiftc.impl │ │ │ └── mul_basecase.impl │ │ └── CUDA │ │ │ ├── mul_2.impl │ │ │ ├── addmul.impl │ │ │ └── mul_basecase.impl │ ├── mpf │ │ ├── clear.impl │ │ ├── init.impl │ │ ├── iset.impl │ │ ├── init2.impl │ │ ├── set.impl │ │ ├── neg.impl │ │ ├── mul.impl │ │ ├── add.impl │ │ └── sub.impl │ ├── utility.cuh │ ├── longlong.cuh │ ├── def.h │ ├── pointer_traits.hpp │ ├── strideptr.cuh │ └── cump.cuh └── Makefile.am ├── cumpf ├── init.c ├── clear.c ├── get_dfl_prec.c ├── init2.c ├── ainit.c ├── aclear.c ├── ainit2.c ├── aset.c ├── set.c ├── set_mpf.c ├── set_dfl_prec.c ├── iset.c ├── iset_mpf.c ├── Makefile.am ├── _ainit.cu ├── aset_mpf.c ├── aiset_mpf.c └── _set.cpp ├── mpf ├── Makefile.am ├── set_cumpf.c └── aset_cumpf.c ├── demos ├── Makefile.am └── axpy.cu ├── Makefile.am ├── configure.ac ├── cump.h ├── README ├── cump-impl.h ├── memory.c ├── COPYING.LIB └── COPYING /AUTHORS: -------------------------------------------------------------------------------- 1 | Authors of CUMP 2 | 3 | Takatoshi Nakayama Main author 4 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | Copyright 2012 Takatoshi Nakayama. 2 | 3 | Verbatim copying and distribution of this entire article is permitted in any 4 | medium, provided this notice is preserved. 5 | 6 | 7 | Changes between CUMP version 1.0.0 and 1.0.1 8 | 9 | BUGS FIXED 10 | * A bug in the configure.ac causing an installation fault has been fixed. 11 | 12 | SPEEDUPS 13 | * None. 14 | 15 | FEATURES 16 | * A demo code added. 17 | * Default compilation targets have been changed to architectures with 18 | Compute Capability 2.0. 19 | 20 | MISC 21 | * Makefile.am and */Makefile.am have been modified slightly. 22 | 23 | 24 | First release of CUMP vesion 1.0.0 25 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | 2012-05-23 Takatoshi Nakayama 2 | 3 | * Version 1.0.1 released. 4 | 5 | 2012-05-22 Takatoshi Nakayama 6 | 7 | * configure.ac: Enclose rvalues with double quotes. 8 | * configure.ac (CUFLAGS): Add "-arch=sm_20" to its default value. 9 | 10 | * Makefile.am: Change ".o" into ".$(OBJEXT)". 11 | * cumpf/Makefile.am: Change ".o" into ".$(OBJEXT)". 12 | * cumpf/Makefile.am: Add "SUFFIXES = .cu". 13 | 14 | * Add a demo suite. 15 | * configure.ac (AC_CONFIG_FILES): Add "demos/Makefile". 16 | * Makefile.am (SUBDIRS): Add "demos". 17 | * demos/axpy.cu: add a demo code. 18 | 19 | 2012-05-19 Takatoshi Nakayama 20 | 21 | * configure.ac (USE_GMP, SPECIFY_GMP_DIR): Fix the conditional expressions. 22 | 23 | 2012-03-31 Takatoshi Nakayama 24 | 25 | * Version 1.0.0 released. 26 | -------------------------------------------------------------------------------- /include/cump/mpn/generic/copyd.impl: -------------------------------------------------------------------------------- 1 | /* mpn::copyd 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | CUMP_FUNCTMPL2 void copyd (mp_ptr(1) rp, mp_srcptr(2) up, mp_size_t n) 22 | { 23 | mp_size_t i; 24 | 25 | for (i = n - 1; i >= 0; i--) 26 | rp [i] = up [i]; 27 | } // copyd () 28 | -------------------------------------------------------------------------------- /cumpf/init.c: -------------------------------------------------------------------------------- 1 | /* cumpf_init -- Make a new multiple precision number with value 0. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #include "cump.h" 22 | #include "cump-impl.h" 23 | 24 | 25 | void cumpf_init (cumpf_ptr r) 26 | { 27 | __cumpf_init (r, __cump_host_default_fp_limb_precision); 28 | } 29 | -------------------------------------------------------------------------------- /cumpf/clear.c: -------------------------------------------------------------------------------- 1 | /* cumpf_clear -- de-allocate the device memory space of a float 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #include "cump.h" 22 | #include "cump-impl.h" 23 | 24 | 25 | void cumpf_clear (cumpf_ptr m) 26 | { 27 | (*__cump_free_func) (m->_dev, __CUMPF_ALLOCSIZE (__cumpf_get_prec (m))); 28 | } 29 | -------------------------------------------------------------------------------- /include/cump/mpn/generic/copyi.impl: -------------------------------------------------------------------------------- 1 | /* mpn::copyi 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | CUMP_FUNCTMPL2 void copyi (mp_ptr(1) rp, mp_srcptr(2) up, mp_size_t n) 22 | { 23 | mp_size_t i; 24 | 25 | up += n; 26 | rp += n; 27 | for (i = -n; i != 0; i++) 28 | rp [i] = up [i]; 29 | } // copyi () 30 | -------------------------------------------------------------------------------- /cumpf/get_dfl_prec.c: -------------------------------------------------------------------------------- 1 | /* cumpf_get_default_prec -- return default precision in bits. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #include "cump.h" 22 | #include "cump-impl.h" 23 | 24 | cump_bitcnt_t cumpf_get_default_prec (void) 25 | { 26 | return __CUMPF_PREC_TO_BITS (__cump_host_default_fp_limb_precision); 27 | } 28 | -------------------------------------------------------------------------------- /cumpf/init2.c: -------------------------------------------------------------------------------- 1 | /* cumpf_init2 -- Make a new multiple precision number with value 0. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #include "cump.h" 22 | #include "cump-impl.h" 23 | 24 | 25 | void cumpf_init2 (cumpf_ptr r, cump_bitcnt_t prec_in_bits) 26 | { 27 | __cumpf_init (r, __CUMPF_BITS_TO_PREC (prec_in_bits)); 28 | } 29 | -------------------------------------------------------------------------------- /cumpf/ainit.c: -------------------------------------------------------------------------------- 1 | /* cumpf_array_init -- Make a new array of multiple precision numbers with value 0. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #include "cump.h" 22 | #include "cump-impl.h" 23 | 24 | 25 | void cumpf_array_init (cumpf_array_ptr r, cump_uint32 n) 26 | { 27 | __cumpf_array_init (r, n, __cump_host_default_fp_limb_precision); 28 | } 29 | -------------------------------------------------------------------------------- /include/cump/mpf/clear.impl: -------------------------------------------------------------------------------- 1 | /* mpf_clear -- de-allocate the space occupied by the dynamic digit space of 2 | an integer. 3 | 4 | Copyright 2012 Takatoshi Nakayama. 5 | 6 | This file is part of the CUMP Library. 7 | 8 | The CUMP Library is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU Lesser General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or (at your 11 | option) any later version. 12 | 13 | The CUMP Library is distributed in the hope that it will be useful, but 14 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16 | License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public License 19 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 20 | 21 | 22 | CUMP_FUNCTYPE void mpf_clear (mpf_t &m) 23 | { 24 | mpf::clear (m); 25 | } // mpf_clear () 26 | 27 | 28 | CUMP_FUNCTYPE void mpf::clear (mpf_t &m) 29 | { 30 | } // mpf::clear () 31 | -------------------------------------------------------------------------------- /cumpf/aclear.c: -------------------------------------------------------------------------------- 1 | /* cumpf_array_clear -- de-allocate the device memory space of an array of 2 | floats 3 | 4 | Copyright 2012 Takatoshi Nakayama. 5 | 6 | This file is part of the CUMP Library. 7 | 8 | The CUMP Library is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU Lesser General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or (at your 11 | option) any later version. 12 | 13 | The CUMP Library is distributed in the hope that it will be useful, but 14 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16 | License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public License 19 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 20 | 21 | 22 | #include "cump.h" 23 | #include "cump-impl.h" 24 | 25 | 26 | void cumpf_array_clear (cumpf_array_ptr m) 27 | { 28 | (*__cump_free_func) (m->_dev, m->_int * __CUMPF_ARRAY_ELEMSIZE (__cumpf_array_get_prec (m))); 29 | } 30 | -------------------------------------------------------------------------------- /include/cump/mpf/init.impl: -------------------------------------------------------------------------------- 1 | /* mpf_init -- Make a new multiple precision number with value 0. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | CUMP_FUNCTYPE void mpf_init (mpf_t &r) 22 | { 23 | mpf::init (r); 24 | } // mpf_init () 25 | 26 | 27 | CUMP_FUNCTYPE void mpf::init (mpf_t &r) 28 | { 29 | mp_size_t prec = __cump_default_fp_limb_precision; 30 | } // mpf::init () 31 | -------------------------------------------------------------------------------- /mpf/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to generate Makefile.in 2 | 3 | 4 | # Copyright 2012 Takatoshi Nakayama. 5 | # 6 | # This file is part of the CUMP Library. 7 | # 8 | # The CUMP Library is free software; you can redistribute it and/or modify 9 | # it under the terms of the GNU Lesser General Public License as published by 10 | # the Free Software Foundation; either version 3 of the License, or (at your 11 | # option) any later version. 12 | # 13 | # The CUMP Library is distributed in the hope that it will be useful, but 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16 | # License for more details. 17 | # 18 | # You should have received a copy of the GNU Lesser General Public License 19 | # along with the CUMP Library. If not, see http://www.gnu.org/licenses/. 20 | 21 | AM_CPPFLAGS = -D__CUMP_WITHIN_CUMP -I@CUDA_DIR@/include -I$(top_srcdir) 22 | 23 | if SPECIFY_GMP_DIR 24 | AM_CPPFLAGS += -I@GMP_DIR@ 25 | endif 26 | 27 | noinst_LIBRARIES = libmpf.a 28 | libmpf_a_SOURCES = aset_cumpf.c set_cumpf.c 29 | -------------------------------------------------------------------------------- /cumpf/ainit2.c: -------------------------------------------------------------------------------- 1 | /* cumpf_array_init2 -- Make a new array of multiple precision numbers with value 0. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #include "cump.h" 22 | #include "cump-impl.h" 23 | 24 | 25 | void cumpf_array_init2 (cumpf_array_ptr r, cump_uint32 n, cump_bitcnt_t prec_in_bits) 26 | { 27 | __cumpf_array_init (r, n, __CUMPF_BITS_TO_PREC (prec_in_bits)); 28 | } 29 | -------------------------------------------------------------------------------- /include/cump/mpf/iset.impl: -------------------------------------------------------------------------------- 1 | /* mpf_init_set -- Initialize a float and assign it from another float. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | CUMP_FUNCTMPL1 void mpf_init_set (mpf_t &r, mp_srcptr(1) s) 22 | { 23 | mpf::init_set (r, float_srcptr(1) (s)); 24 | } // mpf_init_set () 25 | 26 | 27 | CUMP_FUNCTMPL1 void mpf::init_set (mpf_t &r, float_srcptr(1) s) 28 | { 29 | } // mpf::init_set () 30 | -------------------------------------------------------------------------------- /include/cump/mpn/generic/neg.impl: -------------------------------------------------------------------------------- 1 | /* mpn::neg -- negate an mpn. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | CUMP_FUNCTMPL2 mp_limb_t neg (mp_ptr(1) rp, mp_srcptr(2) up, mp_size_t n) 22 | { 23 | mp_limb_t ul, cy; 24 | cy = 0; 25 | do 26 | { 27 | ul = *up++; 28 | *rp++ = -ul - cy; 29 | cy |= ul != 0; 30 | } 31 | while (--n != 0); 32 | return cy; 33 | } // neg () 34 | -------------------------------------------------------------------------------- /include/cump/utility.cuh: -------------------------------------------------------------------------------- 1 | /* Utility functions for CUMP implementation. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #ifndef CUMP_UTILITY_CUH_ 22 | 23 | 24 | namespace utility 25 | { 26 | 27 | 28 | template 29 | CUMP_FUNCTYPE void swap (T &x, T &y) 30 | { 31 | T t (x); 32 | x = y; 33 | y = t; 34 | } 35 | 36 | 37 | } // namespace utility 38 | 39 | 40 | #define CUMP_UTILITY_CUH_ 41 | #endif 42 | -------------------------------------------------------------------------------- /include/cump/mpf/init2.impl: -------------------------------------------------------------------------------- 1 | /* mpf_init2 -- Make a new multiple precision number with value 0. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | CUMP_FUNCTYPE void mpf_init2 (mpf_t &r, mp_bitcnt_t prec_in_bits) 22 | { 23 | mpf::init2 (r, prec_in_bits); 24 | } // mpf_init2 () 25 | 26 | 27 | CUMP_FUNCTYPE void mpf::init2 (mpf_t &r, mp_bitcnt_t prec_in_bits) 28 | { 29 | mp_size_t prec = __CUMPF_BITS_TO_PREC (prec_in_bits); 30 | } // mpf::init2 () 31 | -------------------------------------------------------------------------------- /cumpf/aset.c: -------------------------------------------------------------------------------- 1 | /* cumpf_array_set -- Assign an array of floats from another array of floats. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #include 22 | #include "cump.h" 23 | #include "cump-impl.h" 24 | 25 | 26 | void cumpf_array_set (cumpf_array_ptr r, cumpf_array_srcptr u, cump_uint32 n) 27 | { 28 | (*__cump_memcpy_2D_d2d_func) 29 | ( r->_dev, r->_int, u->_dev, u->_int, n * CUMP_LIMB_BYTES 30 | , __CUMPF_ARRAY_ELEMSIZE (__cumpf_array_get_prec (r)) 31 | ); 32 | } 33 | -------------------------------------------------------------------------------- /cumpf/set.c: -------------------------------------------------------------------------------- 1 | /* cumpf_set -- Assign a float from another float. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #include "cump.h" 22 | #include "cump-impl.h" 23 | 24 | 25 | void __cumpf_set (cumpf_ptr r, cumpf_srcptr u, cumpf_header *h); 26 | 27 | void cumpf_set (cumpf_ptr r, cumpf_srcptr u) 28 | { 29 | cumpf_header hd; 30 | __cumpf_get_header (&hd, u); 31 | hd._mp_prec = __cumpf_get_prec (r); 32 | __cumpf_set (r, u, &hd); 33 | (*__cump_memcpy_h2d_func) (r->_dev, &hd, sizeof (hd)); 34 | } 35 | -------------------------------------------------------------------------------- /mpf/set_cumpf.c: -------------------------------------------------------------------------------- 1 | /* mpf_set_cumpf -- Assign an mpf_t from a float. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #include 22 | #include "cump.h" 23 | #include "cump-impl.h" 24 | 25 | 26 | void __mpf_set_cumpf (mpf_ptr r, cumpf_srcptr u, cumpf_header *h); 27 | 28 | void mpf_set_cumpf (mpf_ptr r, cumpf_srcptr u) 29 | { 30 | cumpf_header hd; 31 | __cumpf_get_header (&hd, u); 32 | hd._mp_prec = r->_mp_prec; 33 | __mpf_set_cumpf (r, u, &hd); 34 | r->_mp_size = hd._mp_size; 35 | r->_mp_exp = hd._mp_exp; 36 | } 37 | -------------------------------------------------------------------------------- /include/cump/mpn/generic/cmp.impl: -------------------------------------------------------------------------------- 1 | /* mpn::cmp -- Compare two low-level natural-number integers. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | CUMP_FUNCTMPL2 int cmp (mp_srcptr(1) xp, mp_srcptr(2) yp, mp_size_t size) 22 | __CUMP_NOTHROW 23 | { 24 | // ASSERT (size>=0); 25 | while (--size >= 0) 26 | { 27 | mp_limb_t x = *--xp, y = *--yp; 28 | if (x != y) 29 | { 30 | // Cannot use x - y, may overflow an "int" 31 | return (x>y ? 1 : -1); 32 | } 33 | } 34 | return 0; 35 | } // cmp () 36 | -------------------------------------------------------------------------------- /include/cump/mpn/generic/add_1.impl: -------------------------------------------------------------------------------- 1 | /* mpn::add_1 -- add limb to mpn. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | namespace _add_1 22 | { 23 | CUMP_FUNCTYPE mp_limb_t op (mp_limb_t x, mp_limb_t y) {return x + y;} 24 | CUMP_FUNCTYPE bool cb (mp_limb_t r, mp_limb_t x, mp_limb_t y) {return r < y;} 25 | } // namespace _add_1 26 | 27 | 28 | CUMP_FUNCTMPL2 mp_limb_t add_1 (mp_ptr(1) dst, mp_srcptr(2) src, mp_size_t size, mp_limb_t n) 29 | __CUMP_NOTHROW 30 | { 31 | return aors_1 <_add_1::op, _add_1::cb> (dst, src, size, n); 32 | } // add_1 () 33 | -------------------------------------------------------------------------------- /cumpf/set_mpf.c: -------------------------------------------------------------------------------- 1 | /* cumpf_set_mpf -- Assign a float from an mpf_t. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #include 22 | #include "cump.h" 23 | #include "cump-impl.h" 24 | 25 | 26 | void __cumpf_set_mpf (cumpf_ptr r, mpf_srcptr u, cumpf_header *h); 27 | 28 | void cumpf_set_mpf (cumpf_ptr r, mpf_srcptr u) 29 | { 30 | cumpf_header hd; 31 | hd._mp_prec = __cumpf_get_prec (r); 32 | hd._mp_size = u->_mp_size; 33 | hd._mp_exp = u->_mp_exp; 34 | __cumpf_set_mpf (r, u, &hd); 35 | (*__cump_memcpy_h2d_func) (r->_dev, &hd, sizeof (hd)); 36 | } 37 | -------------------------------------------------------------------------------- /include/cump/mpn/generic/sub_1.impl: -------------------------------------------------------------------------------- 1 | /* mpn::sub_1 -- subtract limb from mpn. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | namespace _sub_1 22 | { 23 | CUMP_FUNCTYPE mp_limb_t op (mp_limb_t x, mp_limb_t y) {return x - y;} 24 | CUMP_FUNCTYPE bool cb (mp_limb_t r, mp_limb_t x, mp_limb_t y) {return x < y;} 25 | } // namespace _sub_1 26 | 27 | 28 | CUMP_FUNCTMPL2 mp_limb_t sub_1 (mp_ptr(1) dst, mp_srcptr(2) src, mp_size_t size, mp_limb_t n) 29 | __CUMP_NOTHROW 30 | { 31 | return aors_1 <_sub_1::op, _sub_1::cb> (dst, src, size, n); 32 | } // sub_1 () 33 | -------------------------------------------------------------------------------- /include/cump/longlong.cuh: -------------------------------------------------------------------------------- 1 | /* longlong.h -- inlines for mixed size 32/64 bit arithmetic. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #ifndef CUMP_LONGLONG_CUH_ 22 | 23 | 24 | CUMP_FUNCTYPE 25 | void umul_ppmm (cump_uint32 &w1, cump_uint32 &w0, cump_uint32 u, cump_uint32 v) 26 | { 27 | w0 = u * v; 28 | w1 = __umulhi (u, v); 29 | } 30 | 31 | CUMP_FUNCTYPE 32 | void umul_ppmm (cump_uint64 &w1, cump_uint64 &w0, cump_uint64 u, cump_uint64 v) 33 | { 34 | w0 = u * v; 35 | w1 = __umul64hi (u, v); 36 | } 37 | 38 | 39 | #define CUMP_LONGLONG_CUH_ 40 | #endif 41 | -------------------------------------------------------------------------------- /cumpf/set_dfl_prec.c: -------------------------------------------------------------------------------- 1 | /* cumpf_set_default_prec -- set default precision in bits. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #include 22 | #include "cump.h" 23 | #include "cump-impl.h" 24 | 25 | 26 | cump_size_t __cump_host_default_fp_limb_precision = __CUMPF_BITS_TO_PREC (53); 27 | 28 | void cumpf_set_default_prec (cump_bitcnt_t prec_in_bits) 29 | { 30 | cump_size_t prec = __CUMPF_BITS_TO_PREC (prec_in_bits); 31 | __cump_host_default_fp_limb_precision = prec; 32 | cudaMemcpyToSymbol 33 | ( "__cump_default_fp_limb_precision", &prec 34 | , sizeof (prec), 0, cudaMemcpyHostToDevice 35 | ); 36 | } 37 | -------------------------------------------------------------------------------- /cumpf/iset.c: -------------------------------------------------------------------------------- 1 | /* cumpf_init_set -- Initialize a float and assign it from another float. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #include "cump.h" 22 | #include "cump-impl.h" 23 | 24 | 25 | void __cumpf_set (cumpf_ptr r, cumpf_srcptr u, cumpf_header *h); 26 | 27 | void cumpf_init_set (cumpf_ptr r, cumpf_srcptr s) 28 | { 29 | cumpf_header hd; 30 | cump_size_t prec = __cump_host_default_fp_limb_precision; 31 | r->_dev = (*__cump_allocate_func) (__CUMPF_ALLOCSIZE (prec)); 32 | __cumpf_get_header (&hd, s); 33 | hd._mp_prec = prec; 34 | __cumpf_set (r, s, &hd); 35 | (*__cump_memcpy_h2d_func) (r->_dev, &hd, sizeof (hd)); 36 | } 37 | -------------------------------------------------------------------------------- /cumpf/iset_mpf.c: -------------------------------------------------------------------------------- 1 | /* cumpf_init_set_mpf -- Initialize a float and assign it from an mpf_t. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #include 22 | #include "cump.h" 23 | #include "cump-impl.h" 24 | 25 | 26 | void __cumpf_set_mpf (cumpf_ptr r, mpf_srcptr u, cumpf_header *h); 27 | 28 | void cumpf_init_set_mpf (cumpf_ptr r, mpf_srcptr s) 29 | { 30 | cumpf_header hd; 31 | cump_size_t prec = __cump_host_default_fp_limb_precision; 32 | r->_dev = (*__cump_allocate_func) (__CUMPF_ALLOCSIZE (prec)); 33 | hd._mp_prec = prec; 34 | hd._mp_size = s->_mp_size; 35 | hd._mp_exp = s->_mp_exp; 36 | __cumpf_set_mpf (r, s, &hd); 37 | (*__cump_memcpy_h2d_func) (r->_dev, &hd, sizeof (hd)); 38 | } 39 | -------------------------------------------------------------------------------- /demos/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to generate Makefile.in 2 | 3 | 4 | # Copyright 2012 Takatoshi Nakayama. 5 | # 6 | # This file is part of the CUMP Library. 7 | # 8 | # The CUMP Library is free software; you can redistribute it and/or modify 9 | # it under the terms of the GNU Lesser General Public License as published by 10 | # the Free Software Foundation; either version 3 of the License, or (at your 11 | # option) any later version. 12 | # 13 | # The CUMP Library is distributed in the hope that it will be useful, but 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16 | # License for more details. 17 | # 18 | # You should have received a copy of the GNU Lesser General Public License 19 | # along with the CUMP Library. If not, see http://www.gnu.org/licenses/. 20 | 21 | AM_CPPFLAGS = -I@CUDA_DIR@/include -I$(top_srcdir) 22 | 23 | if SPECIFY_GMP_DIR 24 | AM_CPPFLAGS += -I@GMP_DIR@ 25 | endif 26 | 27 | AM_LDFLAGS = -lgmp -lcudart 28 | 29 | LDADD = $(top_builddir)/libcump.a 30 | 31 | CU = @CU@ 32 | CUFLAGS = @CUFLAGS@ -cuda 33 | SUFFIXES = .cu 34 | 35 | .cu.$(OBJEXT): 36 | $(CU) $(CUFLAGS) $(AM_CPPFLAGS) -o $*.cpp $< 37 | $(CXX) $(CXXFLAGS) $(AM_CPPFLAGS) -c -o $@ $*.cpp 38 | 39 | EXTRA_PROGRAMS = axpy 40 | 41 | axpy_SOURCES = axpy.cu 42 | nodist_EXTRA_axpy_SOURCES = dummy.cpp 43 | 44 | CLEANFILES = $(EXTRA_PROGRAMS) 45 | 46 | allprogs: $(EXTRA_PROGRAMS) 47 | -------------------------------------------------------------------------------- /include/cump/mpn/generic/add.impl: -------------------------------------------------------------------------------- 1 | /* mpn::add -- add mpn to mpn. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | namespace _add 22 | { 23 | 24 | 25 | CUMP_FUNCTYPE bool test (mp_limb_t &o, mp_limb_t x) {return (o = (x + 1) & kNumMask) == 0;} 26 | 27 | 28 | struct Func 29 | { 30 | CUMP_FUNCTMPL3 static 31 | mp_limb_t func (mp_ptr(1) r, mp_srcptr(2) u, mp_srcptr(3) v, mp_size_t n) 32 | { 33 | return add_n (r, u, v, n); 34 | } 35 | }; // Add 36 | 37 | 38 | } // namespace _add 39 | 40 | 41 | CUMP_FUNCTMPL3 42 | mp_limb_t 43 | add (mp_ptr(1) wp, mp_srcptr(2) xp, mp_size_t xsize, mp_srcptr(3) yp, mp_size_t ysize) 44 | { 45 | return aors <_add::test, _add::Func> (wp, xp, xsize, yp, ysize); 46 | } // add () 47 | -------------------------------------------------------------------------------- /include/cump/mpn/generic/sub.impl: -------------------------------------------------------------------------------- 1 | /* mpn::sub -- subtract mpn to mpn. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | namespace _sub 22 | { 23 | 24 | 25 | CUMP_FUNCTYPE bool test (mp_limb_t &o, mp_limb_t x) {o = (x - 1) & kNumMask; return x == 0;} 26 | 27 | 28 | struct Func 29 | { 30 | CUMP_FUNCTMPL3 static 31 | mp_limb_t func (mp_ptr(1) r, mp_srcptr(2) u, mp_srcptr(3) v, mp_size_t n) 32 | { 33 | return sub_n (r, u, v, n); 34 | } 35 | }; // Sub 36 | 37 | 38 | } // namespace _sub 39 | 40 | 41 | CUMP_FUNCTMPL3 42 | mp_limb_t 43 | sub (mp_ptr(1) wp, mp_srcptr(2) xp, mp_size_t xsize, mp_srcptr(3) yp, mp_size_t ysize) 44 | { 45 | return aors <_sub::test, _sub::Func> (wp, xp, xsize, yp, ysize); 46 | } // sub () 47 | -------------------------------------------------------------------------------- /include/cump/mpn/generic/add_n.impl: -------------------------------------------------------------------------------- 1 | /* mpn::add_n -- Add equal length limb vectors. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #if CUMP_NAIL_BITS == 0 22 | 23 | CUMP_FUNCTMPL3 mp_limb_t add_n (mp_ptr(1) rp, mp_srcptr(2) up, mp_srcptr(3) vp, mp_size_t n) 24 | { 25 | mp_limb_t ul, vl, sl, rl, cy, cy1, cy2; 26 | 27 | ASSERT (n >= 1); 28 | ASSERT (CUMPN_SAME_OR_INCR_P (rp, up, n)); 29 | ASSERT (CUMPN_SAME_OR_INCR_P (rp, vp, n)); 30 | 31 | cy = 0; 32 | do 33 | { 34 | ul = *up++; 35 | vl = *vp++; 36 | sl = ul + vl; 37 | cy1 = sl < ul; 38 | rl = sl + cy; 39 | cy2 = rl < sl; 40 | cy = cy1 | cy2; 41 | *rp++ = rl; 42 | } 43 | while (--n != 0); 44 | 45 | return cy; 46 | } // add_n () 47 | 48 | #endif 49 | 50 | #if CUMP_NAIL_BITS >= 1 51 | #endif 52 | -------------------------------------------------------------------------------- /include/cump/mpn/generic/mul_1.impl: -------------------------------------------------------------------------------- 1 | /* mpn::mul_1 -- Multiply a limb vector with a single limb and store the 2 | product in a second limb vector. 3 | 4 | Copyright 2012 Takatoshi Nakayama. 5 | 6 | This file is part of the CUMP Library. 7 | 8 | The CUMP Library is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU Lesser General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or (at your 11 | option) any later version. 12 | 13 | The CUMP Library is distributed in the hope that it will be useful, but 14 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16 | License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public License 19 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 20 | 21 | 22 | #include "../../longlong.cuh" 23 | 24 | 25 | #if CUMP_NAIL_BITS == 0 26 | 27 | CUMP_FUNCTMPL2 mp_limb_t mul_1 (mp_ptr(1) rp, mp_srcptr(2) up, mp_size_t n, mp_limb_t vl) 28 | { 29 | mp_limb_t ul, cl, hpl, lpl; 30 | 31 | ASSERT (n >= 1); 32 | ASSERT (CUMPN_SAME_OR_INCR_P (rp, up, n)); 33 | 34 | cl = 0; 35 | do 36 | { 37 | ul = *up++; 38 | umul_ppmm (hpl, lpl, ul, vl); 39 | 40 | lpl += cl; 41 | cl = (lpl < cl) + hpl; 42 | 43 | *rp++ = lpl; 44 | } 45 | while (--n != 0); 46 | 47 | return cl; 48 | } // mul_1 () 49 | 50 | #endif 51 | 52 | #if CUMP_NAIL_BITS >= 1 53 | #endif 54 | -------------------------------------------------------------------------------- /include/cump/mpn/generic/sub_n.impl: -------------------------------------------------------------------------------- 1 | /* mpn::sub_n -- Subtract equal length limb vectors. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #if CUMP_NAIL_BITS == 0 22 | 23 | CUMP_FUNCTMPL3 mp_limb_t sub_n (mp_ptr(1) rp, mp_srcptr(2) up, mp_srcptr(3) vp, mp_size_t n) 24 | { 25 | mp_limb_t ul, vl, sl, rl, cy, cy1, cy2; 26 | 27 | ASSERT (n >= 1); 28 | ASSERT (CUMPN_SAME_OR_INCR_P (rp, up, n)); 29 | ASSERT (CUMPN_SAME_OR_INCR_P (rp, vp, n)); 30 | 31 | cy = 0; 32 | do 33 | { 34 | ul = *up++; 35 | vl = *vp++; 36 | sl = ul - vl; 37 | cy1 = sl > ul; 38 | rl = sl - cy; 39 | cy2 = rl > sl; 40 | cy = cy1 | cy2; 41 | *rp++ = rl; 42 | } 43 | while (--n != 0); 44 | 45 | return cy; 46 | } // sub_n () 47 | 48 | #endif 49 | 50 | #if CUMP_NAIL_BITS >= 1 51 | #endif 52 | -------------------------------------------------------------------------------- /include/cump/def.h: -------------------------------------------------------------------------------- 1 | /* Include file for internal CUMP types and definitions. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #ifndef CUMP_DEF_H_ 22 | 23 | 24 | typedef 25 | struct 26 | { 27 | cump_int32 _mp_prec; 28 | cump_int32 _mp_size; 29 | cump_exp_t _mp_exp; 30 | } 31 | cumpf_header; 32 | 33 | 34 | #define __CUMPF_ALLOCSIZE(prec) (((prec) + 1) * sizeof (cump_limb_t) + sizeof (cumpf_header)) 35 | #define __CUMPF_ARRAY_ELEMSIZE(prec) ((prec) + (1 + sizeof (cumpf_header) / sizeof (cump_limb_t))) 36 | 37 | #define ABS(x) ((x) >= 0 ? (x) : -(x)) 38 | #define __CUMP_MAX(h,i) ((h) > (i) ? (h) : (i)) 39 | 40 | #define __CUMPF_BITS_TO_PREC(n) \ 41 | ((cump_size_t) ((__CUMP_MAX (53, n) + 2 * CUMP_NUMB_BITS - 1) / CUMP_NUMB_BITS)) 42 | #define __CUMPF_PREC_TO_BITS(n) ((cump_bitcnt_t) (n) * CUMP_NUMB_BITS - CUMP_NUMB_BITS) 43 | 44 | 45 | #define CUMP_DEF_H_ 46 | #endif 47 | -------------------------------------------------------------------------------- /include/cump/mpf/set.impl: -------------------------------------------------------------------------------- 1 | /* mpf_set -- Assign a float from another float. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | CUMP_FUNCTMPL2 void mpf_set (mpf_ptr(1) r, mpf_srcptr(2) u) 22 | { 23 | mpf::set (float_ptr(1) (r), float_srcptr(2) (u)); 24 | } // mpf_set () 25 | 26 | 27 | CUMP_FUNCTMPL2 void mpf::set (float_ptr(1) r, float_srcptr(2) u) 28 | { 29 | mp_ptr(1) rp; 30 | mp_srcptr(2) up; 31 | mp_size_t size, asize; 32 | mp_size_t prec; 33 | 34 | prec = r._mp_prec () + 1; /* lie not to lose precision in assignment */ 35 | size = u._mp_size (); 36 | asize = ABS (size); 37 | rp = r._mp_d (); 38 | up = u._mp_d (); 39 | 40 | if (asize > prec) 41 | { 42 | up += asize - prec; 43 | asize = prec; 44 | } 45 | 46 | r._mp_exp () = u._mp_exp (); 47 | r._mp_size () = size >= 0 ? asize : -asize; 48 | CUMPN_COPY (rp, up, asize); 49 | } // mpf::set () 50 | -------------------------------------------------------------------------------- /include/cump/mpf/neg.impl: -------------------------------------------------------------------------------- 1 | /* mpf_neg -- Negate a float. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | CUMP_FUNCTMPL2 void mpf_neg (mpf_ptr(1) r, mpf_srcptr(2) u) 22 | { 23 | mpf::neg (float_ptr(1) (r), float_srcptr(2) (u)); 24 | } // mpf_neg () 25 | 26 | 27 | CUMP_FUNCTMPL2 void mpf::neg (float_ptr(1) r, float_srcptr(2) u) 28 | { 29 | mp_size_t size; 30 | 31 | size = -u._mp_size (); 32 | if (r != u) 33 | { 34 | mp_size_t prec; 35 | mp_size_t asize; 36 | mp_ptr(1) rp; 37 | mp_srcptr(2) up; 38 | 39 | prec = r._mp_prec () + 1; /* lie not to lose precision in assignment */ 40 | asize = ABS (size); 41 | rp = r._mp_d (); 42 | up = u._mp_d (); 43 | 44 | if (asize > prec) 45 | { 46 | up += asize - prec; 47 | asize = prec; 48 | } 49 | 50 | CUMPN_COPY (rp, up, asize); 51 | r._mp_exp () = u._mp_exp (); 52 | size = size >= 0 ? asize : -asize; 53 | } 54 | r._mp_size () = size; 55 | } // mpf::neg () 56 | -------------------------------------------------------------------------------- /cumpf/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to generate Makefile.in 2 | 3 | 4 | # Copyright 2012 Takatoshi Nakayama. 5 | # 6 | # This file is part of the CUMP Library. 7 | # 8 | # The CUMP Library is free software; you can redistribute it and/or modify 9 | # it under the terms of the GNU Lesser General Public License as published by 10 | # the Free Software Foundation; either version 3 of the License, or (at your 11 | # option) any later version. 12 | # 13 | # The CUMP Library is distributed in the hope that it will be useful, but 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16 | # License for more details. 17 | # 18 | # You should have received a copy of the GNU Lesser General Public License 19 | # along with the CUMP Library. If not, see http://www.gnu.org/licenses/. 20 | 21 | AM_CPPFLAGS = -D__CUMP_WITHIN_CUMP -I@CUDA_DIR@/include -I$(top_srcdir) 22 | 23 | if SPECIFY_GMP_DIR 24 | AM_CPPFLAGS += -I@GMP_DIR@ 25 | endif 26 | 27 | CU = @CU@ 28 | CUFLAGS = @CUFLAGS@ -cuda 29 | SUFFIXES = .cu 30 | 31 | .cu.$(OBJEXT): 32 | $(CU) $(CUFLAGS) $(AM_CPPFLAGS) -o $*.cpp $< 33 | $(CXX) $(CXXFLAGS) $(AM_CPPFLAGS) -c -o $@ $*.cpp 34 | 35 | if USE_GMP 36 | CUMPF_OBJECTS_WITH_GMP = \ 37 | iset_mpf.$(OBJEXT) set_mpf.$(OBJEXT) \ 38 | aiset_mpf.$(OBJEXT) aset_mpf.$(OBJEXT) 39 | endif 40 | 41 | noinst_LIBRARIES = libcumpf.a 42 | libcumpf_a_SOURCES = \ 43 | set_dfl_prec.c get_dfl_prec.c \ 44 | init.c init2.c iset.c clear.c set.c \ 45 | ainit.c ainit2.c aclear.c aset.c \ 46 | _set.cpp _ainit.cu 47 | EXTRA_libcumpf_a_SOURCES = \ 48 | aiset_mpf.c aset_mpf.c \ 49 | iset_mpf.c set_mpf.c 50 | libcumpf_a_DEPENDENCIES = $(CUMPF_OBJECTS_WITH_GMP) 51 | libcumpf_a_LIBADD = $(libcumpf_a_DEPENDENCIES) 52 | -------------------------------------------------------------------------------- /include/cump/mpn/generic/mul.impl: -------------------------------------------------------------------------------- 1 | /* mpn::mul -- Multiply two natural numbers. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | /* Multiply the natural numbers u (pointed to by UP, with UN limbs) and v 22 | (pointed to by VP, with VN limbs), and store the result at PRODP. The 23 | result is UN + VN limbs. Return the most significant limb of the result. 24 | 25 | NOTE: The space pointed to by PRODP is overwritten before finished with U 26 | and V, so overlap is an error. 27 | 28 | Argument constraints: 29 | 1. UN >= VN. 30 | 2. PRODP != UP and PRODP != VP, i.e. the destination must be distinct from 31 | the multiplier and the multiplicand. */ 32 | 33 | CUMP_FUNCTMPL3 34 | mp_limb_t mul (mp_ptr(1) prodp, mp_srcptr(2) up, mp_size_t un, mp_srcptr(3) vp, mp_size_t vn) 35 | { 36 | ASSERT (un >= vn); 37 | ASSERT (vn >= 1); 38 | ASSERT (! CUMPN_OVERLAP_P (prodp, un+vn, up, un)); 39 | ASSERT (! CUMPN_OVERLAP_P (prodp, un+vn, vp, vn)); 40 | 41 | mul_basecase (prodp, up, un, vp, vn); 42 | 43 | return prodp [un + vn - 1]; /* historic */ 44 | } // mul () 45 | -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to generate Makefile.in 2 | 3 | 4 | # Copyright 2012 Takatoshi Nakayama. 5 | # 6 | # This file is part of the CUMP Library. 7 | # 8 | # The CUMP Library is free software; you can redistribute it and/or modify 9 | # it under the terms of the GNU Lesser General Public License as published by 10 | # the Free Software Foundation; either version 3 of the License, or (at your 11 | # option) any later version. 12 | # 13 | # The CUMP Library is distributed in the hope that it will be useful, but 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16 | # License for more details. 17 | # 18 | # You should have received a copy of the GNU Lesser General Public License 19 | # along with the CUMP Library. If not, see http://www.gnu.org/licenses/. 20 | 21 | nobase_include_HEADERS = \ 22 | cump/pointer_traits.hpp cump/cump.cuh cump/longlong.cuh \ 23 | cump/def.h cump/strideptr.cuh cump/utility.cuh \ 24 | cump/mpf/add.impl cump/mpf/sub.impl cump/mpf/mul.impl \ 25 | cump/mpf/init.impl cump/mpf/init2.impl cump/mpf/clear.impl \ 26 | cump/mpf/set.impl cump/mpf/iset.impl cump/mpf/neg.impl \ 27 | cump/mpn/generic/rshift.impl cump/mpn/generic/lshift.impl cump/mpn/generic/lshiftc.impl \ 28 | cump/mpn/generic/add.impl cump/mpn/generic/add_1.impl cump/mpn/generic/add_n.impl \ 29 | cump/mpn/generic/sub.impl cump/mpn/generic/sub_1.impl cump/mpn/generic/sub_n.impl \ 30 | cump/mpn/generic/addmul_1.impl cump/mpn/generic/mul_basecase.impl \ 31 | cump/mpn/generic/mul.impl cump/mpn/generic/mul_1.impl \ 32 | cump/mpn/generic/copyd.impl cump/mpn/generic/copyi.impl \ 33 | cump/mpn/generic/neg.impl cump/mpn/generic/cmp.impl \ 34 | cump/mpn/CUDA/addmul.impl cump/mpn/CUDA/mul_2.impl cump/mpn/CUDA/mul_basecase.impl 35 | -------------------------------------------------------------------------------- /include/cump/mpn/generic/addmul_1.impl: -------------------------------------------------------------------------------- 1 | /* mpn::addmul_1 -- multiply the N long limb vector pointed to by UP by VL, 2 | add the N least significant limbs of the product to the limb vector 3 | pointed to by RP. Return the most significant limb of the product, 4 | adjusted for carry-out from the addition. 5 | 6 | Copyright 2012 Takatoshi Nakayama. 7 | 8 | This file is part of the CUMP Library. 9 | 10 | The CUMP Library is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU Lesser General Public License as published by 12 | the Free Software Foundation; either version 3 of the License, or (at your 13 | option) any later version. 14 | 15 | The CUMP Library is distributed in the hope that it will be useful, but 16 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 17 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public License 21 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 22 | 23 | 24 | #include "../../longlong.cuh" 25 | 26 | 27 | #if CUMP_NAIL_BITS == 0 28 | 29 | CUMP_FUNCTMPL2 mp_limb_t addmul_1 (mp_ptr(1) rp, mp_srcptr(2) up, mp_size_t n, mp_limb_t vl) 30 | { 31 | mp_limb_t ul, cl, hpl, lpl, rl; 32 | 33 | ASSERT (n >= 1); 34 | ASSERT (CUMPN_SAME_OR_SEPARATE_P (rp, up, n)); 35 | 36 | cl = 0; 37 | do 38 | { 39 | ul = *up++; 40 | umul_ppmm (hpl, lpl, ul, vl); 41 | 42 | lpl += cl; 43 | cl = (lpl < cl) + hpl; 44 | 45 | rl = *rp; 46 | lpl = rl + lpl; 47 | cl += lpl < rl; 48 | *rp++ = lpl; 49 | } 50 | while (--n != 0); 51 | 52 | return cl; 53 | } // addmul_1 () 54 | 55 | #endif 56 | 57 | #if CUMP_NAIL_BITS == 1 58 | #endif 59 | 60 | #if CUMP_NAIL_BITS >= 2 61 | #endif 62 | -------------------------------------------------------------------------------- /include/cump/mpn/CUDA/mul_2.impl: -------------------------------------------------------------------------------- 1 | /* mpn::mul_2 -- Multiply an n-limb vector with a 2-limb vector and 2 | store the result in a third limb vector. 3 | 4 | Copyright 2012 Takatoshi Nakayama. 5 | 6 | This file is part of the CUMP Library. 7 | 8 | The CUMP Library is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU Lesser General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or (at your 11 | option) any later version. 12 | 13 | The CUMP Library is distributed in the hope that it will be useful, but 14 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16 | License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public License 19 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 20 | 21 | 22 | #include "../../longlong.cuh" 23 | 24 | 25 | #if CUMP_NAIL_BITS == 0 26 | 27 | CUMP_FUNCTMPL3 28 | mp_limb_t mul_2 (mp_ptr(1) rp, mp_srcptr(2) up, mp_size_t n, mp_srcptr(3) vp) 29 | { 30 | mp_limb_t vl0, vl1; 31 | mp_limb_t ul, cl0, cl1, hpl, lpl; 32 | 33 | ASSERT (n >= 1); 34 | ASSERT (CUMPN_SAME_OR_INCR_P (rp, up, n)); 35 | 36 | vl0 = vp [0]; 37 | cl0 = 0; 38 | vl1 = vp [1]; 39 | cl1 = 0; 40 | do 41 | { 42 | ul = *up++; 43 | umul_ppmm (hpl, lpl, ul, vl0); 44 | 45 | lpl += cl0; 46 | cl0 = (lpl < cl0) + hpl; 47 | 48 | *rp++ = lpl; 49 | 50 | umul_ppmm (hpl, lpl, ul, vl1); 51 | 52 | lpl += cl1; 53 | cl1 = (lpl < cl1) + hpl; 54 | 55 | lpl += cl0; 56 | cl1 += lpl < cl0; 57 | cl0 = lpl; 58 | } 59 | while (--n != 0); 60 | 61 | *rp = cl0; 62 | 63 | return cl1; 64 | } 65 | 66 | #endif 67 | 68 | #if CUMP_NAIL_BITS >= 1 69 | #endif 70 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to generate Makefile.in 2 | 3 | 4 | # Copyright 2012 Takatoshi Nakayama. 5 | # 6 | # This file is part of the CUMP Library. 7 | # 8 | # The CUMP Library is free software; you can redistribute it and/or modify 9 | # it under the terms of the GNU Lesser General Public License as published by 10 | # the Free Software Foundation; either version 3 of the License, or (at your 11 | # option) any later version. 12 | # 13 | # The CUMP Library is distributed in the hope that it will be useful, but 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16 | # License for more details. 17 | # 18 | # You should have received a copy of the GNU Lesser General Public License 19 | # along with the CUMP Library. If not, see http://www.gnu.org/licenses/. 20 | 21 | SUBDIRS = cumpf demos include mpf 22 | 23 | include_HEADERS = cump.h 24 | lib_LIBRARIES = libcump.a 25 | 26 | AM_CPPFLAGS = -D__CUMP_WITHIN_CUMP -I@CUDA_DIR@/include 27 | 28 | if SPECIFY_GMP_DIR 29 | AM_CPPFLAGS += -I@GMP_DIR@ 30 | endif 31 | 32 | CUMPF_OBJECTS = \ 33 | cumpf/set_dfl_prec.$(OBJEXT) cumpf/get_dfl_prec.$(OBJEXT) \ 34 | cumpf/init.$(OBJEXT) cumpf/init2.$(OBJEXT) cumpf/iset.$(OBJEXT) \ 35 | cumpf/clear.$(OBJEXT) cumpf/set.$(OBJEXT) \ 36 | cumpf/ainit.$(OBJEXT) cumpf/ainit2.$(OBJEXT) \ 37 | cumpf/aclear.$(OBJEXT) cumpf/aset.$(OBJEXT) \ 38 | cumpf/_ainit.$(OBJEXT) cumpf/_set.$(OBJEXT) 39 | 40 | CUMPF_OBJECTS_WITH_GMP = \ 41 | cumpf/iset_mpf.$(OBJEXT) cumpf/set_mpf.$(OBJEXT) \ 42 | cumpf/aiset_mpf.$(OBJEXT) cumpf/aset_mpf.$(OBJEXT) 43 | 44 | MPF_OBJECTS = mpf/aset_cumpf.$(OBJEXT) mpf/set_cumpf.$(OBJEXT) 45 | 46 | OBJECTS = $(CUMPF_OBJECTS) 47 | 48 | if USE_GMP 49 | OBJECTS += $(CUMPF_OBJECTS_WITH_GMP) $(MPF_OBJECTS) 50 | endif 51 | 52 | libcump_a_SOURCES = cump.h cump-impl.h memory.c 53 | libcump_a_DEPENDENCIES = $(OBJECTS) 54 | libcump_a_LIBADD = $(libcump_a_DEPENDENCIES) 55 | -------------------------------------------------------------------------------- /include/cump/mpn/generic/rshift.impl: -------------------------------------------------------------------------------- 1 | /* mpn::rshift -- Shift right low level. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | /* Shift U (pointed to by up and N limbs long) cnt bits to the right 22 | and store the n least significant limbs of the result at rp. 23 | The bits shifted out to the right are returned. 24 | 25 | Argument constraints: 26 | 1. 0 < cnt < CUMP_NUMB_BITS. 27 | 2. If the result is to be written over the input, rp must be <= up. 28 | */ 29 | 30 | CUMP_FUNCTMPL2 31 | mp_limb_t rshift (mp_ptr(1) rp, mp_srcptr(2) up, mp_size_t n, unsigned int cnt) 32 | { 33 | mp_limb_t high_limb, low_limb; 34 | unsigned int tnc; 35 | mp_size_t i; 36 | mp_limb_t retval; 37 | 38 | ASSERT (n >= 1); 39 | ASSERT (cnt >= 1); 40 | ASSERT (cnt < CUMP_NUMB_BITS); 41 | ASSERT (CUMPN_SAME_OR_INCR_P (rp, up, n)); 42 | 43 | tnc = CUMP_NUMB_BITS - cnt; 44 | high_limb = *up++; 45 | retval = (high_limb << tnc) & CUMP_NUMB_MASK; 46 | low_limb = high_limb >> cnt; 47 | 48 | for (i = n - 1; i != 0; i--) 49 | { 50 | high_limb = *up++; 51 | *rp++ = low_limb | ((high_limb << tnc) & CUMP_NUMB_MASK); 52 | low_limb = high_limb >> cnt; 53 | } 54 | *rp = low_limb; 55 | 56 | return retval; 57 | } // rshift () 58 | -------------------------------------------------------------------------------- /cumpf/_ainit.cu: -------------------------------------------------------------------------------- 1 | /* Inner functions for init functions. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #include 22 | #include "include/cump/cump.cuh" 23 | #include "cump-impl.h" 24 | 25 | 26 | __global__ 27 | void cumpf_array_init_kernel (cump::mpf_array_t r, cump_uint32 n, cump_int32 prec) 28 | { 29 | int i = (blockIdx.y * gridDim.x + blockIdx.x) * blockDim.x + threadIdx.x; 30 | if (i < n) 31 | { 32 | cump::mpf::Float f (r [i]); 33 | f._mp_prec () = prec; 34 | f._mp_size () = 0; 35 | f._mp_exp () = 0; 36 | } 37 | } // cumpf_array_init_kernel () 38 | 39 | 40 | extern "C" void __cumpf_array_init (cumpf_array_ptr r, cump_uint32 n, cump_size_t prec) 41 | { 42 | std::size_t interval; 43 | r->_dev = 44 | (*__cump_allocate_2D_func) (&interval, n * CUMP_LIMB_BYTES, __CUMPF_ARRAY_ELEMSIZE (prec)); 45 | r->_int = interval; 46 | 47 | unsigned int const maxBlocksPerDim = 65535u; 48 | dim3 const threads (128u); 49 | dim3 blocks; 50 | cump_uint32 _n = n / threads.x; 51 | blocks.y = _n / (maxBlocksPerDim + 1u) + 1u; 52 | blocks.x = _n / blocks.y + 1u; 53 | cumpf_array_init_kernel <<>> (r, n, prec); 54 | cudaThreadSynchronize (); 55 | } // __cumpf_array_init () 56 | -------------------------------------------------------------------------------- /include/cump/mpn/generic/lshift.impl: -------------------------------------------------------------------------------- 1 | /* mpn::lshift -- Shift left low level. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | /* Shift U (pointed to by up and n limbs long) cnt bits to the left 22 | and store the n least significant limbs of the result at rp. 23 | Return the bits shifted out from the most significant limb. 24 | 25 | Argument constraints: 26 | 1. 0 < cnt < CUMP_NUMB_BITS. 27 | 2. If the result is to be written over the input, rp must be >= up. 28 | */ 29 | 30 | CUMP_FUNCTMPL2 31 | mp_limb_t lshift (mp_ptr(1) rp, mp_srcptr(2) up, mp_size_t n, unsigned int cnt) 32 | { 33 | mp_limb_t high_limb, low_limb; 34 | unsigned int tnc; 35 | mp_size_t i; 36 | mp_limb_t retval; 37 | 38 | ASSERT (n >= 1); 39 | ASSERT (cnt >= 1); 40 | ASSERT (cnt < CUMP_NUMB_BITS); 41 | ASSERT (CUMPN_SAME_OR_DECR_P (rp, up, n)); 42 | 43 | up += n; 44 | rp += n; 45 | 46 | tnc = CUMP_NUMB_BITS - cnt; 47 | low_limb = *--up; 48 | retval = low_limb >> tnc; 49 | high_limb = (low_limb << cnt) & CUMP_NUMB_MASK; 50 | 51 | for (i = n - 1; i != 0; i--) 52 | { 53 | low_limb = *--up; 54 | *--rp = high_limb | (low_limb >> tnc); 55 | high_limb = (low_limb << cnt) & CUMP_NUMB_MASK; 56 | } 57 | *--rp = high_limb; 58 | 59 | return retval; 60 | } // lshift () 61 | -------------------------------------------------------------------------------- /include/cump/mpn/generic/lshiftc.impl: -------------------------------------------------------------------------------- 1 | /* mpn::lshiftc -- Shift left low level with complement. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | /* Shift U (pointed to by up and n limbs long) cnt bits to the left 22 | and store the n least significant limbs of the result at rp. 23 | Return the bits shifted out from the most significant limb. 24 | 25 | Argument constraints: 26 | 1. 0 < cnt < CUMP_NUMB_BITS. 27 | 2. If the result is to be written over the input, rp must be >= up. 28 | */ 29 | 30 | CUMP_FUNCTMPL2 31 | mp_limb_t lshiftc (mp_ptr(1) rp, mp_srcptr(2) up, mp_size_t n, unsigned int cnt) 32 | { 33 | mp_limb_t high_limb, low_limb; 34 | unsigned int tnc; 35 | mp_size_t i; 36 | mp_limb_t retval; 37 | 38 | ASSERT (n >= 1); 39 | ASSERT (cnt >= 1); 40 | ASSERT (cnt < CUMP_NUMB_BITS); 41 | ASSERT (CUMPN_SAME_OR_DECR_P (rp, up, n)); 42 | 43 | up += n; 44 | rp += n; 45 | 46 | tnc = CUMP_NUMB_BITS - cnt; 47 | low_limb = *--up; 48 | retval = low_limb >> tnc; 49 | high_limb = (low_limb << cnt); 50 | 51 | for (i = n - 1; i != 0; i--) 52 | { 53 | low_limb = *--up; 54 | *--rp = (~(high_limb | (low_limb >> tnc))) & CUMP_NUMB_MASK; 55 | high_limb = low_limb << cnt; 56 | } 57 | *--rp = (~high_limb) & CUMP_NUMB_MASK; 58 | 59 | return retval; 60 | } // lshiftc () 61 | -------------------------------------------------------------------------------- /include/cump/pointer_traits.hpp: -------------------------------------------------------------------------------- 1 | /* PointerTraits -- a class template with typedefs about template parameter of 2 | a pointer type. 3 | 4 | Copyright 2012 Takatoshi Nakayama. 5 | 6 | This file is part of the CUMP Library. 7 | 8 | The CUMP Library is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU Lesser General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or (at your 11 | option) any later version. 12 | 13 | The CUMP Library is distributed in the hope that it will be useful, but 14 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16 | License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public License 19 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 20 | 21 | 22 | #ifndef CUMP_POINTER_TRAITS_HPP_ 23 | 24 | 25 | namespace utility 26 | { 27 | 28 | 29 | namespace _ 30 | { 31 | 32 | 33 | template 34 | struct PointerTraitsImpl 35 | { 36 | typedef T Pointee; 37 | typedef T *Pointer; 38 | typedef T const *ConstPointer; 39 | typedef T* const Parameter; 40 | }; // PointerTraitsImpl 41 | 42 | 43 | } // namespace _ 44 | 45 | 46 | template struct PointerTraits; 47 | 48 | 49 | template struct PointerTraits

: PointerTraits

{}; 50 | template struct PointerTraits : PointerTraits

{}; 51 | 52 | 53 | template 54 | struct PointerTraits 55 | : _::PointerTraitsImpl 56 | { 57 | typedef T *RemoveConstPointer; 58 | }; // PointerTraits 59 | 60 | 61 | template 62 | struct PointerTraits 63 | : _::PointerTraitsImpl 64 | { 65 | typedef T *RemoveConstPointer; 66 | }; // PointerTraits 67 | 68 | 69 | template 70 | struct PointerTraits 71 | { 72 | typedef typename P::Pointee Pointee; 73 | typedef P Pointer; 74 | typedef typename P::ConstPointer ConstPointer; 75 | typedef P const &Parameter; 76 | 77 | typedef typename P::RemoveConstPointer RemoveConstPointer; 78 | }; // PointerTraits 79 | 80 | 81 | } // namespace utility 82 | 83 | 84 | #define CUMP_POINTER_TRAITS_HPP_ 85 | #endif 86 | -------------------------------------------------------------------------------- /mpf/aset_cumpf.c: -------------------------------------------------------------------------------- 1 | /* mpf_array_set_cumpf -- Assign an array of mpf_t from an array of float. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #include 22 | #include 23 | #include "cump.h" 24 | #include "cump-impl.h" 25 | 26 | 27 | void __mpf_array_set_cumpf 28 | ( mpf_ptr r, cump_size_t size, cump_exp_t exp 29 | , char const *up, size_t sLine 30 | ) 31 | { 32 | cump_ptr rp; 33 | cump_size_t asize; 34 | cump_size_t prec; 35 | 36 | prec = r->_mp_prec + 1; /* lie not to lose precision in assignment */ 37 | asize = ABS (size); 38 | 39 | rp = (cump_ptr) r->_mp_d; 40 | 41 | if (asize > prec) 42 | { 43 | up += (asize - prec) * sLine; 44 | asize = prec; 45 | } 46 | 47 | r->_mp_exp = exp; 48 | r->_mp_size = size >= 0 ? asize : -asize; 49 | 50 | CUMPN_COPY_FROM_ARRAY (rp, up, sLine, asize); 51 | } 52 | 53 | 54 | void mpf_array_set_cumpf (mpf_t *ra, cumpf_array_srcptr u, cump_uint32 n) 55 | { 56 | size_t width, height; 57 | cump_size_t prec; 58 | char *dp; 59 | int i; 60 | 61 | prec = __cumpf_array_get_prec (u); 62 | width = n * CUMP_LIMB_BYTES; 63 | height = __CUMPF_ARRAY_ELEMSIZE (prec); 64 | dp = (char*) malloc (width * height); 65 | 66 | (*__cump_memcpy_2D_d2h_func) (dp, width, u->_dev, u->_int, width, height); 67 | 68 | for (i = 0; i < n; ++i) 69 | { 70 | char const *p = dp + i * CUMP_LIMB_BYTES; 71 | cump_size_t s = *(cump_int32*) (p + sizeof (cump_int32)); 72 | cump_exp_t e = *(cump_exp_t*) (p + width); 73 | __mpf_array_set_cumpf (ra [i], s, e, p + width * 2, width); 74 | } 75 | 76 | free (dp); 77 | } 78 | -------------------------------------------------------------------------------- /cumpf/aset_mpf.c: -------------------------------------------------------------------------------- 1 | /* cumpf_array_set_mpf -- Assign an array of floats from an array of mpf_t. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #include 22 | #include 23 | #include "cump.h" 24 | #include "cump-impl.h" 25 | 26 | 27 | void __cumpf_array_set_mpf 28 | ( char *rp, size_t sLine, cump_size_t prec 29 | , cump_size_t *pSize, cump_exp_t *pExp, mpf_srcptr u 30 | ) 31 | { 32 | cump_srcptr up; 33 | cump_size_t size, asize; 34 | 35 | size = u->_mp_size; 36 | asize = ABS (size); 37 | 38 | up = (cump_srcptr) u->_mp_d; 39 | 40 | if (asize > prec) 41 | { 42 | up += asize - prec; 43 | asize = prec; 44 | } 45 | 46 | *pExp = u->_mp_exp; 47 | *pSize = size >= 0 ? asize : -asize; 48 | 49 | CUMPN_COPY_TO_ARRAY (rp, sLine, up, asize); 50 | } 51 | 52 | 53 | void cumpf_array_set_mpf (cumpf_array_ptr r, mpf_t *ua, cump_uint32 n) 54 | { 55 | size_t width, height; 56 | cump_size_t prec; 57 | char *hp; 58 | int i; 59 | 60 | prec = __cumpf_array_get_prec (r); 61 | width = n * CUMP_LIMB_BYTES; 62 | height = __CUMPF_ARRAY_ELEMSIZE (prec); 63 | hp = (char*) malloc (width * height); 64 | 65 | for (i = 0; i < n; ++i) 66 | { 67 | char *p = hp + i * CUMP_LIMB_BYTES; 68 | cump_size_t s; 69 | cump_exp_t e; 70 | __cumpf_array_set_mpf (p + width * 2, width, prec + 1, &s, &e, ua [i]); 71 | *(cump_uint32*) p = prec; 72 | *(cump_uint32*) (p + sizeof (cump_uint32)) = s; 73 | *(cump_exp_t*) (p + width) = e; 74 | } 75 | 76 | (*__cump_memcpy_2D_h2d_func) (r->_dev, r->_int, hp, width, width, height); 77 | 78 | free (hp); 79 | } 80 | -------------------------------------------------------------------------------- /include/cump/mpn/CUDA/addmul.impl: -------------------------------------------------------------------------------- 1 | /* mpn::addmul -- multiply the N long limb vector pointed to by UP by 2 | the N' long limb vector pointed to by VP, 3 | add the (N+N'-1) least significant limbs of the product to the limb vector 4 | pointed to by RP. Return the most significant limb of the product, 5 | adjusted for carry-out from the addition. 6 | 7 | Copyright 2012 Takatoshi Nakayama. 8 | 9 | This file is part of the CUMP Library. 10 | 11 | The CUMP Library is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU Lesser General Public License as published by 13 | the Free Software Foundation; either version 3 of the License, or (at your 14 | option) any later version. 15 | 16 | The CUMP Library is distributed in the hope that it will be useful, but 17 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 19 | License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public License 22 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 23 | 24 | 25 | #include "../../longlong.cuh" 26 | 27 | 28 | #if CUMP_NAIL_BITS == 0 29 | 30 | template 31 | CUMP_FUNCTYPE 32 | mp_limb_t addmul (mp_ptr(1) rp, mp_srcptr(2) up, mp_size_t n, mp_srcptr(3) vp) 33 | { 34 | mp_limb_t vl [N]; 35 | mp_limb_t ul, cl [N], hpl, lpl, rl; 36 | 37 | ASSERT (n >= 1); 38 | ASSERT (CUMPN_SAME_OR_SEPARATE_P (rp, up, n)); 39 | 40 | #pragma unroll 41 | for (int i=0; i= 2 90 | #endif 91 | -------------------------------------------------------------------------------- /cumpf/aiset_mpf.c: -------------------------------------------------------------------------------- 1 | /* cumpf_array_init_set_mpf -- Initialize an array of floats and assign it from 2 | an array of mpf_t. 3 | 4 | Copyright 2012 Takatoshi Nakayama. 5 | 6 | This file is part of the CUMP Library. 7 | 8 | The CUMP Library is free software; you can redistribute it and/or modify 9 | it under the terms of the GNU Lesser General Public License as published by 10 | the Free Software Foundation; either version 3 of the License, or (at your 11 | option) any later version. 12 | 13 | The CUMP Library is distributed in the hope that it will be useful, but 14 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 16 | License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public License 19 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 20 | 21 | 22 | #include 23 | #include 24 | #include "cump.h" 25 | #include "cump-impl.h" 26 | 27 | 28 | void __cumpf_array_init_set_mpf 29 | ( char *rp, size_t sLine, cump_size_t prec 30 | , cump_size_t *pSize, cump_exp_t *pExp, mpf_srcptr s 31 | ) 32 | { 33 | cump_srcptr sp; 34 | cump_size_t size, ssize; 35 | 36 | ssize = s->_mp_size; 37 | size = ABS (ssize); 38 | 39 | sp = (cump_srcptr) s->_mp_d; 40 | 41 | if (size > prec) 42 | { 43 | sp += size - prec; 44 | size = prec; 45 | } 46 | 47 | *pExp = s->_mp_exp; 48 | *pSize = ssize >= 0 ? size : -size; 49 | 50 | CUMPN_COPY_TO_ARRAY (rp, sLine, sp, size); 51 | } 52 | 53 | 54 | void cumpf_array_init_set_mpf (cumpf_array_ptr r, mpf_t *sa, cump_uint32 n) 55 | { 56 | cump_size_t prec = __cump_host_default_fp_limb_precision; 57 | size_t width = n * CUMP_LIMB_BYTES; 58 | size_t height = __CUMPF_ARRAY_ELEMSIZE (prec); 59 | size_t interval; 60 | char *dp, *hp; 61 | int i; 62 | 63 | dp = (char*) (*__cump_allocate_2D_func) (&interval, width, height); 64 | hp = (char*) malloc (width * height); 65 | 66 | for (i = 0; i < n; ++i) 67 | { 68 | char *p = hp + i * CUMP_LIMB_BYTES; 69 | cump_size_t s; 70 | cump_exp_t e; 71 | __cumpf_array_set_mpf (p + width * 2, width, prec + 1, &s, &e, sa [i]); 72 | *(cump_int32*) p = prec; 73 | *(cump_int32*) (p + sizeof (cump_int32)) = s; 74 | *(cump_exp_t*) (p + width) = e; 75 | } 76 | 77 | (*__cump_memcpy_2D_h2d_func) (dp, interval, hp, width, width, height); 78 | 79 | free (hp); 80 | 81 | r->_int = interval; 82 | r->_dev = dp; 83 | } 84 | -------------------------------------------------------------------------------- /include/cump/mpf/mul.impl: -------------------------------------------------------------------------------- 1 | /* mpf_mul -- Multiply two floats. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | CUMP_FUNCTMPL3 void mpf_mul (mpf_ptr(1) r, mpf_srcptr(2) u, mpf_srcptr(3) v) 22 | { 23 | mpf::mul (float_ptr(1) (r), float_srcptr(2) (u), float_srcptr(3) (v)); 24 | } // mpf_mul () 25 | 26 | 27 | CUMP_FUNCTMPL3 28 | void mpf::mul (float_ptr(1) r, float_srcptr(2) u, float_srcptr(3) v) 29 | { 30 | mp_srcptr(2) up; 31 | mp_srcptr(3) vp; 32 | mp_size_t usize, vsize; 33 | mp_size_t sign_product; 34 | mp_size_t prec = r._mp_prec (); 35 | TMP_DECL; 36 | 37 | TMP_MARK; 38 | usize = u._mp_size (); 39 | vsize = v._mp_size (); 40 | sign_product = usize ^ vsize; 41 | 42 | usize = ABS (usize); 43 | vsize = ABS (vsize); 44 | 45 | up = u._mp_d (); 46 | vp = v._mp_d (); 47 | if (usize > prec) 48 | { 49 | up += usize - prec; 50 | usize = prec; 51 | } 52 | if (vsize > prec) 53 | { 54 | vp += vsize - prec; 55 | vsize = prec; 56 | } 57 | 58 | if (usize == 0 || vsize == 0) 59 | { 60 | r._mp_size () = 0; 61 | r._mp_exp () = 0; /* ??? */ 62 | } 63 | else 64 | { 65 | mp_size_t rsize; 66 | mp_limb_t cy_limb; 67 | mp_ptr(1) rp; 68 | mp_limb_t *tp; 69 | mp_size_t adj; 70 | 71 | rsize = usize + vsize; 72 | tp = TMP_ALLOC_LIMBS (rsize); 73 | cy_limb = (usize >= vsize 74 | ? mpn::mul (tp, up, usize, vp, vsize) 75 | : mpn::mul (tp, vp, vsize, up, usize)); 76 | 77 | adj = cy_limb == 0; 78 | rsize -= adj; 79 | prec++; 80 | if (rsize > prec) 81 | { 82 | tp += rsize - prec; 83 | rsize = prec; 84 | } 85 | rp = r._mp_d (); 86 | CUMPN_COPY (rp, tp, rsize); 87 | r._mp_exp () = u._mp_exp () + v._mp_exp () - adj; 88 | r._mp_size () = sign_product >= 0 ? rsize : -rsize; 89 | } 90 | TMP_FREE; 91 | } // mpf::mul () 92 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | 5 | define(CUMP_COPYRIGHT,[[ 6 | 7 | Copyright 2012 Takatoshi Nakayama. 8 | 9 | This file is part of the CUMP Library. 10 | 11 | The CUMP Library is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU Lesser General Public License as published by 13 | the Free Software Foundation; either version 3 of the License, or (at your 14 | option) any later version. 15 | 16 | The CUMP Library is distributed in the hope that it will be useful, but 17 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 18 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 19 | License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public License 22 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. 23 | ]]) 24 | 25 | AC_COPYRIGHT(CUMP_COPYRIGHT) 26 | AH_TOP(/*CUMP_COPYRIGHT*/) 27 | 28 | AC_PREREQ([2.63]) 29 | AC_INIT([CUMP], [1.0.1], [nakayama@hpcs.cs.tsukuba.ac.jp], cump) 30 | AM_INIT_AUTOMAKE 31 | AC_CONFIG_SRCDIR([cump-impl.h]) 32 | AC_CONFIG_HEADERS([config.h]) 33 | 34 | # CUDA compiler. 35 | if test -z $CU ; then 36 | CU="nvcc" 37 | fi 38 | 39 | if test -z $CUFLAGS ; then 40 | CUFLAGS="-arch=sm_20 $CXXFLAGS" 41 | fi 42 | 43 | AC_SUBST(CU) 44 | AC_SUBST(CUFLAGS) 45 | 46 | AC_ARG_VAR(CU, [CUDA compiler command]) 47 | AC_ARG_VAR(CUFLAGS, [CUDA compiler flags]) 48 | 49 | # CUDA toolkit install directory. 50 | AC_ARG_WITH(cuda, 51 | AC_HELP_STRING([--with-cuda[[=DIR]]], 52 | [specify CUDA toolkit install directory [[default=/usr/local/cuda]]]), 53 | [CUDA_DIR="$withval"], [CUDA_DIR="/usr/local/cuda"]) 54 | 55 | AC_SUBST(CUDA_DIR) 56 | 57 | # GNU MP include file directory. 58 | AC_ARG_WITH(gmp, 59 | AC_HELP_STRING([--with-gmp[[=DIR]]], 60 | [use GNU MP (specify GNU MP include file directory) [[default=yes]]]), 61 | [case $withval in 62 | yes|no) ;; 63 | *) GMP_DIR="$withval"; with_gmp="yes";; 64 | esac], 65 | [with_gmp="yes"]) 66 | 67 | AM_CONDITIONAL(USE_GMP, test x$with_gmp = xyes) 68 | AM_CONDITIONAL(SPECIFY_GMP_DIR, test ! x$GMP_DIR = x) 69 | AC_SUBST(GMP_DIR) 70 | 71 | # Checks for programs. 72 | AC_PROG_RANLIB 73 | AC_PROG_CXX 74 | AC_PROG_CC 75 | 76 | # Checks for libraries. 77 | 78 | # Checks for header files. 79 | AC_CHECK_HEADERS([stddef.h stdlib.h]) 80 | 81 | # Checks for typedefs, structures, and compiler characteristics. 82 | AC_C_CONST 83 | AC_C_INLINE 84 | AC_TYPE_SIZE_T 85 | 86 | # Checks for library functions. 87 | AC_FUNC_MALLOC 88 | 89 | AC_CONFIG_FILES([Makefile 90 | cumpf/Makefile 91 | demos/Makefile 92 | include/Makefile 93 | mpf/Makefile]) 94 | AC_OUTPUT 95 | -------------------------------------------------------------------------------- /cump.h: -------------------------------------------------------------------------------- 1 | /* Definitions for CUMP functions. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #ifndef CUMP_H_ 22 | 23 | 24 | #include /* size_t */ 25 | 26 | 27 | /* General macros following GMP */ 28 | #define CUMP_LIMB_BITS (8 * sizeof (cump_limb_t)) 29 | #define CUMP_NAIL_BITS 0 30 | #define CUMP_NUMB_BITS (CUMP_LIMB_BITS - CUMP_NAIL_BITS) 31 | #define CUMP_NUMB_MASK ((~ __CUMP_CAST (cump_limb_t, 0)) >> CUMP_NAIL_BITS) 32 | #define CUMP_NUMB_MAX CUMP_NUMB_MASK 33 | #define CUMP_NAIL_MASK (~ CUMP_NUMB_MASK) 34 | 35 | 36 | #if defined (__cplusplus) 37 | #define __CUMP_CAST(type, expr) static_cast (expr) 38 | #define __CUMP_NOTHROW /*throw ()*/ 39 | #else 40 | #define __CUMP_CAST(type, expr) ((type) (expr)) 41 | #define __CUMP_NOTHROW 42 | #endif 43 | 44 | 45 | typedef int cump_int32; 46 | typedef long int cump_int64; 47 | typedef unsigned int cump_uint32; 48 | typedef unsigned long int cump_uint64; 49 | 50 | #ifdef __CUMP_SHORT_LIMB 51 | typedef cump_uint32 cump_limb_t; 52 | typedef cump_int32 cump_limb_signed_t; 53 | #else 54 | typedef cump_uint64 cump_limb_t; 55 | typedef cump_int64 cump_limb_signed_t; 56 | #endif 57 | typedef cump_uint64 cump_bitcnt_t; 58 | 59 | typedef cump_int64 cump_size_t; 60 | typedef cump_int64 cump_exp_t; 61 | 62 | typedef cump_limb_t *cump_ptr; 63 | typedef cump_limb_t const *cump_srcptr; 64 | 65 | 66 | typedef 67 | struct 68 | { 69 | void *_dev; 70 | } 71 | __cumpf_struct; 72 | 73 | typedef __cumpf_struct *cumpf_ptr, cumpf_t [1]; 74 | typedef __cumpf_struct const *cumpf_srcptr; 75 | 76 | 77 | typedef 78 | struct 79 | { 80 | size_t _int; 81 | void *_dev; 82 | } 83 | __cumpf_array; 84 | 85 | typedef __cumpf_array *cumpf_array_ptr, cumpf_array_t [1]; 86 | typedef __cumpf_array const *cumpf_array_srcptr; 87 | 88 | 89 | #if defined (__cplusplus) 90 | extern "C" 91 | { 92 | #endif 93 | 94 | void cumpf_set_default_prec (cump_bitcnt_t prec_in_bits); 95 | cump_bitcnt_t cumpf_get_default_prec (void); 96 | 97 | void cumpf_init (cumpf_ptr r); 98 | void cumpf_init2 (cumpf_ptr r, cump_bitcnt_t prec_in_bits); 99 | void cumpf_init_set (cumpf_ptr r, cumpf_srcptr s); 100 | void cumpf_clear (cumpf_ptr m); 101 | void cumpf_set (cumpf_ptr r, cumpf_srcptr u); 102 | 103 | void cumpf_array_init (cumpf_array_ptr r, cump_uint32 n); 104 | void cumpf_array_init2 (cumpf_array_ptr r, cump_uint32 n, cump_bitcnt_t prec_in_bits); 105 | void cumpf_array_clear (cumpf_array_ptr m); 106 | void cumpf_array_set (cumpf_array_ptr r, cumpf_array_srcptr u, cump_uint32 n); 107 | 108 | #ifdef __GMP_H__ 109 | void cumpf_init_set_mpf (cumpf_ptr r, mpf_srcptr s); 110 | void cumpf_set_mpf (cumpf_ptr r, mpf_srcptr u); 111 | void mpf_set_cumpf (mpf_ptr r, cumpf_srcptr u); 112 | 113 | void cumpf_array_init_set_mpf (cumpf_array_ptr r, mpf_t *sa, cump_uint32 n); 114 | void cumpf_array_set_mpf (cumpf_array_ptr r, mpf_t *ua, cump_uint32 n); 115 | void mpf_array_set_cumpf (mpf_t *ra, cumpf_array_srcptr u, cump_uint32 n); 116 | #endif /* __GMP_H__ */ 117 | 118 | #if defined (__cplusplus) 119 | } /* extern "C" */ 120 | #endif 121 | 122 | 123 | #define CUMP_H_ 124 | #endif 125 | -------------------------------------------------------------------------------- /demos/axpy.cu: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | #define N 1024 7 | 8 | 9 | void gmp_axpy (int n, mpf_t a, mpf_t X [], mpf_t Y []); 10 | void cump_axpy (int n, cumpf_array_t a, cumpf_array_t X, cumpf_array_t Y); 11 | 12 | 13 | int main () 14 | { 15 | int i; 16 | int prec = 1024; /* precision in bits */ 17 | int seed = 341; /* random seed*/ 18 | 19 | gmp_randstate_t rstate; 20 | 21 | mpf_t a, X [N], Y [N]; 22 | cumpf_array_t a_, X_, Y_; 23 | 24 | /* set default precision of both libraries */ 25 | mpf_set_default_prec (prec); 26 | cumpf_set_default_prec (prec); 27 | 28 | /* initialize mpf_t variables/arrays and set random numbers into them */ 29 | gmp_randinit_default (rstate); 30 | gmp_randseed_ui (rstate, seed); 31 | 32 | mpf_init (a); 33 | mpf_urandomb (a, rstate, prec); 34 | 35 | for (i = 0; i < N; ++i) 36 | { 37 | mpf_init (X [i]); 38 | mpf_urandomb (X [i], rstate, prec); 39 | mpf_init (Y [i]); 40 | mpf_urandomb (Y [i], rstate, prec); 41 | } 42 | 43 | gmp_randclear (rstate); 44 | 45 | /* initialize cumpf_t variables/arrays and set mpf_t ones into them */ 46 | cumpf_array_init_set_mpf (a_, &a, 1); 47 | cumpf_array_init_set_mpf (X_, X, N); 48 | cumpf_array_init_set_mpf (Y_, Y, N); 49 | 50 | printf ("Calculation (vector length = %d):\n", N); 51 | gmp_printf ("\t\t |%Ff\t| |%Ff\t|\n", X [0], Y [0]); 52 | gmp_printf ("\t\t |%Ff\t| |%Ff\t|\n", X [1], Y [1]); 53 | gmp_printf ("\t\t | :\t| | :\t|\n"); 54 | gmp_printf ("%Ff\tx | :\t| + | :\t|\n", a); 55 | gmp_printf ("\t\t | :\t| | :\t|\n"); 56 | gmp_printf ("\t\t |%Ff\t| |%Ff\t|\n\n", X [N-1], Y [N-1]); 57 | 58 | /* run axpy */ 59 | gmp_axpy (N, a, X, Y); 60 | cump_axpy (N, a_, X_, Y_); 61 | 62 | printf ("Result:\n"); 63 | gmp_printf ("\t|%Ff\t|\n", Y [0]); 64 | gmp_printf ("\t|%Ff\t|\n", Y [1]); 65 | gmp_printf ("\t| :\t\t|\n"); 66 | gmp_printf ("\t| :\t\t|\n"); 67 | gmp_printf ("\t| :\t\t|\n"); 68 | gmp_printf ("\t|%Ff\t|\n\n", Y [N-1]); 69 | 70 | /* compare both results */ 71 | printf ("Comparison of both results: "); 72 | mpf_array_set_cumpf (X, Y_, N); 73 | for (i = 0; i < N; ++i) 74 | { 75 | if (mpf_cmp (X [i], Y [i]) != 0) 76 | { 77 | printf ("failed!\n\n"); 78 | goto _Exit; 79 | } 80 | } 81 | printf ("matched!\n\n"); 82 | 83 | _Exit: 84 | /* finalize */ 85 | cumpf_array_clear (a_); 86 | cumpf_array_clear (X_); 87 | cumpf_array_clear (Y_); 88 | 89 | mpf_clear (a); 90 | 91 | for (i = 0; i < N; ++i) 92 | { 93 | mpf_clear (X [i]); 94 | mpf_clear (Y [i]); 95 | } 96 | 97 | return 0; 98 | } 99 | 100 | 101 | void gmp_axpy (int n, mpf_t a, mpf_t X [], mpf_t Y []) 102 | { 103 | int i; 104 | mpf_t aX; 105 | 106 | mpf_init (aX); 107 | 108 | for (i = 0; i < n; ++i) 109 | { 110 | mpf_mul (aX, a, X [i]); 111 | mpf_add (Y [i], aX, Y [i]); 112 | } 113 | 114 | mpf_clear (aX); 115 | } 116 | 117 | 118 | using cump::mpf_array_t; 119 | 120 | __global__ 121 | void cump_axpy_kernel (int n, mpf_array_t a, mpf_array_t X, mpf_array_t Y, mpf_array_t aX) 122 | { 123 | using namespace cump; 124 | 125 | int idx = blockIdx.x * blockDim.x + threadIdx.x; 126 | 127 | if (idx < n) 128 | { 129 | /* Due to CUMP's limitation, 130 | arithmetic between cump::mpf_array_t and cump::mpf_t is unavailable */ 131 | mpf_mul (aX [idx], a [0], X [idx]); 132 | mpf_add (Y [idx], aX [idx], Y [idx]); 133 | } 134 | } 135 | 136 | 137 | void cump_axpy (int n, cumpf_array_t a, cumpf_array_t X, cumpf_array_t Y) 138 | { 139 | int threads = 32; 140 | int blocks = n / threads + (n % threads ? 1 : 0); 141 | cumpf_array_t aX; 142 | 143 | cumpf_array_init (aX, n); 144 | cump_axpy_kernel <<>> (n, a, X, Y, aX); 145 | cumpf_array_clear (aX); 146 | } 147 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Copyright 2012 Takatoshi Nakayama. 2 | 3 | This file is part of the CUMP Library. 4 | 5 | The CUMP Library is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 3 of the License, or (at your 8 | option) any later version. 9 | 10 | The CUMP Library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 13 | License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. 17 | 18 | 19 | 20 | 21 | 22 | 23 | THE CUMP LIBRARY 24 | 25 | 26 | CUMP [1] is a library for arbitrary precision arithmetic on CUDA [2], 27 | operating on floating point numbers. It is based on the GNU MP library 28 | (GMP) [3], and its functions have a GMP-like regular interface. 29 | 30 | CUMP is designed to be faster on NVIDIA GF100/GF110 GPUs than the GARPREC 31 | library [4]. The performance advantage is achieved by using 64-bit fullwords 32 | as the basic arithmetic type, by using a register blocking technique, and by 33 | using "little endian" word order format. 34 | 35 | CUMP is free software and may be freely copied on the terms contained in the 36 | files COPYING.LIB and COPYING (most of CUMP is under the former, some under 37 | the latter). 38 | 39 | 40 | 41 | OVERVIEW OF CUMP 42 | 43 | 44 | CUMP can be a substitute of GMP if arbitrary-precision floating-point 45 | arithmetic is necessary in CUDA. There are functions for host codes and 46 | for device codes in CUMP. 47 | 48 | Functions for HOST codes: 49 | "Host code" means a code operating on CPUs. These functions are C language 50 | functions. Most of them belongs to the cumpf and cumpf_array class 51 | equivalent to the mpf class in GMP. Some which communicate with GMP's 52 | `mpf_t' variables belong to the mpf class. 53 | 54 | Functions for DEVICE codes: 55 | "Device code" means a code operating on GPUs. These functions are CUDA 56 | language functions which have the __device__ qualifier. Since all of them 57 | is in cump namespace (C++), in GPU kernels with "using namespace cump;", 58 | it is possible to use CUMP functions which have the same name with GMP. 59 | 60 | If you want to use CUMP instead of GMP in your CUDA applications, write CUDA 61 | codes roughly (don't consider cudaMemcpy), assuming that GMP operates on CUDA 62 | at first. In your host codes, declare your variables as `cumpf_t' instead of 63 | `mpf_t' and `cumpf_array_t' instead of `mpf_t[]', and call the functions in 64 | the cumpf or cumpf_array class instead of the functions in the mpf class. 65 | In your device codes, declare parameters of your GPU kernels as `cump::mpf_t' 66 | instead of `mpf_t' and `cump::mpf_array_t' instead of `mpf_t[]', and write 67 | "using namespace cump;" to the beginning of your GPU kernels. 68 | 69 | CUMP has a lack of functions and a lot of limitations compared with GMP. 70 | For more information on how to use CUMP, please refer to the documentation. 71 | (Sorry, the documentation is under writing. Please wait for a moment.) 72 | 73 | 74 | 75 | REPORTING BUGS 76 | 77 | If you find a bug in the library, please tell me about it. 78 | Also welcome your questions and suggestions. 79 | 80 | 81 | 82 | REFERENCE 83 | 84 | 85 | 1. T. Nakayama and D. Takahashi: Implementation of Multiple- 86 | Precision Floating-Point Arithmetic Library for GPU Computing, Proc. 23rd 87 | IASTED International Conference on Parallel and Distributed Computing and 88 | Systems (PDCS 2011), pp. 343--349 (2011). 89 | 90 | 2. NVIDIA Corporation: CUDA, http://www.nvidia.com/object/cuda_home_new.html 91 | 92 | 3. T. Granlund: GMP: The GNU Multiple Precision Arithmetic Library, 93 | http://gmplib.org/ 94 | 95 | 4. M. Lu, B. He and Q. Luo: Supporting Extended Precision on Graphics 96 | Processors, Proc. Sixth International Workshop on Data Management on New 97 | Hardware (DaMoN 2010), pp. 19--26 (2010) 98 | -------------------------------------------------------------------------------- /cump-impl.h: -------------------------------------------------------------------------------- 1 | /* Include file for internal CUMP types, definitions and inlines. 2 | 3 | THE CONTENTS OF THIS FILE ARE FOR INTERNAL USE AND ARE ALMOST CERTAIN TO 4 | BE SUBJECT TO INCOMPATIBLE CHANGES IN FUTURE CUMP RELEASES. 5 | 6 | Copyright 2012 Takatoshi Nakayama. 7 | 8 | This file is part of the CUMP Library. 9 | 10 | The CUMP Library is free software; you can redistribute it and/or modify 11 | it under the terms of the GNU Lesser General Public License as published by 12 | the Free Software Foundation; either version 3 of the License, or (at your 13 | option) any later version. 14 | 15 | The CUMP Library is distributed in the hope that it will be useful, but 16 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 17 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public License 21 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 22 | 23 | 24 | #ifndef CUMP_IMPL_H_ 25 | 26 | 27 | #include "include/cump/def.h" 28 | 29 | 30 | #define __CUMP_EXTERN_INLINE static inline 31 | 32 | #define CUMP_LIMB_BYTES (sizeof (cump_limb_t)) 33 | 34 | 35 | extern void* (*__cump_allocate_func) (size_t); 36 | extern void* (*__cump_allocate_2D_func) (size_t*, size_t, size_t); 37 | extern void* (*__cump_reallocate_func) (void*, size_t, size_t); 38 | extern void (*__cump_free_func) (void*, size_t); 39 | 40 | extern void (*__cump_memcpy_func) (void*, void const *, size_t); 41 | extern void (*__cump_memcpy_h2d_func) (void*, void const *, size_t); 42 | extern void (*__cump_memcpy_d2h_func) (void*, void const *, size_t); 43 | extern void (*__cump_memcpy_d2d_func) (void*, void const *, size_t); 44 | extern void (*__cump_memcpy_2D_func) (void*, size_t, void const *, size_t, size_t, size_t); 45 | extern void (*__cump_memcpy_2D_h2d_func) (void*, size_t, void const *, size_t, size_t, size_t); 46 | extern void (*__cump_memcpy_2D_d2h_func) (void*, size_t, void const *, size_t, size_t, size_t); 47 | extern void (*__cump_memcpy_2D_d2d_func) (void*, size_t, void const *, size_t, size_t, size_t); 48 | 49 | extern cump_size_t __cump_host_default_fp_limb_precision; 50 | 51 | 52 | #if defined (__cplusplus) 53 | extern "C" 54 | { 55 | #endif 56 | 57 | 58 | __CUMP_EXTERN_INLINE void __cumpf_get_header (cumpf_header *h, cumpf_srcptr p) 59 | { 60 | (*__cump_memcpy_d2h_func) (h, p->_dev, sizeof (*h)); 61 | } 62 | 63 | 64 | __CUMP_EXTERN_INLINE cump_size_t __cumpf_get_prec (cumpf_srcptr p) 65 | { 66 | cump_int32 prec; 67 | (*__cump_memcpy_d2h_func) (&prec, p->_dev, sizeof (prec)); 68 | return prec; 69 | } 70 | 71 | 72 | __CUMP_EXTERN_INLINE void __cumpf_init (cumpf_ptr r, cump_size_t prec) 73 | { 74 | cumpf_header hd; 75 | hd._mp_exp = 0; 76 | hd._mp_size = 0; 77 | hd._mp_prec = prec; 78 | r->_dev = (*__cump_allocate_func) (__CUMPF_ALLOCSIZE (prec)); 79 | (*__cump_memcpy_h2d_func) (r->_dev, &hd, sizeof (hd)); 80 | } 81 | 82 | 83 | __CUMP_EXTERN_INLINE cump_size_t __cumpf_array_get_prec (cumpf_array_srcptr p) 84 | { 85 | cump_int32 prec; 86 | (*__cump_memcpy_d2h_func) (&prec, p->_dev, sizeof (prec)); 87 | return prec; 88 | } 89 | 90 | 91 | void __cumpf_array_init (cumpf_array_ptr, cump_uint32, cump_size_t); 92 | 93 | 94 | __CUMP_EXTERN_INLINE 95 | void CUMPN_COPY_FROM_ARRAY (cump_ptr dst, char const *src, size_t p, cump_size_t n) 96 | { 97 | if (n) 98 | { 99 | cump_limb_t x = *(cump_srcptr) src; 100 | while (--n) 101 | { 102 | *dst++ = x; 103 | x = *(cump_srcptr) (src += p); 104 | } 105 | *dst++ = x; 106 | } 107 | } 108 | 109 | __CUMP_EXTERN_INLINE 110 | void CUMPN_COPY_TO_ARRAY (char *dst, size_t p, cump_srcptr src, cump_size_t n) 111 | { 112 | if (n) 113 | { 114 | cump_limb_t x = *src++; 115 | while (--n) 116 | { 117 | *(cump_ptr) dst = x; 118 | dst += p; 119 | x = *src++; 120 | } 121 | *(cump_ptr) dst = x; 122 | } 123 | } 124 | 125 | 126 | #if defined (__cplusplus) 127 | } /* extern "C" */ 128 | #endif 129 | 130 | 131 | #define CUMP_IMPL_H_ 132 | #endif 133 | -------------------------------------------------------------------------------- /include/cump/strideptr.cuh: -------------------------------------------------------------------------------- 1 | /* StridePointer -- a pointer wrapper class for coalessed access. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #ifndef CUMP_STRIDEPTR_CUH_ 22 | 23 | 24 | namespace utility 25 | { 26 | 27 | 28 | template 29 | < typename P 30 | , typename D = std::ptrdiff_t 31 | > 32 | class StridePointer 33 | { 34 | typedef PointerTraits

PT_; 35 | 36 | friend struct StridePointer ; 37 | friend struct PointerTraits ; 38 | 39 | // typedefs for PointerTraits 40 | typedef typename PT_::Pointee Pointee; 41 | typedef StridePointer ConstPointer; 42 | typedef StridePointer RemoveConstPointer; 43 | 44 | public: 45 | CUMP_FUNCTYPE StridePointer () 46 | : p_ (), l_ () 47 | {} 48 | 49 | CUMP_FUNCTYPE explicit StridePointer (typename PT_::Parameter p, D l = 1) 50 | : p_ (p), l_ (l) 51 | {} 52 | 53 | CUMP_FUNCTYPE StridePointer (RemoveConstPointer const &x) 54 | : p_ (x.p_), l_ (x.l_) 55 | {} 56 | 57 | CUMP_FUNCTYPE operator typename PT_::Parameter () const {return p_;} 58 | 59 | CUMP_FUNCTYPE Pointee& operator * () const {return *p_;} 60 | 61 | CUMP_FUNCTYPE StridePointer& operator ++ () 62 | { 63 | p_ += l_; 64 | return *this; 65 | } 66 | 67 | CUMP_FUNCTYPE StridePointer& operator -- () 68 | { 69 | p_ -= l_; 70 | return *this; 71 | } 72 | 73 | CUMP_FUNCTYPE StridePointer& operator += (D n) 74 | { 75 | p_ += l_ * n; 76 | return *this; 77 | } 78 | 79 | CUMP_FUNCTYPE StridePointer& operator -= (D n) 80 | { 81 | p_ -= l_ * n; 82 | return *this; 83 | } 84 | 85 | template CUMP_FUNCTYPE bool operator == (T*) const {return false;} 86 | CUMP_FUNCTYPE bool operator == (StridePointer const &x) const {return p_ == x.p_;} 87 | CUMP_FUNCTYPE bool operator < (StridePointer const &x) const {return p_ < x.p_;} 88 | 89 | CUMP_FUNCTYPE D operator - (StridePointer const &x) const {return p_ - x.p_;} 90 | 91 | 92 | 93 | CUMP_FUNCTYPE P operator -> () {return p_;} 94 | CUMP_FUNCTYPE typename PT_::Parameter operator -> () const {return p_;} 95 | CUMP_FUNCTYPE Pointee& operator [] (D n) const {return p_ [l_ * n];} 96 | 97 | CUMP_FUNCTYPE StridePointer operator ++ (int) 98 | { 99 | StridePointer tmp (*this); 100 | p_ += l_; 101 | return tmp; 102 | } 103 | 104 | CUMP_FUNCTYPE StridePointer operator -- (int) 105 | { 106 | StridePointer tmp (*this); 107 | p_ -= l_; 108 | return tmp; 109 | } 110 | 111 | CUMP_FUNCTYPE StridePointer operator + (D n) const 112 | { 113 | StridePointer tmp (*this); 114 | tmp += n; 115 | return tmp; 116 | } 117 | 118 | CUMP_FUNCTYPE StridePointer operator - (D n) const 119 | { 120 | StridePointer tmp (*this); 121 | tmp -= n; 122 | return tmp; 123 | } 124 | 125 | template CUMP_FUNCTYPE bool operator != (T*) const {return true;} 126 | CUMP_FUNCTYPE bool operator != (StridePointer const &x) const {return p_ != x.p_;} 127 | CUMP_FUNCTYPE bool operator > (StridePointer const &x) const {return p_ > x.p_;} 128 | CUMP_FUNCTYPE bool operator <= (StridePointer const &x) const {return p_ <= x.p_;} 129 | CUMP_FUNCTYPE bool operator >= (StridePointer const &x) const {return p_ >= x.p_;} 130 | 131 | 132 | 133 | CUMP_FUNCTYPE void swap (StridePointer &x) 134 | { 135 | using utility::swap; 136 | swap (p_, x.p_); 137 | swap (l_, x.l_); 138 | } 139 | 140 | private: 141 | P p_; 142 | D l_; 143 | }; // StridePointer 144 | 145 | 146 | template 147 | CUMP_FUNCTYPE void swap (StridePointer &x, StridePointer &y) {x.swap (y);} 148 | 149 | 150 | } // namespace utility 151 | 152 | 153 | #define CUMP_STRIDEPTR_CUH_ 154 | #endif 155 | -------------------------------------------------------------------------------- /include/cump/mpn/generic/mul_basecase.impl: -------------------------------------------------------------------------------- 1 | /* mpn::mul_basecase -- Internal routine to multiply two natural numbers 2 | of length m and n. 3 | 4 | THIS IS AN INTERNAL FUNCTION WITH A MUTABLE INTERFACE. IT IS ONLY 5 | SAFE TO REACH THIS FUNCTION THROUGH DOCUMENTED INTERFACES. 6 | 7 | 8 | Copyright 2012 Takatoshi Nakayama. 9 | 10 | This file is part of the CUMP Library. 11 | 12 | The CUMP Library is free software; you can redistribute it and/or modify 13 | it under the terms of the GNU Lesser General Public License as published by 14 | the Free Software Foundation; either version 3 of the License, or (at your 15 | option) any later version. 16 | 17 | The CUMP Library is distributed in the hope that it will be useful, but 18 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 19 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 20 | License for more details. 21 | 22 | You should have received a copy of the GNU Lesser General Public License 23 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 24 | 25 | 26 | /* Multiply {up,usize} by {vp,vsize} and write the result to 27 | {prodp,usize+vsize}. Must have usize>=vsize. 28 | 29 | Note that prodp gets usize+vsize limbs stored, even if the actual result 30 | only needs usize+vsize-1. 31 | 32 | There's no good reason to call here with vsize>=MUL_TOOM22_THRESHOLD. 33 | Currently this is allowed, but it might not be in the future. 34 | 35 | This is the most critical code for multiplication. All multiplies rely 36 | on this, both small and huge. Small ones arrive here immediately, huge 37 | ones arrive here as this is the base case for Karatsuba's recursive 38 | algorithm. */ 39 | 40 | CUMP_FUNCTMPL3 41 | void 42 | mul_basecase (mp_ptr(1) rp, mp_srcptr(2) up, mp_size_t un, mp_srcptr(3) vp, mp_size_t vn) 43 | { 44 | ASSERT (un >= vn); 45 | ASSERT (vn >= 1); 46 | ASSERT (! CUMPN_OVERLAP_P (rp, un+vn, up, un)); 47 | ASSERT (! CUMPN_OVERLAP_P (rp, un+vn, vp, vn)); 48 | 49 | /* We first multiply by the low order limb (or depending on optional function 50 | availability, limbs). This result can be stored, not added, to rp. We 51 | also avoid a loop for zeroing this way. */ 52 | 53 | #if HAVE_NATIVE_mpn_mul_2 54 | if (vn >= 2) 55 | { 56 | rp [un + 1] = mul_2 (rp, up, un, vp); 57 | rp += 2, vp += 2, vn -= 2; 58 | } 59 | else 60 | { 61 | rp [un] = mul_1 (rp, up, un, vp [0]); 62 | return; 63 | } 64 | #else 65 | rp [un] = mul_1 (rp, up, un, vp [0]); 66 | rp += 1, vp += 1, vn -= 1; 67 | #endif 68 | 69 | /* Now accumulate the product of up [] and the next higher limb (or depending 70 | on optional function availability, limbs) from vp []. */ 71 | 72 | #define MAX_LEFT CUMP_SIZE_T_MAX /* Used to simplify loops into if statements */ 73 | 74 | 75 | #if HAVE_NATIVE_mpn_addmul_6 76 | while (vn >= 6) 77 | { 78 | rp [un + 6 - 1] = addmul_6 (rp, up, un, vp); 79 | if (MAX_LEFT == 6) 80 | return; 81 | rp += 6, vp += 6, vn -= 6; 82 | if (MAX_LEFT < 2 * 6) 83 | break; 84 | } 85 | #undef MAX_LEFT 86 | #define MAX_LEFT (6 - 1) 87 | #endif 88 | 89 | #if HAVE_NATIVE_mpn_addmul_5 90 | while (vn >= 5) 91 | { 92 | rp [un + 5 - 1] = addmul_5 (rp, up, un, vp); 93 | if (MAX_LEFT == 5) 94 | return; 95 | rp += 5, vp += 5, vn -= 5; 96 | if (MAX_LEFT < 2 * 5) 97 | break; 98 | } 99 | #undef MAX_LEFT 100 | #define MAX_LEFT (5 - 1) 101 | #endif 102 | 103 | #if HAVE_NATIVE_mpn_addmul_4 104 | while (vn >= 4) 105 | { 106 | rp [un + 4 - 1] = addmul_4 (rp, up, un, vp); 107 | if (MAX_LEFT == 4) 108 | return; 109 | rp += 4, vp += 4, vn -= 4; 110 | if (MAX_LEFT < 2 * 4) 111 | break; 112 | } 113 | #undef MAX_LEFT 114 | #define MAX_LEFT (4 - 1) 115 | #endif 116 | 117 | #if HAVE_NATIVE_mpn_addmul_3 118 | while (vn >= 3) 119 | { 120 | rp [un + 3 - 1] = addmul_3 (rp, up, un, vp); 121 | if (MAX_LEFT == 3) 122 | return; 123 | rp += 3, vp += 3, vn -= 3; 124 | if (MAX_LEFT < 2 * 3) 125 | break; 126 | } 127 | #undef MAX_LEFT 128 | #define MAX_LEFT (3 - 1) 129 | #endif 130 | 131 | #if HAVE_NATIVE_mpn_addmul_2 132 | while (vn >= 2) 133 | { 134 | rp [un + 2 - 1] = addmul_2 (rp, up, un, vp); 135 | if (MAX_LEFT == 2) 136 | return; 137 | rp += 2, vp += 2, vn -= 2; 138 | if (MAX_LEFT < 2 * 2) 139 | break; 140 | } 141 | #undef MAX_LEFT 142 | #define MAX_LEFT (2 - 1) 143 | #endif 144 | 145 | while (vn >= 1) 146 | { 147 | rp [un] = addmul_1 (rp, up, un, vp [0]); 148 | if (MAX_LEFT == 1) 149 | return; 150 | rp += 1, vp += 1, vn -= 1; 151 | } 152 | } // mul_basecase () 153 | -------------------------------------------------------------------------------- /include/cump/mpf/add.impl: -------------------------------------------------------------------------------- 1 | /* mpf_add -- Add two floats. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | CUMP_FUNCTMPL3 void mpf_add (mpf_ptr(1) r, mpf_srcptr(2) u, mpf_srcptr(3) v) 22 | { 23 | typedef typename utility::PointerTraits ::ConstPointer mp_srcptr2; 24 | typedef typename utility::PointerTraits ::ConstPointer mp_srcptr3; 25 | mpf::add (float_ptr(1) (r), mpf::ConstFloat (u), mpf::ConstFloat (v)); 26 | } // mpf_add () 27 | 28 | 29 | template 30 | CUMP_FUNCTYPE 31 | void mpf::add (float_ptr(1) r, float_srcptr(2) u, float_srcptr(2) v) 32 | { 33 | mp_srcptr(2) up, vp; 34 | mp_ptr(1) rp; 35 | mp_limb_t *tp; 36 | mp_size_t usize, vsize, rsize; 37 | mp_size_t prec; 38 | mp_exp_t uexp; 39 | mp_size_t ediff; 40 | mp_limb_t cy; 41 | int negate; 42 | TMP_DECL; 43 | 44 | usize = u._mp_size (); 45 | vsize = signs_are_same ? v._mp_size () : -v._mp_size (); 46 | 47 | /* Handle special cases that don't work in generic code below. */ 48 | if (usize == 0) 49 | { 50 | set_r_v_maybe: 51 | if (r != v) 52 | mpf_set (r, v); 53 | return; 54 | } 55 | if (vsize == 0) 56 | { 57 | v = u; 58 | goto set_r_v_maybe; 59 | } 60 | 61 | /* If signs of U and V are different, perform subtraction. */ 62 | if (signs_are_same) 63 | { 64 | if ((usize ^ vsize) < 0) 65 | { 66 | sub (r, u, v); 67 | return; 68 | } 69 | } 70 | 71 | TMP_MARK; 72 | 73 | /* Signs are now known to be the same. */ 74 | negate = usize < 0; 75 | 76 | /* Make U be the operand with the largest exponent. */ 77 | if (u._mp_exp () < v._mp_exp ()) 78 | { 79 | swap (u, v); 80 | //mpf_srcptr t; 81 | //t = u; u = v; v = t; 82 | usize = u._mp_size (); 83 | vsize = v._mp_size (); 84 | } 85 | 86 | usize = ABS (usize); 87 | vsize = ABS (vsize); 88 | up = u._mp_d (); 89 | vp = v._mp_d (); 90 | rp = r._mp_d (); 91 | prec = r._mp_prec (); 92 | uexp = u._mp_exp (); 93 | ediff = u._mp_exp () - v._mp_exp (); 94 | 95 | /* If U extends beyond PREC, ignore the part that does. */ 96 | if (usize > prec) 97 | { 98 | up += usize - prec; 99 | usize = prec; 100 | } 101 | 102 | /* If V extends beyond PREC, ignore the part that does. 103 | Note that this may make vsize negative. */ 104 | if (vsize + ediff > prec) 105 | { 106 | vp += vsize + ediff - prec; 107 | vsize = prec - ediff; 108 | } 109 | 110 | #if 0 111 | /* Locate the least significant non-zero limb in (the needed parts 112 | of) U and V, to simplify the code below. */ 113 | while (up[0] == 0) 114 | up++, usize--; 115 | while (vp[0] == 0) 116 | vp++, vsize--; 117 | #endif 118 | 119 | /* Allocate temp space for the result. Allocate 120 | just vsize + ediff later??? */ 121 | tp = TMP_ALLOC_LIMBS (prec); 122 | 123 | if (ediff >= prec) 124 | { 125 | /* V completely cancelled. */ 126 | if (rp != up) 127 | CUMPN_COPY (rp, up, usize); 128 | rsize = usize; 129 | } 130 | else 131 | { 132 | /* uuuu | uuuu | uuuu | uuuu | uuuu */ 133 | /* vvvvvvv | vv | vvvvv | v | vv */ 134 | 135 | if (usize > ediff) 136 | { 137 | /* U and V partially overlaps. */ 138 | if (vsize + ediff <= usize) 139 | { 140 | /* uuuu */ 141 | /* v */ 142 | mp_size_t size; 143 | size = usize - ediff - vsize; 144 | CUMPN_COPY (tp, up, size); 145 | cy = mpn::add (tp + size, up + size, usize - size, vp, vsize); 146 | rsize = usize; 147 | } 148 | else 149 | { 150 | /* uuuu */ 151 | /* vvvvv */ 152 | mp_size_t size; 153 | size = vsize + ediff - usize; 154 | CUMPN_COPY (tp, vp, size); 155 | cy = mpn::add (tp + size, up, usize, vp + size, usize - ediff); 156 | rsize = vsize + ediff; 157 | } 158 | } 159 | else 160 | { 161 | /* uuuu */ 162 | /* vv */ 163 | mp_size_t size; 164 | size = vsize + ediff - usize; 165 | CUMPN_COPY (tp, vp, vsize); 166 | CUMPN_ZERO (tp + vsize, ediff - usize); 167 | CUMPN_COPY (tp + size, up, usize); 168 | cy = 0; 169 | rsize = size + usize; 170 | } 171 | 172 | CUMPN_COPY (rp, tp, rsize); 173 | rp[rsize] = cy; 174 | rsize += cy; 175 | uexp += cy; 176 | 177 | } 178 | 179 | r._mp_size () = negate ? -rsize : rsize; 180 | r._mp_exp () = uexp; 181 | TMP_FREE; 182 | } // mpf::add () 183 | -------------------------------------------------------------------------------- /memory.c: -------------------------------------------------------------------------------- 1 | /* Memory allocation routines. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #if defined (_DEBUG) || defined (DEBUG) 22 | #include 23 | #endif 24 | #include 25 | #include "cump.h" 26 | #include "cump-impl.h" 27 | 28 | 29 | void* __cump_default_allocate (size_t); 30 | void* __cump_default_allocate_2D (size_t*, size_t, size_t); 31 | /*void* __cump_default_reallocate (void*, size_t, size_t);*/ 32 | void __cump_default_free (void*, size_t); 33 | 34 | void __cump_default_memcpy (void*, void const *, size_t); 35 | void __cump_default_memcpy_h2d (void*, void const *, size_t); 36 | void __cump_default_memcpy_d2h (void*, void const *, size_t); 37 | void __cump_default_memcpy_d2d (void*, void const *, size_t); 38 | void __cump_default_memcpy_2D (void*, size_t, void const *, size_t, size_t, size_t); 39 | void __cump_default_memcpy_2D_h2d (void*, size_t, void const *, size_t, size_t, size_t); 40 | void __cump_default_memcpy_2D_d2h (void*, size_t, void const *, size_t, size_t, size_t); 41 | void __cump_default_memcpy_2D_d2d (void*, size_t, void const *, size_t, size_t, size_t); 42 | 43 | 44 | void* (*__cump_allocate_func) (size_t) 45 | = __cump_default_allocate; 46 | void* (*__cump_allocate_2D_func) (size_t*, size_t, size_t) 47 | = __cump_default_allocate_2D; 48 | /* 49 | void* (*__cump_reallocate_func) (void*, size_t, size_t) 50 | = __cump_default_reallocate; 51 | */ 52 | void (*__cump_free_func) (void*, size_t) 53 | = __cump_default_free; 54 | void (*__cump_memcpy_func) (void*, void const *, size_t) 55 | = __cump_default_memcpy; 56 | void (*__cump_memcpy_h2d_func) (void*, void const *, size_t) 57 | = __cump_default_memcpy_h2d; 58 | void (*__cump_memcpy_d2h_func) (void*, void const *, size_t) 59 | = __cump_default_memcpy_d2h; 60 | void (*__cump_memcpy_d2d_func) (void*, void const *, size_t) 61 | = __cump_default_memcpy_d2d; 62 | void (*__cump_memcpy_2D_func) (void*, size_t, void const *, size_t, size_t, size_t) 63 | = __cump_default_memcpy_2D; 64 | void (*__cump_memcpy_2D_h2d_func) (void*, size_t, void const *, size_t, size_t, size_t) 65 | = __cump_default_memcpy_2D_h2d; 66 | void (*__cump_memcpy_2D_d2h_func) (void*, size_t, void const *, size_t, size_t, size_t) 67 | = __cump_default_memcpy_2D_d2h; 68 | void (*__cump_memcpy_2D_d2d_func) (void*, size_t, void const *, size_t, size_t, size_t) 69 | = __cump_default_memcpy_2D_d2d; 70 | 71 | 72 | #if defined (_DEBUG) || defined (DEBUG) 73 | #define SAFE_CALL(call) \ 74 | do \ 75 | { \ 76 | cudaError_t e = call; \ 77 | if (e != cudaSuccess) \ 78 | { \ 79 | fprintf \ 80 | ( stderr, "Device memory error (%s): %s.\n" \ 81 | , __func__, cudaGetErrorString (e) \ 82 | ); \ 83 | exit (EXIT_FAILURE); \ 84 | } \ 85 | } \ 86 | while(0) 87 | #else 88 | #define SAFE_CALL(call) (call) 89 | #endif 90 | 91 | 92 | void* __cump_default_allocate (size_t size) 93 | { 94 | void *ret; 95 | SAFE_CALL (cudaMalloc (&ret, size)); 96 | return ret; 97 | } 98 | 99 | 100 | void* __cump_default_allocate_2D (size_t *pitch, size_t width, size_t height) 101 | { 102 | void *ret; 103 | SAFE_CALL (cudaMallocPitch (&ret, pitch, width, height)); 104 | return ret; 105 | } 106 | 107 | 108 | /*void* __cump_default_reallocate (void *oldptr, size_t old_size, size_t new_size) 109 | { 110 | void *ret = 0; 111 | return ret; 112 | }*/ 113 | 114 | 115 | void __cump_default_free (void *blk_ptr, size_t blk_size) 116 | { 117 | SAFE_CALL (cudaFree (blk_ptr)); 118 | } 119 | 120 | 121 | void __cump_default_memcpy (void *dst, void const *src, size_t size) 122 | { 123 | SAFE_CALL (cudaMemcpy (dst, src, size, cudaMemcpyDefault)); 124 | } 125 | 126 | 127 | void __cump_default_memcpy_h2d (void *dst, void const *src, size_t size) 128 | { 129 | SAFE_CALL (cudaMemcpy (dst, src, size, cudaMemcpyHostToDevice)); 130 | } 131 | 132 | 133 | void __cump_default_memcpy_d2h (void *dst, void const *src, size_t size) 134 | { 135 | SAFE_CALL (cudaMemcpy (dst, src, size, cudaMemcpyDeviceToHost)); 136 | } 137 | 138 | 139 | void __cump_default_memcpy_d2d (void *dst, void const *src, size_t size) 140 | { 141 | SAFE_CALL (cudaMemcpy (dst, src, size, cudaMemcpyDeviceToDevice)); 142 | } 143 | 144 | 145 | void __cump_default_memcpy_2D 146 | ( void *dst, size_t dpitch, void const *src, size_t spitch 147 | , size_t width, size_t height 148 | ) 149 | { 150 | SAFE_CALL (cudaMemcpy2D (dst, dpitch, src, spitch, width, height, cudaMemcpyDefault)); 151 | } 152 | 153 | 154 | void __cump_default_memcpy_2D_h2d 155 | ( void *dst, size_t dpitch, void const *src, size_t spitch 156 | , size_t width, size_t height 157 | ) 158 | { 159 | SAFE_CALL (cudaMemcpy2D (dst, dpitch, src, spitch, width, height, cudaMemcpyHostToDevice)); 160 | } 161 | 162 | 163 | void __cump_default_memcpy_2D_d2h 164 | ( void *dst, size_t dpitch, void const *src, size_t spitch 165 | , size_t width, size_t height 166 | ) 167 | { 168 | SAFE_CALL (cudaMemcpy2D (dst, dpitch, src, spitch, width, height, cudaMemcpyDeviceToHost)); 169 | } 170 | 171 | 172 | void __cump_default_memcpy_2D_d2d 173 | ( void *dst, size_t dpitch, void const *src, size_t spitch 174 | , size_t width, size_t height 175 | ) 176 | { 177 | SAFE_CALL (cudaMemcpy2D (dst, dpitch, src, spitch, width, height, cudaMemcpyDeviceToDevice)); 178 | } 179 | -------------------------------------------------------------------------------- /cumpf/_set.cpp: -------------------------------------------------------------------------------- 1 | /* Inner functions for set functions. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #include 22 | #include "cump.h" 23 | #include "cump-impl.h" 24 | 25 | 26 | namespace 27 | { 28 | 29 | 30 | enum CmpResult {LARGER, EQUAL, SMALLER}; 31 | 32 | template struct Setter; 33 | 34 | template 35 | struct Setter 36 | { 37 | static void set (Dst *rp, Src *up, cumpf_header *h) 38 | { 39 | cump_size_t prec = h->_mp_prec + 1; /* lie not to lose precision in assignment */ 40 | cump_size_t size = h->_mp_size; 41 | cump_size_t asize = ABS (size); 42 | 43 | if (asize > prec) 44 | { 45 | up += asize - prec; 46 | asize = prec; 47 | } 48 | 49 | h->_mp_size = size >= 0 ? asize : -asize; 50 | if (asize) {(*__cump_memcpy_func) (rp, up, asize * sizeof (*up));} 51 | } 52 | }; 53 | 54 | template 55 | struct Setter 56 | { 57 | static void set (Dst *rp, Src *up, cumpf_header *h) 58 | { 59 | cump_size_t prec = h->_mp_prec + 1; /* lie not to lose precision in assignment */ 60 | cump_size_t size = h->_mp_size; 61 | cump_size_t asize = ABS (size); 62 | if (asize) 63 | { 64 | int const scale = sizeof (*rp) / sizeof (*up); 65 | Dst const zero = 0; 66 | 67 | cump_exp_t uexp = h->_mp_exp; 68 | cump_exp_t auexp = ABS (uexp); 69 | int expPad = scale - auexp % scale; 70 | int bExpPad = expPad != scale; 71 | auexp /= scale; 72 | cump_exp_t rexp = uexp >= 0 ? auexp + bExpPad : -auexp; 73 | cump_size_t ausize = bExpPad ? asize + expPad : asize; 74 | cump_size_t exSize = ausize % scale; 75 | cump_size_t arsize = ausize / scale + (exSize != 0); 76 | char *rp_ = static_cast (static_cast (rp)); 77 | 78 | if (bExpPad) {(*__cump_memcpy_func) (rp + (arsize - 1), &zero, sizeof (zero));} 79 | if (arsize > prec) 80 | { 81 | up += (arsize - prec) * scale - exSize; 82 | arsize = prec; 83 | } 84 | else 85 | if (exSize) 86 | { 87 | (*__cump_memcpy_func) (rp_, &zero, sizeof (zero)); 88 | rp_ += (arsize * scale - ausize) * sizeof (*up); 89 | } 90 | h->_mp_exp = rexp; 91 | (*__cump_memcpy_func) (rp_, up, asize * sizeof (*up)); 92 | asize = arsize; 93 | } 94 | h->_mp_size = size >= 0 ? asize : -asize; 95 | } 96 | }; 97 | 98 | template 99 | struct Setter 100 | { 101 | static void set (Dst *rp, Src *up, cumpf_header *h) 102 | { 103 | cump_size_t prec = h->_mp_prec + 1; /* lie not to lose precision in assignment */ 104 | cump_size_t size = h->_mp_size; 105 | cump_size_t asize = ABS (size); 106 | if (asize) 107 | { 108 | int const scale = sizeof (*up) / sizeof (*rp); 109 | Dst const zero = 0; 110 | 111 | cump_exp_t uexp = h->_mp_exp; 112 | cump_exp_t rexp = uexp * scale; 113 | cump_size_t ausize = asize; 114 | cump_size_t arsize = ausize * scale; 115 | Dst d [scale]; 116 | char const *up_ = static_cast (static_cast (up)); 117 | 118 | (*__cump_memcpy_func) (d, up + (ausize - 1), sizeof (d)); 119 | { 120 | Dst *dp = d + (scale - 1); 121 | if (*dp == zero) 122 | { 123 | int i = 1; 124 | while (*--dp == zero) {++i;} 125 | arsize -= i; 126 | rexp -= i; 127 | } 128 | } 129 | (*__cump_memcpy_func) (d, up, sizeof (d)); 130 | { 131 | Dst *dp = d; 132 | if (*dp == zero) 133 | { 134 | int i = 1; 135 | while (*++dp == zero) {++i;} 136 | arsize -= i; 137 | up_ += i * sizeof (*rp); 138 | } 139 | } 140 | if (arsize > prec) 141 | { 142 | up_ += (arsize - prec) * sizeof (*rp); 143 | arsize = prec; 144 | } 145 | h->_mp_exp = rexp; 146 | (*__cump_memcpy_func) (rp, up_, arsize * sizeof (*rp)); 147 | asize = arsize; 148 | } 149 | h->_mp_size = size >= 0 ? asize : -asize; 150 | } 151 | }; 152 | 153 | template 154 | struct Translater : 155 | Setter 156 | < (sizeof (Dst) > sizeof (Src) ? LARGER : 157 | sizeof (Dst) < sizeof (Src) ? SMALLER : EQUAL) 158 | , Dst, Src 159 | > 160 | {}; 161 | 162 | inline ::mp_ptr getLimbs (::mpf_ptr x) {return x->_mp_d;} 163 | inline ::mp_srcptr getLimbs (::mpf_srcptr x) {return x->_mp_d;} 164 | 165 | inline ::cump_ptr getLimbs (::cumpf_ptr x) 166 | { 167 | void *p = static_cast (x->_dev) + sizeof (::cumpf_header); 168 | return static_cast < ::cump_ptr> (p); 169 | } 170 | 171 | inline ::cump_srcptr getLimbs (::cumpf_srcptr x) 172 | { 173 | void const *p = static_cast (x->_dev) + sizeof (::cumpf_header); 174 | return static_cast < ::cump_srcptr> (p); 175 | } 176 | 177 | 178 | } // namespce 179 | 180 | 181 | extern "C" 182 | { 183 | 184 | 185 | void __cumpf_set (::cumpf_ptr r, ::cumpf_srcptr u, ::cumpf_header *h) 186 | { 187 | Translater < ::cump_limb_t, ::cump_limb_t const>::set (getLimbs (r), getLimbs (u), h); 188 | } 189 | 190 | void __cumpf_set_mpf (::cumpf_ptr r, ::mpf_srcptr u, ::cumpf_header *h) 191 | { 192 | Translater < ::cump_limb_t, ::mp_limb_t const>::set (getLimbs (r), getLimbs(u), h); 193 | } 194 | 195 | void __mpf_set_cumpf (::mpf_ptr r, ::cumpf_srcptr u, ::cumpf_header *h) 196 | { 197 | Translater < ::mp_limb_t, ::cump_limb_t const>::set (getLimbs (r), getLimbs (u), h); 198 | } 199 | 200 | 201 | } // extern "C" 202 | -------------------------------------------------------------------------------- /include/cump/mpn/CUDA/mul_basecase.impl: -------------------------------------------------------------------------------- 1 | /* mpn::mul_basecase 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | CUMP_FUNCTMPL3 22 | void mul_basecase 23 | ( mp_ptr(1) rp 24 | , mp_srcptr(2) up, mp_size_t un 25 | , mp_srcptr(3) vp, mp_size_t vn 26 | ) 27 | { 28 | ASSERT (un >= vn); 29 | ASSERT (vn >= 1); 30 | ASSERT (! CUMPN_OVERLAP_P (rp, un+vn, up, un)); 31 | ASSERT (! CUMPN_OVERLAP_P (rp, un+vn, vp, vn)); 32 | 33 | int _first = 2, _second = 3; 34 | int b; 35 | 36 | if (vn==1 || vn==3) 37 | { 38 | rp [un] = mul_1 (rp, up, un, vp [0]); 39 | rp += 1, vp += 1, vn -= 1; 40 | } 41 | else 42 | { 43 | rp [un+1] = mul_2 (rp, up, un, vp); 44 | rp += 2, vp += 2, vn -= 2; 45 | } 46 | if (vn==0) {return;} 47 | 48 | do 49 | { 50 | if (__all (vn<=5)) 51 | { 52 | if (__any (vn==5)) 53 | { 54 | if (__any (vn==4)) 55 | { 56 | if (__all (vn>=4)) 57 | { 58 | _first = 1; 59 | _second = 4; 60 | } 61 | else 62 | { 63 | _second = 2; 64 | if (vn==5 || vn==3) {goto __1;} 65 | } 66 | } 67 | } 68 | else 69 | if (__all (vn==4)) {_second = 4;} 70 | else 71 | if (__any (vn==4)) 72 | { 73 | if (__any (vn==3)) 74 | { 75 | _first = 1; 76 | if (__all (vn!=2)) {_second = 3;} 77 | else 78 | { 79 | _second = 2; 80 | if (vn==4) {goto __1;} 81 | } 82 | } 83 | else {_second = 2;} 84 | } 85 | else 86 | if (__any (vn==3)) 87 | { 88 | if (__any (vn==2)) 89 | { 90 | _first = 1; 91 | _second = 2; 92 | } 93 | else {_second = 3;} 94 | } 95 | else {_second = 2;} 96 | break; 97 | } 98 | 99 | while (__any (vn>9) && vn>=6) { 100 | rp [un + 4 - 1] = addmul<4> (rp, up, un, vp); 101 | rp += 4, vp += 4, vn -= 4; 102 | } 103 | 104 | if (__any (vn==9)) 105 | { 106 | if (b = __all (vn==9 || vn==6 || vn==3)) {_first = 3;} 107 | else 108 | if (__all (vn!=8)) 109 | { 110 | if (vn<6 && vn!=4) {break;} 111 | goto __4; 112 | } 113 | if (b ? (vn==9) : (vn>=6)) 114 | { 115 | rp [un + 3 - 1] = addmul<3> (rp, up, un, vp); 116 | rp += 3, vp += 3, vn -= 3; 117 | } 118 | if (b || (vn!=6 && vn!=4)) {break;} 119 | goto __1; 120 | } 121 | else 122 | if (__all (vn==8)) 123 | { 124 | _second = 4; 125 | goto __4; 126 | } 127 | else 128 | if (__any (vn==8)) 129 | { 130 | if (__all (vn!=7)) 131 | { 132 | if (__all (vn!=4)) 133 | { 134 | if (vn<6) {break;} 135 | goto __3; 136 | } 137 | if (__all (vn!=5 && vn!=3)) 138 | { 139 | _second = 4; 140 | if (__any (vn==6 || vn==2)) 141 | { 142 | if (vn!=8) {break;} 143 | goto __2; 144 | } 145 | goto __4; 146 | } 147 | } 148 | if (b = __all (vn!=6 && vn!=2)) 149 | { 150 | _first = 3; 151 | _second = 4; 152 | } 153 | if (vn==8 || vn==(b?5:6)) 154 | { 155 | rp [un] = addmul_1 (rp, up, un, vp [0]); 156 | rp += 1, vp += 1, vn -= 1; 157 | } 158 | if (b || vn<4) {break;} 159 | goto __2; 160 | } 161 | else 162 | if (__any (vn==7)) 163 | { 164 | if (__all (vn!=6)) 165 | { 166 | if (__all (vn!=5 && vn!=2)) 167 | { 168 | _first = 3; 169 | _second = 4; 170 | break; 171 | } 172 | if (vn<4) {break;} 173 | goto __2; 174 | } 175 | if (b = __all (vn!=5 && vn!=2)) {_first = 3;} 176 | else {_second = 4;} 177 | if (vn==7 || (b ? (vn==4) : (vn==5||vn==3))) {goto __1;} 178 | break; 179 | } 180 | else 181 | { // __any (vn==6) 182 | if (__all (vn==6 || vn==3)) {_first = 3;} 183 | else 184 | if (__all (vn!=5 && vn!=3)) {_second = 4;} 185 | else 186 | if (vn==6 || vn==4) {goto __1;} 187 | break; 188 | } 189 | 190 | __1: 191 | rp [un] = addmul_1 (rp, up, un, vp [0]); 192 | rp += 1, vp += 1, vn -= 1; 193 | break; 194 | __2: 195 | rp [un + 2 - 1] = addmul<2> (rp, up, un, vp); 196 | rp += 2, vp += 2, vn -= 2; 197 | break; 198 | __3: 199 | rp [un + 3 - 1] = addmul<3> (rp, up, un, vp); 200 | rp += 3, vp += 3, vn -= 3; 201 | break; 202 | __4: 203 | rp [un + 4 - 1] = addmul<4> (rp, up, un, vp); 204 | if (vn==4) {return;} 205 | rp += 4, vp += 4, vn -= 4; 206 | } 207 | while (0); 208 | 209 | if (vn!=_second) 210 | { 211 | switch (_first) 212 | { 213 | case 1: 214 | rp [un] = addmul_1 (rp, up, un, vp [0]); 215 | if (vn==1) {return;} 216 | rp += 1, vp += 1, vn -= 1; 217 | break; 218 | case 2: 219 | rp [un + 2 - 1] = addmul<2> (rp, up, un, vp); 220 | if (vn==2) {return;} 221 | rp += 2, vp += 2, vn -= 2; 222 | break; 223 | case 3: 224 | rp [un + 3 - 1] = addmul<3> (rp, up, un, vp); 225 | if (vn==3) {return;} 226 | rp += 3, vp += 3, vn -= 3; 227 | break; 228 | default: 229 | break; 230 | } 231 | } 232 | 233 | switch (_second) 234 | { 235 | case 2: 236 | rp [un + 2 - 1] = addmul<2> (rp, up, un, vp); 237 | break; 238 | case 3: 239 | rp [un + 3 - 1] = addmul<3> (rp, up, un, vp); 240 | break; 241 | case 4: 242 | rp [un + 4 - 1] = addmul<4> (rp, up, un, vp); 243 | break; 244 | default: 245 | break; 246 | } 247 | } 248 | -------------------------------------------------------------------------------- /COPYING.LIB: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /include/cump/mpf/sub.impl: -------------------------------------------------------------------------------- 1 | /* mpf_sub -- Subtract two floats. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | CUMP_FUNCTMPL3 void mpf_sub (mpf_ptr(1) r, mpf_srcptr(2) u, mpf_srcptr(3) v) 22 | { 23 | typedef typename utility::PointerTraits ::ConstPointer mp_srcptr2; 24 | typedef typename utility::PointerTraits ::ConstPointer mp_srcptr3; 25 | mpf::sub (float_ptr(1) (r), mpf::ConstFloat (u), mpf::ConstFloat (v)); 26 | } // mpf_sub () 27 | 28 | 29 | template 30 | CUMP_FUNCTYPE 31 | void mpf::sub (float_ptr(1) r, float_srcptr(2) u, float_srcptr(2) v) 32 | { 33 | mp_srcptr(2) up, vp; 34 | mp_ptr(1) rp; 35 | mp_limb_t *tp; 36 | mp_size_t usize, vsize, rsize; 37 | mp_size_t prec; 38 | mp_exp_t exp; 39 | mp_size_t ediff; 40 | int negate; 41 | TMP_DECL; 42 | 43 | usize = u._mp_size (); 44 | vsize = signs_are_same ? v._mp_size () : vsize = -v._mp_size (); 45 | 46 | /* Handle special cases that don't work in generic code below. */ 47 | if (usize == 0) 48 | { 49 | mpf_neg (r, v); 50 | return; 51 | } 52 | if (vsize == 0) 53 | { 54 | if (r != u) 55 | mpf_set (r, u); 56 | return; 57 | } 58 | 59 | if (signs_are_same) 60 | { 61 | /* If signs of U and V are different, perform addition. */ 62 | if ((usize ^ vsize) < 0) 63 | { 64 | add (r, u, v); 65 | return; 66 | } 67 | } 68 | 69 | TMP_MARK; 70 | 71 | /* Signs are now known to be the same. */ 72 | negate = usize < 0; 73 | 74 | /* Make U be the operand with the largest exponent. */ 75 | if (u._mp_exp () < v._mp_exp ()) 76 | { 77 | swap (u, v); 78 | //mpf_srcptr t; 79 | //t = u; u = v; v = t; 80 | negate ^= 1; 81 | usize = u._mp_size (); 82 | vsize = v._mp_size (); 83 | } 84 | 85 | usize = ABS (usize); 86 | vsize = ABS (vsize); 87 | up = u._mp_d (); 88 | vp = v._mp_d (); 89 | rp = r._mp_d (); 90 | prec = r._mp_prec () + 1; 91 | exp = u._mp_exp (); 92 | ediff = u._mp_exp () - v._mp_exp (); 93 | 94 | /* If ediff is 0 or 1, we might have a situation where the operands are 95 | extremely close. We need to scan the operands from the most significant 96 | end ignore the initial parts that are equal. */ 97 | if (ediff <= 1) 98 | { 99 | if (ediff == 0) 100 | { 101 | /* Skip leading limbs in U and V that are equal. */ 102 | if (up[usize - 1] == vp[vsize - 1]) 103 | { 104 | /* This loop normally exits immediately. Optimize for that. */ 105 | do 106 | { 107 | usize--; 108 | vsize--; 109 | exp--; 110 | 111 | if (usize == 0) 112 | { 113 | /* u cancels high limbs of v, result is rest of v */ 114 | negate ^= 1; 115 | cancellation: 116 | /* strip high zeros before truncating to prec */ 117 | while (vsize != 0 && vp[vsize - 1] == 0) 118 | { 119 | vsize--; 120 | exp--; 121 | } 122 | if (vsize > prec) 123 | { 124 | vp += vsize - prec; 125 | vsize = prec; 126 | } 127 | CUMPN_COPY (rp, vp, vsize); 128 | rsize = vsize; 129 | goto done; 130 | } 131 | if (vsize == 0) 132 | { 133 | vp = up; 134 | vsize = usize; 135 | goto cancellation; 136 | } 137 | } 138 | while (up[usize - 1] == vp[vsize - 1]); 139 | } 140 | 141 | if (up[usize - 1] < vp[vsize - 1]) 142 | { 143 | /* For simplicity, swap U and V. Note that since the loop above 144 | wouldn't have exited unless up[usize - 1] and vp[vsize - 1] 145 | were non-equal, this if-statement catches all cases where U 146 | is smaller than V. */ 147 | CUMPN_SRCPTR_SWAP (up,usize, vp,vsize); 148 | negate ^= 1; 149 | /* negating ediff not necessary since it is 0. */ 150 | } 151 | 152 | /* Check for 153 | x+1 00000000 ... 154 | x ffffffff ... */ 155 | if (up[usize - 1] != vp[vsize - 1] + 1) 156 | goto general_case; 157 | usize--; 158 | vsize--; 159 | exp--; 160 | } 161 | else /* ediff == 1 */ 162 | { 163 | /* Check for 164 | 1 00000000 ... 165 | 0 ffffffff ... */ 166 | 167 | if (up[usize - 1] != 1 || vp[vsize - 1] != CUMP_NUMB_MAX 168 | || (usize >= 2 && up[usize - 2] != 0)) 169 | goto general_case; 170 | 171 | usize--; 172 | exp--; 173 | } 174 | 175 | /* Skip sequences of 00000000/ffffffff */ 176 | while (vsize != 0 && usize != 0 && up[usize - 1] == 0 177 | && vp[vsize - 1] == CUMP_NUMB_MAX) 178 | { 179 | usize--; 180 | vsize--; 181 | exp--; 182 | } 183 | 184 | if (usize == 0) 185 | { 186 | while (vsize != 0 && vp[vsize - 1] == CUMP_NUMB_MAX) 187 | { 188 | vsize--; 189 | exp--; 190 | } 191 | } 192 | 193 | if (usize > prec - 1) 194 | { 195 | up += usize - (prec - 1); 196 | usize = prec - 1; 197 | } 198 | if (vsize > prec - 1) 199 | { 200 | vp += vsize - (prec - 1); 201 | vsize = prec - 1; 202 | } 203 | 204 | tp = TMP_ALLOC_LIMBS (prec); 205 | { 206 | mp_limb_t cy_limb; 207 | if (vsize == 0) 208 | { 209 | mp_size_t size, i; 210 | size = usize; 211 | for (i = 0; i < size; i++) 212 | tp[i] = up[i]; 213 | tp[size] = 1; 214 | rsize = size + 1; 215 | exp++; 216 | goto normalize; 217 | } 218 | if (usize == 0) 219 | { 220 | mp_size_t size, i; 221 | size = vsize; 222 | for (i = 0; i < size; i++) 223 | tp[i] = ~vp[i] & CUMP_NUMB_MASK; 224 | cy_limb = 1 - mpn::add_1 (tp, tp, vsize, (mp_limb_t) 1); 225 | rsize = vsize; 226 | if (cy_limb == 0) 227 | { 228 | tp[rsize] = 1; 229 | rsize++; 230 | exp++; 231 | } 232 | goto normalize; 233 | } 234 | if (usize >= vsize) 235 | { 236 | /* uuuu */ 237 | /* vv */ 238 | mp_size_t size; 239 | size = usize - vsize; 240 | CUMPN_COPY (tp, up, size); 241 | cy_limb = mpn::sub_n (tp + size, up + size, vp, vsize); 242 | rsize = usize; 243 | } 244 | else /* (usize < vsize) */ 245 | { 246 | /* uuuu */ 247 | /* vvvvvvv */ 248 | mp_size_t size, i; 249 | size = vsize - usize; 250 | for (i = 0; i < size; i++) 251 | tp[i] = ~vp[i] & CUMP_NUMB_MASK; 252 | cy_limb = mpn::sub_n (tp + size, up, vp + size, usize); 253 | cy_limb+= mpn::sub_1 (tp + size, tp + size, usize, (mp_limb_t) 1); 254 | cy_limb-= mpn::add_1 (tp, tp, vsize, (mp_limb_t) 1); 255 | rsize = vsize; 256 | } 257 | if (cy_limb == 0) 258 | { 259 | tp[rsize] = 1; 260 | rsize++; 261 | exp++; 262 | } 263 | goto normalize; 264 | } 265 | } 266 | 267 | general_case: 268 | /* If U extends beyond PREC, ignore the part that does. */ 269 | if (usize > prec) 270 | { 271 | up += usize - prec; 272 | usize = prec; 273 | } 274 | 275 | /* If V extends beyond PREC, ignore the part that does. 276 | Note that this may make vsize negative. */ 277 | if (vsize + ediff > prec) 278 | { 279 | vp += vsize + ediff - prec; 280 | vsize = prec - ediff; 281 | } 282 | 283 | /* Allocate temp space for the result. Allocate 284 | just vsize + ediff later??? */ 285 | tp = TMP_ALLOC_LIMBS (prec); 286 | 287 | if (ediff >= prec) 288 | { 289 | /* V completely cancelled. */ 290 | if (tp != up) 291 | CUMPN_COPY (rp, up, usize); 292 | rsize = usize; 293 | } 294 | else 295 | { 296 | /* Locate the least significant non-zero limb in (the needed 297 | parts of) U and V, to simplify the code below. */ 298 | for (;;) 299 | { 300 | if (vsize == 0) 301 | { 302 | CUMPN_COPY (rp, up, usize); 303 | rsize = usize; 304 | goto done; 305 | } 306 | if (vp[0] != 0) 307 | break; 308 | vp++, vsize--; 309 | } 310 | for (;;) 311 | { 312 | if (usize == 0) 313 | { 314 | CUMPN_COPY (rp, vp, vsize); 315 | rsize = vsize; 316 | negate ^= 1; 317 | goto done; 318 | } 319 | if (up[0] != 0) 320 | break; 321 | up++, usize--; 322 | } 323 | 324 | /* uuuu | uuuu | uuuu | uuuu | uuuu */ 325 | /* vvvvvvv | vv | vvvvv | v | vv */ 326 | 327 | if (usize > ediff) 328 | { 329 | /* U and V partially overlaps. */ 330 | if (ediff == 0) 331 | { 332 | /* Have to compare the leading limbs of u and v 333 | to determine whether to compute u - v or v - u. */ 334 | if (usize >= vsize) 335 | { 336 | /* uuuu */ 337 | /* vv */ 338 | mp_size_t size; 339 | size = usize - vsize; 340 | CUMPN_COPY (tp, up, size); 341 | mpn::sub_n (tp + size, up + size, vp, vsize); 342 | rsize = usize; 343 | } 344 | else /* (usize < vsize) */ 345 | { 346 | /* uuuu */ 347 | /* vvvvvvv */ 348 | mp_size_t size, i; 349 | size = vsize - usize; 350 | tp[0] = -vp[0] & CUMP_NUMB_MASK; 351 | for (i = 1; i < size; i++) 352 | tp[i] = ~vp[i] & CUMP_NUMB_MASK; 353 | mpn::sub_n (tp + size, up, vp + size, usize); 354 | mpn::sub_1 (tp + size, tp + size, usize, (mp_limb_t) 1); 355 | rsize = vsize; 356 | } 357 | } 358 | else 359 | { 360 | if (vsize + ediff <= usize) 361 | { 362 | /* uuuu */ 363 | /* v */ 364 | mp_size_t size; 365 | size = usize - ediff - vsize; 366 | CUMPN_COPY (tp, up, size); 367 | mpn::sub (tp + size, up + size, usize - size, vp, vsize); 368 | rsize = usize; 369 | } 370 | else 371 | { 372 | /* uuuu */ 373 | /* vvvvv */ 374 | mp_size_t size, i; 375 | size = vsize + ediff - usize; 376 | tp[0] = -vp[0] & CUMP_NUMB_MASK; 377 | for (i = 1; i < size; i++) 378 | tp[i] = ~vp[i] & CUMP_NUMB_MASK; 379 | mpn::sub (tp + size, up, usize, vp + size, usize - ediff); 380 | mpn::sub_1 (tp + size, tp + size, usize, (mp_limb_t) 1); 381 | rsize = vsize + ediff; 382 | } 383 | } 384 | } 385 | else 386 | { 387 | /* uuuu */ 388 | /* vv */ 389 | mp_size_t size, i; 390 | size = vsize + ediff - usize; 391 | tp[0] = -vp[0] & CUMP_NUMB_MASK; 392 | for (i = 1; i < vsize; i++) 393 | tp[i] = ~vp[i] & CUMP_NUMB_MASK; 394 | for (i = vsize; i < size; i++) 395 | tp[i] = CUMP_NUMB_MAX; 396 | mpn::sub_1 (tp + size, up, usize, (mp_limb_t) 1); 397 | rsize = size + usize; 398 | } 399 | 400 | normalize: 401 | /* Full normalize. Optimize later. */ 402 | while (rsize != 0 && tp[rsize - 1] == 0) 403 | { 404 | rsize--; 405 | exp--; 406 | } 407 | CUMPN_COPY (rp, tp, rsize); 408 | } 409 | 410 | done: 411 | r._mp_size () = negate ? -rsize : rsize; 412 | 413 | if (rsize == 0) 414 | exp = 0; 415 | r._mp_exp () = exp; 416 | TMP_FREE; 417 | } 418 | -------------------------------------------------------------------------------- /include/cump/cump.cuh: -------------------------------------------------------------------------------- 1 | /* Definitions and implementations for CUMP device functions. 2 | 3 | Copyright 2012 Takatoshi Nakayama. 4 | 5 | This file is part of the CUMP Library. 6 | 7 | The CUMP Library is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU Lesser General Public License as published by 9 | the Free Software Foundation; either version 3 of the License, or (at your 10 | option) any later version. 11 | 12 | The CUMP Library is distributed in the hope that it will be useful, but 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 | License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with the CUMP Library. If not, see http://www.gnu.org/licenses/. */ 19 | 20 | 21 | #ifndef CUMP_CUH_ 22 | 23 | 24 | #define CUMP_FUNCTYPE __device__ 25 | #define CUMP_HOSTCTOR __host__ 26 | #define CUMP_CONSTANT __constant__ 27 | 28 | 29 | #include // std::ptrdiff_t, std::size_t 30 | #include "cump.h" 31 | #include "def.h" 32 | 33 | 34 | #ifndef __CUMP_WITHIN_CUMP 35 | CUMP_CONSTANT cump_size_t __cump_default_fp_limb_precision = __CUMPF_BITS_TO_PREC (53); 36 | #endif // __CUMP_WITHIN_CUMP 37 | 38 | 39 | namespace // CUMP's classes and functions for device code are always in anonymous namespace 40 | { 41 | namespace cump 42 | { 43 | 44 | 45 | #include "pointer_traits.hpp" 46 | #include "utility.cuh" 47 | #include "strideptr.cuh" 48 | 49 | 50 | static std::size_t const kLimbBits = CUMP_LIMB_BITS; 51 | static std::size_t const kNailBits = CUMP_NAIL_BITS; 52 | static std::size_t const kNumBits = CUMP_NUMB_BITS; 53 | static std::size_t const kNumMask = CUMP_NUMB_MASK; 54 | static std::size_t const kNumMax = CUMP_NUMB_MAX; 55 | static std::size_t const kNailMask = CUMP_NAIL_MASK; 56 | static std::size_t const kFloatMaxPrec = 1040; 57 | 58 | 59 | using ::cump_int32; 60 | using ::cump_uint32; 61 | using ::cump_int64; 62 | using ::cump_uint64; 63 | 64 | using ::cumpf_ptr; 65 | using ::cumpf_srcptr; 66 | using ::cumpf_array_ptr; 67 | using ::cumpf_array_srcptr; 68 | 69 | typedef ::cump_limb_t mp_limb_t; 70 | typedef ::cump_bitcnt_t mp_bitcnt_t; 71 | typedef ::cump_size_t mp_size_t; 72 | typedef ::cump_exp_t mp_exp_t; 73 | 74 | 75 | namespace interface 76 | { 77 | 78 | 79 | template 80 | class Storage 81 | { 82 | typedef utility::PointerTraits PT_; 83 | typedef Storage Storage_; 84 | 85 | friend class Storage ; 86 | 87 | template class, typename, typename> 88 | friend class Array; 89 | 90 | protected: 91 | CUMP_HOSTCTOR CUMP_FUNCTYPE Storage (typename PT_::Parameter p) 92 | : p_ (p) 93 | {} 94 | 95 | CUMP_FUNCTYPE Storage () : p_ () {} 96 | 97 | CUMP_FUNCTYPE typename PT_::Parameter get () const {return p_;} 98 | 99 | public: 100 | CUMP_FUNCTYPE Storage (Storage_ const &x) : p_ (x.p_) {} 101 | 102 | template CUMP_FUNCTYPE bool operator == (Storage ) const {return false;} 103 | template CUMP_FUNCTYPE bool operator != (Storage ) const {return true;} 104 | CUMP_FUNCTYPE bool operator == (Storage const &x) const {return p_ == x.p_;} 105 | CUMP_FUNCTYPE bool operator != (Storage const &x) const {return p_ != x.p_;} 106 | 107 | CUMP_FUNCTYPE void swap (Storage &x) {utility::swap (p_, x.p_);} 108 | 109 | private: 110 | Limbs p_; 111 | }; // Storage 112 | 113 | 114 | template 115 | < typename HostPtr 116 | , typename Limb = mp_limb_t 117 | , typename Limbs = Limb* 118 | > 119 | class Variable 120 | : public Storage 121 | { 122 | typedef Storage Storage_; 123 | 124 | public: 125 | CUMP_HOSTCTOR Variable (HostPtr p) 126 | : Storage_ (static_cast (p->_dev)) 127 | {} 128 | 129 | CUMP_FUNCTYPE Variable () : Storage_ () {} 130 | }; // Variable 131 | 132 | 133 | template struct Common; 134 | template struct Transposed; 135 | 136 | 137 | template 138 | < typename HostPtr 139 | , template class Layout = Transposed 140 | , typename Limb = mp_limb_t 141 | , typename Index = std::ptrdiff_t 142 | > 143 | class Array 144 | : public Layout 145 | { 146 | typedef Storage ::Pointer> Element_; 147 | 148 | public: 149 | CUMP_HOSTCTOR Array (HostPtr p) 150 | : p_ (static_cast (p->_dev)) 151 | , l_ (p->_int/sizeof (Limb)) 152 | {} 153 | 154 | CUMP_FUNCTYPE Element_ operator [] (Index n) const {return at (p_, l_, n);} 155 | 156 | private: 157 | Limb *p_; 158 | Index l_; 159 | }; // Array 160 | 161 | 162 | template 163 | struct Common 164 | { 165 | typedef Limb* Pointer; 166 | 167 | CUMP_FUNCTYPE static Pointer at (Limb *p, Index l, Index n) {return p + l * n;} 168 | }; // Common 169 | 170 | 171 | template 172 | struct Transposed 173 | { 174 | typedef utility::StridePointer Pointer; 175 | 176 | CUMP_FUNCTYPE static Pointer at (Limb *p, Index l, Index n) {return Pointer (p + n, l);} 177 | }; // Transposed 178 | 179 | 180 | } // namespace interface 181 | 182 | 183 | namespace utility 184 | { 185 | 186 | 187 | template 188 | CUMP_FUNCTYPE void swap (interface::Storage &x, interface::Storage &y) 189 | { 190 | x.swap (y); 191 | } // swap () 192 | 193 | 194 | } // namespace utility 195 | 196 | 197 | typedef interface::Variable mpf_t; 198 | typedef interface::Array mpf_array_t; 199 | typedef interface::Array mpf_common_array_t; 200 | typedef interface::Array mpf_transposed_array_t; 201 | typedef 202 | interface::Variable 203 | mpf_src_t; 204 | typedef 205 | interface::Array 206 | mpf_array_src_t; 207 | typedef 208 | interface::Array 209 | mpf_common_array_src_t; 210 | typedef 211 | interface::Array 212 | mpf_transposed_array_src_t; 213 | 214 | 215 | #define ASSERT(expr) 216 | //#define CUMPN_SAME_OR_SEPARATE_P 217 | //#define CUMPN_SAME_OR_SEPARATE2_P 218 | //#define CUMPN_SAME_OR_INCR_P 219 | //#define CUMPN_SAME_OR_DECR_P 220 | //#define CUMPN_OVERLAP_P 221 | 222 | 223 | // TMP schemes 224 | #define TMP_SDECL TMP_DECL 225 | #define TMP_DECL mp_limb_t tmp [kFloatMaxPrec] 226 | #define TMP_SMARK TMP_MARK 227 | #define TMP_MARK 228 | #define TMP_SALLOC(n) TMP_ALLOC(n) 229 | #define TMP_BALLOC(n) TMP_ALLOC(n) 230 | #define TMP_ALLOC(n) tmp 231 | #define TMP_SFREE TMP_FREE 232 | #define TMP_FREE 233 | 234 | /* Allocating various types. */ 235 | //#define TMP_ALLOC_TYPE(n,type) ((type*)TMP_ALLOC((n)*sizeof(type))) 236 | //#define TMP_SALLOC_TYPE(n,type) ((type*)TMP_SALLOC((n)*sizeof(type))) 237 | //#define TMP_BALLOC_TYPE(n,type) ((type*)TMP_BALLOC((n)*sizeof(type))) 238 | #define TMP_ALLOC_LIMBS(n) TMP_ALLOC(n) 239 | #define TMP_SALLOC_LIMBS(n) TMP_SALLOE(n) 240 | #define TMP_BALLOC_LIMBS(n) TMP_BALLOC(n) 241 | //#define TMP_ALLOC_MP_PTRS(n) TMP_ALLOC_TYPE(n,mp_ptr) 242 | //#define TMP_SALLOC_MP_PTRS(n) TMP_SALLOC_TYPE(n,mp_ptr) 243 | //#define TMP_BALLOC_MP_PTRS(n) TMP_BALLOC_TYPE(n,mp_ptr) 244 | 245 | 246 | #define CUMP_1_PTRTYPES typename P1 247 | #define CUMP_2_PTRTYPES CUMP_1_PTRTYPES, typename P2 248 | #define CUMP_3_PTRTYPES CUMP_2_PTRTYPES, typename P3 249 | 250 | #define CUMP_FUNCTMPL1 template CUMP_FUNCTYPE 251 | #define CUMP_FUNCTMPL2 template CUMP_FUNCTYPE 252 | #define CUMP_FUNCTMPL3 template CUMP_FUNCTYPE 253 | 254 | 255 | #define mp_ptr(n) P##n 256 | #define mp_srcptr(n) P##n 257 | 258 | 259 | namespace mpn 260 | { 261 | 262 | 263 | CUMP_FUNCTMPL2 void copy (mp_ptr(1) dst, mp_srcptr(2) src, mp_size_t n) 264 | { 265 | if (n) 266 | { 267 | mp_limb_t x = *src; 268 | while (--n) 269 | { 270 | *dst++ = x; 271 | x = *++src; 272 | } 273 | *dst = x; 274 | } 275 | } // copy () 276 | 277 | 278 | CUMP_FUNCTMPL2 279 | void copy_rest (mp_ptr(1) dst, mp_srcptr(2) src, mp_size_t size, mp_size_t start) 280 | { 281 | ASSERT (size>=0); 282 | ASSERT (start>=0); 283 | ASSERT (start<=size); 284 | ASSERT (CUMPN_SAME_OR_SEPARATE_P (dst, src, size)); 285 | // __CUMP_CUCRAY_Pragma ("_CRI ivdep"); 286 | for (mp_size_t j = start; j < size; ++j) {dst [j] = src [j];} 287 | } // copy_rest () 288 | 289 | 290 | CUMP_FUNCTMPL1 void zero (mp_ptr(1) dst, mp_size_t n) 291 | { 292 | ASSERT (n>=0); 293 | if (n) {*dst=0; while (--n) {*++dst=0;}} 294 | } // zero () 295 | 296 | 297 | CUMP_FUNCTMPL1 void swap_ptr (mp_ptr(1) &xp, mp_size_t &xs, mp_ptr(1) &yp, mp_size_t &ys) 298 | { 299 | using utility::swap; 300 | swap (xp, yp); 301 | swap (xs, ys); 302 | } // swap_ptr () 303 | 304 | 305 | CUMP_FUNCTMPL1 306 | void swap_srcptr (mp_srcptr(1) &xp, mp_size_t &xs, mp_srcptr(1) &yp, mp_size_t &ys) 307 | { 308 | using utility::swap; 309 | swap (xp, yp); 310 | swap (xs, ys); 311 | } // swap_srcptr () 312 | 313 | 314 | template 315 | < bool (&test) (mp_limb_t&, mp_limb_t) 316 | , class AorS 317 | , CUMP_3_PTRTYPES 318 | > 319 | CUMP_FUNCTYPE 320 | int aors (mp_ptr(1) wp, mp_srcptr(2) xp, mp_size_t xsize, mp_srcptr(3) yp, mp_size_t ysize) 321 | { 322 | ASSERT (ysize >= 0); 323 | ASSERT (xsize >= ysize); 324 | ASSERT (CUMPN_SAME_OR_SEPARATE2_P (wp, xsize, xp, xsize)); 325 | ASSERT (CUMPN_SAME_OR_SEPARATE2_P (wp, xsize, yp, ysize)); 326 | mp_size_t i = ysize; 327 | if (i != 0) 328 | { 329 | mp_limb_t x; 330 | if (AorS::func (wp, xp, yp, i)) 331 | { 332 | do 333 | { 334 | if (i >= xsize) {return 1;} 335 | x = xp [i]; 336 | } 337 | while (test (wp [i++], x)); 338 | } 339 | } 340 | if (wp != xp) {copy_rest (wp, xp, xsize, i);} 341 | return 0; 342 | } // aors () 343 | 344 | 345 | template 346 | < mp_limb_t (&op) (mp_limb_t, mp_limb_t) 347 | , bool (&cb) (mp_limb_t, mp_limb_t, mp_limb_t) 348 | , CUMP_2_PTRTYPES 349 | > 350 | CUMP_FUNCTYPE int aors_1 (mp_ptr(1) dst, mp_srcptr(2) src, mp_size_t n, mp_limb_t v) 351 | { 352 | ASSERT (n>=1); 353 | ASSERT (CUMPN_SAME_OR_SEPARATE_P (dst, src, n)); 354 | mp_limb_t x = src [0]; 355 | mp_limb_t r = op (x, v); 356 | dst [0] = (kNailBits == 0 ? r : r & kNumMask); 357 | if (kNailBits == 0 ? cb (r, x, v) : r >> kNumBits == 0) 358 | { 359 | for (mp_size_t i=1; i> kNumBits == 0)) 366 | { 367 | if (src != dst) {copy_rest (dst, src, n, i);} 368 | return 0; 369 | } 370 | } 371 | return 1; 372 | } 373 | else 374 | { 375 | if (src != dst) {copy_rest (dst, src, n, 1);} 376 | return 0; 377 | } 378 | } 379 | 380 | 381 | CUMP_FUNCTMPL2 void copyi (mp_ptr(1), mp_srcptr(2), mp_size_t); 382 | CUMP_FUNCTMPL2 void copyd (mp_ptr(1), mp_srcptr(2), mp_size_t); 383 | CUMP_FUNCTMPL2 mp_limb_t neg (mp_ptr(1), mp_srcptr(2), mp_size_t); 384 | CUMP_FUNCTMPL2 mp_limb_t rshift (mp_ptr(1), mp_srcptr(2), mp_size_t, unsigned int); 385 | CUMP_FUNCTMPL2 mp_limb_t lshift (mp_ptr(1), mp_srcptr(2), mp_size_t, unsigned int); 386 | CUMP_FUNCTMPL2 mp_limb_t lshiftc (mp_ptr(1), mp_srcptr(2), mp_size_t, unsigned int); 387 | CUMP_FUNCTMPL3 mp_limb_t add (mp_ptr(1), mp_srcptr(2), mp_size_t, mp_srcptr(3), mp_size_t); 388 | CUMP_FUNCTMPL2 mp_limb_t add_1 (mp_ptr(1), mp_srcptr(2), mp_size_t, mp_limb_t) __CUMP_NOTHROW; 389 | CUMP_FUNCTMPL3 mp_limb_t add_n (mp_ptr(1), mp_srcptr(2), mp_srcptr(3), mp_size_t); 390 | CUMP_FUNCTMPL3 mp_limb_t sub (mp_ptr(1), mp_srcptr(2), mp_size_t, mp_srcptr(3), mp_size_t); 391 | CUMP_FUNCTMPL2 mp_limb_t sub_1 (mp_ptr(1), mp_srcptr(2), mp_size_t, mp_limb_t) __CUMP_NOTHROW; 392 | CUMP_FUNCTMPL3 mp_limb_t sub_n (mp_ptr(1), mp_srcptr(2), mp_srcptr(3), mp_size_t); 393 | CUMP_FUNCTMPL3 mp_limb_t addmul (mp_ptr(1), mp_srcptr(2), mp_size_t, mp_srcptr(3)); 394 | CUMP_FUNCTMPL2 mp_limb_t addmul_1 (mp_ptr(1), mp_srcptr(2), mp_size_t, mp_limb_t); 395 | CUMP_FUNCTMPL3 mp_limb_t mul (mp_ptr(1), mp_srcptr(2), mp_size_t, mp_srcptr(3), mp_size_t); 396 | CUMP_FUNCTMPL2 mp_limb_t mul_1 (mp_ptr(1), mp_srcptr(2), mp_size_t, mp_limb_t); 397 | CUMP_FUNCTMPL3 mp_limb_t mul_2 (mp_ptr(1), mp_srcptr(2), mp_size_t, mp_srcptr(3)); 398 | CUMP_FUNCTMPL3 void mul_n (mp_ptr(1), mp_srcptr(2), mp_srcptr(3), mp_size_t); 399 | CUMP_FUNCTMPL3 void mul_basecase (mp_ptr(1), mp_srcptr(2), mp_size_t, mp_srcptr(3), mp_size_t); 400 | CUMP_FUNCTMPL2 void sqr (mp_ptr(1), mp_srcptr(2), mp_size_t); 401 | CUMP_FUNCTMPL2 void sqr_basecase (mp_ptr(1), mp_srcptr(2), mp_size_t); 402 | CUMP_FUNCTMPL2 int cmp (mp_srcptr(1), mp_srcptr(2), mp_size_t) __CUMP_NOTHROW; 403 | 404 | 405 | /* mpn functions */ 406 | #include "mpn/generic/add.impl" 407 | #include "mpn/generic/add_1.impl" 408 | #include "mpn/generic/add_n.impl" 409 | #include "mpn/generic/addmul_1.impl" 410 | #include "mpn/generic/cmp.impl" 411 | #include "mpn/generic/copyd.impl" 412 | #include "mpn/generic/copyi.impl" 413 | #include "mpn/generic/lshift.impl" 414 | #include "mpn/generic/lshiftc.impl" 415 | #include "mpn/generic/mul_1.impl" 416 | #include "mpn/CUDA/addmul.impl" 417 | #include "mpn/CUDA/mul_2.impl" 418 | #include "mpn/CUDA/mul_basecase.impl" 419 | //#include "mpn/generic/mul_basecase.impl" 420 | #include "mpn/generic/mul.impl" 421 | #include "mpn/generic/neg.impl" 422 | #include "mpn/generic/rshift.impl" 423 | #include "mpn/generic/sub.impl" 424 | #include "mpn/generic/sub_1.impl" 425 | #include "mpn/generic/sub_n.impl" 426 | 427 | 428 | } // namespace mpn 429 | 430 | 431 | #define CUMPN_COPY mpn::copy 432 | #define CUMPN_ZERO mpn::zero 433 | #define CUMPN_PTR_SWAP mpn::swap_ptr 434 | #define CUMPN_SRCPTR_SWAP mpn::swap_srcptr 435 | 436 | 437 | namespace mpf 438 | { 439 | 440 | 441 | using utility::swap; 442 | 443 | 444 | template 445 | class ConstFloat 446 | : public interface::Storage 447 | { 448 | typedef interface::Storage Storage_; 449 | typedef utility::PointerTraits PT_; 450 | typedef cump_int32 Int_; 451 | typedef mp_exp_t Exp_; 452 | 453 | using Storage_::get; 454 | 455 | public: 456 | template 457 | CUMP_FUNCTYPE ConstFloat (interface::Storage const &x) 458 | : Storage_ (x) 459 | {} 460 | 461 | CUMP_FUNCTYPE Int_ _mp_prec () const {return *ptrcast_ (get ());} 462 | 463 | CUMP_FUNCTYPE Int_ _mp_size () const 464 | { 465 | return *ptrcast_ (increment_by_ (get ())); 466 | } 467 | 468 | CUMP_FUNCTYPE Exp_ _mp_exp () const 469 | { 470 | return *ptrcast_ (increment_by_ <2 * sizeof (Int_)> (get ())); 471 | } 472 | 473 | CUMP_FUNCTYPE Limbs _mp_d () const 474 | { 475 | return increment_and_align_ <2 * sizeof (Int_) + sizeof (Exp_)> (get ()); 476 | } 477 | 478 | private: 479 | template 480 | CUMP_FUNCTYPE static T const * ptrcast_ (void const *p) 481 | { 482 | return static_cast (p); 483 | } // ptrcast_ () 484 | 485 | template 486 | CUMP_FUNCTYPE static void const * increment_by_ (typename PT_::Parameter p) 487 | { 488 | std::size_t const x = bytes / sizeof (*p); 489 | std::size_t const y = bytes % sizeof (*p); 490 | return ptrcast_ (x == 0 ? p : p + x) + y; 491 | } // increment_by_ () 492 | 493 | template 494 | CUMP_FUNCTYPE static Limbs increment_and_align_ (typename PT_::Parameter p) 495 | { 496 | std::size_t const x = bytes / sizeof (*p); 497 | std::size_t const y = bytes % sizeof (*p); 498 | std::size_t const offset = x + (y == 0 ? 0l : 1l); 499 | return p + offset; 500 | } // increment_and_align_ () 501 | }; // ConstFloat 502 | 503 | 504 | template 505 | class Float 506 | : public interface::Storage 507 | { 508 | typedef interface::Storage Storage_; 509 | typedef utility::PointerTraits PT_; 510 | typedef cump_int32 Int_; 511 | typedef mp_exp_t Exp_; 512 | 513 | using Storage_::get; 514 | 515 | public: 516 | template 517 | CUMP_FUNCTYPE Float (interface::Storage const &x) 518 | : Storage_ (x) 519 | {} 520 | 521 | CUMP_FUNCTYPE Int_& _mp_prec () {return *ptrcast_ (get ());} 522 | 523 | CUMP_FUNCTYPE Int_& _mp_size () 524 | { 525 | return *ptrcast_ (increment_by_ (get ())); 526 | } 527 | 528 | CUMP_FUNCTYPE Exp_& _mp_exp () 529 | { 530 | return *ptrcast_ (increment_by_ <2 * sizeof (Int_)> (get ())); 531 | } 532 | 533 | CUMP_FUNCTYPE Limbs _mp_d () 534 | { 535 | return increment_and_align_ <2 * sizeof (Int_) + sizeof (Exp_)> (get ()); 536 | } 537 | 538 | private: 539 | template 540 | CUMP_FUNCTYPE static T* ptrcast_ (void *p) {return static_cast (p);} 541 | 542 | template 543 | CUMP_FUNCTYPE static void* increment_by_ (typename PT_::Parameter p) 544 | { 545 | std::size_t const x = bytes / sizeof (*p); 546 | std::size_t const y = bytes % sizeof (*p); 547 | return ptrcast_ (x == 0 ? p : p + x) + y; 548 | } // increment_by_ () 549 | 550 | template 551 | CUMP_FUNCTYPE static Limbs increment_and_align_ (typename PT_::Parameter p) 552 | { 553 | std::size_t const x = bytes / sizeof (*p); 554 | std::size_t const y = bytes % sizeof (*p); 555 | std::size_t const offset = x + (y == 0 ? 0l : 1l); 556 | return p + offset; 557 | } // increment_and_align_ () 558 | }; // Float 559 | 560 | 561 | #define float_ptr(n) mpf::Float 562 | #define float_srcptr(n) mpf::ConstFloat 563 | 564 | 565 | CUMP_FUNCTYPE void clear (mpf_t&); 566 | CUMP_FUNCTYPE void init (mpf_t&); 567 | CUMP_FUNCTYPE void init2 (mpf_t&, mp_bitcnt_t); 568 | CUMP_FUNCTMPL1 void init_set (mpf_t&, float_srcptr(1)); 569 | CUMP_FUNCTMPL2 void set (float_ptr(1), float_srcptr(2)); 570 | CUMP_FUNCTMPL2 void neg (float_ptr(1), float_srcptr(2)); 571 | 572 | template 573 | CUMP_FUNCTYPE void add (float_ptr(1), float_srcptr(2), float_srcptr(3)); 574 | 575 | template 576 | CUMP_FUNCTYPE void sub (float_ptr(1), float_srcptr(2), float_srcptr(3)); 577 | 578 | template 579 | CUMP_FUNCTYPE void add (float_ptr(1), float_srcptr(2), float_srcptr(2)); 580 | 581 | template 582 | CUMP_FUNCTYPE void sub (float_ptr(1), float_srcptr(2), float_srcptr(2)); 583 | 584 | CUMP_FUNCTMPL3 void mul (float_ptr(1), float_srcptr(2), float_srcptr(3)); 585 | 586 | 587 | } // namespace mpf 588 | 589 | 590 | #define mpf_ptr(n) interface::Storage 591 | #define mpf_srcptr(n) interface::Storage const & 592 | 593 | 594 | CUMP_FUNCTYPE void mpf_clear (mpf_t&); 595 | CUMP_FUNCTYPE void mpf_init (mpf_t&); 596 | CUMP_FUNCTYPE void mpf_init2 (mpf_t&, mp_bitcnt_t); 597 | CUMP_FUNCTMPL1 void mpf_init_set (mpf_t&, mpf_srcptr(1)); 598 | CUMP_FUNCTMPL2 void mpf_set (mpf_ptr(1), mpf_srcptr(2)); 599 | CUMP_FUNCTMPL2 void mpf_neg (mpf_ptr(1), mpf_srcptr(2)); 600 | CUMP_FUNCTMPL3 void mpf_add (mpf_ptr(1), mpf_srcptr(2), mpf_srcptr(3)); 601 | CUMP_FUNCTMPL3 void mpf_sub (mpf_ptr(1), mpf_srcptr(2), mpf_srcptr(3)); 602 | CUMP_FUNCTMPL3 void mpf_mul (mpf_ptr(1), mpf_srcptr(2), mpf_srcptr(3)); 603 | 604 | 605 | #ifndef __CUMP_WITHIN_CUMP 606 | /* mpf functions */ 607 | //#include "mpf/clear.impl" 608 | //#include "mpf/init.impl" 609 | //#include "mpf/init2.impl" 610 | //#include "mpf/iset.impl" 611 | #include "mpf/set.impl" 612 | #include "mpf/neg.impl" 613 | #include "mpf/add.impl" 614 | #include "mpf/sub.impl" 615 | #include "mpf/mul.impl" 616 | #endif // __CUMP_WITHIN_CUMP 617 | 618 | 619 | #undef mpf_srcptr 620 | #undef mpf_ptr 621 | 622 | 623 | #undef float_srcptr 624 | #undef float_ptr 625 | 626 | 627 | #undef CUMPN_COPY 628 | #undef CUMPN_ZERO 629 | #undef CUMPN_PTR_SWAP 630 | #undef CUMPN_SRCPTR_SWAP 631 | 632 | 633 | #undef mp_srcptr 634 | #undef mp_ptr 635 | 636 | 637 | #undef CUMP_FUNCTMPL3 638 | #undef CUMP_FUNCTMPL2 639 | #undef CUMP_FUNCTMPL1 640 | 641 | #undef CUMP_3_PTRTYPES 642 | #undef CUMP_2_PTRTYPES 643 | #undef CUMP_1_PTRTYPES 644 | 645 | 646 | //#undef TMP_BALLOC_MP_PTRS 647 | //#undef TMP_SALLOC_MP_PTRS 648 | //#undef TMP_ALLOC_MP_PTRS 649 | #undef TMP_BALLOC_LIMBS 650 | #undef TMP_SALLOC_LIMBS 651 | #undef TMP_ALLOC_LIMBS 652 | //#undef TMP_BALLOC_TYPE 653 | //#undef TMP_SALLOC_TYPE 654 | //#undef TMP_ALLOC_TYPE 655 | 656 | #undef TMP_FREE 657 | #undef TMP_SFREE 658 | #undef TMP_ALLOC 659 | #undef TMP_BALLOC 660 | #undef TMP_SALLOC 661 | #undef TMP_MARK 662 | #undef TMP_SMARK 663 | #undef TMP_DECL 664 | #undef TMP_SDECL 665 | 666 | 667 | //#undef CUMPN_OVERLAP_P 668 | //#undef CUMPN_SAME_OR_DECR_P 669 | //#undef CUMPN_SAME_OR_INCR_P 670 | //#undef CUMPN_SAME_OR_SEPARATE2_P 671 | //#undef CUMPN_SAME_OR_SEPARATE_P 672 | #undef ASSERT 673 | 674 | 675 | } // namespace cump 676 | } // namespace 677 | 678 | 679 | #undef CUMP_CONSTANT 680 | #undef CUMP_HOSTCTOR 681 | #undef CUMP_FUNCTYPE 682 | 683 | 684 | #define CUMP_CUH_ 685 | #endif 686 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------