• Keine Ergebnisse gefunden

Arithmetic Routine Descriptions

Im Dokument HAL/S COMPILER SYSTEM SPECIFICATION (Seite 158-176)

MEMBER NAME ALIAS OF VERIFIED

6.3 Library Routine Descriptions

6.3.1 Arithmetic Routine Descriptions

This subsection presents the detailed descriptions of a class of routines generally denoted as "Arithmetic". Appendix C of the HAL/S Language Specification contains a list of HAL/S functions which are implemented by the routines described here.

ENTRY POINT DESCRIPTIONS Primary Entry Name: DMDVAL

Function: Finds mid value of three double precision scalar arguments.

Invoked By:

Execution Time (microseconds):

Input Arguments:

Output Results:

Errors Detected:

Comments:

Registers Unsafe Across Call: F0,F1,F2,F3,F4,F5.

DMDVAL HAL/S-FC LIBRARY ROUTINE DESCRIPTION

Source Member Name: DMDVAL Size of Code Area 84 Hw Stack Requirement: 18 Hw Data CSECT Size: 0 Hw

Intrinsic x Procedure

Other Library Modules Referenced: None

X Compiler emitted code for HAL/S construct of the form:

MIDVAL(A,B,C), where A, B, C are double precision scalars.

Other Library Modules:

Type Precision How Passed Units

Scalar(A) DP F0

-Scalar(B) DP F2

-Scalar(C) DP F4

-Type Precision How Passed Units

Scalar DP F0

-Error # Cause Fixup

None

Algorithm:

IF A<=B THEN DO;

IF A =B THEN RETURN A;

IF B <=C THEN RETURN B;

ELSE IF A <=C THEN RETURN C;

ELSE RETURN A;

END;

ELSE DO;

IF C <=B THEN RETURN B;

ELSE IF C < A THEN RETURN C;

ELSE RETURN A;

END;

ENTRY POINT DESCRIPTIONS Primary Entry Name: DMOD

Function: Calclates HAL/S MOD function in double precision.

Invoked By:

Execution Time (microseconds):

Input Arguments:

Output Results:

Errors Detected:

Comments:

The precision of the result of the MOD(A,B) function is limited by the precision of the inputs A and B. Specifically, the EMOD output will be precise to six significant digits of the input of greatest magnitude. Similarly, the DMOD output will be precise to eight significant digits of the input of greatest magnitude. A fixup value of zero is returned by MOD(A,B) if:

DMOD HAL/S-FC LIBRARY ROUTINE DESCRIPTION

Source Member Name: DMOD Size of Code Area 152 Hw Stack Requirement: 0 Hw Data CSECT Size: 4 Hw

x Intrinsic Procedure

Other Library Modules Referenced: None

X Compiler emitted code for HAL/S construct of the form:

MOD(A,B), where at least one of A or B is a double precision scalar.

Other Library Modules:

Type Precision How Passed Units

Scalar(A) DP F0/F1

-Scalar(B) DP F2/F3

-Type Precision How Passed Units

Scalar DP F0/F1

-Error # Cause Fixup

19 MOD domain error when B=0, A < 0 Return 0

33 |A/B| approx. > 1614 Return 0

1. It is a positive operand case and the result computed for MOD(A,B) is greater than

|B|, or

2. It is a negative operand case and the result computed for MOD(A,B) is less than zero.

Warning:

The DMOD routine uses the formula MOD(A,B)=A-|B|*FLOOR(A/|B|).

The operation A-|B| * FLOOR(A/|B|) may cause an underflow when H'8D10000000000000'<A<H0D'10000000000000'

(-2.4308653429145086E-63<A<2.4308653429145086E-63).

An exponent overflow can also be generated during the divide operation (I2DEDR macro for DMOD, DER for EMOD) when A and B differ in order of magnitude as described in the AP101 POO for the operation A/|B|. For overflow, A would be greater than B by approximately half of the floating point exponential range.

Registers Unsafe Across Call: R4,F0,F1,F2,F3,F4,F5,F6,F7.

Algorithm:

