From: Vince Weaver <vince@csl.cornell.edu>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] sparc smul problem
Date: Mon, 1 Sep 2008 12:14:54 -0400 (EDT) [thread overview]
Message-ID: <20080901121035.R83237@stanley.csl.cornell.edu> (raw)
[-- Attachment #1: Type: TEXT/PLAIN, Size: 937 bytes --]
Hello!
I've been stuck on this all weekend, as I can't find where the actual
problem is. I might be completely missing it, but I've tried a lot of
things and can't make it work.
On SPARC, the "smul" instruction multiplies two numbers, puts the result
in the result register but also puts the top 32-bits of the 64-bit result
into the "Y" register.
As the attached code shows, the value of "Y" is wrong. Somehow after the
multiply, the top 32 bits of the product rae all zeros. I've played
around with the code generated by translate.c, and it looks like the shift
and other instructions all work properly, but the 64-bit multiply the
result is somehow being truncated. But I've looked at the generated code
(on x86_64) and it looks like it is doing the right thing.
So anyway, I'll have to take a look at this again later, but in case
anyone else wants to look at it in case I am missing anything obvious.
Thanks
Vince
[-- Attachment #2: Type: TEXT/PLAIN, Size: 1843 bytes --]
! as -o smul.o smul.s ; ld -o smul smul.o
.equ SYSCALL_EXIT,1
.equ SYSCALL_WRITE,4
.equ STDOUT,1
.globl _start
_start:
set 0xc22e4507,%g1
set 0x386d4380,%g4
before:
smul %g4,%g1,%g2
rd %y,%g3
stop:
! g2 should be (f25fbc80) 1f2e5880
! g3 should be (00000000) f25fbc80
set 0x1f2e5880,%g5
cmp %g2,%g5
bne wrong_lower
nop
set correct_answer,%o1
ba print_lower
nop
wrong_lower:
set wrong_answer,%o1
print_lower:
call write_stdout
nop
! Check to see if Y was correct
set 0xf25fbc80,%g5
cmp %g3,%g5
bne print_wrong_y
nop
set correct_y,%o1
ba print_y
nop
print_wrong_y:
set wrong_y,%o1
print_y:
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],%l1 ! load byte
cmp %l1,%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
nop
!===========================================================================
.data
!===========================================================================
data_region:
wrong_answer: .ascii "Wrong answer\n\0"
wrong_y: .ascii "Wrong Y\n\0"
correct_answer: .ascii "Correct answer\n\0"
correct_y: .ascii "Correct Y\n\0"
[-- Attachment #3: Type: APPLICATION/octet-stream, Size: 1226 bytes --]
next reply other threads:[~2008-09-01 16:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-01 16:14 Vince Weaver [this message]
2008-09-01 16:49 ` [Qemu-devel] sparc smul problem Blue Swirl
2008-09-01 17:20 ` Blue Swirl
2008-09-01 19:05 ` Blue Swirl
2008-09-01 23:11 ` Aurelien Jarno
2008-09-02 16:58 ` Blue Swirl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080901121035.R83237@stanley.csl.cornell.edu \
--to=vince@csl.cornell.edu \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).