ieee754.fpcommon package

Submodules

ieee754.fpcommon.basedata module

class ieee754.fpcommon.basedata.FPBaseData(pspec)

Bases: object

eq(i)
ports()

ieee754.fpcommon.corrections module

class ieee754.fpcommon.corrections.FPCorrectionsMod(pspec)

Bases: nmutil.pipemodbase.PipeModBase

elaborate(platform)
ispec()
ospec()

ieee754.fpcommon.denorm module

IEEE754 Floating Point Library

Copyright (C) 2019 Luke Kenneth Casson Leighton <lkcl@lkcl.net>

class ieee754.fpcommon.denorm.FPAddDeNormMod(pspec, m_extra)

Bases: nmutil.pipemodbase.PipeModBase

elaborate(platform)
ispec()
ospec()

ieee754.fpcommon.exphigh module

class ieee754.fpcommon.exphigh.FPEXPHigh(m_width, e_width)

Bases: nmigen.hdl.ir.Elaboratable

elaborate(platform)

ieee754.fpcommon.fpbase module

IEEE754 Floating Point Library

Copyright (C) 2019 Luke Kenneth Casson Leighton <lkcl@lkcl.net> Copyright (C) 2019 Jake Lifshay

class ieee754.fpcommon.fpbase.FPBase

Bases: object

IEEE754 Floating Point Base Class

contains common functions for FP manipulation, such as extracting and packing operands, normalisation, denormalisation, rounding etc.

corrections(m, z, next_state)

denormalisation and sign-bug corrections

denormalise(m, a)

denormalises a number. this is probably the wrong name for this function. for normalised numbers (exponent != minimum) one extra bit (the implicit 1) is added back in. for denormalised numbers, the mantissa is left alone and the exponent increased by 1.

both cases effectively multiply the number stored by 2, which has to be taken into account when extracting the result.

get_op(m, op, v, next_state)

this function moves to the next state and copies the operand when both stb and ack are 1. acknowledgement is sent by setting ack to ZERO.

normalise_1(m, z, of, next_state)

first stage normalisation

NOTE: just like “align”, this one keeps going round every clock
until the result’s exponent is within acceptable “range”
NOTE: the weirdness of reassigning guard and round is due to
the extra mantissa bits coming from tot[0..2]
normalise_2(m, z, of, next_state)

second stage normalisation

NOTE: just like “align”, this one keeps going round every clock
until the result’s exponent is within acceptable “range”
NOTE: the weirdness of reassigning guard and round is due to
the extra mantissa bits coming from tot[0..2]
op_normalise(m, op, next_state)

operand normalisation NOTE: just like “align”, this one keeps going round every clock

until the result’s exponent is within acceptable “range”
pack(m, z, next_state)

packs the result into the output (detects overflow->Inf)

put_z(m, z, out_z, next_state)

put_z: stores the result in the output. raises stb and waits for ack to be set to 1 before moving to the next state. resets stb back to zero when that occurs, as acknowledgement.

roundz(m, z, roundz)

performs rounding on the output. TODO: different kinds of rounding

class ieee754.fpcommon.fpbase.FPFormat(e_width, m_width, has_int_bit=False, has_sign=True)

Bases: object

Class describing binary floating-point formats based on IEEE 754.

Attribute e_width:
 the number of bits in the exponent field.
Attribute m_width:
 the number of bits stored in the mantissa field.
Attribute has_int_bit:
 if the FP format has an explicit integer bit (like the x87 80-bit format). The bit is considered part of the mantissa.
Attribute has_sign:
 if the FP format has a sign bit. (Some Vulkan Image/Buffer formats are FP numbers without a sign bit.)
e_max

get the maximum exponent (minus bias)

e_sub
exponent_bias

Get the exponent bias.

exponent_denormal_zero

Get the value of the exponent field designating denormal/zero.

exponent_inf_nan

Get the value of the exponent field designating infinity/NaN.

exponent_max_normal

Get the maximum value of the exponent field for normal numbers.

exponent_min_normal

Get the minimum value of the exponent field for normal numbers.

fraction_width

Get the number of mantissa bits that are fraction bits.

get_exponent(x)

returns the exponent of its input number, x

get_exponent_field(x)

returns the raw exponent of its input number, x (no bias subtracted)

