home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / fortran / 3302 < prev    next >
Encoding:
Internet Message Format  |  1992-08-31  |  3.8 KB

  1. Path: sparky!uunet!olivea!decwrl!sdd.hp.com!cs.utexas.edu!hellgate.utah.edu!lanl!cochiti.lanl.gov!jlg
  2. From: jlg@cochiti.lanl.gov (Jim Giles)
  3. Newsgroups: comp.lang.fortran
  4. Subject: Re: Scientists as Programmers (was Re: Smal
  5. Message-ID: <1992Aug31.164354.3518@newshost.lanl.gov>
  6. Date: 31 Aug 92 16:43:54 GMT
  7. References: <BttB9z.IAy@mentor.cc.purdue.edu> <1992Aug30.232409.15262@nrao.edu> <1992Aug31.163405.2169@newshost.lanl.gov>
  8. Sender: (null)@(null) ((null))
  9. Organization: Los Alamos National Laboratory
  10. Lines: 72
  11.  
  12. In article <1992Aug30.232409.15262@nrao.edu>, cflatter@nrao.edu (Chris Flatters) writes:
  13. |> [...]
  14. |> Subroutine calls are not that expensive.  Here are some examples.
  15. |> 
  16. |>         function call+return        double precision fp operation
  17. |>         (average time in us)             (average time in us)
  18. |> 
  19. |> SPARCstation IPX     0.115                    0.146
  20. |> 25 MHz 386SX/387SX     1.75                    3.37
  21. |> 
  22. |> (IPX timing from Sun C++ 2.1 using -O4; 386SX/387SX timing taken from
  23. |> GNU C 1.39 with -O under 386BSD 0.1).  Unless the work carried out in
  24. |> a subroutine is trivial the overhead of a function call can be discounted.
  25.  
  26. Very good, you've fallen into the trap of listing the call and return
  27. *instructions* as the only cost of the call.  The *real* cost is in
  28. register scheduling (including canonical interface protocols) around
  29. the call, as well as a break in optimization basic-blocks (and many `live'
  30. values must be assumed `killed' by the call).  Herman Rubin was right
  31. to begin with, procedure calls are, and will remain for a long time, 
  32. among the most expensive of operations.  Calls would be expensive even if
  33. the specific branch instructions used to implement and return from them
  34. were *free*.
  35.  
  36. |> [...]
  37. |> It is rarely necessary to violate type constraints in a strongly typed language.
  38. |> When it is necessary it is possible to localize the code that does this.  Most
  39. |> typesafe languages provide mechanisms to avoid the constraints of the type
  40. |> system in these rare cases (eg. the WORD data type in Modula 2).
  41.  
  42. The definition of the term `strongly typed' is that the types of all
  43. expressions are known to the compiler at compile time (it would be
  44. preferable if that were called static typing, but that's now used to
  45. mean that the data is statically *allocated* - oh well).  It is, however,
  46. *often* useful to be able to violate type constraints (if you know what
  47. you're doing - it's always a machine/system dependent thing to do).
  48.  
  49. No one is recommending (and Herman didn't) that strict typing be abandoned.
  50. It is possible to have type coercion and *still* be able to statically
  51. determine type.  For example, the following declaration might be introduced
  52. (in no particular language):
  53.  
  54.       float :: x(500)
  55.       type float_internal is
  56.          bit.1  :: sign
  57.          bit.8  :: exponent
  58.          bit.23 :: significand
  59.       end type float_internal
  60.       map x as float_internal    ! overlay the structure of floats on the array
  61.       ...
  62.       x.sign(1) = x.sign(1)+1    ! change the sign of x(1)
  63.       x.exponent(5) = x.exponent(5)+1    ! multiply x(5) by 2
  64.  
  65. This is much better than some anonymous `word' type.  Notice that 
  66. everything used above is strongly typed.  The notion of `bit.n' as 
  67. being n-bit unsigned integers was used, as well as the notion that 
  68. a structure or record of such things is *packed* and remains in 
  69. the order declared.  The only thing machine dependent is the map
  70. itself: otherwise the struct, or its components, behave exactly 
  71. as any other objects of their respective declared types.
  72.  
  73. |> [...]
  74. |> Restrictions on the introduction of new operators arise from practical
  75. |> considerations.  The introduction of a new infix operator changes the
  76. |> syntax of the language significantly.
  77.  
  78. Well, it depends on how your syntax is specified and processed.  Haskell
  79. allows just about anything to be used as an operator and yet never has
  80. its syntax changed by user definitions.
  81.  
  82. -- 
  83. J. Giles
  84.