     }
 
     __device__ inline
-    int sort( int my_index )
+    void swap( int& l, int& r )
+    {
+        int m = r;
+        r = l;
+        l = m;
+    }
+
+    __device__ inline
+    int sort32( int my_index )
     {
         for( int outer=0; outer<5; outer++ ) {
             for( int inner=outer; inner>=0; inner-- ) {
-                my_index = shiftit( my_index, inner, outer+1 );
+                my_index = shiftit( my_index, inner, outer+1, false );
             }
         }
         return my_index;
     }
 
+    __device__ inline
+    void sort64( int2& my_indeces )
+    {
+        for( int outer=0; outer<5; outer++ ) {
+            for( int inner=outer; inner>=0; inner-- ) {
+                my_indeces.x = shiftit( my_indeces.x, inner, outer+1, false );
+                my_indeces.y = shiftit( my_indeces.y, inner, outer+1, true );
+            }
+        }
+
+        if( _array[my_indeces.x] < _array[my_indeces.y] ) swap( my_indeces.x, my_indeces.y );
+
+        for( int outer=0; outer<5; outer++ ) {
+            for( int inner=outer; inner>=0; inner-- ) {
+                my_indeces.x = shiftit( my_indeces.x, inner, outer+1, false );
+                my_indeces.y = shiftit( my_indeces.y, inner, outer+1, false );
+            }
+        }
+    }
+
 private:
     __device__ inline
-    int shiftit( int my_index, int shift, int direction )
+    int shiftit( const int my_index, const int shift, const int direction, const bool increasing )
     {
         const T    my_val      = _array[my_index];
         const T    other_val   = __shfl_xor( my_val, 1 << shift );
         const bool my_less     = ( my_val < other_val );
         const bool reverse     = ( threadIdx.x & ( 1 << direction ) );
         const bool id_less     = ( ( threadIdx.x & ( 1 << shift ) ) == 0 );
-        const bool must_swap   = not ( my_less ^ id_less ^ reverse );
+        const bool must_swap   = not ( my_less ^ id_less ^ reverse ^ increasing );
 
         return ( must_swap ? __shfl_xor( my_index, 1 << shift )
                            : my_index );

}

__global__
void print_32( )
{
    for( int i=0; i<32; i++ ) {
        printf( "%d ", array_32[index_array_32[i]] );
    }
    printf("\n");
}


__device__ int array_32[32];
__device__ int index_array_32[32];
__device__ int array_64[64];
__device__ int index_array_64[64];

__global__
void sort_32( )