get_mantissa_field(x)

returns the mantissa of its input number, x

get_sign_field(x)

returns the sign bit of its input number, x (assumes FPFormat is set to signed - has_sign=True)

is_inf(x)

returns true if x is infinite

is_nan(x)

returns true if x is a nan (quiet or signalling)

is_nan_signaling(x)

returns true if x is a signalling nan

is_quiet_nan(x)

returns true if x is a quiet nan

is_subnormal(x)

returns true if x is subnormal (exp at minimum)

is_zero(x)

returns true if x is +/- zero

mantissa_mask

Get a mantissa mask based on the mantissa width

static standard(width)

Get standard IEEE 754-2008 format.

Parameters:width – bit-width of requested format.
Returns:the requested FPFormat instance.
width

Get the total number of bits in the FP format.

class ieee754.fpcommon.fpbase.FPID(id_wid)

Bases: object

idsync(m)
class ieee754.fpcommon.fpbase.FPNumBase(fp)

Bases: ieee754.fpcommon.fpbase.FPNumBaseRecord, nmigen.hdl.ir.Elaboratable

Floating-point Base Number Class

elaborate(platform)
class ieee754.fpcommon.fpbase.FPNumBaseRecord(width, m_extra=True, e_extra=False, name=None)

Bases: object

Floating-point Base Number Class.

This class is designed to be passed around in other data structures (between pipelines and between stages). Its “friend” is FPNumBase, which is a module. The reason for the discernment is because nmigen modules that are not added to submodules results in the irritating “Elaboration” warning. Despite not needing FPNumBase in many cases to be added as a submodule (because it is just data) this was not possible to solve without splitting out the data from the module.

create(s, e, m)

creates a value from sign / exponent / mantissa

bias is added here, to the exponent.

NOTE: order is important, because e_start/e_end can be a bit too long (overwriting s).

create2(s, e, m)

creates a value from sign / exponent / mantissa

bias is added here, to the exponent

drop_in(fp)
eq(inp)
inf(s)
inf2(s)
nan(s)
nan2(s)
zero(s)
zero2(s)
class ieee754.fpcommon.fpbase.FPNumDecode(op, fp)

Bases: ieee754.fpcommon.fpbase.FPNumBase

Floating-point Number Class

Contains signals for an incoming copy of the value, decoded into sign / exponent / mantissa. Also contains encoding functions, creation and recognition of zero, NaN and inf (all signed)

Four extra bits are included in the mantissa: the top bit (m[-1]) is effectively a carry-overflow. The other three are guard (m[2]), round (m[1]), and sticky (m[0])

decode(v)

decodes a latched value into sign / exponent / mantissa

bias is subtracted here, from the exponent. exponent is extended to 10 bits so that subtract 127 is done on a 10-bit number

elaborate(platform)
class ieee754.fpcommon.fpbase.FPNumIn(op, fp)

Bases: ieee754.fpcommon.fpbase.FPNumBase

Floating-point Number Class

Contains signals for an incoming copy of the value, decoded into sign / exponent / mantissa. Also contains encoding functions, creation and recognition of zero, NaN and inf (all signed)

Four extra bits are included in the mantissa: the top bit (m[-1]) is effectively a carry-overflow. The other three are guard (m[2]), round (m[1]), and sticky (m[0])

decode(v)

decodes a latched value into sign / exponent / mantissa

bias is subtracted here, from the exponent. exponent is extended to 10 bits so that subtract 127 is done on a 10-bit number

decode2(m)

decodes a latched value into sign / exponent / mantissa

bias is subtracted here, from the exponent. exponent is extended to 10 bits so that subtract 127 is done on a 10-bit number

shift_down(inp)

shifts a mantissa down by one. exponent is increased to compensate

accuracy is lost as a result in the mantissa however there are 3 guard bits (the latter of which is the “sticky” bit)

shift_down_multi(diff, inp=None)

shifts a mantissa down. exponent is increased to compensate

accuracy is lost as a result in the mantissa however there are 3 guard bits (the latter of which is the “sticky” bit)

this code works by variable-shifting the mantissa by up to its maximum bit-length: no point doing more (it’ll still be zero).

the sticky bit is computed by shifting a batch of 1s by the same amount, which will introduce zeros. it’s then inverted and used as a mask to get the LSBs of the mantissa. those are then |’d into the sticky bit.

