home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 110_01 / bytebnch.c < prev    next >
Text File  |  1984-03-03  |  7KB  |  158 lines

  1. /*
  2.  * For BDS C, a quicker version of prime number prog in Sep 81 BYTE p. 186
  3.  * Timings (Bell to Bell)
  4.  *    ZPU (4mHz)    13.7 Seconds
  5.  *    Z89 (2mHz)    28.0 Seconds
  6.  */
  7. #include "A:BDSCIO.H"
  8. #define TRUE 1
  9. #define FALSE 0
  10. #define SIZE 8190
  11. #define SIZEP1 8191
  12.  
  13. char flags[SIZEP1], *p,*s;
  14. int i,prime,count,iter;
  15.  
  16. main()
  17. {
  18.     printf("10 Iterations\007\n");
  19.     for(iter=10; --iter>=0;) {
  20.         count=0;
  21.         setmem(flags, SIZE, TRUE);
  22.  
  23.         for(p=flags+(i= -1); ++i<=SIZE;) {
  24.             if(*++p) {
  25.                 prime= i+i+3;
  26.                 for(s=p; (s+=prime)<=(flags+SIZE);)
  27.                     *s = FALSE;
  28.                 ++count;
  29.                 /*printf("%d\n",prime);*/
  30.             }
  31.         }
  32.     }
  33.     printf("\n%d primes\007", count);
  34. }
  35.  
  36. /* submit file for above
  37. xsub
  38. cc1 b:bytebnch.c -e 1000 -o
  39. clink b:bytebnch -d
  40. 50.9 seconds RETURN to first bell with Z89 and dd 8" drives (Magnolia)
  41.  
  42. Observations:
  43.     C compilers are notoriously inefficient at optimizing subscript
  44. calculations.  In many cases, such as the above, array indexing can be
  45. replaced by pointer arithmetic, a more idiomatic usage of C.
  46.     A few of the "tricks" I used for BDS C:
  47.     0.  All array refrences were recoded as pointer arithmetic.  Pointers
  48. are one of C's great strength, so use them when performance is critical.
  49.     1.  All variables were made external. This places them in fixed
  50. memory locations which can be accesses by direct addressing on the 8080.
  51.     2.  The array is cleared by "setmem", a function provided in the
  52. BDS C library, which corresponds to "aryset" in ZSPL.  This would be faster
  53. than a loop coded in BDS C.
  54.     3.  Combining operations may produce better code.  On machines such as
  55. the 8080 or even 8086, arithmetic operations are carried out in an accumulator,
  56. so try to avoid unnecessary loads and stores.
  57.     4.  When the value is needed, preincrement and predecrement wins
  58. over postincrement.  When postincrement is used, a copy of the old value must
  59. be saved, then the increment takes place, and finally the saved copy of the
  60. old value is used.  Much quicker to modify the value, then use it.
  61.     5.  Note that some of the choices would not be optimal for a machine
  62. such as the PDP-11 or 68000, whose hardware supports address autoincrement.
  63. However, the program will still be correct!
  64. 8-4-81
  65. Chuck Forsberg
  66. Computer Development Inc
  67. Beaverton OR
  68. RCP/M 503/621-3193 (300,450,1200baud: 24hrs intermittent)
  69.  
  70. */es by direct addressing on the 8080.
  71.     2.  The array is cleared by "setmem", tion 1A to 4F, 1B to 20, and 1C to 11.
  72. e0a 00w        set buffer location 0a to 0 and write buffer
  73.             Note no space after last data                     YAM (Yet Another Modem program)
  74.  
  75.                            by Chuck Forsberg
  76.  
  77.                          Manual Revised 8-29-81
  78.  
  79.  YAM  performs  a  number  of  "Super-Terminal"  functions.  It may be
  80.  regarded  as  a  (not  proper)  superset  of  MODEM7.   Commands  and
  81.  subcommands are listed below.
  82.  
  83.  XYAM is a version of yam which corresponds to XMODEM.
  84.  
  85.  
  86.  
  87.  a:               Change to a: disk (or b, etc.)
  88.  
  89.  a1:              Change to a: disk user 1
  90.  
  91.  bm               Set baudrate to m.  Example: "b19200"
  92.  
  93.  bye              Drop any call in progress and prepare to make/answer
  94.                   another.
  95.  
  96.  call name        Enable Data  Terminal  Ready (DTR), and set baudrate
  97.                   to the value (if present) corresponding to name.  If
  98.                   autodial is supported,  dial  the telephone number.
  99.                   If autodial is not  supported,  the telephone number
  100.                   and  preferred baudrate are displayed.   It  is  not
  101.                   necessary to type the entire  name  as it appears in
  102.                   the file.  Example: "call tcbbs" or "call tc"
  103.  
  104.  close            Dump cpature buffer if a recrive file is open, close
  105.                   files.
  106.  
  107.  dir [pattern ...] Display  pathnames  matching  pattern  alphabetized
  108.                   across the page.  The usual  ambiguous filenames are
  109.                   allowed under CP/M  provided  a  correct  version of
  110.                   setfcb() is used.   Since  dir or any other commands
  111.                   which  accept  a pattern use the circular buffer for
  112.                   filename  expansion,  be  sure  to  write  out   any
  113.                   captured data first!  Example: "dir" "dir  *.c" "dir
  114.                   *.c *.h"
  115.  
  116.  dirr [pattern ...]
  117.                   Displays the directory with the number of sectors in
  118.                   each file.  The  number  of files matched, number of
  119.                   blocks,  number  of kb allocated to those files, and
  120.                   estimated  transmission time at the current baudrate
  121.                   for  all  files  listed are displayed.  Transmission
  122.                   time estimate is  based on batch transmission from a
  123.                   Z89 with 700kb Tandon drives to a Cromenco 4mHz 4fdc
  124.                   system  with  Persci  277 drive.  Time includes file
  125.                   i/o but not error correction.
  126.  
  127.  d{mode}           Disable  mode,  where  mode is 1  or  more  of  the
  128.                   following.        (Modes       affecting        file
  129.                   transmission/reception affect term mode; the "s" and
  130.                   "r" commands always send data transparently.
  131.  
  132.                   e              Exit  from  term  mode  when  EOF  is
  133.                                encountered on transmitted file.
  134.  
  135.                   f            Full duplex.
  136.  
  137.                   h            Half Duplex.
  138.  
  139.                   g            Resumes (GO) sending  file once in term
  140.                                mode, equivalent to XON.
  141.  
  142.                   i            Image transparent  data  capture, all 8
  143.                                bits   of  all   characters   received,
  144.                                including NULLS. This  overrides  the t
  145.                                and/or z modes.
  146.  
  147.                   l             List  unit  (Printer)  on.   Since the
  148.                                printer   is  separately  buffered,  it
  149.                                needn't be as fast as the incoming data
  150.                                as   long  as  the  difference  doesn't
  151.                                exceed  the  buffer  size.   The rewind
  152.                                command may be used to get extra copies
  153.                                of the received data.
  154.  
  155.                   n               Send   NEWLINE   (lf)   only    when
  156.                                transmitting file (no CR).
  157.  
  158.