RPE API: rp_emulator.mod

Derived types

type rpe_type [abstract]

An abstract type defining a reduced-precision floating-point number. You cannot construct an instance of this type, but you can construct an instance of any type that extends this type.

Type fields:
  • % sbits [INTEGER] :: Number of bits in the significand of the floating-point number
function rpe_type%get_value()

Retrieve the real value stored within an rpe_type instance.

Return:value [REAL,KIND=RPE_REAL_KIND] :: Reduced-precision value stored in a built-in real-typed variable.
type rpe_var [extends(rpe_type)]

A type extending rpe_type representing a reduced-precision floating-point number. This type stores the number it represents internally.

type rpe_shadow [extends(rpe_type)]

A type extending rpe_type representing a reduced-precision floating-point number. The rpe_shadow provides a memory-view onto an existing double precision floating point number defined outside the type itself. Changing the value of the rpe_shadow also changes the value of the floating point number it is shadowing and vice-versa, since they both refer to the same block of memory. However, when values are assigned to the rpe_shadow their precision is reduced, which is not the case when assigning to the variable being shadowed.

User-callable procedures

subroutine init_shadow(shadow, target)

Initialize an rpe_shadow instance by associating it with a real-valued variable.

Parameters:
  • shadow [rpe_shadow,INOUT] :: The rpe_shadow instance to initialize.
  • target [REAL,KIND=RPE_REAL_KIND,IN] :: A floating-point variable to shadow. This must be a variable defined within the scope of the init_shadow() call otherwise invalid memory references will occur.
subroutine apply_truncation(rpe) [elemental]

Apply the required truncation to the value stored within an rpe_type instance. Operates on the input in-place, modifying its value. The truncation is determined by the sbits attribute of the rpe_type instance, if this is not set then the value of RPE_DEFAULT_SBITS.

Parameters:rpe [rpe_type,INOUT] :: The rpe_type instance to alter the precision of.

Variables

RPE_ACTIVE [LOGICAL,default=.TRUE.]

Logical value determining whether emulation is on or off. If set to .FALSE. then calls to apply_truncation() will have no effect and all operations will be carried out at full precision.

RPE_DEFAULT_SBITS [INTEGER,default=23]

The default number of bits used in the significand of an rpe_type instance when not explicitly specified. This takes effect internally when determining precision levels, but does not bind an rpe_type instance to a particular precision level (doesn’t set rpe_type%sbits).

RPE_IEEE_HALF [LOGICAL,default=.FALSE.]

Logical value determining if IEEE half-precision emulation is turned on. If set to .TRUE. and a 10-bit significand is being emulated the emulator will additionally impose range constraints when applying truncation:

  • Values that overflow IEEE half-precision will lead to real overflows with a corresponding floating-point overflow exception.
  • Values out of the lower range of IEEE half-precision will be denormalised.

This option only affects the emulation when emulating a 10-bit significand.

Parameters

RPE_DOUBLE_KIND [INTEGER]

The kind number for double precision real types.

RPE_SINGLE_KIND [INTEGER]

The kind number for single precision real types.

RPE_REAL_KIND [INTEGER]

The kind number of the real-values held by reduced precision types. This is a reference to RPE_DOUBLE_KIND, but could be changed (in source) to be RPE_SINGLE_KIND.

RPE_ALTERNATE_KIND [INTEGER]

The kind number of an alternate type of real-value. This is a reference to RPE_SINGLE_KIND, but can be changed (in source) if the value referenced by RPE_REAL_KIND is changed.