Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
uses: flutter-actions/setup-flutter@v2
with:
channel: stable
version: 3.24.2
version: 3.27.0

- name: Analyze flutter source
run: tool/gh_actions/analyze_flutter_source.sh
Expand Down Expand Up @@ -157,7 +157,7 @@ jobs:
uses: flutter-actions/setup-flutter@v2
with:
channel: stable
version: 3.24.2
version: 3.27.0

- name: Build static site
run: tool/gh_actions/hcl_site_generation_build.sh
Expand Down
12 changes: 6 additions & 6 deletions confapp/lib/hcl/view/screen/sidebar_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const canvasColor = Color(0xFF2E2E48);
const scaffoldBackgroundColor = Color(0xFF464667);
const accentCanvasColor = Color(0xFF3E3E61);
const white = Colors.white;
final actionColor = const Color(0xFF5F5FA7).withOpacity(0.6);
final divider = Divider(color: white.withOpacity(0.3), height: 1);
final actionColor = const Color(0xFF5F5FA7).withValues(alpha: 0.6);
final divider = Divider(color: white.withValues(alpha: 0.3), height: 1);

class ComponentsSidebar extends StatefulWidget {
final Function(void) updateForm;
Expand Down Expand Up @@ -67,7 +67,7 @@ class _ComponentsSidebarState extends State<ComponentsSidebar> {
borderRadius: BorderRadius.circular(20),
),
hoverColor: scaffoldBackgroundColor,
textStyle: TextStyle(color: Colors.white.withOpacity(0.7)),
textStyle: TextStyle(color: Colors.white.withValues(alpha: 0.7)),
selectedTextStyle: const TextStyle(color: Colors.white),
itemTextPadding: const EdgeInsets.only(left: 5),
selectedItemTextPadding: const EdgeInsets.only(left: 5),
Expand All @@ -78,20 +78,20 @@ class _ComponentsSidebarState extends State<ComponentsSidebar> {
selectedItemDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: actionColor.withOpacity(0.37),
color: actionColor.withValues(alpha: 0.37),
),
gradient: const LinearGradient(
colors: [accentCanvasColor, canvasColor],
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.28),
color: Colors.black.withValues(alpha: 0.28),
blurRadius: 30,
)
],
),
iconTheme: IconThemeData(
color: Colors.white.withOpacity(0.7),
color: Colors.white.withValues(alpha: 0.7),
size: 20,
),
selectedIconTheme: const IconThemeData(
Expand Down
6 changes: 3 additions & 3 deletions doc/components/fixed_point.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ Fixed-point binary representation of numbers is useful several applications incl

## FixedPointValue

A [FixedPointValue](https://intel.github.io/rohd-hcl/rohd_hcl/FixedPointValue-class.html) represents a signed or unsigned fixed-point value following the Q notation (Qm.n format) as introduced by [Texas Instruments](https://www.ti.com/lit/ug/spru565b/spru565b.pdf). It comprises an optional sign, integer part and/or a fractional part. [FixedPointValue](https://intel.github.io/rohd-hcl/rohd_hcl/FixedPointValue-class.html)s can be constructed from individual fields or from a Dart [double](https://api.dart.dev/stable/3.6.0/dart-core/double-class.html), converted to Dart [double](https://api.dart.dev/stable/3.6.0/dart-core/double-class.html), can be compared and can be operated on (+, -, *, /).
A [FixedPointValue](https://intel.github.io/rohd-hcl/rohd_hcl/FixedPointValue-class.html) represents a signed or unsigned fixed-point value following the Q notation (Qm.n format) as introduced by [Texas Instruments](https://www.ti.com/lit/ug/spru565b/spru565b.pdf). It comprises an optional sign, integer part and/or a fractional part. [FixedPointValue](https://intel.github.io/rohd-hcl/rohd_hcl/FixedPointValue-class.html)s can be constructed from individual fields or from a Dart [double](https://api.dart.dev/stable/3.6.0/dart-core/double-class.html), converted to Dart [double](https://api.dart.dev/stable/3.6.0/dart-core/double-class.html), can be compared and can be operated on (+, -, *, /). A `FixedPointValuePopulator` can be used to construct `FixedPointValue` using different kinds of converters.

## FixedPoint

The [FixedPoint](https://intel.github.io/rohd-hcl/rohd_hcl/FixedPoint-class.html) type is an extension of [Logic](https://intel.github.io/rohd/rohd/Logic-class.html) with additional attributes (signed or unsigned, integer width and fraction width). This type is provided to simplify the design of fixed-point arithmetic blocks.
The [FixedPoint](https://intel.github.io/rohd-hcl/rohd_hcl/FixedPoint-class.html) type is an extension of [LogicStructure](https://intel.github.io/rohd/rohd/LogicStructure-class.html) with additional attributes (signed or unsigned, integer width and fraction width). This type is provided to simplify the design of fixed-point arithmetic blocks.

## FixedToFloat

Expand All @@ -18,7 +18,7 @@ The [FixedToFloat](https://intel.github.io/rohd-hcl/rohd_hcl/FixedToFloat-class.

This component converts a floating-point signal to a signed fixed-point signal. Infinities and NaN's are not supported. The integer and fraction widths are auto-calculated to achieve lossless conversion.

If the `m` and `n` integer and fraction widths are supplied, then lossy conversion is performed to fit the floating-point value into the fixed-point value. For testing, [FixedPointValue](https://intel.github.io/rohd-hcl/rohd_hcl/FixedPointValue-class.html) has a `canStore` method to predetermine if a given double can fit. For execution, [FloatToFixed](https://intel.github.io/rohd-hcl/rohd_hcl/FloatToFixed-class.html) can perform overflow detection by setting a `checkOverflow` option, which is a property of the class and set in the constructor (default is false as it must add significant logic to do the check).
If the `integerWidth` and `fractionWidth` integer and fraction widths are supplied, then lossy conversion is performed to fit the floating-point value into the fixed-point value. For testing, [FixedPointValue](https://intel.github.io/rohd-hcl/rohd_hcl/FixedPointValue-class.html) has a `canStore` method to predetermine if a given double can fit. For execution, [FloatToFixed](https://intel.github.io/rohd-hcl/rohd_hcl/FloatToFixed-class.html) can perform overflow detection by setting a `checkOverflow` option, which is a property of the class and set in the constructor (default is false as it must add significant logic to do the check).

Currently, the FloatToFixed converter, when in lossy mode, is not performing any real rounding (just truncating).

Expand Down
28 changes: 20 additions & 8 deletions lib/src/arithmetic/fixed_sqrt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,26 @@ class FixedPointSqrt extends FixedPointSqrtBase {
throw RohdHclException('Signed values not supported');
}

Logic solution =
FixedPoint(signed: a.signed, name: 'solution', m: a.m + 1, n: a.n + 1);
Logic remainder =
FixedPoint(signed: a.signed, name: 'remainder', m: a.m + 1, n: a.n + 1);
Logic subtractionValue =
FixedPoint(signed: a.signed, name: 'subValue', m: a.m + 1, n: a.n + 1);
Logic aLoc =
FixedPoint(signed: a.signed, name: 'aLoc', m: a.m + 1, n: a.n + 1);
Logic solution = FixedPoint(
signed: a.signed,
name: 'solution',
integerWidth: a.integerWidth + 1,
fractionWidth: a.fractionWidth + 1);
Logic remainder = FixedPoint(
signed: a.signed,
name: 'remainder',
integerWidth: a.integerWidth + 1,
fractionWidth: a.fractionWidth + 1);
Logic subtractionValue = FixedPoint(
signed: a.signed,
name: 'subValue',
integerWidth: a.integerWidth + 1,
fractionWidth: a.fractionWidth + 1);
Logic aLoc = FixedPoint(
signed: a.signed,
name: 'aLoc',
integerWidth: a.integerWidth + 1,
fractionWidth: a.fractionWidth + 1);

solution = Const(0, width: aLoc.width).named('solution');
remainder = Const(0, width: aLoc.width).named('remainder');
Expand Down
8 changes: 5 additions & 3 deletions lib/src/arithmetic/fixed_to_float.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class FixedToFloat extends Module {
final bias = float.floatingPointValue.bias;
final eMax = pow(2, float.exponent.width) - 2;
final iWidth = (1 +
max(log2Ceil(fixed.n),
max(log2Ceil(fixed.fractionWidth),
max(log2Ceil(fixed.width), float.exponent.width)))
.toInt();

Expand All @@ -82,7 +82,7 @@ class FixedToFloat extends Module {
..gets(mux(_convertedFloat.sign, fixed, fixed));
}

final maxShift = fixed.width - fixed.n + bias - 2;
final maxShift = fixed.width - fixed.fractionWidth + bias - 2;

final jBit = Logic(name: 'jBit', width: iWidth);
Logic estimatedJBit;
Expand Down Expand Up @@ -166,7 +166,9 @@ class FixedToFloat extends Module {
// Calculate biased exponent
final eRaw = mux(
absValueShifted[-1],
(Const(bias + fixed.width - fixed.n - 1, width: iWidth) - jBit)
(Const(bias + fixed.width - fixed.fractionWidth - 1,
width: iWidth) -
jBit)
.named('eShift'),
Const(0, width: iWidth))
.named('eRaw');
Expand Down
54 changes: 34 additions & 20 deletions lib/src/arithmetic/float_to_fixed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import 'package:rohd_hcl/rohd_hcl.dart';
/// ```
class FloatToFixed extends Module {
/// Width of output integer part.
late final int m;
late final int integerWidth;

/// Width of output fractional part.
late final int n;
late final int fractionWidth;

/// Add overflow checking logic
final bool checkOverflow;
Expand All @@ -35,20 +35,25 @@ class FloatToFixed extends Module {
Logic? get overflow => tryOutput('overflow');

/// Internal representation of the output port
late final FixedPoint _fixed = FixedPoint(signed: true, m: m, n: n);
late final FixedPoint _fixed =
FixedPoint(integerWidth: integerWidth, fractionWidth: fractionWidth);

/// Output fixed point port
late final FixedPoint fixed = _fixed.clone()..gets(output('fixed'));

/// Build a [FloatingPoint] to [FixedPoint] converter.
/// - if [m] and [n] are supplied, an m.n fixed-point output will be produced.
/// Otherwise, the converter will compute a lossless size for [m] and [n] for
/// outputing the floating-point value into a fixed-point value.
/// - if [integerWidth] and [fractionWidth] are supplied, an m.n fixed-point
/// output will be produced. Otherwise, the converter will compute a
/// lossless size for [integerWidth] and [fractionWidth] for outputing the
/// floating-point value into a fixed-point value.
/// - [checkOverflow] set to true will cause overflow detection to happen in
/// case that loss can occur and an optional output [overflow] will be
/// produced that returns true when overflow occurs.
/// case that loss can occur and an optional output [overflow] will be
/// produced that returns true when overflow occurs.
FloatToFixed(FloatingPoint float,
{super.name = 'FloatToFixed', int? m, int? n, this.checkOverflow = false})
{super.name = 'FloatToFixed',
int? integerWidth,
int? fractionWidth,
this.checkOverflow = false})
: super(
definitionName: 'FloatE${float.exponent.width}'
'M${float.mantissa.width}ToFixed') {
Expand All @@ -61,35 +66,42 @@ class FloatToFixed extends Module {
: bias + 1; // accomodate the jbit
final noLossN = bias + float.mantissa.width - 1;

this.m = m ?? noLossM;
this.n = n ?? noLossN;
final outputWidth = this.m + this.n + 1;
// TODO(desmonddak): Check what happens with an explicitJBit FP

this.integerWidth = integerWidth ?? noLossM;
this.fractionWidth = fractionWidth ?? noLossN;
final outputWidth = this.integerWidth + this.fractionWidth + 1;

final jBit = Logic(name: 'jBit')..gets(float.isNormal);
final fullMantissa = [jBit, float.mantissa].swizzle().named('fullMantissa');

final eWidth = max(log2Ceil(this.n + this.m), float.exponent.width) + 2;
final eWidth = max(log2Ceil(this.fractionWidth + this.integerWidth),
float.exponent.width) +
2;
final shift = Logic(name: 'shift', width: eWidth);
final exp = (float.exponent - 1).zeroExtend(eWidth).named('expMinus1');

if (this.n > noLossN) {
if (this.fractionWidth > noLossN) {
shift <=
mux(jBit, exp, Const(0, width: eWidth)) +
Const(this.n - noLossN, width: eWidth).named('deltaN');
} else if (this.n == noLossN) {
Const(this.fractionWidth - noLossN, width: eWidth)
.named('deltaN');
} else if (this.fractionWidth == noLossN) {
shift <= mux(jBit, exp, Const(0, width: eWidth));
} else {
shift <=
mux(jBit, exp, Const(0, width: eWidth)) -
Const(noLossN - this.n, width: eWidth).named('deltaN');
Const(noLossN - this.fractionWidth, width: eWidth)
.named('deltaN');
}
// TODO(desmonddak): Could use signed shifter if we unified shift math
final shiftRight = ((fullMantissa.width > outputWidth)
? (~shift + 1) - (fullMantissa.width - outputWidth)
: (~shift + 1))
.named('shiftRight');

if (checkOverflow & ((this.m < noLossM) | (this.n < noLossN))) {
if (checkOverflow &
((this.integerWidth < noLossM) | (this.fractionWidth < noLossN))) {
final overflow = Logic(name: 'overflow');
final leadDetect = RecursiveModulePriorityEncoder(fullMantissa.reversed,
name: 'leadone_detector');
Expand Down Expand Up @@ -151,10 +163,12 @@ class Float8ToFixed extends Module {
Logic get fixed => output('fixed');

/// Getter for Q23.9
FixedPoint get q23p9 => FixedPoint.of(fixed, signed: true, m: 23, n: 9);
FixedPoint get q23p9 =>
FixedPoint.of(fixed, integerWidth: 23, fractionWidth: 9);

/// Getter for Q16.16
FixedPoint get q16p16 => FixedPoint.of(fixed, signed: true, m: 16, n: 16);
FixedPoint get q16p16 =>
FixedPoint.of(fixed, integerWidth: 16, fractionWidth: 16);

/// Constructor
Float8ToFixed(Logic float, Logic mode, {super.name = 'Float8ToFixed'}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class FloatingPointSqrtSimple<FpType extends FloatingPoint>
final isExpOdd = deBiasExp[0];

// use fixed sqrt unit
final aFixed = FixedPoint(signed: false, m: 3, n: a.mantissa.width);
final aFixed = FixedPoint(
signed: false, integerWidth: 3, fractionWidth: a.mantissa.width);
aFixed <=
[Const(1, width: 3), a.mantissa.getRange(0)].swizzle().named('aFixed');

Expand Down
Loading