add_sub

Date:

09-12-2012

NAME

_add_carry_s, _get_carry_s, _set_carry_s, _sub_borrow_s, _get_borrow_s, _set_borrow_s, ADD_CARRY_S@, GET_CARRY_S@, SET_CARRY_S@, SUB_BORROW_S@, GET_BORROW_S@, SET_BORROW_S@ - Support fast add-with-carry and subtract-with-borrow operations

SYNOPSIS

C Synopsis

Scalar Procedures

#include <intrinsics.h>

void          _set_carry_s(unsigned long x);
unsigned long _add_carry_s(unsigned long x, unsigned long y);
unsigned long _get_carry_s(void);

void          _set_borrow_s(unsigned long x);
unsigned long _sub_borrow_s(unsigned long x, unsigned long y);
unsigned long _get_borrow_s(void);

Fortran Synopsis

Scalar Procedures

INTEGER(KIND=8) :: RESULT, X, Y

CALL SET_CARRY_S@([[X=]X])
RESULT = ADD_CARRY_S@([X=]X, [Y=]Y)
RESULT = GET_CARRY_S@()

CALL SET_BORROW_S@([[X=]X])
RESULT = SUB_BORROW_S@([X=]X, [Y=]Y)
RESULT = GET_BORROW_S@()

DESCRIPTION

Note: Within this man page, the procedures that support addition with carry are referred to as the add-with-carry (ADDC) procedures. The procedures that support subtraction with borrow are referred to as the subtract-with-borrow (SUBB) procedures.

The ADDC procedures support addition involving a carry bit from a previous ADDC operation, and support setting and retrieving the carry bit. The SUBB procedures support subtraction involving a borrow bit from a previous SUBB operation, and support setting and retrieving the borrow bit. All these procedures can be used in many contexts for fast computations, but are normally used for fast addition or subtractions of arbitrary-precision integers whose size can exceed the size of 64-bit integers.

Each ADDC and SUBB operation has a scalar version. Implementation is deferred for the vector versions.The operations performed by the scalar procedures are emulated in software. The scalar procedures do not vectorize.

Fortran: The procedures treat all argument values as unsigned integers; however, Fortran does not support unsigned integers. Therefore, you must take care in your code to treat the results and arguments as unsigned values.

Note: See the NOTES section for guidelines for using these procedures and the effects that the registers may have on the results of subsequent ADDC and SUBB procedure calls.

Procedures that Support Add with Carry Operations

The following description applies to the Fortran and C versions of the ADDC procedures unless noted:

_set_carry_s, SET_CARRY_S@

The scalar set carry procedures set the state of the scalar carry register according to the low order bit of argument x. That is, if the bit is one, the state of the register is set to carry. If the bit is zero, the state is set to no carry.

  • Fortran: The x argument defaults to 1 if it is not specified. This default causes the procedure to set the state of the carry register to carry.

  • See the NOTES section for additional information about the carry registers.

_add_carry_s, ADD_CARRY_S@

The scalar add procedures add the arguments using unsigned arithmetic and add one to the result if the state of the scalar carry register is set to carry. If the result produces a carry, the state of the scalar carry register is set to carry; otherwise it is set to no carry.

  • See the NOTES section for additional information about the carry registers.

_get_carry_s, GET_CARRY_S@

Fortran: The DESTROY argument defaults to .FALSE. if it is not specified.

  • See the NOTES section for additional information about the get carry procedures.

Procedures that Support Subtract with Borrow Operations

The following description applies to the Fortran and C versions of the SUBB procedures unless noted:

_set_borrow_s, SET_BORROW_S@

The scalar set borrow procedures set the state of the scalar borrow register according to the low order bit of argument x. That is, if the bit is one, the state of the register is set to borrow. If the bit is zero, the state is set to no borrow.

  • Fortran: The x argument defaults to 1 if it is not specified. This default causes the procedure to set the state of the borrow register to borrow.

_sub_borrow_s, SUB_BORROW_S@

The scalar subtract procedures subtract the arguments using unsigned arithmetic and subtract one from the result if the state of the scalar borrow register is set to borrow. If the subtraction results in a borrow, the state of the scalar borrow register is set to borrow.

  • See the NOTES section for additional information about the borrow registers.

_get_borrow_s, GET_BORROW_S@

The get borrow procedures return the contents of the borrow registers. The scalar get borrow procedures return one if the state of the scalar borrow register is set to borrow. Zero is returned if the state is set to no borrow.

  • Fortran: The DESTROY argument defaults to .FALSE. if it is not specified.

NOTES

Fortran: These ADDC and SUBB intrinsics are transformational procedures. Their names cannot be passed as arguments.