handling arithmei'ic error conditions on the ibm …
TRANSCRIPT
/
HANDLING ARITHMEI'IC ERROR CONDITIONS ON THE IBM SYSTmy'360
CGTM #36 John H. Welsch January 1968
Abstract: The concept of an Error Status Word is proposed to
allovT the prograrrnner complete control over the disposition of
arithmetic error conditions arising from both hardware (e.g.,
floating-point exponent overflow) and software (e.g., square
root of a negative number). A description of the implementation
for BPS FORTRAN is included.
Introduction
The IBM 360 computer hardware recognizes fifteen different program
interruptions, eight of which are arithmetic errors (reference 1). In
addition there are numerous arithmetic subroutines which produce "interruptions"
when supplied with incorrect operands. A well designed computer language
should allow the programmer to control and take appropriate action whenever
one of these interrupts occurs. On the other hand there should be default
actions supplied by the system if no others are given.
The 08/360 PL/I programming language has the ¢N statement and ¢N
condition (reference 2) which allow the programmer to control arithmetic interrupts
interrupts as well aSAfor I/O, program checking (e.g., array bounds) and
programmer-defined interrupts. Neither ALG¢L nor 08/360 FORTRAN IV has
such a language feature, and interrupt control can be given to the programmer
only through procedures or subroutines appended to the system. Kahan
(reference 3) and Green (reference 4) have implemented such subprograms
for IBM 7094 FORTRAN and B5500 ALGOL respectively, but limited to exponent
overflow and underflow.
Below we describe a system of subprograms designed to give the FORTRAN
programmer more control over arithmetic error interrupts.
Desirable Features
To give the programmer control of everything (if it were possible) is
to give him too much power. With generality also goes confusion. Keeping
the above "conventional wisdom" in mind and restricting ourselves to control
of arithmetic errors, we propose that the system provide the following "features".
1. Default actions. If the programmer ignores errors he will
get consistent "well defined" system action, which will allow
him to determine at least where in his source language the
error was detected.
2. Intelligent error messages. The message should give the name
of the error, where in his source language it was detected
and the action taken following the error.
3. Error trace back. A subroutine call trace back to the main
program with source language references.
4. Print out control. The programmer should be able to control
for which errors he wishes messages and/or trace back printed
out.
5. Kick-off control. The programmer should be able to control
for which errors he wishes his job terminated.
6. Define results. The result supplied following the error should
be under program control, e.g. change result of 00 from 1 to o.
7. Error test. Each error condition should set a toggle for
later interrogation by the programmer.
8. Save and Reset. Error handling modes should be savable and
resetable so that library routines can suspend and then
reinstate the caller's error disposition mode.
9. Expandibility. The programmer should be able to define new
error conditions and trigger their occurrence.
-2-
The system described below does not have all of these features
mainly to do "systems" problems with BPS. Using 08/360 most could be
implemented for FORTRAN IV with the major part of the work being to change
the error reporting of the function library.
-3-
Brief Description of System
There is one Error Status Word (ESW) for each error condition recognized
by the system (see Fig. 1) with the possibility of adding more as the system
grows. The format of an ESW is given on Fig. 2. A description of each
function follows.
Error Counter contains the net number of times that this error has
occurred (the total number minus the number of times CHKERR has found the
error toggle on).
Message Counter contains the total number of times (modulo 28) that
this error message has been printed.
Error Toggle is set on by an occurrence of this error condition and off
by CHKERR.
Error Kickoff, if on when this error condition occurs, forces message
printout, trace, and program termination.
Message Kickoff, if on when the message counter goes to zero, causes
program termination, and if off causes position 31 (message) to be set off.
Trace position controls the printing of a save area trace (the history
of subroutine calls).
Message position controls the printing of the error message and operation-
operand decoding.
The are four FORTRAN-callable subroutines in the system.
BEGIN(MP) sets the program mask of the program status word with the
low-order four bits of the integer MP. Bit 28 controls fixed point overflow;
bit 29: decimal overflow; bit 30: exponent underflow; bit 31: significance.
-4-
A one bit equals on and permits an interrupt. For example: CALL BEGIN(14)
enables the first three and masks off the significance exception.
SETESW(N,~l,NOLD) places ESW number N in NOLD and replaces it with
NEW (all 32 bits). For example: the sequence
CALL SETESW(6,3,NOLD)
CALL SETESW(6,NOLD,NOLD)
allows the statements in between to run even with exponent overflow (but
with error messages and traces) and then return the ESW to its original
setting.
CHKESW(N) has the value zero if the error toggle (position 24) of ESW
number N is off and has a non-zero value if the error toggle is on (the
error toggle is set off and the error count is decreased by one).
PROERR(N,MESS) causes the system to interrogate ESW number N and take
the indica.ted action. Any error message is taken from the array MESS. This
subroutine is called mainly by library routines to signal an error condition,
but could be used by the FORTRAN programmer to cause his own error interrupts.
The listing of a test program and the results a.re appended.
-5-
Figure 1
ERROR CONDITIONS and STANDARD SE'ITINGS
All are normally set for message) trace and message kickoff.
Name Kickoff Result
• 1. FIXED-Pr OVERFLOW yes * 2. FIXED-Pr DIVIDE yes *
• 3· DECIMAL OVERFLOW yes * 4. DEC IMAL DIVIDE yes * 5. EXPON OVERFLOW no ± 00
• 6. EXPON UNDERFLOW no 0.0
• 7· SIGNIFICANCE no 0.0
8. FLT-PT DIVIDE (X f 0)/0.0 no ± 00
9· FLT-PT DIVIDE 0.0/0.0 yes + 00
10. FIXFI 00 no 1
11. FIXFI 0-1 yes * 12. FRXPI) FDXPI 0.00 no 1.0
13. FRXPI) FDXPI 0.0-1 no + 00
14. FRXPR) FDXPD 0.00 • 0 yes 1.0
15. FRXPR) FDXPD O.O-y no + 00
16. FRXPR) PDXPD (-X)Y no IxI Y
17· EXP) DEXP X ~ 174.673 no + 00
18. ALOG) DLCG X = 0 no - 00
ALCG10) DLCG10
19. ALCG) DLOG X < 0 no log Ixi ALCG10) DLCG10
20. SIN) COS Ixi ~ 218n no * 2l. DSIN) DCOS Ixi ~ 250n no * 22. SQ,RT) DSQ,RT X < 0 no -sqrt Ixi 23- MOD) AMOD X MOD 0 no X 24. IFIX Ixi > 231 yes *
* Undefined
• Hardware controlled by PSW
-6-
Figure 2
ERROR STATUS WORD (ESW) FORMAT
one full word (4 bytes)
~I _____ --:=-'-::-:� 7 .. --------o;::~I~1 1_ ,-=-_ __ :=J o 15 10 23 2~ 25 2~ 27 28 29 30 31
Positions 0-15 (Error counter)
Positions 16-23 (Message counter)
Position 24 (Error toggle)
Position 25, 26, 27 (not used)
Position 28 (Error kickoff)
Position 29 (Message kickoff)
Position 30 (Trace)
Position 31 (Message)
-7-
BPS FORTRAN IVD COMPILER VERSION 1 LEVEL 0 JUNE 1965
/FTC NAME=TEST2,NODECK,LIST,NOMAP BEGIN COMPILATION
S 0001 S:0002 S.0003 S.0004 S.0005 S.0006 5.0007 S.0008 S.0009 S.0010 S.OOll S.0012 S.0013 S.0014 S.0015 S.0016 S.0017 S.0018 S.0019 S.0020 S.0021 S.0022 S.0023 S.0024 '$.0025 S.0026 S.0027 S.0028 S.0029 S.0030 S.0031 S.0032 S.0033 S.0034 S.0035 S.0036 S.0037 S.0038 S.0039 S.0040 S.0041 S.0042 S.0043 S.0044 S.0045 S.0046 S.0047 S.0048
C TEST
99
96
98
97
100
101
OF ARITHMETIC ERROR CONDITION ERROR STATUS WORD CO INTEGER STEP, BIG, NEW' OLD, MESS(10) REAL BIGGER 1'1 E S S ( 1) = 1 93 MESS(2) = 194 1'1 E S S ( 3) = 1 9 5 fviESS(4) = 196 "'RITE(6,99) FO~MAT( 'lCALL BEGIN') CALL BEGIN(14) STEP = 1 WRITE(6,96) STEP FORMAT(' BEGIN STEP " 12) CALL SUBRI ~IRITE(6,98)
FORMAT(' CALL SETESW') NEW = 7 CALL SETESW(2, NEW, MOLD) \.-IRITE(6,97) NEW, MOLD FORMAT(' NEW AND OLD ESW(l) " 2112) STEP = 2 WRITE(6,96) STEP BIG = 1/0 WRITE(6,100) STEP,BIG FORi..,AT(' STEP " 12, 'COMPLETED. RESULT =', 115/) STEP = 5 WRITE(6,96) STEP BIGGER = 1.0E+74 * 1.0E+5 WRITE(6,101l STEP, BIGGER FORl'lAT(' STEP', 12, 'COMPLETED. RESULT = " E20.7 STEP = 6 1,IRITE(6,96) STEP BIGGER = 1.0E-74 * 1.0E-5 WRITE(6,101) STEP, BIGGER STEP = 7 WRITE(6,96) STEP BIGGER = 10.0 - 10.0 WRITE(6,101) STEP, BIGGER STEP = 8 WRITE(6,96) STEP BIGGER = 1.0/0.0 WRITE(6,101) STEP, BIGGER STEP = 10 WRITE(6,96) STEP BIGGER = 0.0 CALL SETESW(10, 3, MOLD) CALL PROERR(10, MESS) WRITE(b,lOl) STEP, BIGGER ENO
-8-
CALL BEGIN BEGI N STEP 1
***ARITHMETIC ERROR NUMBER 1 FIX-PT OVERFLOW ************************************************************************ LOCATION 11212 OP-CODE 90 R1 3 OPDl -2147483639 10936
R2/ADDRESS 11144 OPD2 10 0 SUBROUTINE PROERR (BASE ADDR 13208) CALLED FROM INTERNAL STATEMENT NUMBER S.-285 (LOCATION 12920) IN SUBR3
STEP 1 COMPLETED. RESULT = -2147483639
CALL SETESW NEW AND OLD ESW(I) BEGIN STEP 2
7 15
***ARITHMETIC ERROR NUMBER 2 FIX-PT DIVIDE ************************************************************************ LOCATION 9992 OP-CODE 93 R1 2 OPD1 0 1
R2/ADDRESS 9476 OPD2 0 0 SUBROUTINE PRO ERR (BASE ADDR 13208) CALLED FROM INTERNAL STATEMENT NUMB ER S.-285 (LOCATIU N 12920) IN TEST2
STEP 2 COMPLETED. RESULT = 1
BEGIN STEP 5
***ARITHMETIC ERROR NUMBER 5 EXPUN OVERFLOW ************************************************************************ LOCATION 10076 OP-CODE 124 Rl 6 OPDl -2108269417 834666496
R2/ADDRESS 9504 OPD2 1159227904 55074491 SUBROUTINE PROERR (BASE AD DR 13208) CALLED FROM INTERNAL STATE MENT NUMBER S.-285 (LOCATION 12920) IN TEST2
STEP 5 COMPLETED. RESULT = -0.7237005E 76
BEGIN STEP 6
***ARITHMETIC ERROR NUMBER 6 EXPON UNDERFLOW ************************************************************************ LOCATION 10160 OP-CODE 124 R1 6 OPD1 0 0
R2/ADDRESS 9512 OPD2 1017628076 1101004800 SUBROUTINE PROERR (BASE ADDR 13208) CALLED FROM INTERNAL STATEMENT NUMBER S.-285 (LOCATION 12920) IN TEST2
STEP 6 COMPLETED. RESULT = 0.0
BEGIN STEP 7 STEP 7 COMPLETED. RESULT 0.0
BEGIN STEP 8
***ARITHMETIC ERROR NUMBER 8 FLT-PT DIVIDE ************************************************************************ LOCATION 10328 OP-CODE 125 R1 6 OPD1 1091567616 0
R2/ADDRESS 9524 OPD2 0 35261425 SUBROUTINE PROERR (BASE ADDR 13208 ) CALLED FROM INTERNAL STATEMENT NUMBER S.-2 85 (LOCATION 12920) IN TEST2
STEP 8 COMPLETED. RESULT = 0.7237005E 76
BEGIN STEP 10
***ARITHMETIC ERROR NUMBER 10 SURROUTINE PROERR (BASE ADDR
STEP 10 COMPLETED. RESULT =
ABC D************************************************************************ 13208 ) CALLED FRO M INTE RNAL STATEMENT NUMBER S. 46 (LOCATION 10440) IN TEST2 0.0
-9-
References
1. IBM System/360 Principles of Operation A22-6821-6, pages 15 and 16.
2. IBM System/360 Operating System PL/I Language Specifications, c28-6571-4, pages 79-83, 122-124, appendix 3.
3. w. Kahan, 7094-11 System Support for Numerical Analysis, Department of Computer Science, University of Toronto, August, 1966.
4. Michael D. Green, Coping with Over/Underflow on the B5500, Computation Center, Stanford University, July 15, 1966.
-10-