First check for mod domain error (B=0 and A < 0) and signal an error 19 and return a fixup value of zero. If B< >0, then take |B|. For positive A values, MOD(A,B) is computed as A-(|B|*FLOOR(A/|B|)). For positive A values, a pre-divide check is performed, and if A < |B| then return A as the answer. For negative A values, MOD(A,B) is computed as A+(|B|*FLOOR(|A|/|B|)). For negative A values, a pre-divide check is performed, and if |A|<|B| then return A+|B| as the answer. For both positive and negative A's, the FLOOR function is accomplished by adding and then subtracting a value BIGNUM (X'4E80000000000000' for DMOD and X'4680000000000000' for EMOD), which causes all the fractional part of the quotient to be lost, leaving only the integer portion. The positive and negative A parts of the algorithm then converge for pre-exit validation of the result. If the answer is negative, then add in one more |B|. If the answer is still negative, then log a GPC error and return a fixup value of zero. If the answer is positive or zero, check that it is less than |B|. If not, subtract one |B| from the answer and check it again. If the answer is still greater than or equal to |B| then log a GPC error and return a fixup value of zero.

ENTRY POINT DESCRIPTIONS Primary Entry Name: EMOD

Function: Calculates HAL/S MOD function in single precision.

Invoked By:

Execution Time (microseconds):

Input Arguments:

Output Results:

Errors Detected:

Comments:

See DMOD.

Registers Unsafe Across Call: R4,F0,F2,F4,F5.

Algorithm:

See DMOD.

EMOD HAL/S-FC LIBRARY ROUTINE DESCRIPTION

Source Member Name: EMOD Size of Code Area 52 Hw Stack Requirement: 0 Hw Data CSECT Size: 4 Hw

x Intrinsic Procedure

Other Library Modules Referenced: None

X Compiler emitted code for HAL/S construct of the form:

MOD(A,B), where A and B are single precision scalars.

Other Library Modules:

Type Precision How Passed Units

Scalar(A) SP F0

-Scalar(B) SP F2

-Type Precision How Passed Units

Scalar SP F0

-Error # Cause Fixup

19 MOD domain error when B=0,A<0 Return 0

33 |A/B| approx.>166 Return 0

ENTRY POINT DESCRIPTIONS Primary Entry Name: IMOD

Function: Calculates HAL/S MOD(A,B) in double precision.

Invoked By:

Execution Time (microseconds): 29.4 Input Arguments:

Output Results:

Errors Detected:

Comments:

MOD(A,B) is defined to be the smallest non-negative value that can be reached by starting from A and adding or subtracting |B| as often as is necessary.

Registers Unsafe Across Call: R2,R4,R5,R6,R7.

Algorithm:

If B = 0

If A≥0 Return A

If A<0 Error #19 generated If B ≠ 0

