Skip to contentSkip to conversation

sparc y register

Qemu-devel Vince Weaver 2 participants 6 messages Sep 11, 2008 – Sep 13, 2008

lore
Share & tools
lore
#0 lore raw

Hello

I'm wasting a lot of time trying to get the sixtrack spec2k benchmark going. (It crashes 30 minutes into the program, deep in a long FORTRAN program). One of the problems eventually traces back to a routine reading long floating point numbers from a text file.

In any case, part of the problem is that the write y instruction is writing a 64-bit value, but from what I can tell in the documentation the top 32-bits of y should always be zero.

What this means is sometimes in sparc32plus mode, we write a register to y that has some of the higher 32 bits set, which causes later mulscc instructions to get the wrong results.

The patch below seems to fix this particular problem (and a test case I have that exhibits it) but it seems as if there's still another bug at work somewhere because sixtrack still won't run.

Vince

translate.c +1 -0
Index: target-sparc/translate.c
===================================================================
@@ -3196,6 +3196,7 @@
                             switch(rd) {
                             case 0: /* wry */
                                 tcg_gen_xor_tl(cpu_y, cpu_src1, cpu_src2);
+			        tcg_gen_andi_tl(cpu_y,cpu_y,0xffffffff);
                                 break;
 #ifndef TARGET_SPARC64
                             case 0x01 ... 0x0f: /* undefined in the
#1 lore raw
Quoted 11 lines · Vince Weaver

Hello

I'm wasting a lot of time trying to get the sixtrack spec2k benchmark
going. (It crashes 30 minutes into the program, deep in a long FORTRAN program). One of the problems eventually traces back to a routine reading long floating point numbers from a text file.

In any case, part of the problem is that the write y instruction is writing
a 64-bit value, but from what I can tell in the documentation the top 32-bits of y should always be zero.

Quoted 7 lines

What this means is sometimes in sparc32plus mode, we write a register to y
that has some of the higher 32 bits set, which causes later mulscc instructions to get the wrong results.

The patch below seems to fix this particular problem (and a test case I
have that exhibits it) but it seems as if there's still another bug at work somewhere because sixtrack still won't run.

Thanks, I applied a fix based on this. There was also a similar problem in mulscc, maybe your tests run better now?

#2 lore raw
Quoted 2 lines · Blue Swirl

Thanks, I applied a fix based on this. There was also a similar problem in mulscc, maybe your tests run better now?

So it turns out there are three problems:

  1.  mulscc when y has upper word bits set
  2.  mulscc when src1 has upper word bits set
  3.  mulscc when src2 has upper word bits set

The patch from yesterday fixed case 1, but there were still problems for 2&3.

Below is a patch I made that seems to get this all working properly. I've also attached a small test program that exhibits the 3 problems...

I'm running the big Fortran program again, but it would take a few hours to finish if this is a proper fix so I thought I'd send this off now rather than waiting.

Vince

translate.c +4 -4
Index: target-sparc/translate.c
===================================================================
@@ -708,7 +708,7 @@
     // env->y = (b2 << 31) | (env->y >> 1);
     tcg_gen_andi_tl(r_temp, cpu_cc_src, 0x1);
     tcg_gen_shli_tl(r_temp, r_temp, 31);
-    tcg_gen_shri_tl(cpu_tmp0, cpu_y, 1);
+    tcg_gen_shri_i32(cpu_tmp0, cpu_y, 1);
     tcg_gen_or_tl(cpu_tmp0, cpu_tmp0, r_temp);
     tcg_gen_andi_tl(cpu_y, cpu_tmp0, 0xffffffff);
 
@@ -721,11 +721,11 @@
     // T0 = (b1 << 31) | (T0 >> 1);
     // src1 = T0;
     tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, 31);
-    tcg_gen_shri_tl(cpu_cc_src, cpu_cc_src, 1);
-    tcg_gen_or_tl(cpu_cc_src, cpu_cc_src, cpu_tmp0);
+    tcg_gen_shri_i32(cpu_cc_src, cpu_cc_src, 1);
+    tcg_gen_or_i32(cpu_cc_src, cpu_cc_src, cpu_tmp0);
 
     /* do addition and update flags */
-    tcg_gen_add_tl(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
+    tcg_gen_add_i32(cpu_cc_dst, cpu_cc_src, cpu_cc_src2);
 
     gen_cc_clear_icc();
     gen_cc_NZ_icc(cpu_cc_dst);

! as -Av8plus -o mulscc.o mulscc.s ; ld -o mulscc mulscc.o

.equ SYSCALL_EXIT,1
.equ SYSCALL_WRITE,4
.equ STDOUT,1

! This problem was noticed in the ____strtod_l_internal ! routine, Deep inside a Fortran program that is reading in ! Some floating point values from disk

.globl _start
_start:

	!
	! TEST1 - high bits in y
	! 
	
	set	test1,%o1
	call	write_stdout
	nop
tun_test1:	
	! Set some high bits in y
	! have to use sllx to get them there
	
	set	0xff0fb28a, %o5
	sllx	%o5,8,%o5
	or	%o5,0x67,%o5
	set	0x00989680, %o3
	wr  %g0, %o5, %y
	andcc  %g0, %g0, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1	
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1	
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1	
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1
	mulscc  %g1, %o3, %g1	
	mulscc  %g1, %g0, %g1
	rd  %y, %g3
	
	! g1 should be 00095b3c
	! g3 should be a3858d80
	
	set	0x00095b3c,%g2
	cmp	%g1,%g2
	beq	test1_pass
	nop

test1_fail:

	set	fail,%o1
	ba	test1_print
	nop
test1_pass:
	set	pass,%o1
test1_print:
	call	write_stdout
	nop
	

	!
	! Test2 - high bits in src
	! 	- to force issue, N^V should be 0
	!
	
	set	test2,%o1
	call	write_stdout
	nop	

run_test2:

	set	0xffffffff,%g1
	wr      %g0, %g1, %y  		! stores g0 XOR g1 into y (so, g1)
	sllx	%g1,8,%g1		! set some >32 bits in g1
	
	set	0x00002c2f,%l0
	
	andcc   %g0, 0, %g2   		! sets v,c to 0.  n=hi bit, z if zero
		     			! since g0,0 we clear all flags
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1

	! Proper result, g1 = 0x585e
	!                 y = 0xffffa6a2	


	set	0x0000585e,%g2
	cmp	%g1,%g2
	beq	test2_pass
	nop

test2_fail:

	set	fail,%o1
	ba	test2_print
	nop
test2_pass:
	set	pass,%o1
test2_print:
	call	write_stdout
	nop

	
	!
	! Test3 - high bits in src2
	!
	
	set	test3,%o1
	call	write_stdout
	nop	

run_test3:

	set	0xffffffff,%l0
	wr      %g0, %l0, %y  		! stores g0 XOR l0 into y (so, l0)
	sllx	%l0,32,%l0		! set some >32 bits in l0
	or	%l0,0xff,%l0
	
	set	0x00002c2f,%g1
	
	andcc   %g0, 0, %g2   		! sets v,c to 0.  n=hi bit, z if zero
		     			! since g0,0 we clear all flags
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
	mulscc  %g1, %l0, %g1
larp:	
	! Proper result, g1 = 0x1fe
	!                 y = 0x0000 2a31


	set	0x1fe,%g2
	cmp	%g1,%g2
	bne	test3_fail
	nop

	rd  	%y, %g3
	set	0x2a31,%g2
	cmp	%g2,%g3
	beq	test3_pass
	nop

test3_fail:

	set	fail,%o1
	ba	test3_print
	nop
test3_pass:
	set	pass,%o1
test3_print:
	call	write_stdout
	nop	
	
	!================================
	! Exit
	!================================
exit:		
        mov	0,%o0			! exit value
        mov	SYSCALL_EXIT,%g1        ! put the exit syscall number in g1
        ta      0x10			! and exit


        !================================
	! WRITE_STDOUT
	!================================
	! %o1 has string

write_stdout:

	set     SYSCALL_WRITE,%g1       ! Write syscall in %g1
	set     STDOUT,%o0              ! 1 in %o0 (stdout)
	set     0,%o2                   ! 0 (count) in %o2

str_loop1:

	ldub    [%o1+%o2],%l0           ! load byte
	cmp     %l0,%g0                 ! compare against zero
	bnz     str_loop1               ! if not nul, repeat

! BRANCH DELAY SLOT
inc %o2 ! increment count

dec %o2 ! correct count
ta 0x10 ! run the syscall

retl ! return
nop

.data
fail: .ascii "Fail!\n\0"
pass: .ascii "Pass\n\0"
test1: .ascii "Test1: High bits in y : \0"
test2: .ascii "Test2: High bits in src : \0"
test3: .ascii "Test3: High bits in src2 : \0"

#3 lore raw
Quoted 15 lines · Vince Weaver
Quoted 3 lines · Blue Swirl

Thanks, I applied a fix based on this. There was also a similar problem in mulscc, maybe your tests run better now?

So it turns out there are three problems:

  1.  mulscc when y has upper word bits set
  2.  mulscc when src1 has upper word bits set
  3.  mulscc when src2 has upper word bits set

The patch from yesterday fixed case 1, but there were still problems for
2&3.

Quoted 6 lines

Below is a patch I made that seems to get this all working properly. I've
also attached a small test program that exhibits the 3 problems...

I'm running the big Fortran program again, but it would take a few hours to
finish if this is a proper fix so I thought I'd send this off now rather than waiting.

It's not proper to use i32 operations on i64 TCG registers. So I'd add explicit masking operations.

With this patch applied, I get:
Test1: High bits in y : Pass
Test2: High bits in src : Pass
Test3: High bits in src2 : Pass

target-sparc/translate.c +3 -2
Index: qemu/target-sparc/translate.c
===================================================================
@@ -697,9 +697,9 @@
     if (!(env->y & 1))
         T1 = 0;
     */
-    tcg_gen_mov_tl(cpu_cc_src, src1);
+    tcg_gen_andi_tl(cpu_cc_src, src1, 0xffffffff);
     tcg_gen_andi_tl(r_temp, cpu_y, 0x1);
-    tcg_gen_mov_tl(cpu_cc_src2, src2);
+    tcg_gen_andi_tl(cpu_cc_src2, src2, 0xffffffff);
     tcg_gen_brcondi_tl(TCG_COND_NE, r_temp, 0, l1);
     tcg_gen_movi_tl(cpu_cc_src2, 0);
     gen_set_label(l1);
@@ -709,6 +709,7 @@
     tcg_gen_andi_tl(r_temp, cpu_cc_src, 0x1);
     tcg_gen_shli_tl(r_temp, r_temp, 31);
     tcg_gen_shri_tl(cpu_tmp0, cpu_y, 1);
+    tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0x7fffffff);
     tcg_gen_or_tl(cpu_tmp0, cpu_tmp0, r_temp);
     tcg_gen_andi_tl(cpu_y, cpu_tmp0, 0xffffffff);
 
#4 lore raw

Hello

Quoted 2 lines

It's not proper to use i32 operations on i64 TCG registers. So I'd add explicit masking operations.

I tried your patch, and it does work.

Sorry for the delay responding, that benchmark takes 6+ hours to run.

Vince

#5 lore raw
Quoted 10 lines · Vince Weaver

Hello

Quoted 3 lines

It's not proper to use i32 operations on i64 TCG registers. So I'd add explicit masking operations.

I tried your patch, and it does work.

Sorry for the delay responding, that benchmark takes 6+ hours to run.

Thanks for confirming, I applied the patch.