Blob Blame History Raw
From 966b9076fb3303b6e5191222c63229700f30a00e Mon Sep 17 00:00:00 2001
From: Aina Niemetz <aina.niemetz@gmail.com>
Date: Fri, 9 Sep 2022 08:24:53 -0700
Subject: [PATCH] rounder: Fix invalid creation of zero-size bit-vector.

Fixes #8.

This fixes an issue where the rounder attempts to generate a bit-vector
of size 0 in fixedPositionRound() when converting an FP to an unsigned
BV of size 1.
---
 core/rounder.h | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/core/rounder.h b/core/rounder.h
index 99749fa..1eeefd4 100644
--- a/core/rounder.h
+++ b/core/rounder.h
@@ -223,8 +223,13 @@ namespace symfpu {
     ubv roundedSignificand(conditionalIncrement<t>(roundUp, extractedSignificand));
 
     ubv overflowBit(roundedSignificand.extract(targetWidth, targetWidth) & ubv(roundUp));
-    ubv carryUpMask((overflowBit | ubv(knownLeadingOne)).append(ubv::zero(targetWidth - 1)));   // Cheaper than conditional shift
-    
+    // Cheaper than conditional shift
+    ubv carryUpMask(overflowBit | ubv(knownLeadingOne));
+    if (targetWidth > 1)
+    {
+      carryUpMask = carryUpMask.append(ubv::zero(targetWidth - 1));
+    }
+
     // Build result
     significandRounderResult<t> result(roundedSignificand.extract(targetWidth-1,0) | carryUpMask,
 				    overflowBit.isAllOnes());