* [Qemu-devel] Effective way to test PowerPC lwbrx instruction
@ 2016-08-25 18:54 G 3
2016-08-25 22:03 ` Thomas Huth
0 siblings, 1 reply; 5+ messages in thread
From: G 3 @ 2016-08-25 18:54 UTC (permalink / raw)
To: qemu-ppc, QEMU Developers
I'm chasing down a bug with QEMU that causes audio to fail on a Mac
OS guest. In this file: https://github.com/nixxcode/
AppleUSBAudio-273.4.1/blob/master/AppleUSBAudioClip.cpp is where a
lot of assembly language code is located. I think one or more of the
PowerPC instructions might be incorrectly implemented so I am
checking each one that the file uses. Starting with lwbrx I made this
program that gives this instruction sample inputs and checks them
with real outputs. According to the program QEMU implements this
instruction correctly. Does this program effectively check the lwbrx
instruction or is it missing something?
#include <stdio.h>
// instructions to test
// lwbrx, lhbrx, rlwimi, stwbrx, stfiwx, fctiw, fmadd, sthbrx, mffs,
// mtfsf
void test_lwbrx()
{
// http://www.ds.ewi.tudelft.nl/vakken/in1006/instruction-set/
lwbrx.html
// rA can be 0, 4, 8, 12
long index, result, rA;
const int rB_size = 32;
long rB[rB_size];
long *answer_array;
float total, correct;
// answers with rA = 0
long answer_array0[] = {0x0, 0x78563412, 0xf0ac6824, 0x68039d36,
0xe059d148,
0x58b0055b, 0xd0063a6d, 0x485d6e7f, 0xc0b3a291, 0x380ad7a3,
0xb0600bb6,
0x28b73fc8, 0xa00d74da, 0x1864a8ec, 0x90badcfe, 0x8111111,
0x80674523,
0xf8bd7935, 0x7014ae47, 0xe86ae259, 0x60c1166c, 0xd8174b7e,
0x506e7f90,
0xc8c4b3a2, 0x401be8b4, 0xb8711cc7, 0x30c850d9, 0xa81e85eb,
0x2075b9fd,
0x98cbed0f, 0x10222222, 0x88785634};
// answers with rA = 4
long answer_array4[] = {0x78563412, 0xf0ac6824, 0x68039d36,
0xe059d148,
0x58b0055b, 0xd0063a6d, 0x485d6e7f, 0xc0b3a291, 0x380ad7a3,
0xb0600bb6,
0x28b73fc8, 0xa00d74da, 0x1864a8ec, 0x90badcfe, 0x8111111,
0x80674523,
0xf8bd7935, 0x7014ae47, 0xe86ae259, 0x60c1166c, 0xd8174b7e,
0x506e7f90,
0xc8c4b3a2, 0x401be8b4, 0xb8711cc7, 0x30c850d9, 0xa81e85eb,
0x2075b9fd,
0x98cbed0f, 0x10222222, 0x88785634, 0x0};
// answers with rA = 8
long answer_array8[] = {0xf0ac6824, 0x68039d36, 0xe059d148,
0x58b0055b,
0xd0063a6d, 0x485d6e7f, 0xc0b3a291, 0x380ad7a3, 0xb0600bb6,
0x28b73fc8,
0xa00d74da, 0x1864a8ec, 0x90badcfe, 0x8111111, 0x80674523,
0xf8bd7935,
0x7014ae47, 0xe86ae259, 0x60c1166c, 0xd8174b7e, 0x506e7f90,
0xc8c4b3a2,
0x401be8b4, 0xb8711cc7, 0x30c850d9, 0xa81e85eb, 0x2075b9fd,
0x98cbed0f,
0x10222222, 0x88785634, 0x0, 0x0};
// answers with rA = 12
long answer_array12[] = {0x68039d36, 0xe059d148, 0x58b0055b,
0xd0063a6d,
0x485d6e7f, 0xc0b3a291, 0x380ad7a3, 0xb0600bb6, 0x28b73fc8,
0xa00d74da,
0x1864a8ec, 0x90badcfe, 0x8111111, 0x80674523, 0xf8bd7935,
0x7014ae47,
0xe86ae259, 0x60c1166c, 0xd8174b7e, 0x506e7f90, 0xc8c4b3a2,
0x401be8b4,
0xb8711cc7, 0x30c850d9, 0xa81e85eb, 0x2075b9fd, 0x98cbed0f,
0x10222222,
0x88785634, 0x0, 0x0, 0x0};
// Fill up rB array
for(index = 0; index < rB_size; index++)
{
rB[index] = 0x12345678 * index;
}
total = 0;
correct = 0;
// Go thru each rA value
for(rA = 0; rA <=12; rA=rA+4)
{
// set the correct answer array for each rA value
if(rA == 0)
answer_array = answer_array0;
else if(rA == 4)
answer_array = answer_array4;
else if(rA == 8)
answer_array = answer_array8;
else
answer_array = answer_array12;
// Go thru each rB value
for(index = 0; index < rB_size; index++)
{
asm volatile("lwbrx %0, %1, %2" : "=r" (result) : "b
%" (rA), "r" (&(rB[index])));
printf("lwbrx rA: %d rB: 0x%x result: 0x%x", rA, rB
[index], result);
//printf("0x%x, ", result); // used to make answers
total++;
// check recorded answer with calculated answer
if(result == answer_array[index]) {
printf(" correct\n");
correct++;
} else {
printf(" WRONG! should be 0x%x\n", answer_array
[index]);
}
}
}
printf("Percent correct: %.2f%c\n", correct/total*100, '%');
}
int main (int argc, const char * argv[]) {
test_lwbrx();
return 0;
}
This program was tested on a real PowerPC G3 and G5. The results were
100% when ran in QEMU in a Mac OS 10.4 guest.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] Effective way to test PowerPC lwbrx instruction
2016-08-25 18:54 [Qemu-devel] Effective way to test PowerPC lwbrx instruction G 3
@ 2016-08-25 22:03 ` Thomas Huth
2016-08-25 22:55 ` G 3
0 siblings, 1 reply; 5+ messages in thread
From: Thomas Huth @ 2016-08-25 22:03 UTC (permalink / raw)
To: G 3, qemu-ppc; +Cc: QEMU Developers
On 25.08.2016 14:54, G 3 wrote:
> I'm chasing down a bug with QEMU that causes audio to fail on a Mac OS
> guest. In this file:
> https://github.com/nixxcode/AppleUSBAudio-273.4.1/blob/master/AppleUSBAudioClip.cpp
> is where a lot of assembly language code is located. I think one or more
> of the PowerPC instructions might be incorrectly implemented so I am
> checking each one that the file uses. Starting with lwbrx I made this
> program that gives this instruction sample inputs and checks them with
> real outputs. According to the program QEMU implements this instruction
> correctly. Does this program effectively check the lwbrx instruction or
> is it missing something?
...
> // Go thru each rA value
> for(rA = 0; rA <=12; rA=rA+4)
> {
> // set the correct answer array for each rA value
> if(rA == 0)
> answer_array = answer_array0;
> else if(rA == 4)
> answer_array = answer_array4;
> else if(rA == 8)
> answer_array = answer_array8;
> else
> answer_array = answer_array12;
>
> // Go thru each rB value
> for(index = 0; index < rB_size; index++)
> {
> asm volatile("lwbrx %0, %1, %2" : "=r" (result) : "b%" (rA),
> "r" (&(rB[index])));
I think you're not testing the case where rA is r0 here (only where the
content of rA is 0) ... and rA == r0 is a special case for this
instruction, see the PowerISA for details. So you'd need a separate asm
volatile statement to test this.
(Also a question: What is the "%" here good for? I did not quite
understand why you're using that here)
Thomas
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] Effective way to test PowerPC lwbrx instruction
2016-08-25 22:03 ` Thomas Huth
@ 2016-08-25 22:55 ` G 3
2016-08-26 2:30 ` Thomas Huth
0 siblings, 1 reply; 5+ messages in thread
From: G 3 @ 2016-08-25 22:55 UTC (permalink / raw)
To: Thomas Huth; +Cc: qemu-ppc, QEMU Developers
On Aug 25, 2016, at 6:03 PM, Thomas Huth wrote:
> On 25.08.2016 14:54, G 3 wrote:
>> I'm chasing down a bug with QEMU that causes audio to fail on a
>> Mac OS
>> guest. In this file:
>> https://github.com/nixxcode/AppleUSBAudio-273.4.1/blob/master/
>> AppleUSBAudioClip.cpp
>> is where a lot of assembly language code is located. I think one
>> or more
>> of the PowerPC instructions might be incorrectly implemented so I am
>> checking each one that the file uses. Starting with lwbrx I made this
>> program that gives this instruction sample inputs and checks them
>> with
>> real outputs. According to the program QEMU implements this
>> instruction
>> correctly. Does this program effectively check the lwbrx
>> instruction or
>> is it missing something?
> ...
>> // Go thru each rA value
>> for(rA = 0; rA <=12; rA=rA+4)
>> {
>> // set the correct answer array for each rA value
>> if(rA == 0)
>> answer_array = answer_array0;
>> else if(rA == 4)
>> answer_array = answer_array4;
>> else if(rA == 8)
>> answer_array = answer_array8;
>> else
>> answer_array = answer_array12;
>>
>> // Go thru each rB value
>> for(index = 0; index < rB_size; index++)
>> {
>> asm volatile("lwbrx %0, %1, %2" : "=r" (result) : "b
>> %" (rA),
>> "r" (&(rB[index])));
>
> I think you're not testing the case where rA is r0 here (only where
> the
> content of rA is 0) ... and rA == r0 is a special case for this
> instruction, see the PowerISA for details. So you'd need a separate
> asm
> volatile statement to test this.
> (Also a question: What is the "%" here good for? I did not quite
> understand why you're using that here)
>
> Thomas
Thank you very much for commenting. For the case where rA is r0, are
you saying something like this:
asm volatile("lwbrx %0, 0, %1" : "=r" (result) : "r" (&(rB[index])));
http://webcache.googleusercontent.com/search?
q=cache:Z7TDqMWVLZ0J:https://www.ibm.com/support/knowledgecenter/
ssw_aix_71/com.ibm.aix.alangref/idalangref_lwbrx_lbx_lwbri_instrs.htm%
2Blwbrx+powerpc&client=safari&rls=en&hl=en&ct=clnk
Didn't find the text 'r0' here, but it did mention this:
"If GPR RA is 0, then the EA is the contents of GPR RB". Is that the
same thing?
The percent is for me to quickly see if any of the test failed. QEMU
is at 100% for this test.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] Effective way to test PowerPC lwbrx instruction
2016-08-25 22:55 ` G 3
@ 2016-08-26 2:30 ` Thomas Huth
2016-08-26 12:33 ` G 3
0 siblings, 1 reply; 5+ messages in thread
From: Thomas Huth @ 2016-08-26 2:30 UTC (permalink / raw)
To: G 3; +Cc: qemu-ppc, QEMU Developers
On 25.08.2016 18:55, G 3 wrote:
>
> On Aug 25, 2016, at 6:03 PM, Thomas Huth wrote:
>
>> On 25.08.2016 14:54, G 3 wrote:
>>> I'm chasing down a bug with QEMU that causes audio to fail on a Mac OS
>>> guest. In this file:
>>> https://github.com/nixxcode/AppleUSBAudio-273.4.1/blob/master/AppleUSBAudioClip.cpp
>>>
>>> is where a lot of assembly language code is located. I think one or more
>>> of the PowerPC instructions might be incorrectly implemented so I am
>>> checking each one that the file uses. Starting with lwbrx I made this
>>> program that gives this instruction sample inputs and checks them with
>>> real outputs. According to the program QEMU implements this instruction
>>> correctly. Does this program effectively check the lwbrx instruction or
>>> is it missing something?
>> ...
>>> // Go thru each rA value
>>> for(rA = 0; rA <=12; rA=rA+4)
>>> {
>>> // set the correct answer array for each rA value
>>> if(rA == 0)
>>> answer_array = answer_array0;
>>> else if(rA == 4)
>>> answer_array = answer_array4;
>>> else if(rA == 8)
>>> answer_array = answer_array8;
>>> else
>>> answer_array = answer_array12;
>>>
>>> // Go thru each rB value
>>> for(index = 0; index < rB_size; index++)
>>> {
>>> asm volatile("lwbrx %0, %1, %2" : "=r" (result) : "b%" (rA),
>>> "r" (&(rB[index])));
>>
>> I think you're not testing the case where rA is r0 here (only where the
>> content of rA is 0) ... and rA == r0 is a special case for this
>> instruction, see the PowerISA for details. So you'd need a separate asm
>> volatile statement to test this.
>> (Also a question: What is the "%" here good for? I did not quite
>> understand why you're using that here)
>>
>> Thomas
>
> Thank you very much for commenting. For the case where rA is r0, are you
> saying something like this:
>
> asm volatile("lwbrx %0, 0, %1" : "=r" (result) : "r" (&(rB[index])));
Yes, this is what I had in mind.
> Didn't find the text 'r0' here, but it did mention this:
> "If GPR RA is 0, then the EA is the contents of GPR RB". Is that the
> same thing?
Yes, I am normally using "r0" instead of "0" so that it can not be
confused that easily with an immediate value.
By the way, if you don't know it yet, you can get the official Power ISA
here:
https://www.power.org/wp-content/uploads/2013/05/PowerISA_V2.07_PUBLIC.pdf
> The percent is for me to quickly see if any of the test failed. QEMU is
> at 100% for this test.
I didn't mean the printf statement, but the % character in the "b%" part
of the asm volatile statement.
Thomas
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] Effective way to test PowerPC lwbrx instruction
2016-08-26 2:30 ` Thomas Huth
@ 2016-08-26 12:33 ` G 3
0 siblings, 0 replies; 5+ messages in thread
From: G 3 @ 2016-08-26 12:33 UTC (permalink / raw)
To: Thomas Huth; +Cc: qemu-ppc, QEMU Developers
On Aug 25, 2016, at 10:30 PM, Thomas Huth wrote:
> On 25.08.2016 18:55, G 3 wrote:
>>
>> On Aug 25, 2016, at 6:03 PM, Thomas Huth wrote:
>>
>>> On 25.08.2016 14:54, G 3 wrote:
>>>> I'm chasing down a bug with QEMU that causes audio to fail on a
>>>> Mac OS
>>>> guest. In this file:
>>>> https://github.com/nixxcode/AppleUSBAudio-273.4.1/blob/master/
>>>> AppleUSBAudioClip.cpp
>>>>
>>>> is where a lot of assembly language code is located. I think one
>>>> or more
>>>> of the PowerPC instructions might be incorrectly implemented so
>>>> I am
>>>> checking each one that the file uses. Starting with lwbrx I made
>>>> this
>>>> program that gives this instruction sample inputs and checks
>>>> them with
>>>> real outputs. According to the program QEMU implements this
>>>> instruction
>>>> correctly. Does this program effectively check the lwbrx
>>>> instruction or
>>>> is it missing something?
>>> ...
>>>> // Go thru each rA value
>>>> for(rA = 0; rA <=12; rA=rA+4)
>>>> {
>>>> // set the correct answer array for each rA value
>>>> if(rA == 0)
>>>> answer_array = answer_array0;
>>>> else if(rA == 4)
>>>> answer_array = answer_array4;
>>>> else if(rA == 8)
>>>> answer_array = answer_array8;
>>>> else
>>>> answer_array = answer_array12;
>>>>
>>>> // Go thru each rB value
>>>> for(index = 0; index < rB_size; index++)
>>>> {
>>>> asm volatile("lwbrx %0, %1, %2" : "=r" (result) : "b
>>>> %" (rA),
>>>> "r" (&(rB[index])));
>>>
>>> I think you're not testing the case where rA is r0 here (only
>>> where the
>>> content of rA is 0) ... and rA == r0 is a special case for this
>>> instruction, see the PowerISA for details. So you'd need a
>>> separate asm
>>> volatile statement to test this.
>>> (Also a question: What is the "%" here good for? I did not quite
>>> understand why you're using that here)
>>>
>>> Thomas
>>
>> Thank you very much for commenting. For the case where rA is r0,
>> are you
>> saying something like this:
>>
>> asm volatile("lwbrx %0, 0, %1" : "=r" (result) : "r" (&(rB
>> [index])));
>
> Yes, this is what I had in mind.
>
>> Didn't find the text 'r0' here, but it did mention this:
>> "If GPR RA is 0, then the EA is the contents of GPR RB". Is that the
>> same thing?
>
> Yes, I am normally using "r0" instead of "0" so that it can not be
> confused that easily with an immediate value.
>
> By the way, if you don't know it yet, you can get the official
> Power ISA
> here:
>
> https://www.power.org/wp-content/uploads/2013/05/
> PowerISA_V2.07_PUBLIC.pdf
>
>> The percent is for me to quickly see if any of the test failed.
>> QEMU is
>> at 100% for this test.
>
> I didn't mean the printf statement, but the % character in the "b%"
> part
> of the asm volatile statement.
That is something that I copied from Apple's source code I am working
on.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-08-26 13:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-25 18:54 [Qemu-devel] Effective way to test PowerPC lwbrx instruction G 3
2016-08-25 22:03 ` Thomas Huth
2016-08-25 22:55 ` G 3
2016-08-26 2:30 ` Thomas Huth
2016-08-26 12:33 ` G 3
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.