The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: grog@lemis.com (Greg 'groggy' Lehey)
Subject: [TUHS] arithmetic IF (was origin of string.h and ctype.h)
Date: Thu, 17 Aug 2017 09:54:19 +1000	[thread overview]
Message-ID: <20170816235419.GA91313@eureka.lemis.com> (raw)
In-Reply-To: <CABH=_VR3_Fp6Fw4weAC0n-Q-sFbs+-L-zmpTXPCSSQXUzP0TmA@mail.gmail.com>

On Wednesday, 16 August 2017 at 14:04:47 -0400, Paul Winalski wrote:
> On 8/16/17, Doug McIlroy <doug at cs.dartmouth.edu> wrote:
>>>> the 709 added CAS
>>
>>> It was my understanding that the 704 had this instruction too
>>
>> Yes. It's in the manual.
>>
>> (I searched in vain for an online manual. A quick trip to the
>> attic turned up the real thing in less time.)
>
> From what I've been able to determine, FORTRAN came out shortly
> after the IBM 704.  Undoubtedly both were under development at the
> same time.

I think there's some doubt about those statements.  The 704 was
introduced in 1954, and FORTRAN didn't appear until late 1956 or 1957.
That's a long time in the history of computing.

> So the question is, was arithmetic IF put in FORTRAN to take
> advantage of the CAS instruction, or was CAS added to the IBM 704
> instruction set to provide hardware support for arithmetic IF?  Or
> maybe neither?

I think the arithmetic IF was put into FORTRAN because it was easy to
implement with the CAS instruction.  It doesn't make much sense from a
mathematical point of view.

> According to the Wikipedia article on FORTRAN, CAS was usually not the
> most efficient way to implement arithmetic IF anyway.  CAS takes up
> four words of memory and takes three cycles to execute, whereas you
> can do it in two words and two cycles with the transfer instructions.

Looking at the assembly listings of the FORTRAN II compiler
(http://www.softwarepreservation.org/projects/FORTRAN/source/fortran-ii/fort1.lst.html,
mentioned by Paul McJones), a typical use of CAS is followed by two
unconditional TRA (transfer) instructions and further code, though
presumably early FORTRAN compilers would not optimize in this way.
Timing includes loading an operand from memory.  The conditional
transfer instructions are based on accumulator contents, so you'd need
to perform some arithmetic operation first, in the process possibly
destroying accumulator contents that you want.

Doubtless you're right in some (many) cases, but my guess is that the
authors of FORTRAN were looking for the cheapest solution, not the
fastest one.  For decades to come, the fastest solution was assembler.

Greg
--
Sent from my desktop computer.
Finger grog at lemis.com for PGP public key.
See complete headers for address and phone numbers.
This message is digitally signed.  If your Microsoft mail program
reports problems, please read http://lemis.com/broken-MUA
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 163 bytes
Desc: not available
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20170817/fc50a99c/attachment.sig>


  reply	other threads:[~2017-08-16 23:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-16 18:04 Paul Winalski
2017-08-16 23:54 ` Greg 'groggy' Lehey [this message]
2017-08-17 14:04   ` arnold
2017-08-17 13:38 Doug McIlroy
2017-08-17 15:14 Doug McIlroy
     [not found] <mailman.921.1502995544.3779.tuhs@minnie.tuhs.org>
2017-08-17 22:19 ` Paul McJones
2017-08-18 10:49   ` arnold

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170816235419.GA91313@eureka.lemis.com \
    --to=grog@lemis.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).