Skip to contentSkip to conversation

target-sh4: get rid of CPU_{Float,Double}U

PATCH In review Aurelien Jarno 4 participants 7 messages Apr 10, 2011 – Apr 12, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target-sh4: get rid of CPU_{Float,Double}U

SH4 is always using softfloat, so it's possible to have helpers directly taking float32 or float64 value. This allow to get rid of conversions through CPU_{Float,Double}U.

Cc Peter Maydell <[email protected]>
Cc Nathan Froyd <[email protected]>
---
 target-sh4/helper.h    |   48 ++++++------
 target-sh4/op_helper.c |  202 ++++++++++++++++--------------------------------
 2 files changed, 92 insertions(+), 158 deletions(-)
target-sh4/helper.h +24 -24
index 2e52768..95e3c7c 100644
@@ -23,31 +23,31 @@ DEF_HELPER_2(macw, void, i32, i32)
 
 DEF_HELPER_1(ld_fpscr, void, i32)
 
-DEF_HELPER_1(fabs_FT, i32, i32)
-DEF_HELPER_1(fabs_DT, i64, i64)
-DEF_HELPER_2(fadd_FT, i32, i32, i32)
-DEF_HELPER_2(fadd_DT, i64, i64, i64)
-DEF_HELPER_1(fcnvsd_FT_DT, i64, i32)
-DEF_HELPER_1(fcnvds_DT_FT, i32, i64)
+DEF_HELPER_1(fabs_FT, f32, f32)
+DEF_HELPER_1(fabs_DT, f64, f64)
+DEF_HELPER_2(fadd_FT, f32, f32, f32)
+DEF_HELPER_2(fadd_DT, f64, f64, f64)
+DEF_HELPER_1(fcnvsd_FT_DT, f64, f32)
+DEF_HELPER_1(fcnvds_DT_FT, f32, f64)
 
-DEF_HELPER_2(fcmp_eq_FT, void, i32, i32)
-DEF_HELPER_2(fcmp_eq_DT, void, i64, i64)
-DEF_HELPER_2(fcmp_gt_FT, void, i32, i32)
-DEF_HELPER_2(fcmp_gt_DT, void, i64, i64)
-DEF_HELPER_2(fdiv_FT, i32, i32, i32)
-DEF_HELPER_2(fdiv_DT, i64, i64, i64)
-DEF_HELPER_1(float_FT, i32, i32)
-DEF_HELPER_1(float_DT, i64, i32)
-DEF_HELPER_3(fmac_FT, i32, i32, i32, i32)
-DEF_HELPER_2(fmul_FT, i32, i32, i32)
-DEF_HELPER_2(fmul_DT, i64, i64, i64)
-DEF_HELPER_1(fneg_T, i32, i32)
-DEF_HELPER_2(fsub_FT, i32, i32, i32)
-DEF_HELPER_2(fsub_DT, i64, i64, i64)
-DEF_HELPER_1(fsqrt_FT, i32, i32)
-DEF_HELPER_1(fsqrt_DT, i64, i64)
-DEF_HELPER_1(ftrc_FT, i32, i32)
-DEF_HELPER_1(ftrc_DT, i32, i64)
+DEF_HELPER_2(fcmp_eq_FT, void, f32, f32)
+DEF_HELPER_2(fcmp_eq_DT, void, f64, f64)
+DEF_HELPER_2(fcmp_gt_FT, void, f32, f32)
+DEF_HELPER_2(fcmp_gt_DT, void, f64, f64)
+DEF_HELPER_2(fdiv_FT, f32, f32, f32)
+DEF_HELPER_2(fdiv_DT, f64, f64, f64)
+DEF_HELPER_1(float_FT, f32, i32)
+DEF_HELPER_1(float_DT, f64, i32)
+DEF_HELPER_3(fmac_FT, f32, f32, f32, f32)
+DEF_HELPER_2(fmul_FT, f32, f32, f32)
+DEF_HELPER_2(fmul_DT, f64, f64, f64)
+DEF_HELPER_1(fneg_T, f32, f32)
+DEF_HELPER_2(fsub_FT, f32, f32, f32)
+DEF_HELPER_2(fsub_DT, f64, f64, f64)
+DEF_HELPER_1(fsqrt_FT, f32, f32)
+DEF_HELPER_1(fsqrt_DT, f64, f64)
+DEF_HELPER_1(ftrc_FT, i32, f32)
+DEF_HELPER_1(ftrc_DT, i32, f64)
 DEF_HELPER_2(fipr, void, i32, i32)
 DEF_HELPER_1(ftrv, void, i32)
 
target-sh4/op_helper.c +68 -134

342 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#1 lore raw

[Qemu-devel] Re: [PATCH] target-sh4: get rid of CPU_{Float, Double}U

Quoted 3 lines · Aurelien Jarno

SH4 is always using softfloat, so it's possible to have helpers directly taking float32 or float64 value. This allow to get rid of conversions through CPU_{Float,Double}U.

Eh, I think this punning on i32/f32 and i64/f64 values is not healthy. But Peter's already said that the floats-as-structs bit of softfloat is broken, so maybe it's not worth trying to ensure floats-as-structs works (or even making it the default, to discourage people from bit-twiddling directly).

