Skip to contentSkip to conversation

Full implementation of IEEE exceptions

PATCH In review Aurelien Jarno 2 participants 5 messages Apr 5, 2007 – Apr 6, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Full implementation of IEEE exceptions

Hi,

The attached patch fully implements IEEE exceptions on the SPARC target. Some more details:
- Any floating point operation that does not trap should clear the ftt flags. Similary, any floating point operation that does not generate an IEEE exception should clear the cexec flags. In the patch this operation is actually done at the same place before emulating the instruction via op_clear_ieee_excp_and_FTT, and set back to the correct value in the unlikely case of a trap.
- To compute the IEEE flags, and to trap if needed, every floating point instruction that can generate a trap is precedeed by a clear of the IEEE flags of the softmmu functions. After the instruction, the check_ieee_exceptions function copies the softmmu flags into the FSR flags (aexec, cexec), and if the corresponding TEM flag is set, a trap is generated.
- GEN_FCMP has to set the FSR_NVC flag, and should set the ftt flags to IEEE_754_exception.
- This patch also correctly implements the fcmpes and fcmped instructions by adding a sixth parameter. If this parameter is set, the comparaison generates a trap for unordered relations even if FSR_NVM is not set.

Bye,
Aurelien

Signature · 4 lines
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   [email protected]         | [email protected]
   `-    people.debian.org/~aurel32 | www.aurel32.net
target-sparc/exec.h +9 -0
diff -u -d -p -r1.17 exec.h
@@ -61,6 +61,8 @@ void do_fsqrts(void);
 void do_fsqrtd(void);
 void do_fcmps(void);
 void do_fcmpd(void);
+void do_fcmpes(void);
+void do_fcmped(void);
 #ifdef TARGET_SPARC64
 void do_fabsd(void);
 void do_fcmps_fcc1(void);
@@ -69,6 +71,12 @@ void do_fcmps_fcc2(void);
 void do_fcmpd_fcc2(void);
 void do_fcmps_fcc3(void);
 void do_fcmpd_fcc3(void);
+void do_fcmpes_fcc1(void);
+void do_fcmped_fcc1(void);
+void do_fcmpes_fcc2(void);
+void do_fcmped_fcc2(void);
+void do_fcmpes_fcc3(void);
+void do_fcmped_fcc3(void);
 void do_popc();
 void do_wrpstate();
 void do_done();
@@ -79,6 +87,7 @@ void do_ldd_user(target_ulong addr);
 void do_ldd_raw(target_ulong addr);
 void do_interrupt(int intno);
 void raise_exception(int tt);
+void check_ieee_exceptions();
 void memcpy32(target_ulong *dst, const target_ulong *src);
 target_ulong mmu_probe(CPUState *env, target_ulong address, int mmulev);
 void dump_mmu(CPUState *env);
target-sparc/op.c +63 -0

157 lines not on this page · raw message

target-sparc/op_helper.c +61 -10

112 lines not on this page · raw message

target-sparc/translate.c +21 -4
diff -u -d -p -r1.46 translate.c
@@ -943,6 +943,21 @@ static GenOpFunc * const gen_fcmpd[4] = 
     gen_op_fcmpd_fcc2,
     gen_op_fcmpd_fcc3,
 };
+
+static GenOpFunc * const gen_fcmpes[4] = {
+    gen_op_fcmpes,
+    gen_op_fcmpes_fcc1,
+    gen_op_fcmpes_fcc2,
+    gen_op_fcmpes_fcc3,
+};
+
+static GenOpFunc * const gen_fcmped[4] = {
+    gen_op_fcmped,
+    gen_op_fcmped_fcc1,
+    gen_op_fcmped_fcc2,
+    gen_op_fcmped_fcc3,
+};
+
 #endif
 
 static int gen_trap_ifnofpu(DisasContext * dc)
@@ -1289,6 +1304,7 @@ static void disas_sparc_insn(DisasContex
 	    } else if (xop == 0x34) {	/* FPU Operations */
                 if (gen_trap_ifnofpu(dc))
                     goto jmp_insn;
+		gen_op_clear_ieee_excp_and_FTT();
                 rs1 = GET_FIELD(insn, 13, 17);
 	        rs2 = GET_FIELD(insn, 27, 31);
 	        xop = GET_FIELD(insn, 18, 26);
@@ -1476,6 +1492,7 @@ static void disas_sparc_insn(DisasContex
 #endif
                 if (gen_trap_ifnofpu(dc))
                     goto jmp_insn;
+		gen_op_clear_ieee_excp_and_FTT();
                 rs1 = GET_FIELD(insn, 13, 17);
 	        rs2 = GET_FIELD(insn, 27, 31);
 	        xop = GET_FIELD(insn, 18, 26);
@@ -1653,18 +1670,18 @@ static void disas_sparc_insn(DisasContex
                 	gen_op_load_fpr_FT0(rs1);
                 	gen_op_load_fpr_FT1(rs2);
 #ifdef TARGET_SPARC64
-			gen_fcmps[rd & 3]();
+			gen_fcmpes[rd & 3]();
 #else
-			gen_op_fcmps(); /* XXX should trap if qNaN or sNaN  */
+			gen_op_fcmpes();
 #endif
 			break;
 		    case 0x56: /* fcmped, V9 %fcc */
                 	gen_op_load_fpr_DT0(DFPREG(rs1));
                 	gen_op_load_fpr_DT1(DFPREG(rs2));
 #ifdef TARGET_SPARC64
-			gen_fcmpd[rd & 3]();
+			gen_fcmped[rd & 3]();
 #else
-			gen_op_fcmpd(); /* XXX should trap if qNaN or sNaN  */
+			gen_op_fcmped();
 #endif
 			break;
 		    case 0x57: /* fcmpeq */
#1 lore raw
Quoted 1 line

The attached patch fully implements IEEE exceptions on the SPARC target.

Nice work, thank you. Do you know of any code that uses the exceptions?

The flags enabling exceptions could be recorded to TB flags so that the check code is generated only when needed, see cpu-exec.c:180.

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

#2 lore raw
Quoted 3 lines · Blue Swirl
Quoted 1 line

The attached patch fully implements IEEE exceptions on the SPARC target.

Nice work, thank you. Do you know of any code that uses the exceptions?

I guess no code is using IEEE exceptions to generate a trap, because defining a signal handler for SIGFPE is highly non-standard. However a few programs are querying FSR to check the AEXC flags after a sequence of floating point instructions. This is the case for example of the SUN Java J2RE.

Quoted 2 lines

The flags enabling exceptions could be recorded to TB flags so that the check code is generated only when needed, see cpu-exec.c:180.

Well I doubt it is possible, because check_ieee_exceptions() generates a trap if the TEM flags in the FSR register are set, but also update the AEXC flag in FSR. I even doubt lazy FSR is possible here, because it accumulates the exceptions of all floating points instructions since those flags are cleared.

Signature · 4 lines
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   [email protected]         | [email protected]
   `-    people.debian.org/~aurel32 | www.aurel32.net
