1 from openpower
.test
.common
import TestAccumulatorBase
, skip_case
2 from openpower
.sv
.trans
.svp64
import SVP64Asm
3 from openpower
.test
.state
import ExpectedState
4 from openpower
.simulator
.program
import Program
5 from openpower
.decoder
.isa
.caller
import SVP64State
6 from openpower
.fpscr
import FPSCRState
11 class FMvFCvtCases(TestAccumulatorBase
):
12 def js_toint32(self
, inp
, expected
, test_title
="", inp_bits
=None):
15 inp_bits
= struct
.unpack("<Q", struct
.pack("<d", inp
))[0]
17 with self
.subTest(inp
=inp
.hex(), inp_bits
=hex(inp_bits
),
18 expected
=hex(expected
), test_title
=test_title
):
19 lst
= list(SVP64Asm(["fcvttg 3,0,5,0"]))
23 e
= ExpectedState(pc
=4, int_regs
=gprs
, fp_regs
=fprs
)
24 e
.intregs
[3] = expected
26 if math
.isnan(inp
) and (inp_bits
& 2 ** 51) == 0: # SNaN
30 if not math
.isfinite(inp
) or not (
31 -0x8000_0000 <= math
.trunc(inp
) <= 0x7fff_ffff):
34 elif math
.trunc(inp
) != inp
: # inexact
38 fpscr
.FPRF
= 0 # undefined value we happen to pick
39 fpscr
.FR
= 0 # trunc never increments
40 with self
.subTest(expected_VXSNAN
=fpscr
.VXSNAN
,
41 expected_VXCVI
=fpscr
.VXCVI
,
43 expected_FI
=fpscr
.FI
):
46 Program(lst
, False), gprs
, fpregs
=fprs
, expected
=e
)
48 def case_js_toint32(self
):
49 min_value
= pow(2, -1074)
51 # https://chromium.googlesource.com/v8/v8.git/+/d94dfc2b01f988566aa410ce871588cf23b1285d/test/mjsunit/toint32.js
52 # Copyright 2008 the V8 project authors. All rights reserved.
53 # Redistribution and use in source and binary forms, with or without
54 # modification, are permitted provided that the following conditions are
57 # * Redistributions of source code must retain the above copyright
58 # notice, this list of conditions and the following disclaimer.
59 # * Redistributions in binary form must reproduce the above
60 # copyright notice, this list of conditions and the following
61 # disclaimer in the documentation and/or other materials provided
62 # with the distribution.
63 # * Neither the name of Google Inc. nor the names of its
64 # contributors may be used to endorse or promote products derived
65 # from this software without specific prior written permission.
67 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
68 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
69 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
70 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
71 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
72 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
73 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
74 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
75 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
76 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
77 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
79 self
.js_toint32(math
.inf
, 0, "Inf")
80 self
.js_toint32(-math
.inf
, 0, "-Inf")
81 self
.js_toint32(math
.nan
, 0, "NaN")
82 self
.js_toint32(math
.nan
, 0, "SNaN", inp_bits
=0x7ff0_0000_0000_0001)
83 self
.js_toint32(0.0, 0, "zero")
84 self
.js_toint32(-0.0, 0, "-zero")
85 self
.js_toint32(min_value
, 0)
86 self
.js_toint32(-min_value
, 0)
87 self
.js_toint32(0.1, 0)
88 self
.js_toint32(-0.1, 0)
89 self
.js_toint32(1, 1, "one")
90 self
.js_toint32(1.1, 1, "onepointone")
91 self
.js_toint32(-1, -1, "-one")
92 self
.js_toint32(0.6, 0, "truncate positive (0.6)")
93 self
.js_toint32(1.6, 1, "truncate positive (1.6)")
94 self
.js_toint32(-0.6, 0, "truncate negative (-0.6)")
95 self
.js_toint32(-1.6, -1, "truncate negative (-1.6)")
96 self
.js_toint32(2147483647, 2147483647)
97 self
.js_toint32(2147483648, -2147483648)
98 self
.js_toint32(2147483649, -2147483647)
99 self
.js_toint32(4294967295, -1)
100 self
.js_toint32(4294967296, 0)
101 self
.js_toint32(4294967297, 1)
102 self
.js_toint32(-2147483647, -2147483647)
103 self
.js_toint32(-2147483648, -2147483648)
104 self
.js_toint32(-2147483649, 2147483647)
105 self
.js_toint32(-4294967295, 1)
106 self
.js_toint32(-4294967296, 0)
107 self
.js_toint32(-4294967297, -1)
108 self
.js_toint32(2147483648.25, -2147483648)
109 self
.js_toint32(2147483648.5, -2147483648)
110 self
.js_toint32(2147483648.75, -2147483648)
111 self
.js_toint32(4294967295.25, -1)
112 self
.js_toint32(4294967295.5, -1)
113 self
.js_toint32(4294967295.75, -1)
114 self
.js_toint32(3000000000.25, -1294967296)
115 self
.js_toint32(3000000000.5, -1294967296)
116 self
.js_toint32(3000000000.75, -1294967296)
117 self
.js_toint32(-2147483648.25, -2147483648)
118 self
.js_toint32(-2147483648.5, -2147483648)
119 self
.js_toint32(-2147483648.75, -2147483648)
120 self
.js_toint32(-4294967295.25, 1)
121 self
.js_toint32(-4294967295.5, 1)
122 self
.js_toint32(-4294967295.75, 1)
123 self
.js_toint32(-3000000000.25, 1294967296)
124 self
.js_toint32(-3000000000.5, 1294967296)
125 self
.js_toint32(-3000000000.75, 1294967296)
127 self
.js_toint32(base
+ 0, 0)
128 self
.js_toint32(base
+ 1117, 0)
129 self
.js_toint32(base
+ 2234, 4096)
130 self
.js_toint32(base
+ 3351, 4096)
131 self
.js_toint32(base
+ 4468, 4096)
132 self
.js_toint32(base
+ 5585, 4096)
133 self
.js_toint32(base
+ 6702, 8192)
134 self
.js_toint32(base
+ 7819, 8192)
135 self
.js_toint32(base
+ 8936, 8192)
136 self
.js_toint32(base
+ 10053, 8192)
137 self
.js_toint32(base
+ 11170, 12288)
138 self
.js_toint32(base
+ 12287, 12288)
139 self
.js_toint32(base
+ 13404, 12288)
140 self
.js_toint32(base
+ 14521, 16384)
141 self
.js_toint32(base
+ 15638, 16384)
142 self
.js_toint32(base
+ 16755, 16384)
143 self
.js_toint32(base
+ 17872, 16384)
144 self
.js_toint32(base
+ 18989, 20480)
145 self
.js_toint32(base
+ 20106, 20480)
146 self
.js_toint32(base
+ 21223, 20480)
147 self
.js_toint32(base
+ 22340, 20480)
148 self
.js_toint32(base
+ 23457, 24576)
149 self
.js_toint32(base
+ 24574, 24576)
150 self
.js_toint32(base
+ 25691, 24576)
151 self
.js_toint32(base
+ 26808, 28672)
152 self
.js_toint32(base
+ 27925, 28672)
153 self
.js_toint32(base
+ 29042, 28672)
154 self
.js_toint32(base
+ 30159, 28672)
155 self
.js_toint32(base
+ 31276, 32768)
156 # bignum is (2 ^ 53 - 1) * 2 ^ 31 - highest number with bit 31 set.
157 bignum
= pow(2, 84) - pow(2, 31)
158 self
.js_toint32(bignum
, -pow(2, 31))
159 self
.js_toint32(-bignum
, -pow(2, 31))
160 self
.js_toint32(2 * bignum
, 0)
161 self
.js_toint32(-(2 * bignum
), 0)
162 self
.js_toint32(bignum
- pow(2, 31), 0)
163 self
.js_toint32(-(bignum
- pow(2, 31)), 0)
164 # max_fraction is largest number below 1.
165 max_fraction
= (1 - pow(2, -53))
166 self
.js_toint32(max_fraction
, 0)
167 self
.js_toint32(-max_fraction
, 0)
170 class SVP64FMvFCvtCases(TestAccumulatorBase
):
171 @skip_case("FIXME: rewrite to fmv/fcvt tests")
172 def case_sv_fmaxmag19(self
):
173 lst
= list(SVP64Asm(["sv.fmaxmag19 *32,*64,*96"]))
176 svstate
= SVP64State()
179 r
= range(svstate
.vl
)
180 for i
, rev_i
in zip(r
, reversed(r
)):
181 fprs
[64 + i
] = struct
.unpack("<Q", struct
.pack("<d", i
))[0]
182 fprs
[96 + i
] = struct
.unpack("<Q", struct
.pack("<d", rev_i
))[0]
183 e
= ExpectedState(pc
=8, int_regs
=gprs
, fp_regs
=fprs
)
184 e
.fpregs
[32] = 0x403f000000000000
185 e
.fpregs
[33] = 0x403e000000000000
186 e
.fpregs
[34] = 0x403d000000000000
187 e
.fpregs
[35] = 0x403c000000000000
188 e
.fpregs
[36] = 0x403b000000000000
189 e
.fpregs
[37] = 0x403a000000000000
190 e
.fpregs
[38] = 0x4039000000000000
191 e
.fpregs
[39] = 0x4038000000000000
192 e
.fpregs
[40] = 0x4037000000000000
193 e
.fpregs
[41] = 0x4036000000000000
194 e
.fpregs
[42] = 0x4035000000000000
195 e
.fpregs
[43] = 0x4034000000000000
196 e
.fpregs
[44] = 0x4033000000000000
197 e
.fpregs
[45] = 0x4032000000000000
198 e
.fpregs
[46] = 0x4031000000000000
199 e
.fpregs
[47] = 0x4030000000000000
200 e
.fpregs
[48] = 0x4030000000000000
201 e
.fpregs
[49] = 0x4031000000000000
202 e
.fpregs
[50] = 0x4032000000000000
203 e
.fpregs
[51] = 0x4033000000000000
204 e
.fpregs
[52] = 0x4034000000000000
205 e
.fpregs
[53] = 0x4035000000000000
206 e
.fpregs
[54] = 0x4036000000000000
207 e
.fpregs
[55] = 0x4037000000000000
208 e
.fpregs
[56] = 0x4038000000000000
209 e
.fpregs
[57] = 0x4039000000000000
210 e
.fpregs
[58] = 0x403a000000000000
211 e
.fpregs
[59] = 0x403b000000000000
212 e
.fpregs
[60] = 0x403c000000000000
213 e
.fpregs
[61] = 0x403d000000000000
214 e
.fpregs
[62] = 0x403e000000000000
215 e
.fpregs
[63] = 0x403f000000000000
216 self
.add_case(Program(lst
, False), gprs
, fpregs
=fprs
,
217 initial_svstate
=svstate
, expected
=e
)