/usr/include/fflas-ffpack/fflas/fflas_freduce.inl is in fflas-ffpack-common 2.2.2-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 | /* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
// vim:sts=8:sw=8:ts=8:noet:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s
/* fflas/fflas_freduce.inl
* Copyright (C) 2014 Pascal Giorgi
*
* Written by Pascal Giorgi <Pascal.Giorgi@lirmm.fr>
* Brice Boyer (briceboyer) <boyer.brice@gmail.com>
*
* Part of this code is taken from http://libdivide.com/
*
* ========LICENCE========
* This file is part of the library FFLAS-FFPACK.
*
* FFLAS-FFPACK is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*.
*/
#ifndef __FFLASFFPACK_fflas_freduce_INL
#define __FFLASFFPACK_fflas_freduce_INL
#include <givaro/udl.h>
#include "fflas-ffpack/fflas/fflas_fassign.h"
#include "fflas-ffpack/utils/bit_manipulation.h"
#define FFLASFFPACK_COPY_REDUCE 32 /* TO BENCMARK LATER */
namespace FFLAS { namespace vectorised { /* for casts (?) */
template<class T>
inline typename std::enable_if< ! std::is_integral<T>::value, T>::type
monfmod(T A, T B)
{
return fmod(A,B);
}
template<class T>
inline typename std::enable_if< std::is_integral<T>::value, T>::type
monfmod(T A, T B)
{
return A % B; // B > 0
}
template<>
inline Givaro::Integer monfmod(Givaro::Integer A, Givaro::Integer B) // @bug B is not integer, but uint64_t usually
{
return A % B; // B > 0
}
template<>
inline float monfmod(float A, float B)
{
return fmodf(A,B);
}
template<>
inline double monfmod(double A, double B)
{
//std::cerr<<"fmod"<<std::endl;
return fmod(A,B);
}
template<size_t K, size_t MG>
inline RecInt::rmint<K,MG>& monfmod(RecInt::rmint<K,MG>& A, RecInt::rmint<K,MG>& B)
{
return RecInt::rmint<K>::mod_n(A, B);
}
template<class T>
inline typename std::enable_if< ! std::is_integral<T>::value, T>::type
monrint(T A)// @bug pass by reference ?
{
return rint(A);
}
template<class T>
inline typename std::enable_if< std::is_integral<T>::value, T>::type
monrint( T A)
{
return A ;
}
template<>
inline double monrint(double A)
{
return rint(A);
}
template<>
inline float monrint(float A)
{
return rintf(A);
}
template<>
inline Givaro::Integer monrint(Givaro::Integer A) // @bug B is not integer, but uint64_t usually
{
return A ; // B > 0
}
template<bool overflow, bool poweroftwo>
inline int64_t monfmod(int64_t A, int64_t p, int8_t shifter, int64_t magic)
{
if (poweroftwo) { //shift path
int64_t q = A + ((A >> 63) & ((1_i64 << shifter) - 1));
q = A - ((q>>shifter)<< shifter) ;
return (q<0)?(q+p):q ;
}
else {
int64_t q = mulhi_64(magic, A);
if (overflow) {
q += A ;
}
q >>= shifter;
A = A - q * p ;
if (A >= p) A-= p ; // because of mulhi_fast
return A ;
}
}
} // vectorised
} // FFLAS
namespace FFLAS { namespace vectorised {
template<class T>
inline void fast_mod_generate(bool & overflow, bool & poweroftwo, int8_t & shift, T & magic, T denom)
{
overflow = false ;
poweroftwo = false ;
shift = 0 ;
magic = 0 ;
}
//! @pre d > 0
template<>
inline void fast_mod_generate(bool & overflow, bool & poweroftwo, int8_t & shift, int64_t & magic, int64_t denom)
{
// overflow = false ;
// poweroftwo = false ;
// shift = 0 ;
// magic = 0 ;
if ((denom & (denom- 1)) == 0) {
shift = (int8_t)ctz((uint64_t)denom) ;
magic = 0;
poweroftwo = true ;
}
else {
const uint32_t floor_log_2_d = 63 - clz((uint64_t)denom);
/*the dividend here is 2**(floor_log_2_d + 63), so the low 64 bit word is 0 and the high word is floor_log_2_d - 1 */
uint64_t rem, proposed_m;
proposed_m = getpoweroftwoden_128(floor_log_2_d, denom, &rem);
const uint64_t e = denom- rem;
/* We are going to start with a power of floor_log_2_d - 1. This works if works if e < 2**floor_log_2_d. */
if (e < (1_ui64 << floor_log_2_d)) {
/* This power works */
shift = (int8_t)(floor_log_2_d - 1);
}
else {
/* We need to go one higher. This should not make proposed_m overflow, but it will make it negative when interpreted as an int32_t. */
proposed_m += proposed_m;
const uint64_t twice_rem = rem + rem;
if (twice_rem >= (uint64_t)denom || twice_rem < rem) proposed_m += 1;
shift = (int8_t) floor_log_2_d ;
overflow = true ;
}
proposed_m += 1;
magic = (int64_t)proposed_m ;
}
}
template<class Field, class ElementTraits = typename ElementTraits<typename Field::Element>::value>
struct HelperMod ;
template<class Field>
struct HelperMod<Field, ElementCategories::MachineIntTag> {
bool overflow = false ;
bool poweroftwo = false ;
int8_t shift = 0 ;
typename Field::Element magic = (typename Field::Element)0 ;
typename Field::Element p;
HelperMod()
{
// std::cout << "empty cstor called" << std::endl;
} ;
HelperMod( const Field & F)
{
// std::cout << "field cstor called" << std::endl;
p = (typename Field::Element) F.characteristic();
fast_mod_generate(overflow, poweroftwo, shift, magic, p);
// std::cout << overflow << ',' << poweroftwo << std::endl;
// std::cout << (int) shift << ',' << magic << std::endl;
// std::cout << this->shift << std::endl;
}
int getAlgo() const
{
// std::cout << "will be " << (2*overflow + poweroftwo) << std::endl;
return 2* (int)overflow + (int) poweroftwo ;
// return overflow << 1 | poweroftwo ;
}
} ;
template<class Field>
struct HelperMod<Field, FFLAS::ElementCategories::MachineFloatTag> {
typename Field::Element p;
typename Field::Element invp;
// typename Field::Elmeent min ;
// typename Field::Elmeent max ;
HelperMod() {} ;
HelperMod( const Field & F)
{
p = (typename Field::Element) F.characteristic();
invp = (typename Field::Element)1/p;
// min = F.minElement();
// max = F.maxElement();
}
int getAlgo() const
{
return 0;
}
} ;
template<class Field>
struct HelperMod<Field, FFLAS::ElementCategories::ArbitraryPrecIntTag> {
typename Field::Element p;
// typename Field::Element invp;
// typename Field::Elmeent min ;
// typename Field::Elmeent max ;
HelperMod() {} ;
HelperMod( const Field & F)
{
p = (typename Field::Element) F.characteristic();
// invp = (typename Field::Element)1/p;
// min = F.minElement();
// max = F.maxElement();
}
int getAlgo() const
{
return 0;
}
} ;
template<class Field>
struct HelperMod<Field, FFLAS::ElementCategories::FixedPrecIntTag> {
typename Field::Element p;
// typename Field::Element invp;
// typename Field::Elmeent min ;
// typename Field::Elmeent max ;
HelperMod() {} ;
HelperMod( const Field & F)
{
p = (typename Field::Element) F.characteristic();
// invp = (typename Field::Element)1/p;
// min = F.minElement();
// max = F.maxElement();
}
int getAlgo() const
{
return 0;
}
} ;
#ifdef __FFLASFFPACK_HAVE_SSE4_1_INSTRUCTIONS
template<class Field, class SimdT, class ElementTraits = typename ElementTraits<typename Field::Element>::value>
struct HelperModSimd ;
template<class Field, class SimdT>
struct HelperModSimd<Field, SimdT, ElementCategories::MachineIntTag> : public HelperMod<Field> {
typedef typename SimdT::vect_t vect_t ;
// bool overflow ;
// int8_t shift ;
// typename Field::Element p;
typename Field::Element magic ;
vect_t M ;
vect_t P ;
vect_t MIN ;
vect_t MAX ;
vect_t NEGP ;
vect_t Q ;
vect_t T ;
HelperModSimd ( const Field & F) :
HelperMod<Field>(F)
{
// std::cout << "HelperMod constructed " << this->shift << std::endl;
// p = F.characteristic();
P = SimdT::set1(this->p);
NEGP = SimdT::set1(-this->p);
MIN = SimdT::set1(F.minElement());
MAX = SimdT::set1(F.maxElement());
// fast_mod_generate(overflow, shift, magic, p);
M = SimdT::set1(magic);
}
HelperModSimd( const Field & F, const HelperMod<Field> & G)
{
this->overflow=G.overflow;
this->poweroftwo=G.poweroftwo;
this->shift=G.shift;
this->magic=G.magic;
this->p=G.p;
// std::cout << "magic is = " << this->magic<< ',' << G.magic<< std::endl;
P = SimdT::set1(this->p);
NEGP = SimdT::set1(-(this->p));
MIN = SimdT::set1(F.minElement());
MAX = SimdT::set1(F.maxElement());
// fast_mod_generate(overflow, shift, magic, p);
M = SimdT::set1(magic);
}
} ;
template<class Field, class SimdT>
struct HelperModSimd<Field, SimdT, ElementCategories::MachineFloatTag> : public HelperMod<Field> {
typedef typename SimdT::vect_t vect_t ;
vect_t INVP;
vect_t MIN ;
vect_t MAX ;
vect_t NEGP ;
vect_t P ;
vect_t Q ;
vect_t T ;
HelperModSimd( const Field & F) :
HelperMod<Field>(F)
{
P = SimdT::set1(this->p);
NEGP = SimdT::set1(-(this->p));
// MIN = SimdT::set1(max);
MIN = SimdT::set1(F.minElement());
// MAX = SimdT::set1(min);
MAX = SimdT::set1(F.maxElement());
INVP = SimdT::set1(this->invp);
}
HelperModSimd( const Field & F, const HelperMod<Field> & G)
{
this->p = G.p;
this->invp = G.invp ;
P = SimdT::set1(this->p);
NEGP = SimdT::set1(-this->p);
// MIN = SimdT::set1(max);
MIN = SimdT::set1(F.minElement());
// MAX = SimdT::set1(min);
MAX = SimdT::set1(F.maxElement());
INVP = SimdT::set1(this->invp);
}
} ;
#endif // __FFLASFFPACK_HAVE_SSE4_1_INSTRUCTIONS
#ifdef __x86_64__
template<class Field, int ALGO>
typename std::enable_if< std::is_same<typename Field::Element,int64_t>::value , int64_t>::type
monfmod (typename Field::Element A, HelperMod<Field,ElementCategories::MachineIntTag> & H)
{
switch(ALGO) {
case 3 :
// std::cout << 3 << std::endl;
return monfmod<true,true> (A,H.p,H.shift,H.magic);
case 2 :
// std::cout << 2 << std::endl;
return monfmod<true,false> (A,H.p,H.shift,H.magic);
case 1 :
// std::cout << 1 << std::endl;
return monfmod<false,true> (A,H.p,H.shift,H.magic);
case 0 :
// std::cout << "using " << 0 << std::endl;
return monfmod<false,false>(A,H.p,H.shift,H.magic);
default :
FFLASFFPACK_abort("unknown algo");
}
}
#endif // __x86_64__
template<class Field, int ALGO>
#ifdef __x86_64__
typename std::enable_if< ! std::is_same<typename Field::Element,int64_t>::value , typename Field::Element>::type
#else
typename Field::Element
#endif // __x86_64__
monfmod (typename Field::Element A, HelperMod<Field,ElementCategories::MachineIntTag> & H)
{
return monfmod(A,H.p);
}
template<class Field, int ALGO>
typename Field::Element monfmod (typename Field::Element A, HelperMod<Field,ElementCategories::MachineFloatTag> & H)
{
return monfmod(A,H.p);
}
template<class Field, int ALGO>
typename Field::Element monfmod (typename Field::Element A, HelperMod<Field,ElementCategories::ArbitraryPrecIntTag> & H)
{
return monfmod(A,H.p);
}
#ifdef __FFLASFFPACK_HAVE_SSE4_1_INSTRUCTIONS
template<class Field, class SimdT, int ALGO>
inline void
VEC_MOD(typename SimdT::vect_t & C, HelperModSimd<Field,SimdT,ElementCategories::MachineFloatTag> & H)
{
C = SimdT::mod( C, H.P, H.INVP, H.NEGP, H.MIN, H.MAX, H.Q, H.T );
}
template<class Field, class SimdT, int ALGO>
inline void
VEC_MOD(typename SimdT::vect_t & C, HelperModSimd<Field,SimdT,ElementCategories::MachineIntTag> & H)
{
// std::cout << "magic " << H.magic<< std::endl;
// std::cout << H.P << std::endl;
switch (ALGO) {
case 0 :
C = SimdT::template mod<false,false>( C, H.P, H.shift, H.M, H.NEGP, H.MIN, H.MAX, H.Q, H.T );
break;
case 1 :
C = SimdT::template mod<true,false> ( C, H.P, H.shift, H.M, H.NEGP, H.MIN, H.MAX, H.Q, H.T );
break;
case 2 :
C = SimdT::template mod<false,true> ( C, H.P, H.shift, H.M, H.NEGP, H.MIN, H.MAX, H.Q, H.T );
break;
case 3 :
C = SimdT::template mod<true,true> ( C, H.P, H.shift, H.M, H.NEGP, H.MIN, H.MAX, H.Q, H.T );
break;
}
}
#endif // __FFLASFFPACK_HAVE_SSE4_1_INSTRUCTIONS
} // vectorised
} // FFLAS
namespace FFLAS { namespace vectorised { namespace unswitch {
#ifdef __FFLASFFPACK_HAVE_SSE4_1_INSTRUCTIONS
template<class Field, bool round, int algo>
inline typename std::enable_if<FFLAS::support_simd_mod<typename Field::Element>::value, void>::type
modp(const Field &F, typename Field::ConstElement_ptr U, const size_t & n,
typename Field::Element_ptr T
, HelperMod<Field> & G
)
{
// std::cerr<<"modp vectorized"<<std::endl;
typedef typename Field::Element Element;
Element min = (Element)F.minElement(), max = (Element)F.maxElement();
using simd = Simd<Element>;
using vect_t = typename simd::vect_t;
bool positive = ! FieldTraits<Field>::balanced ; // known at compile time
HelperModSimd<Field,simd> H(F,G);
size_t i = 0;
if (n < simd::vect_size)
{
// std::cerr<< n<< " < "<<simd::vect_size<<std::endl;
for (; i < n ; i++)
{
if (round)
{
T[i] = monrint(U[i]);
T[i] = monfmod<Field,algo>(T[i],H);
}
else
{
T[i]=monfmod<Field,algo>(U[i],H);
}
if (!positive)
{
T[i]-=(T[i]>max)?H.p:0;
}
T[i]+=(T[i]<min)?H.p:0;
}
return;
}
long st = long(T) % simd::alignment;
// the array T is not 32 byte aligned (process few elements s.t. (T+i) is 32 bytes aligned)
if (st)
{
// std::cerr<< st << " not aligned on "<<simd::alignment<<std::endl;
for (size_t j = static_cast<size_t>(st) ; j < simd::alignment ; j += sizeof(Element), i++)
{
if (round)
{
T[i] = monrint(U[i]);
T[i] = monfmod<Field,algo>(T[i],H);
}
else
{
T[i] = monfmod<Field,algo>(U[i],H);
}
if (!positive)
{
T[i] -= (T[i] > max) ? H.p : 0;
}
T[i] += (T[i] < min) ? H.p : 0;
}
}
FFLASFFPACK_check((long(T+i) % simd::alignment == 0));
vect_t C ;
if((long(U+i) % simd::alignment == 0))
{
// perform the loop using 256 bits SIMD
for (; i<= n - simd::vect_size ; i += simd::vect_size)
{
C = simd::load(U + i);
if (round)
{
C = simd::round(C);
}
VEC_MOD<Field,simd,algo>(C,H);
simd::store(T+i, C);
}
}
// perform the last elt from T without SIMD
// std::cerr<< n-i<< " unaligned elements left "<<std::endl;
for (;i<n;i++)
{
if (round)
{
T[i] = monrint(U[i]);
T[i] = monfmod<Field,algo>(T[i],H);
}
else
{
T[i] = monfmod<Field,algo>(U[i],H);
}
if (!positive)
{
T[i] -= (T[i] > max) ? H.p : 0;
}
T[i] += (T[i] < min) ? H.p : 0;
}
}
#endif
// not vectorised but allows better code than % or fmod via helper
template<class Field, bool round, int algo>
inline typename std::enable_if< !FFLAS::support_simd_mod<typename Field::Element>::value, void>::type
modp(const Field &F, typename Field::ConstElement_ptr U, const size_t & n,
typename Field::Element_ptr T
, HelperMod<Field> & H
)
{
// std::cerr<<"modp not vectorized"<<std::endl;
typedef typename Field::Element Element;
Element min = (Element)F.minElement(), max = (Element)F.maxElement();
bool positive = ! FieldTraits<Field>::balanced ;
size_t i = 0;
for (; i < n ; i++)
{
if (round)
{
T[i] = monrint(U[i]);
T[i] = monfmod<Field,algo>(T[i],H);
}
else
{
T[i]=monfmod<Field,algo>(U[i],H);
}
if (!positive)
{
T[i]-=(T[i]>max)?H.p:(typename Field::Element)0;
}
T[i]+=(T[i]<min)?H.p:(typename Field::Element)0;
}
}
} // unswitch
} // vectorised
} // FFLAS
namespace FFLAS { namespace vectorised {
template<class Field, bool round>
//inline typename std::enable_if<FFLAS::support_simd_mod<typename Field::Element>::value, void>::type
void
modp(const Field &F, typename Field::ConstElement_ptr U, const size_t & n,
typename Field::Element_ptr T)
{
HelperMod<Field> H(F);
int ALGO = H.getAlgo();
switch (ALGO) {
case 0 :
unswitch::modp<Field,round,0>(F,U,n,T,H);
break;
case 1 :
unswitch::modp<Field,round,1>(F,U,n,T,H);
break;
case 2 :
unswitch::modp<Field,round,2>(F,U,n,T,H);
break;
case 3 :
unswitch::modp<Field,round,3>(F,U,n,T,H);
break;
}
}
} // vectorised
} // FFLAS
namespace FFLAS { namespace details {
// specialised
template<class Field>
typename std::enable_if<FFLAS::support_simd_mod<typename Field::Element>::value, void>::type
freduce (const Field & F, const size_t m,
typename Field::Element_ptr A, const size_t incX, FieldCategories::ModularTag)
{
if(incX == 1) {
vectorised::modp<Field,false>(F,A,m,A);
}
else { /* faster with copy, use incX=1, copy back ? */
if (m < FFLASFFPACK_COPY_REDUCE) {
typename Field::Element_ptr Xi = A ;
for (; Xi < A+m*incX; Xi+=incX )
F.reduce(*Xi);
}
else {
typename Field::Element_ptr Ac = fflas_new (F,m,1) ;
fassign (F,m,A,incX,Ac,1);
freduce (F,m,Ac,1,FieldCategories::ModularTag());
fassign (F,m,Ac,1,A,incX);
fflas_delete (Ac);
}
}
}
template<class Field>
typename std::enable_if< ! FFLAS::support_simd_mod<typename Field::Element>::value, void>::type
freduce (const Field & F, const size_t m,
typename Field::Element_ptr A, const size_t incX, FieldCategories::ModularTag)
{ /* ??? ( faster with copy, use incX=1, copy back ? */
// CP: no SIMD supported here!
// if(incX == 1) {
// vectorised::modp<Field,false>(F,A,m,A);
// }
// else {
typename Field::Element_ptr Xi = A ;
for (; Xi < A+m*incX; Xi+=incX )
F.reduce(*Xi);
// }
}
template<class Field>
void
freduce (const Field & F, const size_t m,
typename Field::Element_ptr A, const size_t incX,
FieldCategories::GenericTag)
{
typename Field::Element_ptr Xi = A ;
for (; Xi < A+m*incX; Xi+=incX )
F.reduce (*Xi);
}
template<class Field>
void
freduce (const Field & F, const size_t m,
typename Field::Element_ptr A, const size_t incX,
FieldCategories::UnparametricTag)
{
typename Field::Element_ptr Xi = A ;
for (; Xi < A+m*incX; Xi+=incX )
F.reduce (*Xi);
}
template<class Field>
typename std::enable_if< FFLAS::support_simd_mod<typename Field::Element>::value, void>::type
freduce (const Field & F, const size_t m,
typename Field::ConstElement_ptr B, const size_t incY,
typename Field::Element_ptr A, const size_t incX,
FieldCategories::ModularTag)
{
if(incX == 1 && incY == 1) {
vectorised::modp<Field,false>(F,B,m,A);
}
else {
typename Field::Element_ptr Xi = A ;
typename Field::ConstElement_ptr Yi = B ;
for (; Xi < A+m*incX; Xi+=incX, Yi += incY )
F.reduce (*Xi , *Yi);
}
}
template<class Field>
typename std::enable_if< ! FFLAS::support_simd_mod<typename Field::Element>::value, void>::type
freduce (const Field & F, const size_t m,
typename Field::ConstElement_ptr B, const size_t incY,
typename Field::Element_ptr A, const size_t incX,
FieldCategories::ModularTag)
{
typename Field::Element_ptr Xi = A ;
typename Field::ConstElement_ptr Yi = B ;
for (; Xi < A+m*incX; Xi+=incX, Yi += incY )
F.reduce (*Xi , *Yi);
}
template<class Field>
void
freduce (const Field & F, const size_t m,
typename Field::ConstElement_ptr B, const size_t incY,
typename Field::Element_ptr A, const size_t incX,
FieldCategories::GenericTag)
{
typename Field::Element_ptr Xi = A ;
typename Field::ConstElement_ptr Yi = B ;
for (; Xi < A+m*incX; Xi+=incX, Yi += incY )
F.reduce (*Xi , *Yi);
}
template<class Field>
void
freduce (const Field & F, const size_t m,
typename Field::ConstElement_ptr B, const size_t incY,
typename Field::Element_ptr A, const size_t incX,
FieldCategories::UnparametricTag)
{
typename Field::Element_ptr Xi = A ;
typename Field::ConstElement_ptr Yi = B ;
for (; Xi < A+m*incX; Xi+=incX, Yi += incY )
F.reduce (*Xi , *Yi);
}
} // details
} // FFLAS
#endif // __FFLASFFPACK_fflas_freduce_INL
|