#3 lore raw
In reply to Aurelien Jarno
Quoted 1 line

The attached patch fully implements IEEE exceptions on the SPARC target.

The patch is broken:
gcc-3.3 -Wall -O2 -g -fno-strict-aliasing -fno-reorder-blocks -fno-gcse -fno-optimize-sibling-calls -fno-crossjumping -fno-align-labels -fno-align-jumps -fno-align-functions -mpreferred-stack-boundary=2 -fomit-frame-pointer -I. -I.. -I/tmp/qemu.aurel/target-sparc -I/tmp/qemu.aurel -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -I/tmp/qemu.aurel/fpu -I/tmp/qemu.aurel/slirp -c -o op.o /tmp/qemu.aurel/target-sparc/op.c
/tmp/qemu.aurel/target-sparc/op.c: In function `op_clear_ieee_excp_and_FTT':
/tmp/qemu.aurel/target-sparc/op.c:1539: error: `FSR_CEXEC_MASK' undeclared (first use in this function) /tmp/qemu.aurel/target-sparc/op.c:1539: error: (Each undeclared identifier is reported only once /tmp/qemu.aurel/target-sparc/op.c:1539: error: for each function it appears in.)

_________________________________________________________________
Don't just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/

#4 lore raw
Quoted 9 lines · Blue Swirl
Quoted 1 line

The attached patch fully implements IEEE exceptions on the SPARC target.

The patch is broken:
gcc-3.3 -Wall -O2 -g -fno-strict-aliasing -fno-reorder-blocks -fno-gcse

(quoted diff) +0 -5
-fno-optimize-sibling-calls  -fno-crossjumping  -fno-align-labels  
-fno-align-jumps  -fno-align-functions -mpreferred-stack-boundary=2 
-fomit-frame-pointer  -I. -I.. -I/tmp/qemu.aurel/target-sparc 
-I/tmp/qemu.aurel -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 
-I/tmp/qemu.aurel/fpu -I/tmp/qemu.aurel/slirp -c -o op.o 
Quoted 9 lines

/tmp/qemu.aurel/target-sparc/op.c /tmp/qemu.aurel/target-sparc/op.c: In function `op_clear_ieee_excp_and_FTT':
/tmp/qemu.aurel/target-sparc/op.c:1539: error: `FSR_CEXEC_MASK' undeclared (first use in this function) /tmp/qemu.aurel/target-sparc/op.c:1539: error: (Each undeclared identifier is reported only once
/tmp/qemu.aurel/target-sparc/op.c:1539: error: for each function it appears in.)

