[TUHS] arithmetic IF (was origin of string.h and ctype.h)

Greg 'groggy' Lehey grog at lemis.com
Thu Aug 17 09:54:19 AEST 2017


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>


More information about the TUHS mailing list