OpenCores
Issue List
ORPSoCv2 does not implement overflow for l.add #101
Closed jeremybennett opened this issue over 14 years ago
jeremybennett commented over 14 years ago
<p> <tt>l.add</tt> is <em>signed</em> addition, which should set the CY (for 1's complement overflow) and OV (for 2's complement overflow) flags appropriately, and if appropriate trigger the overflow exception. </p> <p> The following code fragment shows that the OV flag is never set. </p> <pre> /* Jeremy stuff. First two small positive numbers */ l.addi r4,r0,1 l.addi r5,r0,2
l.mfspr	r3,r0,SPR_SR
l.jal	_report
l.nop

l.add	r3,r5,r4
l.mfspr	r6,r0,SPR_SR

l.jal	_report
l.nop

l.add	r3,r0,r6
l.jal	_report
l.nop

/* Two small negative numbers */
l.movhi	r4,hi(0xffffffff)
l.ori	r4,r4,lo(0xffffffff)
l.movhi	r5,hi(0xfffffffe)
l.ori	r5,r5,lo(0xfffffffe)

l.mfspr	r3,r0,SPR_SR
l.jal	_report
l.nop

l.add	r3,r5,r4
l.mfspr	r6,r0,SPR_SR

l.jal	_report
l.nop

l.add	r3,r0,r6
l.jal	_report
l.nop

/* Two large positive numbers. 2's complement should overflow, but not
   1's complement. So the OV flag should be set, but not the CY flag.
*/
l.movhi	r4,hi(0x40000000)
l.ori	r4,r4,lo(0x40000000)
l.movhi	r5,hi(0x40000000)
l.ori	r5,r5,lo(0x40000000)

l.mfspr	r3,r0,SPR_SR
l.jal	_report
l.nop

l.add	r3,r5,r4
l.mfspr	r6,r0,SPR_SR

l.jal	_report
l.nop

l.add	r3,r0,r6
l.jal	_report
l.nop

/* Two large negative numbers. 2's complement should overflow, and
   also 1's complement, since these are also very big unsigned
   numbers. So the OV flag and CY flags should both be set.  */
l.movhi	r4,hi(0xbfffffff)
l.ori	r4,r4,lo(0xbfffffff)
l.movhi	r5,hi(0xbfffffff)
l.ori	r5,r5,lo(0xbfffffff)

l.mfspr	r3,r0,SPR_SR
l.jal	_report
l.nop

l.add	r3,r5,r4
l.mfspr	r6,r0,SPR_SR

l.jal	_report
l.nop

l.add	r3,r0,r6
l.jal	_report
l.nop

l.jal	_or32_exit
l.nop
l.nop
</pre> <p> The output is: </p> <pre> 57200.00 ns: report (8001) 59080.00 ns: report (3) 60840.00 ns: report (8001) 63080.00 ns: report (8001) 64960.00 ns: report (fffffffd) 66720.00 ns: report (8401) 68960.00 ns: report (8001) 70840.00 ns: report (80000000) 72600.00 ns: report (8001) 74840.00 ns: report (8001) 76720.00 ns: report (7ffffffe) 78480.00 ns: report (8401) </pre> <p> As can be seen only the CY flag (0x400) is ever set. The OV flag (0x800) should have been set in the third and fourth cases. </p> <p> Jeremy </p> <p> -- <br /> Tel: +44 (1590) 610184<br /> Cell: +44 (7970) 676050<br /> SkypeID: jeremybennett<br /> Email: <a href="mailto:jeremy.bennett@embecosm.com">jeremy.bennett@embecosm.com</a><br /> Web: <a href="http://www.embecosm.com">www.embecosm.com</a> </p>
julius was assigned over 14 years ago
rherveille commented over 14 years ago

Hi Jeremy,

That is correct. Overflow is not implemented at all in the OR1200. I added this in the new code, but it will take a while before all of that is working.

Richard

jeremybennett commented over 14 years ago
<p> Hi Richard </p> <p> Thanks for the update. I look forward to seeing the new code. </p> <p> For testing you may like to know that Or1ksim does implement overflow (and overflow exceptions in SR) in the current SVN tree. It will shortly have that implemented for all arithmetic operations, together with matching tests which should be reusable. </p> <p> Jeremy </p>
olof commented over 13 years ago

Has this been tested in hardware yet?

jeremybennett commented over 13 years ago
<p> Transferred to OpenRISC bugzilla (<a href="http://bugzilla.opencores.org/show_bug.cgi?id=16">Bug 16</a>). </p> <p> Marking closed in this bugtracker. </p>
jeremybennett closed this over 13 years ago

Assignee
julius
Labels
Bug