Commit 9850d1e82c3712f5ab2b4f1c40e452570a4a21e5
1 parent
0f2f39c2
target-sh4: use CPU_Float/CPU_Double instead of ugly casts
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5757 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
102 additions
and
40 deletions
target-sh4/op_helper.c
| ... | ... | @@ -389,31 +389,45 @@ void helper_ld_fpscr(uint32_t val) |
| 389 | 389 | |
| 390 | 390 | uint32_t helper_fabs_FT(uint32_t t0) |
| 391 | 391 | { |
| 392 | - float32 ret = float32_abs(*(float32*)&t0); | |
| 393 | - return *(uint32_t*)(&ret); | |
| 392 | + CPU_FloatU f; | |
| 393 | + f.l = t0; | |
| 394 | + f.f = float32_abs(f.f); | |
| 395 | + return f.l; | |
| 394 | 396 | } |
| 395 | 397 | |
| 396 | 398 | uint64_t helper_fabs_DT(uint64_t t0) |
| 397 | 399 | { |
| 398 | - float64 ret = float64_abs(*(float64*)&t0); | |
| 399 | - return *(uint64_t*)(&ret); | |
| 400 | + CPU_DoubleU d; | |
| 401 | + d.ll = t0; | |
| 402 | + d.d = float64_abs(d.d); | |
| 403 | + return d.ll; | |
| 400 | 404 | } |
| 401 | 405 | |
| 402 | 406 | uint32_t helper_fadd_FT(uint32_t t0, uint32_t t1) |
| 403 | 407 | { |
| 404 | - float32 ret = float32_add(*(float32*)&t0, *(float32*)&t1, &env->fp_status); | |
| 405 | - return *(uint32_t*)(&ret); | |
| 408 | + CPU_FloatU f0, f1; | |
| 409 | + f0.l = t0; | |
| 410 | + f1.l = t1; | |
| 411 | + f0.f = float32_add(f0.f, f1.f, &env->fp_status); | |
| 412 | + return f0.l; | |
| 406 | 413 | } |
| 407 | 414 | |
| 408 | 415 | uint64_t helper_fadd_DT(uint64_t t0, uint64_t t1) |
| 409 | 416 | { |
| 410 | - float64 ret = float64_add(*(float64*)&t0, *(float64*)&t1, &env->fp_status); | |
| 411 | - return *(uint64_t*)(&ret); | |
| 417 | + CPU_DoubleU d0, d1; | |
| 418 | + d0.ll = t0; | |
| 419 | + d1.ll = t1; | |
| 420 | + d0.d = float64_add(d0.d, d1.d, &env->fp_status); | |
| 421 | + return d0.ll; | |
| 412 | 422 | } |
| 413 | 423 | |
| 414 | 424 | void helper_fcmp_eq_FT(uint32_t t0, uint32_t t1) |
| 415 | 425 | { |
| 416 | - if (float32_compare(*(float32*)&t0, *(float32*)&t1, &env->fp_status) == 0) | |
| 426 | + CPU_FloatU f0, f1; | |
| 427 | + f0.l = t0; | |
| 428 | + f1.l = t1; | |
| 429 | + | |
| 430 | + if (float32_compare(f0.f, f1.f, &env->fp_status) == 0) | |
| 417 | 431 | set_t(); |
| 418 | 432 | else |
| 419 | 433 | clr_t(); |
| ... | ... | @@ -421,7 +435,11 @@ void helper_fcmp_eq_FT(uint32_t t0, uint32_t t1) |
| 421 | 435 | |
| 422 | 436 | void helper_fcmp_eq_DT(uint64_t t0, uint64_t t1) |
| 423 | 437 | { |
| 424 | - if (float64_compare(*(float64*)&t0, *(float64*)&t1, &env->fp_status) == 0) | |
| 438 | + CPU_DoubleU d0, d1; | |
| 439 | + d0.ll = t0; | |
| 440 | + d1.ll = t1; | |
| 441 | + | |
| 442 | + if (float64_compare(d0.d, d1.d, &env->fp_status) == 0) | |
| 425 | 443 | set_t(); |
| 426 | 444 | else |
| 427 | 445 | clr_t(); |
| ... | ... | @@ -429,7 +447,11 @@ void helper_fcmp_eq_DT(uint64_t t0, uint64_t t1) |
| 429 | 447 | |
| 430 | 448 | void helper_fcmp_gt_FT(uint32_t t0, uint32_t t1) |
| 431 | 449 | { |
| 432 | - if (float32_compare(*(float32*)&t0, *(float32*)&t1, &env->fp_status) == 1) | |
| 450 | + CPU_FloatU f0, f1; | |
| 451 | + f0.l = t0; | |
| 452 | + f1.l = t1; | |
| 453 | + | |
| 454 | + if (float32_compare(f0.f, f1.f, &env->fp_status) == 1) | |
| 433 | 455 | set_t(); |
| 434 | 456 | else |
| 435 | 457 | clr_t(); |
| ... | ... | @@ -437,7 +459,11 @@ void helper_fcmp_gt_FT(uint32_t t0, uint32_t t1) |
| 437 | 459 | |
| 438 | 460 | void helper_fcmp_gt_DT(uint64_t t0, uint64_t t1) |
| 439 | 461 | { |
| 440 | - if (float64_compare(*(float64*)&t0, *(float64*)&t1, &env->fp_status) == 1) | |
| 462 | + CPU_DoubleU d0, d1; | |
| 463 | + d0.ll = t0; | |
| 464 | + d1.ll = t1; | |
| 465 | + | |
| 466 | + if (float64_compare(d0.d, d1.d, &env->fp_status) == 1) | |
| 441 | 467 | set_t(); |
| 442 | 468 | else |
| 443 | 469 | clr_t(); |
| ... | ... | @@ -445,88 +471,124 @@ void helper_fcmp_gt_DT(uint64_t t0, uint64_t t1) |
| 445 | 471 | |
| 446 | 472 | uint64_t helper_fcnvsd_FT_DT(uint32_t t0) |
| 447 | 473 | { |
| 448 | - float64 ret = float32_to_float64(*(float32*)&t0, &env->fp_status); | |
| 449 | - return *(uint64_t*)(&ret); | |
| 474 | + CPU_DoubleU d; | |
| 475 | + CPU_FloatU f; | |
| 476 | + f.l = t0; | |
| 477 | + d.d = float32_to_float64(f.f, &env->fp_status); | |
| 478 | + return d.ll; | |
| 450 | 479 | } |
| 451 | 480 | |
| 452 | 481 | uint32_t helper_fcnvds_DT_FT(uint64_t t0) |
| 453 | 482 | { |
| 454 | - float32 ret = float64_to_float32(*(float64*)&t0, &env->fp_status); | |
| 455 | - return *(uint32_t*)(&ret); | |
| 483 | + CPU_DoubleU d; | |
| 484 | + CPU_FloatU f; | |
| 485 | + d.ll = t0; | |
| 486 | + f.f = float64_to_float32(d.d, &env->fp_status); | |
| 487 | + return f.l; | |
| 456 | 488 | } |
| 457 | 489 | |
| 458 | 490 | uint32_t helper_fdiv_FT(uint32_t t0, uint32_t t1) |
| 459 | 491 | { |
| 460 | - float32 ret = float32_div(*(float32*)&t0, *(float32*)&t1, &env->fp_status); | |
| 461 | - return *(uint32_t*)(&ret); | |
| 492 | + CPU_FloatU f0, f1; | |
| 493 | + f0.l = t0; | |
| 494 | + f1.l = t1; | |
| 495 | + f0.f = float32_div(f0.f, f1.f, &env->fp_status); | |
| 496 | + return f0.l; | |
| 462 | 497 | } |
| 463 | 498 | |
| 464 | 499 | uint64_t helper_fdiv_DT(uint64_t t0, uint64_t t1) |
| 465 | 500 | { |
| 466 | - float64 ret = float64_div(*(float64*)&t0, *(float64*)&t1, &env->fp_status); | |
| 467 | - return *(uint64_t*)(&ret); | |
| 501 | + CPU_DoubleU d0, d1; | |
| 502 | + d0.ll = t0; | |
| 503 | + d1.ll = t1; | |
| 504 | + d0.d = float64_div(d0.d, d1.d, &env->fp_status); | |
| 505 | + return d0.ll; | |
| 468 | 506 | } |
| 469 | 507 | |
| 470 | 508 | uint32_t helper_float_FT(uint32_t t0) |
| 471 | 509 | { |
| 472 | - float32 ret = int32_to_float32(t0, &env->fp_status); | |
| 473 | - return *(uint32_t*)(&ret); | |
| 510 | + CPU_FloatU f; | |
| 511 | + f.f = int32_to_float32(t0, &env->fp_status); | |
| 512 | + return f.l; | |
| 474 | 513 | } |
| 475 | 514 | |
| 476 | 515 | uint64_t helper_float_DT(uint32_t t0) |
| 477 | 516 | { |
| 478 | - float64 ret = int32_to_float64(t0, &env->fp_status); | |
| 479 | - return *(uint64_t*)(&ret); | |
| 517 | + CPU_DoubleU d; | |
| 518 | + d.d = int32_to_float64(t0, &env->fp_status); | |
| 519 | + return d.ll; | |
| 480 | 520 | } |
| 481 | 521 | |
| 482 | 522 | uint32_t helper_fmul_FT(uint32_t t0, uint32_t t1) |
| 483 | 523 | { |
| 484 | - float32 ret = float32_mul(*(float32*)&t0, *(float32*)&t1, &env->fp_status); | |
| 485 | - return *(uint32_t*)(&ret); | |
| 524 | + CPU_FloatU f0, f1; | |
| 525 | + f0.l = t0; | |
| 526 | + f1.l = t1; | |
| 527 | + f0.f = float32_mul(f0.f, f1.f, &env->fp_status); | |
| 528 | + return f0.l; | |
| 486 | 529 | } |
| 487 | 530 | |
| 488 | 531 | uint64_t helper_fmul_DT(uint64_t t0, uint64_t t1) |
| 489 | 532 | { |
| 490 | - float64 ret = float64_mul(*(float64*)&t0, *(float64*)&t1, &env->fp_status); | |
| 491 | - return *(uint64_t*)(&ret); | |
| 533 | + CPU_DoubleU d0, d1; | |
| 534 | + d0.ll = t0; | |
| 535 | + d1.ll = t1; | |
| 536 | + d0.d = float64_mul(d0.d, d1.d, &env->fp_status); | |
| 537 | + return d0.ll; | |
| 492 | 538 | } |
| 493 | 539 | |
| 494 | 540 | uint32_t helper_fneg_T(uint32_t t0) |
| 495 | 541 | { |
| 496 | - float32 ret = float32_chs(*(float32*)&t0); | |
| 497 | - return *(uint32_t*)(&ret); | |
| 542 | + CPU_FloatU f; | |
| 543 | + f.l = t0; | |
| 544 | + f.f = float32_chs(f.f); | |
| 545 | + return f.l; | |
| 498 | 546 | } |
| 499 | 547 | |
| 500 | 548 | uint32_t helper_fsqrt_FT(uint32_t t0) |
| 501 | 549 | { |
| 502 | - float32 ret = float32_sqrt(*(float32*)&t0, &env->fp_status); | |
| 503 | - return *(uint32_t*)(&ret); | |
| 550 | + CPU_FloatU f; | |
| 551 | + f.l = t0; | |
| 552 | + f.f = float32_sqrt(f.f, &env->fp_status); | |
| 553 | + return f.l; | |
| 504 | 554 | } |
| 505 | 555 | |
| 506 | 556 | uint64_t helper_fsqrt_DT(uint64_t t0) |
| 507 | 557 | { |
| 508 | - float64 ret = float64_sqrt(*(float64*)&t0, &env->fp_status); | |
| 509 | - return *(uint64_t*)(&ret); | |
| 558 | + CPU_DoubleU d; | |
| 559 | + d.ll = t0; | |
| 560 | + d.d = float64_sqrt(d.d, &env->fp_status); | |
| 561 | + return d.ll; | |
| 510 | 562 | } |
| 511 | 563 | |
| 512 | 564 | uint32_t helper_fsub_FT(uint32_t t0, uint32_t t1) |
| 513 | 565 | { |
| 514 | - float32 ret = float32_sub(*(float32*)&t0, *(float32*)&t1, &env->fp_status); | |
| 515 | - return *(uint32_t*)(&ret); | |
| 566 | + CPU_FloatU f0, f1; | |
| 567 | + f0.l = t0; | |
| 568 | + f1.l = t1; | |
| 569 | + f0.f = float32_sub(f0.f, f1.f, &env->fp_status); | |
| 570 | + return f0.l; | |
| 516 | 571 | } |
| 517 | 572 | |
| 518 | 573 | uint64_t helper_fsub_DT(uint64_t t0, uint64_t t1) |
| 519 | 574 | { |
| 520 | - float64 ret = float64_sub(*(float64*)&t0, *(float64*)&t1, &env->fp_status); | |
| 521 | - return *(uint64_t*)(&ret); | |
| 575 | + CPU_DoubleU d0, d1; | |
| 576 | + d0.ll = t0; | |
| 577 | + d1.ll = t1; | |
| 578 | + d0.d = float64_sub(d0.d, d1.d, &env->fp_status); | |
| 579 | + return d0.ll; | |
| 522 | 580 | } |
| 523 | 581 | |
| 524 | 582 | uint32_t helper_ftrc_FT(uint32_t t0) |
| 525 | 583 | { |
| 526 | - return float32_to_int32_round_to_zero(*(float32*)&t0, &env->fp_status); | |
| 584 | + CPU_FloatU f; | |
| 585 | + f.l = t0; | |
| 586 | + return float32_to_int32_round_to_zero(f.f, &env->fp_status); | |
| 527 | 587 | } |
| 528 | 588 | |
| 529 | 589 | uint32_t helper_ftrc_DT(uint64_t t0) |
| 530 | 590 | { |
| 531 | - return float64_to_int32_round_to_zero(*(float64*)&t0, &env->fp_status); | |
| 591 | + CPU_DoubleU d; | |
| 592 | + d.ll = t0; | |
| 593 | + return float64_to_int32_round_to_zero(d.d, &env->fp_status); | |
| 532 | 594 | } | ... | ... |