/usr/include/fflas-ffpack/fflas/fflas_fscal.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 | /* -*- 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_faxpy.inl
* Copyright (C) 2014 FFLAS-FFPACK group
*
* Written by Brice Boyer (briceboyer) <boyer.brice@gmail.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_fscal_INL
#define __FFLASFFPACK_fscal_INL
namespace FFLAS { namespace vectorised {
#ifdef __FFLASFFPACK_HAVE_SSE4_1_INSTRUCTIONS
template<class SimdT, class Element>
inline typename std::enable_if<is_simd<SimdT>::value, void>::type
VEC_SCAL(SimdT & C, SimdT & ALPHA, SimdT & Q, SimdT & T, SimdT & P, SimdT & NEGP, SimdT & INVP, SimdT & MIN, SimdT & MAX)
{
using simd = Simd<Element>;
Q = simd::mul(C,INVP);
C = simd::mul(C,ALPHA);
Q = simd::floor(Q);
C = simd::fnmadd(C,Q,P);
Q = simd::greater(C,MAX);
T = simd::lesser(C,MIN);
Q = simd::vand(Q,NEGP);
T = simd::vand(T,P);
Q = simd::vor(Q,T);
C = simd::add(C,Q);
}
template<class Element, class T1, class T2>
inline typename std::enable_if<std::is_floating_point<Element>::value, void>::type
scalp(Element *T, const Element alpha, const Element * U, const size_t n, const Element p, const Element invp, const T1 min_, const T2 max_)
{
Element min = (Element)min_, max=(Element)max_;
using simd = Simd<Element>;
using vect_t = typename simd::vect_t;
size_t i = 0;
if (n < simd::vect_size)
{
for (; i < n ; i++)
{
T[i]=monfmod(alpha*U[i], p);
T[i] -= (T[i] > max) ? p : 0;
T[i] += (T[i] < min) ? p : 0;
}
return;
}
vect_t C,Q,P,NEGP,INVP,TMP,MIN,MAX,ALPHA;
ALPHA = simd::set1(alpha);
P = simd::set1(p);
NEGP = simd::set1(-p);
INVP = simd::set1(invp);
MIN = simd::set1(min);
MAX = simd::set1(max);
long st = long(T) % simd::alignment;
if (st)
{ // the array T is not 32 byte aligned (process few elements s.t. (T+i) is 32 bytes aligned)
for (size_t j = static_cast<size_t>(st) ; j < simd::alignment ; j+=sizeof(Element), i++)
{
T[i] = monfmod(alpha*U[i], p);
T[i] -= (T[i] > max) ? p : 0;
T[i] += (T[i] < min) ? p : 0;
}
}
FFLASFFPACK_check((long(T+i) % simd::alignment == 0));
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);
VEC_SCAL<vect_t,Element>(C, ALPHA, Q, TMP, P, NEGP, INVP, MIN, MAX);
simd::store(T+i,C);
}
}
// perform the last elt from T without SIMD
for (; i < n ; i++)
{
T[i] = monfmod(alpha*U[i],p);
T[i] -= (T[i] > max) ? p : 0;
T[i] += (T[i] < min) ? p : 0;
}
}
#else
template<class Element, class T1, class T2>
void
scalp(Element *T, const Element alpha, const Element * U, const size_t n, const Element p, const Element invp, const T1 min_, const T2 max_)
{
Element min = (Element)min_, max=(Element)max_;
size_t i = 0;
{
for (; i < n ; i++)
{
T[i]=monfmod(alpha*U[i], p);
T[i] -= (T[i] > max) ? p : 0;
T[i] += (T[i] < min) ? p : 0;
}
return;
}
}
#endif // __FFLASFFPACK_HAVE_SSE4_1_INSTRUCTIONS
} // vectorised
} // FFLAS
namespace FFLAS {
/***************************/
/* LEVEL 1 */
/***************************/
template<class Field>
inline void
fscal( const Field& F, const size_t N,
const typename Field::Element a,
typename Field::ConstElement_ptr X, const size_t incX,
typename Field::Element_ptr Y, const size_t incY )
{
// details::fscal(F,N,a,X,incX,Y,incY, typename FieldTraits<Field>::value() );
if (F.isOne(a)) {
fassign(F,N,X,incX,Y,incY);
return ;
}
typename Field::ConstElement_ptr Xi = X;
typename Field::Element_ptr Yi = Y;
if (F.areEqual(a,F.mOne)){
fneg(F,N,X,incX,Y,incY);
return;
}
if (F.isZero(a)){
fzero(F,N,Y,incY);
return;
}
if (incX == 1 && incY == 1)
for (size_t i = 0 ; i < N ; ++i)
F.mul( Y[i], a, X[i] );
else
for (; Xi < X+N*incX; Xi+=incX, Yi+=incY )
F.mul( *Yi, a, *Xi );
}
template<class Field>
inline void
fscalin (const Field& F, const size_t n, const typename Field::Element a,
typename Field::Element_ptr X, const size_t incX)
{
if (F.isOne(a))
return ;
if (F.isMOne(a)){
fnegin(F,n,X,incX);
return;
}
if (F.isZero(a)){
fzero(F,n,X,incX);
return;
}
typename Field::Element_ptr Xi = X ;
if ( incX == 1)
for (size_t i = 0 ; i < n ; ++i)
F.mulin( X[i], a);
else
for (; Xi < X+n*incX; Xi+=incX )
F.mulin( *Xi, a);
}
template<>
inline void
fscal( const Givaro::DoubleDomain& , const size_t N,
const Givaro::DoubleDomain::Element a,
Givaro::DoubleDomain::ConstElement_ptr x, const size_t incx,
Givaro::DoubleDomain::Element_ptr y, const size_t incy )
{
cblas_dcopy( (int)N, x, (int)incy, y, (int)incy);
cblas_dscal( (int)N, a, y, (int)incy);
}
template<>
inline void
fscal( const Givaro::FloatDomain& , const size_t N,
const Givaro::FloatDomain::Element a,
Givaro::FloatDomain::ConstElement_ptr x, const size_t incx,
Givaro::FloatDomain::Element_ptr y, const size_t incy )
{
cblas_scopy( (int)N, x, (int)incy, y, (int)incy);
cblas_sscal( (int)N, a, y, (int)incy);
}
template<>
inline void
fscalin( const Givaro::DoubleDomain& , const size_t N,
const Givaro::DoubleDomain::Element a,
Givaro::DoubleDomain::Element_ptr y, const size_t incy )
{
cblas_dscal( (int)N, a, y, (int)incy);
}
template<>
inline void
fscalin( const Givaro::FloatDomain& , const size_t N,
const Givaro::FloatDomain::Element a,
Givaro::FloatDomain::Element_ptr y, const size_t incy )
{
cblas_sscal( (int)N, a, y, (int)incy);
}
template<>
inline void
fscalin( const Givaro::Modular<float>& F , const size_t N,
const float a,
float * X, const size_t incX )
{
if(incX == 1) {
float p, invp;
p=(float)F.cardinality();
invp=a/p;
vectorised::scalp(X,a,X,N,p,invp,0,p-1);
}
else {
float * Xi = X ;
for (; Xi < X+N*incX; Xi+=incX )
F.mulin( *Xi , a);
}
}
template<>
inline void
fscalin( const Givaro::ModularBalanced<float>& F , const size_t N,
const float a,
float * X, const size_t incX )
{
if(incX == 1) {
float p, invp;
p=(float)F.cardinality();
invp=a/p;
vectorised::scalp(X,a,X,N,p,invp,F.minElement(),F.maxElement());
}
else {
float * Xi = X ;
for (; Xi < X+N*incX; Xi+=incX )
F.mulin( *Xi , a);
}
}
template<>
inline void
fscalin( const Givaro::Modular<double>& F , const size_t N,
const double a,
double * X, const size_t incX )
{
if(incX == 1) {
double p, invp;
p=(double)F.cardinality();
invp=a/p;
vectorised::scalp(X,a,X,N,p,invp,0,p-1);
}
else {
double * Xi = X ;
for (; Xi < X+N*incX; Xi+=incX )
F.mulin( *Xi , a);
}
}
template<>
inline void
fscal( const Givaro::Modular<double>& F , const size_t N,
const double a,
const double * X, const size_t incX,
double * Y, const size_t incY )
{
if(incX == 1 && incY==1) {
double p, invp;
p=(double)F.cardinality();
invp=a/p;
vectorised::scalp(Y,a,X,N,p,invp,0,p-1);
}
else {
const double * Xi = X ;
double * Yi = Y ;
for (; Xi < X+N*incX; Xi+=incX,Yi+=incY )
F.mul(*Yi, *Xi , a);
}
}
template<>
inline void
fscalin( const Givaro::ModularBalanced<double>& F , const size_t N,
const double a,
double * X, const size_t incX )
{
if(incX == 1) {
double p, invp;
p=(double)F.cardinality();
invp=a/p;
vectorised::scalp(X,a,X,N,p,invp,F.minElement(),F.maxElement());
}
else {
double * Xi = X ;
for (; Xi < X+N*incX; Xi+=incX )
F.mulin( *Xi , a);
}
}
/***************************/
/* LEVEL 2 */
/***************************/
template<class Field>
void
fscalin (const Field& F, const size_t m , const size_t n,
const typename Field::Element a,
typename Field::Element_ptr A, const size_t lda)
{
if (F.isOne(a)) {
return ;
}
else if (F.isZero(a)) {
fzero(F,m,n,A,lda);
}
else if (F.isMOne(a)) {
fnegin(F,m,n,A,lda);
}
else {
if (lda == n) {
fscalin(F,n*m,a,A,1);
}
else {
for (size_t i = 0 ; i < m ; ++i)
fscalin(F,n,a,A+i*lda,1);
}
return;
}
}
template<class Field>
void
fscal (const Field& F, const size_t m , const size_t n,
const typename Field::Element a,
typename Field::ConstElement_ptr A, const size_t lda,
typename Field::Element_ptr B, const size_t ldb)
{
if (F.isOne(a)) {
fassign(F,m,n,A,lda,B,ldb) ;
}
else if (F.isZero(a)) {
fzero(F,m,n,B,ldb);
}
else if (F.isMOne(a)) {
fneg(F,m,n,A,lda,B,ldb);
}
else {
if (n == lda && m == lda)
fscal(F,m*n,a,A,lda,B,ldb);
else {
for (size_t i = 0; i < m ; ++i)
fscal(F,n,a,A+i*lda,1,B+i*ldb,1);
}
}
return;
}
} // FFLAS
#endif // __FFLASFFPACK_fscal_INL
|