Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.asm.x86    |    Ahh, the lost art of x86 assembly    |    4,675 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 2,854 of 4,675    |
|    Robert Prins to All    |
|    Process at read-in time, or use post-rea    |
|    19 Jul 17 13:03:43    |
   
   From: robert@nospicedham.prino.org   
      
   This question isn't specific x86, but given that the program incorporating this   
   change is mostly written in (inline) assembler, this might well be acceptable.   
      
   It was suggested that I add three "top-10/25/40" tables to an existing program   
   (yes, "that" program"), for distance, time (these two are mildly correlated),   
   and velocity, where equal values are tie-broken by a second sort-key, velocity,   
   distance, and distance.   
      
   The current input file contains just over 4,000 records, and is unlikely to   
   grow   
   much over 5,000.   
      
   The two options I seem to have is to read in the whole lot, and do three sorts   
   before the generation of the three new tables, or, but I have a strong gut   
   feeling, insert new max values into three tables at read-in time.   
      
   I only a "top-1" of max values would be required, this would without a grain of   
   doubt orders of magnitude faster than a final sort, and even generating a top-5   
   on-the-fly at read-in time might be faster (three times (up to) 20,000 compares   
   and re-ordering five items) then a full blown sort, but obviously(?) generating   
   a top-40 on the fly would be very expensive, both on compares and   
   data-movement.   
      
   What I have also been thinking about is a series of partial sorts, i.e. first   
   sort the whole set with a reasonably efficient algorithm (Shell?) into two   
   parts   
   and repeat that process with the top-half until the final top-ha   
   f/quarter/eight   
   is finally sorted completely - an initial thought that this might also reduce   
   the time to do the second sort (on time) turned out to be too optimistic one of   
   the top time-values is in the bottom of the distance half.   
      
   And finally, to the x86 nitty gritty, if only 32-bit code is possible, is there   
   a better way to do the compares than a   
      
   cmp a,b   
   jg ok   
   jne next   
      
   cmp c,d   
   jle next   
      
   ok:   
   process a(/c) > b(/d)   
      
   and second, is there an easy way to make this a generic process?   
      
   For what it's worth, I do have working Shellsort and Heapsort routines, so I'm   
   not really looking for code. I think they are quite efficiently coded, but   
   maybe   
   someone would like to have a look at the Shellsort code below, and point out if   
   there's any room for improvement - the code is followed by the original Pascal   
   code.   
      
   {************** Copyright (C) Robert AH Prins 1999-2015 ****************   
   * *   
   * This program is free software; you can redistribute it and/or modify *   
   * it under the terms of the GNU General Public License as published by *   
   * the Free Software Foundation; either version 3, or (at your option) *   
   * any later version. *   
   * *   
   * This program is distributed in the hope that it will be useful, *   
   * but WITHOUT ANY WARRANTY; without even the implied warranty of *   
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *   
   * GNU General Public License for more details. *   
   * *   
   * You should have received a copy of the GNU General Public License *   
   * along with this program; if not, write to the Free Software *   
   * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA *   
   ************************************************************************   
   * SORTWAIT: *   
   * *   
   * Sort the array of waits in wait/trip, trip/wait, country/wait or *   
   * year/wait order (using a Shell sort) *   
   ***********************************************************************}   
   {$ifdef asm}   
   procedure sortwait(mode: char; _wait: longint; var wait: _wait_ptr); assembler;   
   var _g : longint;   
   var _h : longint;   
   var _i : longint;   
   var _jh: longint;   
      
   var sort_wptr : liftptr;   
   var sort_trip : longint;   
   var sort_cnty : tycona; (* array [1..4] of char *)   
   var sort_year : longint;   
   var sort_wtime: longint;   
   const _gap : array [1..9] of longint =   
    (1, 4, 10, 23, 57, 132, 301, 701, 1750);   
      
   asm   
    //a-in sortwait   
    mov edx, _wait   
    cmp edx, 1   
    jle @17   
      
    shr edx, 1   
      
    mov ecx, offset _gap - 4   
    mov eax, 10   
      
   @01:   
    dec eax   
    cmp eax, 1   
    je @02   
      
    cmp edx, [ecx + eax * 4]   
    jl @01   
      
   @02:   
    mov _g, eax   
      
    mov esi, wait   
    mov esi, [esi]   
    sub esi, 4   
      
   @03:   
    mov eax, _g   
    mov eax, [eax * 4 + offset _gap - 4]   
    mov ecx, eax   
    inc eax   
    mov _i, eax   
      
   @04:   
    mov ebx, _i   
    mov edx, [ebx * 4 + esi]   
    mov sort_wptr, edx   
      
    mov eax, [edx + offset lift_list.trip]   
    mov sort_trip, eax   
      
    mov eax, [edx + offset lift_list.s_cnty]   
    bswap eax   
    mov sort_cnty, eax   
      
    mov eax, [edx + offset lift_list.date.dyear]   
    mov sort_year, eax   
      
    mov eax, [edx + offset lift_list.wtime]   
    mov sort_wtime, eax   
      
    mov eax, ebx   
    sub eax, ecx   
    mov edi, eax   
      
    mov eax, ecx   
      
    cmp mode, " "   
    jne @07   
      
   @05:   
    inc eax   
    cmp eax, ebx   
    jg @16   
      
    mov edx, [edi * 4 + esi]   
      
    mov eax, [edx + offset lift_list.wtime]   
    cmp eax, sort_wtime   
    jg @06   
    jne @16   
      
    mov eax, [edx + offset lift_list.trip]   
    cmp eax, sort_trip   
    jle @16   
      
   @06:   
    mov [ebx * 4 + esi], edx   
      
    mov eax, ecx   
    sub ebx, eax   
    sub edi, eax   
    jmp @05   
      
   @07:   
    cmp mode, "T"   
    jne @10   
      
   @08:   
    inc eax   
    cmp eax, ebx   
    jg @16   
      
    mov edx, [edi * 4 + esi]   
      
    mov eax, [edx + offset lift_list.trip]   
    cmp eax, sort_trip   
    jg @09   
    jne @16   
      
    mov eax, [edx + offset lift_list.wtime]   
    cmp eax, sort_wtime   
    jle @16   
      
   @09:   
    mov [ebx * 4 + esi], edx   
      
    mov eax, ecx   
    sub ebx, eax   
    sub edi, eax   
    jmp @08   
      
   @10:   
    cmp mode, "C"   
    jne @13   
      
   @11:   
    inc eax   
    cmp eax, ebx   
    jg @16   
      
    mov edx, [edi * 4 + esi]   
      
    mov eax, [edx + offset lift_list.s_cnty]   
    bswap eax   
    cmp eax, sort_cnty   
    jg @12   
    jne @16   
      
    mov eax, [edx + offset lift_list.wtime]   
    cmp eax, sort_wtime   
    jle @16   
      
   @12:   
    mov [ebx * 4 + esi], edx   
      
    mov eax, ecx   
    sub ebx, eax   
    sub edi, eax   
    jmp @11   
      
   @13:   
    cmp mode, "Y"   
    jne @16   
      
   @14:   
    inc eax   
    cmp eax, ebx   
    jg @16   
      
    mov edx, [edi * 4 + esi]   
      
    mov eax, [edx + offset lift_list.date.dyear]   
    cmp eax, sort_year   
    jg @15   
    jne @16   
      
    mov eax, [edx + offset lift_list.wtime]   
      
   [continued in next message]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca