view example/bitonic_sort/ppe/swap.cc @ 2038:a78f8360c7f9 draft

modify bitonic sort. use sorting network
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Sat, 07 Feb 2015 02:34:46 +0900
parents 0b3d1d2863c8
children bc010492ade4
line wrap: on
line source

#include "swap.h"

SchedDefineTask1(swap,swap);

static int
swap(SchedTask* s, void* rbuf,void* wbuf)
{
    int* inData = (int*)s->get_input(rbuf, 0);
    int* outData = (int*)s->get_output(wbuf, 0);
    long block = (long)s->get_param(0);
    bool first = (bool)s->get_param(1);
    int x = s->x;
    
    int position = x/block;
    int index = x+block*position;

    block = first ? ((block<<1)*(position+1))-(index%block)-1 : index+block;
    
    if (inData[block] < inData[index]) {
        int tmp = inData[index];
        outData[index] = inData[block];
        outData[block] = tmp;
    }
    
    return 0;
}