|
25 | 25 |
|
26 | 26 | using namespace wasm;
|
27 | 27 |
|
| 28 | +// uInt32 |
28 | 29 | TEST(InterpreterTest, AddI32) {
|
29 | 30 | Module wasm;
|
30 | 31 | IRBuilder builder(wasm);
|
@@ -76,6 +77,7 @@ TEST(InterpreterTest, MulI32) {
|
76 | 77 | EXPECT_EQ(results, expected);
|
77 | 78 | }
|
78 | 79 |
|
| 80 | +// Float32 |
79 | 81 | TEST(InterpreterTest, AddF32) {
|
80 | 82 | Module wasm;
|
81 | 83 | IRBuilder builder(wasm);
|
@@ -223,3 +225,152 @@ TEST(InterpreterTest, NearF32) {
|
223 | 225 |
|
224 | 226 | EXPECT_EQ(results, expected);
|
225 | 227 | }
|
| 228 | + |
| 229 | +// Float 64 |
| 230 | +TEST(InterpreterTest, AddF64) { |
| 231 | + Module wasm; |
| 232 | + IRBuilder builder(wasm); |
| 233 | + |
| 234 | + ASSERT_FALSE(builder.makeConst(Literal(double(0.0))).getErr()); |
| 235 | + ASSERT_FALSE(builder.makeConst(Literal(double(1.0))).getErr()); |
| 236 | + ASSERT_FALSE(builder.makeBinary(AddFloat64).getErr()); |
| 237 | + |
| 238 | + auto expr = builder.build(); |
| 239 | + ASSERT_FALSE(expr.getErr()); |
| 240 | + |
| 241 | + auto results = Interpreter{}.run(*expr); |
| 242 | + std::vector<Literal> expected{Literal(double(1.0))}; |
| 243 | + |
| 244 | + EXPECT_EQ(results, expected); |
| 245 | +} |
| 246 | + |
| 247 | +TEST(InterpreterTest, SubF64) { |
| 248 | + Module wasm; |
| 249 | + IRBuilder builder(wasm); |
| 250 | + |
| 251 | + ASSERT_FALSE(builder.makeConst(Literal(double(1.0))).getErr()); |
| 252 | + ASSERT_FALSE(builder.makeConst(Literal(double(2.0))).getErr()); |
| 253 | + ASSERT_FALSE(builder.makeBinary(SubFloat64).getErr()); |
| 254 | + |
| 255 | + auto expr = builder.build(); |
| 256 | + ASSERT_FALSE(expr.getErr()); |
| 257 | + |
| 258 | + auto results = Interpreter{}.run(*expr); |
| 259 | + std::vector<Literal> expected{Literal(double(-1.0))}; |
| 260 | + |
| 261 | + EXPECT_EQ(results, expected); |
| 262 | +} |
| 263 | + |
| 264 | +TEST(InterpreterTest, MulF64) { |
| 265 | + Module wasm; |
| 266 | + IRBuilder builder(wasm); |
| 267 | + |
| 268 | + ASSERT_FALSE(builder.makeConst(Literal(double(1.5))).getErr()); |
| 269 | + ASSERT_FALSE(builder.makeConst(Literal(double(2.0))).getErr()); |
| 270 | + ASSERT_FALSE(builder.makeBinary(MulFloat64).getErr()); |
| 271 | + |
| 272 | + auto expr = builder.build(); |
| 273 | + ASSERT_FALSE(expr.getErr()); |
| 274 | + |
| 275 | + auto results = Interpreter{}.run(*expr); |
| 276 | + std::vector<Literal> expected{Literal(double(3.0))}; |
| 277 | + |
| 278 | + EXPECT_EQ(results, expected); |
| 279 | +} |
| 280 | + |
| 281 | +TEST(InterpreterTest, DivF64) { |
| 282 | + Module wasm; |
| 283 | + IRBuilder builder(wasm); |
| 284 | + |
| 285 | + ASSERT_FALSE(builder.makeConst(Literal(double(5.0))).getErr()); |
| 286 | + ASSERT_FALSE(builder.makeConst(Literal(double(2.0))).getErr()); |
| 287 | + ASSERT_FALSE(builder.makeBinary(DivFloat64).getErr()); |
| 288 | + |
| 289 | + auto expr = builder.build(); |
| 290 | + ASSERT_FALSE(expr.getErr()); |
| 291 | + |
| 292 | + auto results = Interpreter{}.run(*expr); |
| 293 | + std::vector<Literal> expected{Literal(double(2.5))}; |
| 294 | + |
| 295 | + EXPECT_EQ(results, expected); |
| 296 | +} |
| 297 | + |
| 298 | +TEST(InterpreterTest, SqrtF64) { |
| 299 | + Module wasm; |
| 300 | + IRBuilder builder(wasm); |
| 301 | + |
| 302 | + ASSERT_FALSE(builder.makeConst(Literal(double(5.0))).getErr()); |
| 303 | + ASSERT_FALSE(builder.makeUnary(SqrtFloat64).getErr()); |
| 304 | + |
| 305 | + auto expr = builder.build(); |
| 306 | + ASSERT_FALSE(expr.getErr()); |
| 307 | + |
| 308 | + auto results = Interpreter{}.run(*expr); |
| 309 | + std::vector<Literal> expected{Literal(double(2.23606797749979))}; |
| 310 | + |
| 311 | + EXPECT_EQ(results, expected); |
| 312 | +} |
| 313 | + |
| 314 | +TEST(InterpreterTest, CeilF64) { |
| 315 | + Module wasm; |
| 316 | + IRBuilder builder(wasm); |
| 317 | + |
| 318 | + ASSERT_FALSE(builder.makeConst(Literal(double(1.5))).getErr()); |
| 319 | + ASSERT_FALSE(builder.makeUnary(CeilFloat64).getErr()); |
| 320 | + |
| 321 | + auto expr = builder.build(); |
| 322 | + ASSERT_FALSE(expr.getErr()); |
| 323 | + |
| 324 | + auto results = Interpreter{}.run(*expr); |
| 325 | + std::vector<Literal> expected{Literal(double(2.0))}; |
| 326 | + |
| 327 | + EXPECT_EQ(results, expected); |
| 328 | +} |
| 329 | + |
| 330 | +TEST(InterpreterTest, FloorF64) { |
| 331 | + Module wasm; |
| 332 | + IRBuilder builder(wasm); |
| 333 | + |
| 334 | + ASSERT_FALSE(builder.makeConst(Literal(double(1.5))).getErr()); |
| 335 | + ASSERT_FALSE(builder.makeUnary(FloorFloat64).getErr()); |
| 336 | + |
| 337 | + auto expr = builder.build(); |
| 338 | + ASSERT_FALSE(expr.getErr()); |
| 339 | + |
| 340 | + auto results = Interpreter{}.run(*expr); |
| 341 | + std::vector<Literal> expected{Literal(double(1.0))}; |
| 342 | + |
| 343 | + EXPECT_EQ(results, expected); |
| 344 | +} |
| 345 | + |
| 346 | +TEST(InterpreterTest, TruncF64) { |
| 347 | + Module wasm; |
| 348 | + IRBuilder builder(wasm); |
| 349 | + |
| 350 | + ASSERT_FALSE(builder.makeConst(Literal(double(2.017281))).getErr()); |
| 351 | + ASSERT_FALSE(builder.makeUnary(TruncFloat64).getErr()); |
| 352 | + |
| 353 | + auto expr = builder.build(); |
| 354 | + ASSERT_FALSE(expr.getErr()); |
| 355 | + |
| 356 | + auto results = Interpreter{}.run(*expr); |
| 357 | + std::vector<Literal> expected{Literal(double(2.0))}; |
| 358 | + |
| 359 | + EXPECT_EQ(results, expected); |
| 360 | +} |
| 361 | + |
| 362 | +TEST(InterpreterTest, NearF64) { |
| 363 | + Module wasm; |
| 364 | + IRBuilder builder(wasm); |
| 365 | + |
| 366 | + ASSERT_FALSE(builder.makeConst(Literal(double(2.5))).getErr()); |
| 367 | + ASSERT_FALSE(builder.makeUnary(NearestFloat64).getErr()); |
| 368 | + |
| 369 | + auto expr = builder.build(); |
| 370 | + ASSERT_FALSE(expr.getErr()); |
| 371 | + |
| 372 | + auto results = Interpreter{}.run(*expr); |
| 373 | + std::vector<Literal> expected{Literal(double(2.0))}; |
| 374 | + |
| 375 | + EXPECT_EQ(results, expected); |
| 376 | +} |
0 commit comments