coreblocks.func_blocks.fu.fpu package

Submodules

coreblocks.func_blocks.fu.fpu.close_path module

class coreblocks.func_blocks.fu.fpu.close_path.ClosePathMethodLayout

Bases: object

Close path module layouts for methods

Parameters
fpu_params; FPUParams

FPU parameters

__init__(*, fpu_params: FPUParams)

r_sign - sign of the result sig_a - two’s complement form of first significand sig_2 - two’s complement form of second significand exp - exponent of result before shifts rounding_mode - rounding mode guard_bit - guard_bit (pth bit of second significand where p is precision)

class coreblocks.func_blocks.fu.fpu.close_path.ClosePathModule

Bases: Elaboratable

Close path module Based on http://i.stanford.edu/pub/cstr/reports/csl/tr/90/442/CSL-TR-90-442.pdf. This module computes results for efficient subtraction, whenever difference of exponents is lesser than 2. Besides computing the result, this implementation also performs rounding at the same time as subtraction by using two adders (one computing a+b and the other one computing a+b+1). The correct output is chosen based on flags that are different for each rounding mode.

Parameters
fpu_params: FPUParams

FPU rounding module parameters

Attributes
close_path_request: Method

Transactional method for initiating close path computation. Takes ‘close_path_in_layout’ as argument. Returns result as ‘close_path_out_layout’.

__init__(*, fpu_params: FPUParams)

coreblocks.func_blocks.fu.fpu.far_path module

class coreblocks.func_blocks.fu.fpu.far_path.FarPathMethodLayout

Bases: object

Far path module layouts for methods

Parameters
fpu_params; FPUParams

FPU parameters

__init__(*, fpu_params: FPUParams)

r_sign - result sign sig_a - significand of first operand (for effective subtraction in two’s complement form) sig_b - significand of second operand (for effective subtraction in two’s complement form) exp - exponent of result before shift sub_op - effective operation. 1 for subtraction 0 for addition rounding_mode - rounding mode guard_bit - guard bit (pth bit of second significand where p is precision) round_bit - round bit ((p+1)th bit of second significand where p is precision) sticky_bit - sticky_bit (OR of all bits with index >=p of second significand where p is precision)

class coreblocks.func_blocks.fu.fpu.far_path.FarPathModule

Bases: Elaboratable

Far Path module Based on: https://userpages.cs.umbc.edu/phatak/645/supl/lza/lza-survey-arith01.pdf. This module implements far path of adder/subtractor. It performs subtraction for operands whose exponent differs by more than 1 and addition for all combinations of operands. Besides addition it also performs rounding at the same time as addition using two adders (one producing a+b and second one producing a+b+1). The correct output is chosen by flags that differ for each rounding mode. To deal with certain complication that may arise during addition in certain rounding modes the input of second may be either input operand or (a & b)<<1 and (a^b). This allows second adder to compute a+b+2 in special cases that are better explained in paper linked above.

Parameters
fpu_params: FPUParams

FPU rounding module parameters

Attributes
far_path_request: Method

Transactional method for initiating far path computation. Takes ‘far_path_in_layout’ as argument. Returns result as ‘far_path_out_layout’.

__init__(*, fpu_params: FPUParams)

coreblocks.func_blocks.fu.fpu.float_to_int module

class coreblocks.func_blocks.fu.fpu.float_to_int.FloatToIntMethodLayout

Bases: object

FPU float to int conversion module method layout

Parameters
fpu_params: FPUParams

FPU parameters

int_width: int

Width of result

__init__(*, fpu_params: FPUParams, int_width: int)
fti_in_layout
Input layout for float to int conversion
op - layout containing data of the float create_data_input_layout
signed - bit indicating if result is signed or unsigned
rounding_mode - selected rounding mode
fti_out_layout
Output layout for comparision created using
result - result of the conversion
errors - exceptions
class coreblocks.func_blocks.fu.fpu.float_to_int.FloatToIntModule

Bases: Elaboratable

Module for float to int conversion Module responsible for performing conversion from float to int. This module doesn’t extend 32 bit number when XLEN > 32

Parameters
fpu_params: FPUParams

FPU module parameters

int_width: int

Width of the result

Attributes
fti_request: Method

Transactional method for initiating conversion. Takes ‘fti_in_layout’ as argument Returns result as ‘fti_out_layout’

__init__(*, fpu_params: FPUParams, int_width: int)

coreblocks.func_blocks.fu.fpu.fpu_add_sub module