-Nathan

#2 lore raw

[Qemu-devel] Re: [PATCH] target-sh4: get rid of CPU_{Float, Double}U

Quoted 10 lines · Nathan Froyd
Quoted 3 lines · Aurelien Jarno

SH4 is always using softfloat, so it's possible to have helpers directly taking float32 or float64 value. This allow to get rid of conversions through CPU_{Float,Double}U.

Eh, I think this punning on i32/f32 and i64/f64 values is not healthy. But Peter's already said that the floats-as-structs bit of softfloat is broken, so maybe it's not worth trying to ensure floats-as-structs works (or even making it the default, to discourage people from bit-twiddling directly).

I guess I should clarify that about the floats-as-structs thing.

(1) It does compile cleanly for the ARM target. Some other targets don't compile because they're (buggily) not using the boxing/unboxing macros when they do bit-twiddling of floats; that should be fixed.
(2) I think most of the value is in whether it compiles OK or not, rather than trying to actually run with it as a config (which I agree with Nathan is likely to go wrong if you have a host which doesn't pass 32/64 bit structs in registers). The compile test catches cases where the C code is doing bit-twiddling on float32s.
(3) If we did say you shouldn't be passing 'float32' etc into helper functions, this would make the def-helper.h support for 'f32' and 'f64' a bit pointless because they could never be used
(4) I think you should be able to write a helper function for an add as just

 float32 HELPER(my_float_add)(float32 a, float32 b) {
     return float32_add(a, b, status);

}
and having to add boxing/unboxing macros to this reduces clarity for no real gain. Using the macros should be a sign you're doing something wrong, not that you're doing it right :-)

-- PMM

#3 lore raw

Re: [Qemu-devel] [PATCH] target-sh4: get rid of CPU_{Float, Double}U

Quoted 5 lines · Peter Maydell

(4) I think you should be able to write a helper function for an add as just

 float32 HELPER(my_float_add)(float32 a, float32 b) {
     return float32_add(a, b, status);

}

While this is a laudable goal, this will fail for hosts that pass all structures by reference. This is true of, e.g. PPC32.

r~

#4 lore raw

Re: [Qemu-devel] Re: [PATCH] target-sh4: get rid of CPU_{Float, Double}U

Quoted 9 lines · Richard Henderson
Quoted 5 lines · Peter Maydell

(4) I think you should be able to write a helper function for an add as just
 float32 HELPER(my_float_add)(float32 a, float32 b) { return float32_add(a, b, status);
 }

While this is a laudable goal, this will fail for hosts that pass all structures by reference.  This is true of, e.g. PPC32.

...but only if float32 is a struct, which is where we came in. In the sane default configuration float32 is just a uint32_t in disguise.

In other words, my point is that I'd prefer to give up[*] being able to run with float32-is-a-struct rather than give up having clean and straightforward helper functions.

[*] actually I suspect we've never actually had this capability so we're not really giving anything up except philosophically...

-- PMM

#5 lore raw

Re: [Qemu-devel] [PATCH] target-sh4: get rid of CPU_{Float, Double}U

Quoted 8 lines · Peter Maydell
Quoted 7 lines · Richard Henderson
Quoted 5 lines · Peter Maydell

(4) I think you should be able to write a helper function for an add as just

 float32 HELPER(my_float_add)(float32 a, float32 b) {
     return float32_add(a, b, status);

}

Quoted 6 lines
Quoted 2 lines

While this is a laudable goal, this will fail for hosts that pass all structures by reference. This is true of, e.g. PPC32.

...but only if float32 is a struct, which is where we came in. In the sane default configuration float32 is just a uint32_t in disguise.

Well, that's all right then. So long as we restrict ourselves to passing around (typedefed) integers and pointers only, we'll be ok.

r~

#6 lore raw

[Qemu-devel] Re: [PATCH] target-sh4: get rid of CPU_{Float, Double}U

In reply to Peter Maydell
Quoted 6 lines · Peter Maydell
Quoted 5 lines · Nathan Froyd
Quoted 3 lines · Aurelien Jarno

SH4 is always using softfloat, so it's possible to have helpers directly taking float32 or float64 value. This allow to get rid of conversions through CPU_{Float,Double}U.

Quoted 8 lines
Quoted 5 lines

Eh, I think this punning on i32/f32 and i64/f64 values is not healthy. But Peter's already said that the floats-as-structs bit of softfloat is broken, so maybe it's not worth trying to ensure floats-as-structs works (or even making it the default, to discourage people from bit-twiddling directly).

I guess I should clarify that about the floats-as-structs thing.

I think I should ask some more details about this floats-as-structs history. It has been added when a lot of targets were still using softfloat-native and it was still possible to think about being able to switch from one to another (at least having this goal). The idea was to avoid doing float computation on the wrong value. For example this code does work with softfloat-native, but will produce wrong results with softfloat:

  float64 fadd(float64 a, float64 b)
  {
      return a + b;
  }

The problem with this kind of code is that it compiles both with softfloat and softfloat-native, but gives wrong results on softfloat. By adding this floats-as-structs, it was possible to catch such errors during compile time.

However now that most targets (except i386) default to softfloat, we don't really need to forbid bit twiddling in target code.

Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net