home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / virus / ddj0491.zip / 386BSD.491 next >
Text File  |  1991-03-15  |  3KB  |  73 lines

  1. _PORTING UNIX TO THE 386: LANGUAGE TOOLS CROSS SUPPORT_
  2. by William Frederick Jolitz and Lynne Greer Jolitz
  3.  
  4. [LISTING ONE]
  5.  
  6. /* fixdfsi.s: Copyright (c) 1990 William Jolitz. All rights reserved.
  7.  * Written by William Jolitz 1/90
  8.  * Redistribution and use in source and binary forms are freely permitted
  9.  * provided that the above copyright notice and attribution and date of work
  10.  * and this paragraph are duplicated in all such forms.
  11.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  12.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  13.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  14.  * GCC compiler support function, truncates a double float into a signed long.
  15.  */
  16.  
  17.     .globl ___fixdfsi
  18. ___fixdfsi:
  19.     pushl   $0xe7f      /* truncate, long real, mask all */
  20.     fnstcw  2(%esp)     /* save my old control word */
  21.     fldcw   (%esp)      /* load truncating one */
  22.  
  23.     fldl    8(%esp)     /* load double */
  24.     fistpl  8(%esp)     /* store back as an integer */
  25.     fldcw   2(%esp)     /* load prior control word */
  26.     popl    %eax
  27.     movl    4(%esp),%eax
  28.     ret
  29.  
  30.  
  31. [LISTING TWO]
  32.  
  33. /* fixunsdfsi.s: Copyright (c) 1990 William Jolitz. All rights reserved.
  34.  * Written by William Jolitz 4/90
  35.  * Redistribution and use in source and binary forms are freely permitted
  36.  * provided that the above copyright notice and attribution and date of work
  37.  * and this paragraph are duplicated in all such forms.
  38.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  39.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  40.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  41.  * GCC compiler support function, truncates a double float into unsigned long.
  42.  */
  43.  
  44.     .globl ___fixunsdfsi
  45. ___fixunsdfsi:
  46.     pushl   $0xe7f          /* truncate, long real, mask all */
  47.     fnstcw  2(%esp)         /* save my old control word */
  48.     fldcw   (%esp)          /* load truncating one */
  49.     fldl    8(%esp)         /* argument double to accum stack */
  50.     frndint             /* create integer */
  51.     fcoml   fbiggestsigned      /* bigger than biggest signed? */
  52.     fstsw   %ax
  53.     sahf
  54.     jnb 1f
  55.     
  56.     fistpl  8(%esp)
  57.     fldcw   2(%esp)         /* load prior control word */
  58.     popl    %eax
  59.     movl    4(%esp),%eax
  60.     ret
  61.  
  62. 1:  fsubl   fbiggestsigned      /* reduce for proper conversion */
  63.     fistpl  8(%esp)         /* convert */
  64.     fldcw   2(%esp)         /* load prior control word */
  65.     popl    %eax
  66.     movl    4(%esp),%eax
  67.     addl    $2147483648,%eax    /* restore bias of 2^31 */
  68.     ret
  69.  
  70. fbiggestsigned: .double 0r2147483648.0  /* 2^31 */
  71.  
  72.  
  73.