Sorry this is a small typo in my patch, please find an update patch attached.

Signature · 4 lines
  .''`.  Aurelien Jarno	            | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   [email protected]         | [email protected]
   `-    people.debian.org/~aurel32 | www.aurel32.net
target-sparc/exec.h +9 -0
diff -u -d -p -r1.17 exec.h
@@ -61,6 +61,8 @@ void do_fsqrts(void);
 void do_fsqrtd(void);
 void do_fcmps(void);
 void do_fcmpd(void);
+void do_fcmpes(void);
+void do_fcmped(void);
 #ifdef TARGET_SPARC64
 void do_fabsd(void);
 void do_fcmps_fcc1(void);
@@ -69,6 +71,12 @@ void do_fcmps_fcc2(void);
 void do_fcmpd_fcc2(void);
 void do_fcmps_fcc3(void);
 void do_fcmpd_fcc3(void);
+void do_fcmpes_fcc1(void);
+void do_fcmped_fcc1(void);
+void do_fcmpes_fcc2(void);
+void do_fcmped_fcc2(void);
+void do_fcmpes_fcc3(void);
+void do_fcmped_fcc3(void);
 void do_popc();
 void do_wrpstate();
 void do_done();
@@ -79,6 +87,7 @@ void do_ldd_user(target_ulong addr);
 void do_ldd_raw(target_ulong addr);
 void do_interrupt(int intno);
 void raise_exception(int tt);
+void check_ieee_exceptions();
 void memcpy32(target_ulong *dst, const target_ulong *src);
 target_ulong mmu_probe(CPUState *env, target_ulong address, int mmulev);
 void dump_mmu(CPUState *env);
target-sparc/op.c +63 -0

157 lines not on this page · raw message

target-sparc/op_helper.c +61 -10

112 lines not on this page · raw message

target-sparc/translate.c +21 -4
diff -u -d -p -r1.46 translate.c
@@ -943,6 +943,21 @@ static GenOpFunc * const gen_fcmpd[4] = 
     gen_op_fcmpd_fcc2,
     gen_op_fcmpd_fcc3,
 };
+
+static GenOpFunc * const gen_fcmpes[4] = {
+    gen_op_fcmpes,
+    gen_op_fcmpes_fcc1,
+    gen_op_fcmpes_fcc2,
+    gen_op_fcmpes_fcc3,
+};
+
+static GenOpFunc * const gen_fcmped[4] = {
+    gen_op_fcmped,
+    gen_op_fcmped_fcc1,
+    gen_op_fcmped_fcc2,
+    gen_op_fcmped_fcc3,
+};
+
 #endif
 
 static int gen_trap_ifnofpu(DisasContext * dc)
@@ -1289,6 +1304,7 @@ static void disas_sparc_insn(DisasContex
 	    } else if (xop == 0x34) {	/* FPU Operations */
                 if (gen_trap_ifnofpu(dc))
                     goto jmp_insn;
+		gen_op_clear_ieee_excp_and_FTT();
                 rs1 = GET_FIELD(insn, 13, 17);
 	        rs2 = GET_FIELD(insn, 27, 31);
 	        xop = GET_FIELD(insn, 18, 26);
@@ -1476,6 +1492,7 @@ static void disas_sparc_insn(DisasContex
 #endif
                 if (gen_trap_ifnofpu(dc))
                     goto jmp_insn;
+		gen_op_clear_ieee_excp_and_FTT();
                 rs1 = GET_FIELD(insn, 13, 17);
 	        rs2 = GET_FIELD(insn, 27, 31);
 	        xop = GET_FIELD(insn, 18, 26);
@@ -1653,18 +1670,18 @@ static void disas_sparc_insn(DisasContex
                 	gen_op_load_fpr_FT0(rs1);
                 	gen_op_load_fpr_FT1(rs2);
 #ifdef TARGET_SPARC64
-			gen_fcmps[rd & 3]();
+			gen_fcmpes[rd & 3]();
 #else
-			gen_op_fcmps(); /* XXX should trap if qNaN or sNaN  */
+			gen_op_fcmpes();
 #endif
 			break;
 		    case 0x56: /* fcmped, V9 %fcc */
                 	gen_op_load_fpr_DT0(DFPREG(rs1));
                 	gen_op_load_fpr_DT1(DFPREG(rs2));
 #ifdef TARGET_SPARC64
-			gen_fcmpd[rd & 3]();
+			gen_fcmped[rd & 3]();
 #else
-			gen_op_fcmpd(); /* XXX should trap if qNaN or sNaN  */
+			gen_op_fcmped();
 #endif
 			break;
 		    case 0x57: /* fcmpeq */