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
#include <ulmblas.h>

void
ULMBLAS(dswap)(const int n,
               double    *x,
               const int incX,
               double    *y,
               const int incY)
{
//
//  Local scalars
//
    int    i, m;
    double tmp;

//
//  Quick return if possible
//
    if (n==0) {
        return;
    }
    if (incX==1 && incY==1) {
//
//      Code for both increments equal to 1
//
        m = n % 3;
        if (m!=0) {
            for (i=0; i<m; ++i) {
                tmp  =  x[i];
                x[i] = y[i];
                y[i] = tmp;
            }
            if (n<3) {
                return;
            }
        }
        for (i=m; i<n; i+=3) {
            tmp  =  x[i];
            x[i] = y[i];
            y[i] = tmp;

            tmp    =  x[i+1];
            x[i+1] = y[i+1];
            y[i+1] = tmp;

            tmp    =  x[i+2];
            x[i+2] = y[i+2];
            y[i+2] = tmp;
        }
    } else {
//
//      Code for unequal increments or equal increments not equal to 1
//
        if (incX<0) {
            x -= incX*(n-1);
        }
        if (incY<0) {
            y -= incY*(n-1);
        }
        for (i=0; i<n; ++i, x+=incX, y+=incY) {
            tmp = *x;
            *x  = *y;
            *y  = tmp;
        }
    }
}

void
F77BLAS(dswap)(const int *_n,
               double    *x,
               const int *_incX,
               double    *y,
               const int *_incY)
{
//
//  Dereference scalar parameters
//
    int n    = *_n;
    int incX = *_incX;
    int incY = *_incY;

    ULMBLAS(dswap)(n, x, incX, y, incY);
}