Libre RISC-V Mailing list Archives (accessible via public-inbox)
 help / color / Atom feed
From: Luke Kenneth Casson Leighton <lkcl@lkcl.net>
To: Jacob Lifshay <programmerjake@gmail.com>,
	 Libre-RISCV General Development
	<libre-riscv-dev@lists.libre-riscv.org>
Cc: "openpower-hdl-cores@mailinglist.openpowerfoundation.org"
	<openpower-hdl-cores@mailinglist.openpowerfoundation.org>
Subject: Re: [libre-riscv-dev] spec ambiguity divwe - divwue v3.0B / v3.1B
Date: Fri, 10 Jul 2020 18:06:43 +0100
Message-ID: <CAPweEDwaJqeEOn8=VnwKxM34AL32DFXErFdVjME395QTdvBDpg@mail.gmail.com> (raw)
In-Reply-To: <CAPweEDwzjjgFmwXFFznY5D_NaqY-K1gSfagRb-rPPNaM4rSTNg@mail.gmail.com>

continuing on this same subject, we have progress on part-resolving the
overflow on divw* and have moved on to divuw*

this is where another spanner in the pseudocode works was discovered.

divw* text (including divwe) says that the integers shall be treated as
signed.

divuw* text says unsigned.

unfortunately the actual behaviour of the divide operator "/" is
*different* for certain identical values.

here is the implementation of a signed trunc div:

x = abs(n)
y = abs(d)
result = y FLOORDIV x
if sign(n) == sign(d) return result
return -result

which works perfectly well for unsigned input as long as the top bit of
either n or d is zero.

the bottom line is that to properly represent the operations in the
pseudocode, a signed div operator needs to be introduced.

(likewise for mod *and mul*)

without these operators the implementor - every implementor - is forced to
read the words rather than rely on the accuracy of the pseudocode.

as we have seen in at least one instance (the sail power implementation
which was derived directly from the IBM XML variant of the spec using a
code generator) that simply does not happen because people trust the
pseudocode to be unambiguous.

unfortunately with there being no discernment between div-signed operator
or div-unsigned, mistakes are being made.

there is actually precedent for postfixing "u" on operators in the spec,
and after some thought that is what i would advocate in this case:

* /u to discern div-unsigned from / for div-signed
* likewise for multiply
* likewise for mod.

more when i am happy with the quantity of unit tests covering a large
enough range of values on all operations.

l.



-- 
---
crowd-funded eco-conscious hardware: https://www.crowdsupply.com/eoma68
_______________________________________________
libre-riscv-dev mailing list
libre-riscv-dev@lists.libre-riscv.org
http://lists.libre-riscv.org/mailman/listinfo/libre-riscv-dev

       reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAPweEDz_cPmfKbqCsAjJOamM5vMGJNzd9f2O0T8y0h-vFOb1=Q@mail.gmail.com>
     [not found] ` <CAC2bXD4D9ToTMKwn3mkx-irMfSc3j8V4mj0LB7VL0NJq_kunvg@mail.gmail.com>
     [not found]   ` <CAPweEDwzjjgFmwXFFznY5D_NaqY-K1gSfagRb-rPPNaM4rSTNg@mail.gmail.com>
2020-07-10 17:06     ` Luke Kenneth Casson Leighton [this message]
2020-07-10 22:26       ` Luke Kenneth Casson Leighton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPweEDwaJqeEOn8=VnwKxM34AL32DFXErFdVjME395QTdvBDpg@mail.gmail.com' \
    --to=lkcl@lkcl.net \
    --cc=libre-riscv-dev@lists.libre-riscv.org \
    --cc=openpower-hdl-cores@mailinglist.openpowerfoundation.org \
    --cc=programmerjake@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Libre RISC-V Mailing list Archives (accessible via public-inbox)

Archives are clonable: git clone --mirror https://inbox.libre-soc.org/libre-riscv-dev

Example config snippet for mirrors


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git