[aarch64-port-dev ] frintz instruction in simulator
D.Sturm
D.Sturm42 at gmail.com
Sat Apr 26 14:45:47 UTC 2014
Ah does the mailing list swallow the attachments or did you overlook it?
(not usual to not inline patches here I see, sorry!)
Here's the patch:
# HG changeset patch
# User Daniel Sturm <d.sturm42 at gmail.com>
# Date 1398462569 -7200
# Fri Apr 25 23:49:29 2014 +0200
# Node ID 8866f73c6637b0ff0107eb9f14c1fd319e1f50bd
# Parent d70a2050eb423046283bc8f1280fd9d9e1fabc21
implemented frintz instruction.
diff -r d70a2050eb42 -r 8866f73c6637 simulator.cpp
--- a/simulator.cpp Fri Jan 03 13:42:36 2014 +0000
+++ b/simulator.cpp Fri Apr 25 23:49:29 2014 +0200
@@ -1373,10 +1373,19 @@
case 0b000111: // FCVT double/single to half precision
errorCode = ERROR_NYI;
return error();
+ case 0b001011: // FRINTZ
+ if (type == 0b01) {
+ frintzd();
+ } else if (type == 0b00) {
+ frintzs();
+ } else {
+ errorCode = ERROR_UNALLOC;
+ return error();
+ }
+ return STATUS_READY;
case 0b001000: // FRINTN etc
case 0b001001:
case 0b001010:
- case 0b001011:
case 0b001100:
case 0b001110:
case 0b001111:
@@ -7988,6 +7997,32 @@
dreg(0) = (double)sreg(5);
}
+template <class T>
+static inline T frintz(T val)
+{
+ if (val == -0.0 || isinf(val) || isnan(val)) {
+ return val;
+ }
+ return (T)(int64_t)val;
+}
+
+// round to integral towards zero
+void AArch64Simulator::frintzs()
+{
+ // instr[9,5] = Sn
+ // instr[4,0] = Sd
+ sreg(0) = frintz(sreg(5));
+}
+
+// round to integral towards zero
+void AArch64Simulator::frintzd()
+{
+ // instr[9,5] = Dn
+ // instr[4,0] = Dd
+ dreg(0) = frintz(dreg(5));
+}
+
+
// 2 sources
// float add
diff -r d70a2050eb42 -r 8866f73c6637 simulator.hpp
--- a/simulator.hpp Fri Jan 03 13:42:36 2014 +0000
+++ b/simulator.hpp Fri Apr 25 23:49:29 2014 +0200
@@ -1287,6 +1287,10 @@
// etc
// TODO FP round to integral/ nearest integral floating
+ // float round to integral, towards zero.
+ void frintzs();
+ // double round to integral, towards zero.
+ void frintzd();
// TODO FP arithmetic
//
On 26 April 2014 15:47, Andrew Haley <aph at redhat.com> wrote:
> On 04/25/2014 11:16 PM, D.Sturm wrote:
> > Hi,
> > Since I need a frintz instruction when generating the floating point
> > remainder operation* I had to implement it in the simulator.
> >
> > The implementation should be correct except in case of a signaling NaN
> > since that should throw an exception (could make a difference if someone
> > generates a signaling NaN manually from the integer pattern, but that
> seems
> > like an extreme edge case).
> >
> > Maybe useful for the general branch too.
>
> Sure, er, please post it. :-)
>
> Andrew.
>
>
>
More information about the aarch64-port-dev
mailing list