MOD(A,B) = A - [(|B|(A/|B|)]

If this result < 0, then add |B| to this to make it positive.

For all values of A and B, the result is always non-negative.

For A≥0, MOD = REMAINDER(A,B). These equations are used because AP-101 division (scalar or integer) does not yield a remainder.

IMOD HAL/S-FC LIBRARY ROUTINE DESCRIPTION

Source Member Name: IMOD Size of Code Area 152 Hw Stack Requirement: 0 Hw Data CSECT Size: 4 Hw

x Intrinsic Procedure

Other Library Modules Referenced: None

X Compiler emitted code for HAL/S construct of the form:

MOD(A,B), where A and B are both integers and at least A or B is a fullword integer value.

Other Library Modules:

Type Precision How Passed Units

Integer(A) DP R5

-Integer(B) DP R6

-Type Precision How Passed Units

Integer DP R5

-Error # Cause Fixup

19 MOD not defined for A<0 and B=0 Return A

IMOD Secondary Entry Name: HMOD

Function: Performs HAL/S MOD(A,B) where both A and B are single precision integers.

Invoked By:

Execution Time (microseconds): 29.4 Input Arguments:

Output Results:

Errors Detected:

Comments:

MOD(A,B) is defined to be the smallest non-negative value that can be reached by starting from A and adding or subtracting |B| as often as is necessary.

Registers Unsafe Across Call: R2,R4,R5,R6,R7.

Algorithm:

Same as IMOD

X Compiler emitted code for HAL/S construct of the form:

MOD(A,B), where A and B are both integers and at least A or B is a fullword integer value.

Other Library Modules:

Type Precision How Passed Units

Integer(A) SP R5

-Integer(B) SP R6

-Type Precision How Passed Units

Integer SP R5

-Error # Cause Fixup

Same as IMOD

ENTRY POINT DESCRIPTIONS Primary Entry Name: IREM

Function: Calculates integer remainder of (A,B).

Invoked By:

Execution Time (microseconds): 27.0 Input Arguments:

Output Results:

Errors Detected:

Comments:

Registers Unsafe Across Call: R2,R4,R5,R6,R7.

Algorithm:

If B=0, then error. For B ≠ 0, the remainder is found using REMAINDER(A,B) = [A - B*(A/B)]. The result can be negative.

IREM HAL/S-FC LIBRARY ROUTINE DESCRIPTION

Source Member Name: IREM Size of Code Area 16 Hw Stack Requirement: 0 Hw Data CSECT Size: 2 Hw

x Intrinsic Procedure

Other Library Modules Referenced: None

X Compiler emitted code for HAL/S construct of the form:

MOD(A,B), where A and B are both single precision integers.

Other Library Modules:

Type Precision How Passed Units

Integer(A) DP⎫ R5

⎬ one can be SP

Integer(B) DP⎭ R6

-Type Precision How Passed Units

Integer DP R5

-Error # Cause Fixup

16 Zero denominator (B) Return A

IREM Secondary Entry Name: HREM

Function: Calculates integer remainder of A/B.

Invoked By:

Execution Time (microseconds): 27.0 Input Arguments:

Output Results:

Errors Detected:

Comments:

Registers Unsafe Across Call: R2,R4,R5,R6,R7.

Algorithm:

Same as IREM.

X Compiler emitted code for HAL/S construct of the form:

REMAINDER(A,B), where A and B are both single precision integers.

Other Library Modules:

Type Precision How Passed Units

Integer(A) SP R5

-Integer(B) SP R6

-Type Precision How Passed Units

Integer SP R5

-Error # Cause Fixup

16 Zero denominator (B) Return A

ENTRY POINT DESCRIPTIONS Primary Entry Name: ROUND

Function: Converts single precision scalar to fullword integer.

Invoked By:

QSHAPQ

Execution Time (microseconds): 39.0 Input Arguments:

Output Results:

Errors Detected:

Comments:

See DROUND.

Registers Unsafe Across Call: R4,R5,F0,F1.

Algorithm:

Second register of a floating point register pair is cleared then routine merges into the double precision float-to- fix routine, DROUND.

ROUND HAL/S-FC LIBRARY ROUTINE DESCRIPTION

Source Member Name: ROUND Size of Code Area 80 Hw Stack Requirement: 0 Hw Data CSECT Size: 2 Hw

x Intrinsic - Sector - 0 Procedure Other Library Modules Referenced: None

X Compiler emitted code for HAL/S construct of the form:

ROUND(X), where X is a single precision scalar.

X Other Library Modules:

Type Precision How Passed Units

Scalar SP F0

-Type Precision How Passed Units

Integer DP R5

-Error # Cause Fixup

15 Scalar too large for integer

conversion

Return either:

Posmax = X'7FFFFFFF' or Negmax = X'80000000'

ROUND Secondary Entry Name: CEIL

Function: Performs HAL/S CEILING function: Returns smallest integer > the argument.

Invoked By:

Execution Time (microseconds): 31.4 if X > 0 40.8 if X < 0 Input Arguments:

Output Results:

Errors Detected:

Comments:

See DCEIL.

Registers Unsafe Across Call: R4,R5,F0,F1.

An invalid result of 0 is returned for arguments between 0 < N < 1.0 X 16 E-14.

Algorithm:

Second register of floating point register pair is cleared, then routine merges with DCEIL.

X Compiler emitted code for HAL/S construct of the form:

CEILING(X), where X is a single precision scalar.

Other Library Modules:

Type Precision How Passed Units

Scalar SP F0

-Type Precision How Passed Units

Integer DP R5

-Error # Cause Fixup

15 Scalar too large for integer

conversion

Return either:

Posmax = X'7FFFFFFF' or Negmax = X'80000000'

ROUND Secondary Entry Name: DCEIL

Function: Performs HAL/S CEILING function: Finds the smallest integer ≥ the argument.

Invoked By:

Execution Time (microseconds): 26.6 if X ≥ 0 36.0 if X < 0 Input Arguments:

Output Results:

Errors Detected:

Comments:

Negative args become less negative after CEILING, positive args more positive.

Registers Unsafe Across Call: R4,R5,F0,F1.

An invalid result of 0 is returned for arguments between 0 < N < 1.0 X 16 E-14.

Algorithm:

Same as DROUND, except positive arguments are rounded up by almost 1.

Negative arguments are not rounded.

X Compiler emitted code for HAL/S construct of the form:

CEILING(X), where X is a double precision scalar.

Other Library Modules:

Type Precision How Passed Units

Scalar DP F0, F1

-Type Precision How Passed Units

Integer DP R5

-Error # Cause Fixup

15 Scalar too large for integer

conversion

Return either:

Posmax = X'7FFFFFFF' or Negmax = X'80000000'

-3 α -2 -1 0 1 β 2 3

| | | | | | | | |

←⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯→

| |

CEILING(α) CEILING(β)

ROUND Secondary Entry Name: DFLOOR

Function: Performs HAL/S FLOOR function: Finds the largest integer < the argument.

Invoked By:

Execution Time (microseconds): 27.0 if X ≥ 0 36.4 if X < 0 Input Arguments:

Output Results:

Errors Detected:

Comments:

Negative arguments become more negative, positive arguments less positive.

Registers Unsafe Across Call: R4,R5,F0,F1.

An invalid result of 0 is returned from the DFLOOR function for arguments between -1.0 X 16 E-14 < N < 0.

Algorithm:

Same as DROUND, except argument is rounded down by almost 1 (X'40FFFFFFFFFFFFFF') if negative. Positive arguments are not rounded.

X Compiler emitted code for HAL/S construct of the form:

FLOOR(X), where X is a double precision scalar.

Other Library Modules:

Type Precision How Passed Units

Scalar DP F0, F1

-Type Precision How Passed Units

Integer DP R5

-Error # Cause Fixup

15 Scalar too large for integer

conversion

Return either:

Posmax = X'7FFFFFFF' or Negmax = X'80000000'

-3 α -2 -1 0 1 2 β 3

| | | | | | | | |

←⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯→

| |

FLOOR(α) FLOOR(β)

ROUND Secondary Entry Name: DROUND

Function: Converts double precision scalar to fullword integer.

Invoked By:

Execution Time (microseconds): 33.8 Input Arguments:

Output Results:

Errors Detected:

Comments:

Negative arguments are converted to the next more negative integer value; positive args to the next greater positive integer value, unless the original argument is an integer (argument rounded up or down by not quite 1 before truncating decimal places). Values such as xx.5 are rounded down to xx.0 and values such as -xx.5 are rounded up to -xx.0.

Registers Unsafe Across Call: R4,R5,F0,F1.

Algorithm:

The argument is checked for negative/not negative. If the argument is negative, the value is rounded down by subtracting just under 1/2. The resulting value is then checked against MAXNEG(X'C880000000FFFFFF'). If within the legal range, the integer part of the scalar is shifted to the second register of the floating point register pair. This remaining integer value is then put in a fixed point register and complemented to leave it in the correct two's complement fixed point form. If the argument is not negative, the value is rounded up by adding almost 1/2, and the resulting value is compared to MAXPOS(X'487FFFFFFFFFFFFF'). Then, as with negative values, it is shifted to leave the integer part in floating point format and loaded into a fixed point register.

X Compiler emitted code for HAL/S construct of the form:

ROUND(X), where X is a double precision scalar.

Other Library Modules:

Type Precision How Passed Units

Scalar DP F0, F1

-Type Precision How Passed Units

Integer DP R5

-Error # Cause Fixup

15 Scalar too large for integer

conversion

Return either:

Posmax = X'7FFFFFFF' or Negmax = X'80000000'

ROUND Secondary Entry Name: DTOI

Function: Converts double precision scalar to fullword integer.

Invoked By:

Execution Time (microseconds): 33.8 Input Arguments:

Output Results:

Errors Detected:

Comments:

DTOI is identical entry point to DROUND.

Registers Unsafe Across Call: R4,R5,F0,F1.

Algorithm:

Algorithm: Same as DROUND.

X Compiler emitted code for HAL/S construct of the form:

I = D; where I is a double precision integer, and D is a double precision scalar.

Other Library Modules:

Type Precision How Passed Units

Scalar DP F0

-Type Precision How Passed Units

Integer DP R5

-Error # Cause Fixup

15 Scalar too large for integer

conversion

Return either:

Posmax = X'7FFFFFFF' or Negmax = X'80000000'

ROUND Secondary Entry Name: DTRUNC

Invoked By:

Execution Time (microseconds): 28.6 Input Arguments:

Output Results:

Errors Detected:

Comments:

After truncation, negative and positive arguments are closer to 0; no rounding done before truncation.

Registers Unsafe Across Call: R4,R5,F0,F1.

Algorithm:

Same as DROUND, except argument is not rounded up or down.

Function: Performs HAL/S TRUNCATE function: Finds the signed value that is the largest integer < absolute value of the argument.

X Compiler emitted code for HAL/S construct of the form:

TRUNCATE(X), where X is a double precision scalar.

Other Library Modules:

Type Precision How Passed Units

Scalar DP F0, F1

-Type Precision How Passed Units

Integer DP R5

-Error # Cause Fixup

15 Scalar too large for integer

conversion

Return either:

Posmax: X'7FFFFFFF' or

Negmax: X'80000000'

-3 α -2 -1 0 1 2 β 3

| | | | | | | | |

←⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯→

| |

TRUNCATE(α) TRUNCATE(β)

ROUND Secondary Entry Name: ETOI

Function: Converts single precision scalar to fullword integer.

Invoked By:

Execution Time (microseconds): 39.0 Input Arguments:

Output Results:

Errors Detected:

Comments:

ETOI is identical entry point to ROUND; also see DTOI.

Registers Unsafe Across Call: R4,R5,F0,F1.

Algorithm:

Same as ROUND.

Secondary Entry Name: FLOOR

Function: Performs HAL/S FLOOR function: Returns largest integer < the argument.

The compiler uses the convert to fixed point instruction which is valid only in the range:

.7FFFFF X 16E04 (16) > N > -.800000 X 16E04 (16)

~ 32767.99 (10) > N > -32768(10)

A convert overflow will occur for FLOOR arguments outside this range.

An invalid result is returned from the FLOOR function for arguments between -16 and 0 which have a fractional portion whose absolute value is smaller than 1/16**4 (I.E. - (X + 1/16**4) < N <-X where X is an integer between 0 and 15 inclusive).

X Compiler emitted code for HAL/S construct of the form:

I=S where I is a double precision integer, S is a single precision scalar.

Other Library Modules:

Type Precision How Passed Units

Scalar SP F0

-Type Precision How Passed Units

Integer DP R5

-Error # Cause Fixup

15 Scalar too large for integer

conversion

Return either:

Posmax =X'7FFFFFFF' or Negmax = X'80000000'

Note: The compiler now uses inline code for the FLOOR function instead of calling this routine.

ROUND Secondary Entry Name: TRUNC

Invoked By:

Execution Time (microseconds): 31.4 Input Arguments:

Output Results:

Errors Detected:

Comments:

See DTRUNC

Registers Unsafe Across Call: R4,R5,F0,F1.

Algorithm:

Second register of floating point register pair is cleared, then routine merges with DTRUNC.

Function: Performs HAL/S TRUNCATE function: Returns signed value that is the largest integer < absolute value of the argument.

X Compiler emitted code for HAL/S construct of the form:

TRUNCATE(X), where X is a single precision scalar.

Other Library Modules:

Type Precision How Passed Units

Scalar SP F0

-Type Precision How Passed Units

Integer DP R5

-Error # Cause Fixup

15 Scalar too large for integer

conversion

Return either:

Posmax =X'7FFFFFFF' or Negmax =X'80000000'

Im Dokument HAL/S COMPILER SYSTEM SPECIFICATION (Seite 158-176)