@@ -163,13 +163,23 @@ SORT_IMPL(stable_node)( SORT_KEY_T * x,
163
163
/* Note that nl and nr are both at least one at this point so at least
164
164
one interation of the loop body is necessary. */
165
165
166
- do {
166
+ for (;;) { /* Minimal C language operations */
167
+ if ( SORT_BEFORE ( yr [k ], yl [j ] ) ) {
168
+ x [i ++ ] = yr [k ++ ];
169
+ if ( k >=nr ) { /* append left stragglers (at least one) */ do x [i ++ ] = yl [j ++ ]; while ( j < nl ); break ; }
170
+ } else {
171
+ x [i ++ ] = yl [j ++ ];
172
+ if ( j >=nl ) { /* append right stragglers (at least one) */ do x [i ++ ] = yr [k ++ ]; while ( k < nr ); break ; }
173
+ }
174
+ }
175
+
176
+ # if 0 /* These variants of the above don't seem to produce much better code */
177
+ do { /* Single loop exit */
167
178
if ( SORT_BEFORE ( yr [k ], yl [j ] ) ) x [i ++ ] = yr [k ++ ];
168
179
else x [i ++ ] = yl [j ++ ];
169
180
} while ( (j < nl ) && (k < nr ) );
170
181
171
- # if 0 /* These variants of the above don't seem to produce much better code */
172
- do { /* Minimal mem ops and branching */
182
+ do { /* Single loop exit, minimal mem ops and branching */
173
183
SORT_KEY_T yj = yl [j ];
174
184
SORT_KEY_T yk = yr [k ];
175
185
int c = SORT_BEFORE ( yk , yj );
@@ -178,34 +188,22 @@ SORT_IMPL(stable_node)( SORT_KEY_T * x,
178
188
k += (SORT_IDX_T ) c ;
179
189
} while ( (j < nl ) & (k < nr ) );
180
190
181
- do { /* Minimal mem ops */
191
+ do { /* Single loop exit, Minimal mem ops */
182
192
SORT_KEY_T yj = yl [j ];
183
193
SORT_KEY_T yk = yr [k ];
184
194
if ( SORT_BEFORE ( yk , yj ) ) x [i ++ ] = yk , k ++ ;
185
195
else x [i ++ ] = yj , j ++ ;
186
196
} while ( (j < nl ) && (k < nr ) );
187
197
188
- do { /* Trinary variant of above */
198
+ do { /* Single loop exit, trinary variant of above */
189
199
x [i ++ ] = SORT_BEFORE ( yr [k ], yl [j ] ) ? yr [k ++ ] : yl [j ++ ];
190
200
} while ( (j < nl ) && (k < nr ) );
191
201
192
- for (;;) { /* Minimal mem ops and exit condition tests */
193
- SORT_KEY_T yj = yl [j ];
194
- SORT_KEY_T yk = yr [k ];
195
- if ( SORT_BEFORE ( yk , yj ) ) { x [i ++ ] = yk ; k ++ ; if ( k >=nr ) break ; }
196
- else { x [i ++ ] = yj ; j ++ ; if ( j >=nl ) break ; }
197
- }
198
-
199
- for (;;) { /* Minimal exit condition tests */
200
- if ( SORT_BEFORE ( yr [k ], yl [j ] ) ) { x [i ++ ] = yr [k ]; k ++ ; if ( k >=nr ) break ; }
201
- else { x [i ++ ] = yl [j ]; j ++ ; if ( j >=nl ) break ; }
202
- }
203
- # endif
204
-
205
202
/* Append any stragglers */
206
203
207
204
if ( j < nl ) do x [i ++ ] = yl [j ++ ]; while ( j < nl );
208
205
else do x [i ++ ] = yr [k ++ ]; while ( k < nr );
206
+ # endif
209
207
210
208
return x ;
211
209
}
0 commit comments