shift_up_multi(diff)

shifts a mantissa up. exponent is decreased to compensate

class ieee754.fpcommon.fpbase.FPNumOut(fp)

Bases: ieee754.fpcommon.fpbase.FPNumBase

Floating-point Number Class

Contains signals for an incoming copy of the value, decoded into sign / exponent / mantissa. Also contains encoding functions, creation and recognition of zero, NaN and inf (all signed)

Four extra bits are included in the mantissa: the top bit (m[-1]) is effectively a carry-overflow. The other three are guard (m[2]), round (m[1]), and sticky (m[0])

elaborate(platform)
class ieee754.fpcommon.fpbase.FPNumShift(mainm, op, inv, width, m_extra=True)

Bases: ieee754.fpcommon.fpbase.FPNumBase, nmigen.hdl.ir.Elaboratable

Floating-point Number Class for shifting

elaborate(platform)
shift_down(inp)

shifts a mantissa down by one. exponent is increased to compensate

accuracy is lost as a result in the mantissa however there are 3 guard bits (the latter of which is the “sticky” bit)

shift_down_multi(diff)

shifts a mantissa down. exponent is increased to compensate

accuracy is lost as a result in the mantissa however there are 3 guard bits (the latter of which is the “sticky” bit)

this code works by variable-shifting the mantissa by up to its maximum bit-length: no point doing more (it’ll still be zero).

the sticky bit is computed by shifting a batch of 1s by the same amount, which will introduce zeros. it’s then inverted and used as a mask to get the LSBs of the mantissa. those are then |’d into the sticky bit.

shift_up_multi(diff)

shifts a mantissa up. exponent is decreased to compensate

class ieee754.fpcommon.fpbase.FPOpIn(width)

Bases: nmutil.iocontrol.PrevControl

chain_from(in_op, extra=None)
chain_inv(in_op, extra=None)
v
class ieee754.fpcommon.fpbase.FPOpOut(width)

Bases: nmutil.iocontrol.NextControl

chain_from(in_op, extra=None)
chain_inv(in_op, extra=None)
v
class ieee754.fpcommon.fpbase.FPState(state_from)

Bases: ieee754.fpcommon.fpbase.FPBase

set_inputs(inputs)
set_outputs(outputs)
class ieee754.fpcommon.fpbase.MultiShift(width)

Bases: object

Generates variable-length single-cycle shifter from a series of conditional tests on each bit of the left/right shift operand. Each bit tested produces output shifted by that number of bits, in a binary fashion: bit 1 if set shifts by 1 bit, bit 2 if set shifts by 2 bits, each partial result cascading to the next Mux.

Could be adapted to do arithmetic shift by taking copies of the MSB instead of zeros.

lshift(op, s)
rshift(op, s)
class ieee754.fpcommon.fpbase.MultiShiftR(width)

Bases: object

elaborate(platform)
class ieee754.fpcommon.fpbase.MultiShiftRMerge(width, s_max=None)

Bases: nmigen.hdl.ir.Elaboratable

shifts down (right) and merges lower bits into m[0]. m[0] is the “sticky” bit, basically

elaborate(platform)
class ieee754.fpcommon.fpbase.Overflow(name=None)

Bases: object