class coreblocks.func_blocks.fu.fpu.fpu_add_sub.FPUAddSubMethodLayout

Bases: object

FPU addition/subtraction top module method layout

Parameters
fpu_params; FPUParams

FPU parameters

__init__(*, fpu_params: FPUParams)
add_sub_in_layout
Input layout for addition/subtraction
op_1 - layout containing data of the first operand
op_2 - layout containing data of the second operand
rounding_mode - selected rounding mode
operation - selected operation; 1 - subtraction, 0 - addition
op_1 and op_2 are created using create_data_input_layout
add_sub_out_layout

Output layout for addition/subtraction. Created using create_output_layout

ext_float_layout

Output layout for raw float with significand larger by two bits from selected format. Created using create_raw_float_layout

raw_float_layout

Output layout for raw float. Created using create_raw_float_layout

class coreblocks.func_blocks.fu.fpu.fpu_add_sub.FPUAddSubModule

Bases: Elaboratable

FPU addition/subtraction top module
This module implements addition and subtraction using two path approach with rounding prediction.
The module can be divided into two segments:
1. Receiving data and preparing it for one of the two path submodules by calculating effective operation, swapping operands and aligning exponents.
2. Receiving data from one of the path submodules and preparing it for error checking module by checking for various conditions
For more info about close path and far path check close path module and far path module
Parameters
fpu_params: FPUParams

FPU rounding module parameters

Attributes
add_sub_request: Method

Transactional method for initiating addition or subtraction. Takes add_sub_in_layout as argument. Returns result as add_sub_out_layout.

__init__(*, fpu_params: FPUParams)

coreblocks.func_blocks.fu.fpu.fpu_class module

class coreblocks.func_blocks.fu.fpu.fpu_class.FPUClassMethodLayout

Bases: object

FPU classification module method layout

Parameters
fpu_params; FPUParams

FPU parameters

__init__(*, fpu_params: FPUParams)
class_in_layout
Input layout for classification
op - layout containing data of the only operand
class_out_layout
Output layout for classification
result - Class of operand
errors - Exceptions, in case of classification it is always 0 (empty mask)
class coreblocks.func_blocks.fu.fpu.fpu_class.FPUClassModule

Bases: Elaboratable

Classification module Module responsible for performing classification.

Parameters
fpu_params: FPUParams

FPU format parameters

Attributes
class_request: Method

Transactional method for initiating classification. Takes ‘class_in_layout’ as argument Returns result as ‘class_out_layout’

__init__(*, fpu_params: FPUParams)

coreblocks.func_blocks.fu.fpu.fpu_common module

class coreblocks.func_blocks.fu.fpu.fpu_common.ComparisionTypes

Bases: IntFlag

EQ = 1
LE = 4
LT = 2
__new__(value)
class coreblocks.func_blocks.fu.fpu.fpu_common.Errors

Bases: IntFlag

DIVISION_BY_ZERO = 8
INEXACT = 1
INVALID_OPERATION = 16
OVERFLOW = 4
UNDERFLOW = 2
__new__(value)
class coreblocks.func_blocks.fu.fpu.fpu_common.FPUClasses

Bases: IntFlag

NEG_INF = 1
NEG_NORM = 2
NEG_SUB = 4
NEG_ZERO = 8
POS_INF = 128
POS_NORM = 64
POS_SUB = 32
POS_ZERO = 16
QUIET_NAN = 512
SIG_NAN = 256
__new__(value)
class coreblocks.func_blocks.fu.fpu.fpu_common.FPUCommonValues

Bases: object

__init__(fpu_params: FPUParams)
class coreblocks.func_blocks.fu.fpu.fpu_common.FPUParams

Bases: object

FPU parameters

Parameters
sig_width: int

Width of significand, including implicit bit

exp_width: int

Width of exponent

__init__(*, sig_width: int = 24, exp_width: int = 8)
class coreblocks.func_blocks.fu.fpu.fpu_common.IntConversionValues

Bases: object

Various values for conversion from int to float

Parameters
int_width: int

Width of int

sig_width: int

Width of significand

bias: int

Value of bias used for calculating base exponent value

__init__(*, int_width: int = 32, sig_width: int = 24, bias: int = 127)
class coreblocks.func_blocks.fu.fpu.fpu_common.RoundingModes

Bases: Enum

ROUND_DOWN = 2
ROUND_NEAREST_AWAY = 4
ROUND_NEAREST_EVEN = 0
ROUND_UP = 3
ROUND_ZERO = 1
coreblocks.func_blocks.fu.fpu.fpu_common.create_data_input_layout(params: FPUParams)

