From: Jos v.d.V. <jo...@us...> - 2017-02-10 11:39:59
|
Update of /cvsroot/win32forth/win32forth/src/kernel In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv24485 Modified Files: fkernel.f Log Message: Jos: The code came from Herbert Weidner. The new CELL-SORT ( insertionsort ) is more than 10 times faster. And if one record is changed in an array of 200,000 records then the sort is more than 10 times faster than a quick sort. Index: fkernel.f =================================================================== RCS file: /cvsroot/win32forth/win32forth/src/kernel/fkernel.f,v retrieving revision 1.105 retrieving revision 1.106 diff -C2 -d -r1.105 -r1.106 *** fkernel.f 8 Jan 2016 16:05:36 -0000 1.105 --- fkernel.f 10 Feb 2017 11:39:57 -0000 1.106 *************** *** 1807,1831 **** next c; ! CODE CELL-SORT ( a1 n1 -- ) \ perform in place sort buffer a1 of n1 cells ! push ebx ! cmp ebx, # 2 \ don't sort if less than 2 elements ! jnl short @@2 ! jmp short @@3 ! @@1: mov eax, 0 [ebx] ! xchg eax, 4 [ebx] ! xchg eax, 0 [ebx] ! cmp eax, 0 [ebx] ! jl short @@1 ! add ebx, # 4 ! loop @@1 ! @@2: pop ecx ! pop ebx ! push ebx ! sub ecx, # 1 ! push ecx ! jg short @@1 ! @@3: add esp, # 8 ! pop ebx ! next c; CODE BYTE-SORT ( a1 n1 -- ) \ perform in place sort buffer a1 of n1 bytes --- 1807,1838 ---- next c; ! CODE CELL-SORT ( a1 n1 -- ) \ perform in place sort buffer a1 of n1 cells ! mov eax, ebx ! cmp eax, # 2 \ don't sort if less than 2 elements ! jnl short @@9 ! pop ebx \ No sort remove adr ! jmp short @@5 ! @@9: pop ecx \ adr ! push edx \ save UP ! push esi ! mov eax, # 1 \ counter do-loop (i) ! @@1: mov edx, 0 [ecx] [eax*4] \ insertion sort value ! mov esi, eax \ j ! @@4: mov edi, -4 [ecx] [esi*4] \ A[j-1] ! cmp edx, edi ! jge short @@2 \ for unsigned numbers use jae ! mov 0 [ecx] [esi*4], edi \ destination ! dec esi \ j>0? ! jne short @@4 ! @@2: mov [ecx] [esi*4], edx \ insertion sort value ! inc eax ! cmp eax, ebx \ All done? ! jne short @@1 ! pop esi ! pop edx ! @@5: ! pop ebx \ stack ok ! xor edi, edi \ should be 0 ! next c; CODE BYTE-SORT ( a1 n1 -- ) \ perform in place sort buffer a1 of n1 bytes |