Mercurial > hg > Game > Cerium
comparison 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 |
comparison
equal
deleted
inserted
replaced
2037:0b3d1d2863c8 | 2038:a78f8360c7f9 |
---|---|
5 static int | 5 static int |
6 swap(SchedTask* s, void* rbuf,void* wbuf) | 6 swap(SchedTask* s, void* rbuf,void* wbuf) |
7 { | 7 { |
8 int* inData = (int*)s->get_input(rbuf, 0); | 8 int* inData = (int*)s->get_input(rbuf, 0); |
9 int* outData = (int*)s->get_output(wbuf, 0); | 9 int* outData = (int*)s->get_output(wbuf, 0); |
10 long i = (long)s->get_param(0); | 10 long block = (long)s->get_param(0); |
11 long j = (long)s->get_param(1); | 11 bool first = (bool)s->get_param(1); |
12 int k = s->x; | 12 int x = s->x; |
13 | |
14 int position = x/block; | |
15 int index = x+block*position; | |
13 | 16 |
14 int point = j^k; | 17 block = first ? ((block<<1)*(position+1))-(index%block)-1 : index+block; |
15 int temp = inData[k]; | 18 |
16 | 19 if (inData[block] < inData[index]) { |
17 if (k < point) { | 20 int tmp = inData[index]; |
18 if ((i&k)==0 && inData[point] < inData[k]) { | 21 outData[index] = inData[block]; |
19 outData[k] = inData[point]; | 22 outData[block] = tmp; |
20 outData[point] = temp; | |
21 } | |
22 if ((i&k)!=0 && inData[k] < inData[point]) { | |
23 outData[k] = inData[point]; | |
24 outData[point] = temp; | |
25 } | |
26 } | 23 } |
27 | 24 |
28 return 0; | 25 return 0; |
29 } | 26 } |