A function that creates a layout for FPU modules operands.

Parameters
fpu_params; FPUParams

FPU parameters

coreblocks.func_blocks.fu.fpu.fpu_common.create_data_layout(params: FPUParams)
coreblocks.func_blocks.fu.fpu.fpu_common.create_data_output_layout(params: FPUParams)

A function that creates a layout for FPU modules results.

Parameters
fpu_params; FPUParams

FPU parameters

coreblocks.func_blocks.fu.fpu.fpu_common.create_output_layout(params: FPUParams)
coreblocks.func_blocks.fu.fpu.fpu_common.create_raw_float_layout(params: FPUParams)

coreblocks.func_blocks.fu.fpu.fpu_comp module

class coreblocks.func_blocks.fu.fpu.fpu_comp.FPUCompMethodLayout

Bases: object

FPU comparision module method layout

Parameters
fpu_params; FPUParams

FPU parameters

__init__(*, fpu_params: FPUParams)
comp_in_layout
Input layout for comparision
op_1 - layout containing data of the first operand
op_2 - layout containing data of the second operand
operation - selected operation, values come from ComparisionTypes
comp_out_layout
Output layout for comparision
result - 1 if true or 0 otherwise
errors - Exceptions, in this case the only possible exception is invalid operation
class coreblocks.func_blocks.fu.fpu.fpu_comp.FPUCompModule

Bases: Elaboratable

Comparision module Module responsible for performing LT, EQ and LE operations.

Parameters
fpu_params: FPUParams

FPU rounding module parameters

Attributes
comp_request: Method

Transactional method for initiating comparision. Takes ‘comp_in_layout’ as argument Returns result as ‘comp_out_layout’

__init__(*, fpu_params: FPUParams)

coreblocks.func_blocks.fu.fpu.fpu_error_module module

class coreblocks.func_blocks.fu.fpu.fpu_error_module.FPUErrorMethodLayout

Bases: object

FPU error checking module layouts for methods

Parameters
fpu_params: FPUParams

FPU parameters

__init__(*, fpu_params: FPUParams)

input_inf is a flag that comes from previous stage. Its purpose is to indicate that the infinity on input is a result of infinity arithmetic and not a result of overflow

class coreblocks.func_blocks.fu.fpu.fpu_error_module.FPUErrorModule

Bases: Elaboratable

FPU error checking module

Parameters
fpu_params: FPUParams

FPU rounding module parameters

Attributes
error_checking_request: Method

Transactional method for initiating error checking of a floating point number. Takes ‘error_in_layout’ as argument Returns final number and errors as ‘error_out_layout’

__init__(*, fpu_params: FPUParams)

coreblocks.func_blocks.fu.fpu.fpu_mul module

class coreblocks.func_blocks.fu.fpu.fpu_mul.FPUMulMethodLayout

Bases: object

FPU multiplication module method layout

Parameters
fpu_params; FPUParams

FPU parameters

__init__(*, fpu_params: FPUParams)
mul_in_layout
Input layout for multiplication
op_1 - layout containing data of the first operand
op_2 - layout containing data of the second operand
rounding_mode - selected rounding mode
op_1 and op_2 are created using create_data_input_layout
mul_out_layout

Output layout for multiplication. Created using create_output_layout

class coreblocks.func_blocks.fu.fpu.fpu_mul.FPUMulModule

Bases: Elaboratable

FPU multiplication top module
The floating point multiplication consists of two parts:
1. Exponent calcuation - turning both exponents from biased form into un-biased form
and then adding them together and turing result back into biased form
2. Significand multiplication - This is essentialy fixed-point multiplication with
two bits for integer part and 2*n - 2 bits for fractional part.
We deal with with subnormal number by extending exponents range and turning subnormal
numbers into normalised numbers.
Parameters
fpu_params: FPUParams

FPU rounding module parameters

Attributes
mul_request: Method

Transactional method for initiating multiplication. Takes mul_in_layout as argument. Returns result as mul_out_layout.

__init__(*, fpu_params: FPUParams)

coreblocks.func_blocks.fu.fpu.fpu_rounding_module module

class coreblocks.func_blocks.fu.fpu.fpu_rounding_module.FPURoudningMethodLayout

Bases: object

FPU Rounding module layouts for methods

Parameters
fpu_params: FPUParams

FPU parameters

__init__(*, fpu_params: FPUParams)
class coreblocks.func_blocks.fu.fpu.fpu_rounding_module.FPURounding

