53 #pragma global noalias 56 #pragma cdir options -pvctl,nodep 59 #if defined(VPP) || defined(NECSX) 74 typedef long long int ll_t;
76 #define ALLOC(x,size) \ 77 { ll_t bytes = (ll_t)sizeof(*x) * (size); \ 78 bytes = (bytes < 1) ? 1 : bytes; \ 79 x = THEmalloc(bytes); \ 80 if (!x) { fprintf(stderr, \ 81 "malloc() of %s (%lld bytes) failed in file=%s, line=%d\n", \ 82 #x, bytes, __FILE__, __LINE__); RAISE(SIGABRT); } } 84 #define FREE(x) if (x) { THEfree(x); x = NULL; } 86 #define BITSUM(x) bitsum[x] += ((item >> x) & 1U) 88 #define SIGNBIT32 0x80000000 89 #define MASKALL32 0xFFFFFFFF 90 #define ZEROALL32 0x00000000 92 #define CVMGM(a,b,c) ( ((c) & SIGNBIT32) ? (a) : (b) ) 100 const int *Start_addr,
103 const int *Index_adj,
111 int index_adj = *Index_adj;
112 int addr = (*Start_addr) - 1;
116 Uchar alloc_data = 0;
122 if (method != SORT_UINT &&
123 method != SORT_INT &&
124 method != SORT_R64 &&
125 method != SORT_R32 &&
126 method != SORT_I64 &&
127 method != SORT_U64 ) {
158 if (method == SORT_R64 ||
159 method == SORT_I64 ||
160 method == SORT_U64) {
167 for (i=0; i<
n; i++) index[i] = i + index_adj;
170 alloc_data = ((inc > 1)
171 || (method == SORT_R32)
172 || (method == SORT_R64)
173 || (method == SORT_I64)
174 || (method == SORT_U64)
176 if (alloc_data) ALLOC(data, n);
178 if (method == SORT_R32) {
183 for (i=0; i<
n; i++) {
184 Uint32 mask = CVMGM(MASKALL32, SIGNBIT32, Data[j]);
185 data[
i] = Data[j] ^
mask;
191 else if (method == SORT_R64) {
192 int Method = 10 + SORT_UINT;
193 const int aStart_addr = 1;
196 int aIndex_adj = index_adj;
204 for (i=0; i<
n; i++) {
205 Uint32 mask = CVMGM(MASKALL32, ZEROALL32, Data[jj]);
206 data[
i] = Data[j] ^
mask;
211 rsort32_(&Method, &aN, &aInc, &aStart_addr, data, index, &aIndex_adj, &rc);
213 if (rc != n)
goto finish;
220 for (i=0; i<
n; i++) {
221 Uint32 mask = CVMGM(MASKALL32, SIGNBIT32, Data[jj]);
222 data[
i] = Data[jj] ^
mask;
228 else if (method == SORT_I64 || method == SORT_U64) {
229 int Method = 10 + SORT_UINT;
230 const int aStart_addr = 1;
233 int aIndex_adj = index_adj;
237 for (i=0; i<
n; i++) {
242 rsort32_(&Method, &aN, &aInc, &aStart_addr, data, index, &aIndex_adj, &rc);
244 if (rc != n)
goto finish;
247 if (method == SORT_I64) {
249 for (i=0; i<
n; i++) {
250 data[
i] = Data[jj] ^ SIGNBIT32;
256 for (i=0; i<
n; i++) {
269 for (i=0; i<
n; i++) {
278 xorit = (method == SORT_INT);
282 for (j=0; j<N32BITS; j++) bitsum[j] = 0;
284 for (i=0; i<
n; i++) {
286 if (xorit) data[
i] ^= SIGNBIT32;
289 BITSUM(0) ; BITSUM(1) ; BITSUM(2) ; BITSUM(3) ;
290 BITSUM(4) ; BITSUM(5) ; BITSUM(6) ; BITSUM(7) ;
291 BITSUM(8) ; BITSUM(9) ; BITSUM(10); BITSUM(11);
292 BITSUM(12); BITSUM(13); BITSUM(14); BITSUM(15);
293 BITSUM(16); BITSUM(17); BITSUM(18); BITSUM(19);
294 BITSUM(20); BITSUM(21); BITSUM(22); BITSUM(23);
295 BITSUM(24); BITSUM(25); BITSUM(26); BITSUM(27);
296 BITSUM(28); BITSUM(29); BITSUM(30); BITSUM(31);
302 for (j=0; j<N32BITS; j++) {
304 if (sum > 0 && sum < n) {
325 if ( (data[i1[i]-index_adj] & mask) == 0 ) i2[k++] = i1[i];
331 if ( (data[i1[i]-index_adj] & mask) ==
mask ) i2[k++] = i1[i];
335 int k1 = 0, k2 = n-
sum;
339 for (i=0; i<
n; i++) {
341 i2[value == 0 ? k1++ : k2++] = i1[
i];
343 if (k1 + sum != n || k2 != n) {
345 "***Programming error in rsort32_(): k1 + sum != n || k2 != n; k1=%d,k2=%d,sum=%d,n=%d\n",
359 for (i=0; i<
n; i++) index[i] = tmp[i];
364 if (!alloc_data && xorit && inc == 1) {
366 for (i=0; i<
n; i++) data[i] ^= SIGNBIT32;
369 if (alloc_data) FREE(data);
381 const int *Start_addr,
384 const int *Index_adj,
390 int index_adj = *Index_adj;
392 if (method == SORT_INT && index_adj == 1) {
393 jisort_( N, Inc, Start_addr, Data, index );
396 else if (method == SORT_R64 && index_adj == 1) {
397 jdsort_( N, Inc, Start_addr, Data, index );
401 rsort32_(Mode, N, Inc, Start_addr, Data, index, Index_adj, retc);
405 rsort32_(Mode, N, Inc, Start_addr, Data, index, Index_adj, retc);
414 const int *Start_addr,
417 const int *Index_adj,
430 const int *Start_addr,
433 const int *Index_adj,
450 const int *Start_addr,
453 const int *Index_adj,
458 if (speedup)
SpeedUp = *speedup;
void rsort32_ibm_(const int *Mode, const int *N, const int *Inc, const int *Start_addr, Uint32 Data[], int index[], const int *Index_adj, int *retc)
void rsort32_setup_(void(*func)(const int *Mode, const int *N, const int *Inc, const int *Start_addr, Uint32 Data[], int index[], const int *Index_adj, int *retc), int *speedup)
static void(* default_rsort32_func)(const int *Mode, const int *N, const int *Inc, const int *Start_addr, Uint32 Data[], int index[], const int *Index_adj, int *retc)
void rsort32_(const int *Mode, const int *N, const int *Inc, const int *Start_addr, Uint32 Data[], int index[], const int *Index_adj, int *retc)
int ec_is_little_endian()
intent(out) overrides sub arrays one Sort by the least significant key first sum(iindex(1:n))
void rsort32_func_(const int *Mode, const int *N, const int *Inc, const int *Start_addr, Uint32 Data[], int index[], const int *Index_adj, int *retc)