FFLAGS_DZ = (const 5'd8)
FFLAGS_NV = (const 5'd16)
FFLAGS_NX = (const 5'd1)
FFLAGS_OF = (const 5'd4)
FFLAGS_UF = (const 5'd2)
eq(inp)
roundz
class ieee754.fpcommon.fpbase.OverflowMod(name=None)

Bases: nmigen.hdl.ir.Elaboratable, ieee754.fpcommon.fpbase.Overflow

elaborate(platform)
eq(inp)
class ieee754.fpcommon.fpbase.TestFPFormat(methodName='runTest')

Bases: unittest.case.TestCase

very quick test for FPFormat

test_fpformat_fp32()
test_fpformat_fp64()
class ieee754.fpcommon.fpbase.Trigger

Bases: nmigen.hdl.ir.Elaboratable

elaborate(platform)
eq(inp)
ports()

ieee754.fpcommon.getop module

class ieee754.fpcommon.getop.FPGet2OpMod(width, id_wid, op_wid=None)

Bases: nmutil.iocontrol.PrevControl

elaborate(platform)
ispec()
ospec()
process(i)
class ieee754.fpcommon.getop.FPGetOpMod(width)

Bases: nmigen.hdl.ir.Elaboratable

elaborate(platform)
class ieee754.fpcommon.getop.FPNumBase2Ops(width, id_wid, m_extra=True)

Bases: object

eq(i)
ports()

ieee754.fpcommon.msbhigh module

module for adjusting a mantissa and exponent so that the MSB is always 1

class ieee754.fpcommon.msbhigh.FPMSBHigh(m_width, e_width, limclz=False, loprop=False)

Bases: nmigen.hdl.ir.Elaboratable

makes the top mantissa bit hi (i.e. shifts until it is)

NOTE: this does NOT do any kind of checks. do not pass in zero (empty) stuff, and it’s best to check if the MSB is already 1 before calling it. although it’ll probably work in both cases…

  • exponent is signed
  • mantissa is unsigned.
  • loprop: propagates the low bit (LSB) on the shift
  • limclz: use this to limit the amount of shifting.

examples: exp = -30, mantissa = 0b00011 - output: -33, 0b11000 exp = 2, mantissa = 0b01111 - output: 1, 0b11110

elaborate(platform)

ieee754.fpcommon.normtopack module

IEEE754 Floating Point Pipeline

Copyright (C) 2019 Luke Kenneth Casson Leighton <lkcl@lkcl.net>

class ieee754.fpcommon.normtopack.FPNormToPack(pspec, e_extra=False)

Bases: nmutil.pipemodbase.PipeModBaseChain

get_chain()

gets chain of modules

ieee754.fpcommon.pack module

class ieee754.fpcommon.pack.FPPackMod(pspec)

Bases: nmutil.pipemodbase.PipeModBase

elaborate(platform)
ispec()
ospec()

ieee754.fpcommon.packdata module

class ieee754.fpcommon.packdata.FPPackData(pspec)

Bases: object

eq(i)
ports()

ieee754.fpcommon.postcalc module

class ieee754.fpcommon.postcalc.FPPostCalcData(pspec, e_extra=False)

Bases: object

eq(i)

ieee754.fpcommon.postnormalise module

class ieee754.fpcommon.postnormalise.FPNorm1Data(pspec)

Bases: object

eq(i)
class ieee754.fpcommon.postnormalise.FPNorm1ModMulti(pspec, single_cycle=True)

Bases: object

elaborate(platform)
class ieee754.fpcommon.postnormalise.FPNorm1ModSingle(pspec, e_extra=False)

Bases: nmutil.pipemodbase.PipeModBase

elaborate(platform)
ispec()
ospec()
class ieee754.fpcommon.postnormalise.FPNorm1Multi(width, id_wid)

Bases: ieee754.fpcommon.fpbase.FPState

action(m)
setup(m, in_z, in_of, norm_stb)

links module to inputs and outputs

class ieee754.fpcommon.postnormalise.FPNorm1Single(width, id_wid, single_cycle=True)

Bases: ieee754.fpcommon.fpbase.FPState

action(m)
ispec()
ospec()
setup(m, i)

links module to inputs and outputs

ieee754.fpcommon.pscdata module

IEEE754 Floating Point Library

Copyright (C) 2019 Luke Kenneth Casson Leighton <lkcl@lkcl.net>

class ieee754.fpcommon.pscdata.FPSCData(pspec, m_extra)

Bases: object

eq(i)

ieee754.fpcommon.putz module

class ieee754.fpcommon.putz.FPPutZ(state, in_z, out_z, in_mid, out_mid, to_state=None)

Bases: ieee754.fpcommon.fpbase.FPState

action(m)
class ieee754.fpcommon.putz.FPPutZIdx(state, in_z, out_zs, in_mid, to_state=None)

Bases: ieee754.fpcommon.fpbase.FPState

action(m)

ieee754.fpcommon.roundz module

class ieee754.fpcommon.roundz.FPRoundData(pspec)

Bases: object

eq(i)
class ieee754.fpcommon.roundz.FPRoundMod(pspec)

Bases: nmutil.pipemodbase.PipeModBase

elaborate(platform)
ispec()
ospec()

Module contents