Bases: Elaboratable

FPU Rounding module

Parameters
fpu_params: FPUParams

FPU parameters

Attributes
rounding_request: Method

Transactional method for initiating rounding of a floating point number. Takes ‘rounding_in_layout’ as argument Returns rounded number and errors as ‘rounding_out_layout’

__init__(*, fpu_params: FPUParams)

coreblocks.func_blocks.fu.fpu.fpu_sign_injection module

class coreblocks.func_blocks.fu.fpu.fpu_sign_injection.SIMethodLayout

Bases: object

Sign injection module layouts for methods

Parameters
fpu_params: FPUParams

FPU parameters

__init__(*, fpu_params: FPUParams)

op_1 - first operand op_2 - second operand operation - type of sign injection operation

class coreblocks.func_blocks.fu.fpu.fpu_sign_injection.SIModule

Bases: Elaboratable

Sign injection module Module responsible for performing sign injection operations. Only things worth noting about this module are: 1. Sign injection do not set floating-point exception flags 2. Sign injection do not canonicalize NaNs

Parameters
fpu_params: FPUParams

FPU rounding module parameters

Attributes
si_request: Method

Transactional method for initiating leading sign injection. Takes ‘si_in_layout’ as argument Returns result as ‘si_out_layout’

__init__(*, fpu_params: FPUParams)
class coreblocks.func_blocks.fu.fpu.fpu_sign_injection.SIOperations

Bases: IntFlag

FSGNJN_S = 2
FSGNJX_S = 4
FSGNJ_S = 1
__new__(value)

coreblocks.func_blocks.fu.fpu.int_to_float module

class coreblocks.func_blocks.fu.fpu.int_to_float.IntToFloatMethodLayout

Bases: object

FPU integer to float conversion module method layout

Parameters
fpu_params: FPUParams

FPU parameters

int_values: IntConversionValues

Values for int to float conversion

__init__(*, fpu_params: FPUParams, int_values: IntConversionValues)
itf_in_layout
Input layout for int to float conversion
op - layout containing data of the integer
signed - bit indicating if op is signed or unsigned
rounding_mode - selected rounding mode
itf_out_layout
Output layout for int to float conversion created using create_data_output_layout
class coreblocks.func_blocks.fu.fpu.int_to_float.IntToFloatModule

Bases: Elaboratable

Module for int to float conversion Module responsible for performing conversion from int to float.

Parameters
fpu_params: FPUParams

FPU module parameters

int_values: IntConversionValues

Values for int to float conversion

Attributes
itf_request: Method

Transactional method for initiating conversion. Takes ‘itf_in_layout’ as argument Returns result as ‘itf_out_layout’

__init__(*, fpu_params: FPUParams, int_values: IntConversionValues)

coreblocks.func_blocks.fu.fpu.lza module

class coreblocks.func_blocks.fu.fpu.lza.LZAMethodLayout

Bases: object

LZA module layouts for methods

Parameters
fpu_params: FPUParams

FPU parameters

__init__(*, fpu_params: FPUParams)

sig_a - significand of a sig_b - significand of b carry - indicates if we want to predict result of a+b or a+b+1 shift_amount - position to shift needed to normalize number is_zero - indicates if result is zero

class coreblocks.func_blocks.fu.fpu.lza.LZAModule

Bases: Elaboratable

LZA module Based on: https://userpages.cs.umbc.edu/phatak/645/supl/lza/lza-survey-arith01.pdf After performing subtracion, we may have to normalize floating point numbers and For that, we have to know the number of leading zeros. The most basic approach includes using LZC (leading zero counter) after subtracion, a more advanced approach includes using LZA (Leading Zero Anticipator) to predict the number of leading zeroes. It is worth noting that this LZA module works under assumptions that significands are in two’s complement and that before complementation sig_a was greater or equal to sig_b. Another thing worth noting is that LZA works with error = 1. That means that if ‘n’ is the result of the LZA module, in reality, to normalize number we may have to shift left by ‘n’ or ‘n+1’. There are few techniques of dealing with that error like specially designed shifters or predicting the error but the most basic approach is to just use multiplexer after shifter to perform one more shift left if necessary.

Parameters
fpu_params: FPUParams

FPU rounding module parameters

Attributes
predict_request: Method

Transactional method for initiating leading zeros prediction. Takes ‘predict_in_layout’ as argument Returns shift amount as ‘predict_out_layout’

__init__(*, fpu_params: FPUParams)

Module contents