 |
|
 |
|
Next: CW inline assembly and Rosetta
|
| Author |
Message |
External

Since: Apr 14, 2004 Posts: 25
|
(Msg. 1) Posted: Wed Jul 20, 2005 1:23 pm
Post subject: Inline assembly and Rosetta Archived from groups: comp>sys>mac>programmer>misc (more info?)
|
|
|
The function below is the (PowerPC/CodeWarrior) core of a
pseudo-random-number generator which is nearly four times faster than
the best C equivalent I can write. [The basic operation,
subtract-with-borrow (subfe), is a single instruction that must be
simulated in C.]
Can anyone tell me whether Rosetta will handle a function like this,
including fetching and storing the globals, or will I have to write an
x86 assembly routine? [I do not have an x86 computer and have never
written x86 assembly.]
Thanks in advance.
asm void URandomLib::Refill()
{
lwz r3,Ultra_brw // fetch global addresses from TOC
lwz r6,Ultra_SWB
lwz r4,0(r3) // ~borrow
la r7,48(r6) // &Ultra_SWB[12]
sub r5,r5,r5 // clear entire word
mr r8,r5 // counter
li r5,1
sraw r4,r4,r5 // restore XER|CA
li r8,24
mtctr r8
la r4,-4(r6)
UR1: lwzu r9,4(r7)
lwz r10,4(r4)
subfe r9,r10,r9 // r9 -= r10
stwu r9,4(r4)
bdnz+ UR1
mr r7,r6 // &Ultra_SWB
li r8,13
mtctr r8
la r7,-4(r6)
UR2: lwzu r9,4(r7)
lwz r10,4(r4)
subfe r9,r10,r9 // r9 -= r10
stwu r9,4(r4)
bdnz+ UR2
lwz r4,0(r3) // ~borrow again
addme r4,r5 // r5 = 1
neg r4,r4
stw r4,0(r3) // new ~borrow
la r6,-4(r6) // &SWB[-1]
lwz r7,Ultra_FSR
lwz r5,Ultra_ptr
lwz r4,Ultra_seed1
stw r7,0(r5) // reset running pointer to FSR
la r7,-4(r7) // overlay congruential PRNG
lis r10,1 // r10 = 69069
addi r10,r10,3533
lwz r5,0(r4) // Ultra_seed1
li r8,37
mtctr r8
UR3: lwzu r9,4(r6) // SWB
mullw r5,r5,r10 // Ultra_seed1 *= 69069
xor r9,r9,r5
stwu r9,4(r7)
bdnz+ UR3
stw r5,0(r4) // save Ultra_seed1 for next time
lwz r7,Ultra_byt
li r5,148 // 4*37 bytes
sth r5,0(r7) // reinitialize
blr
}
--
Mike McLaughlin >> Stay informed about: Inline assembly and Rosetta |
|
| Back to top |
|
 |  |
External

Since: Jun 01, 2004 Posts: 525
|
(Msg. 2) Posted: Wed Jul 20, 2005 4:19 pm
Post subject: Re: Inline assembly and Rosetta [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Michael McLaughlin <mpmcl DeleteThis @mitre.org> wrote:
> The function below is the (PowerPC/CodeWarrior) core of a
> pseudo-random-number generator which is nearly four times faster than
> the best C equivalent I can write. [The basic operation,
> subtract-with-borrow (subfe), is a single instruction that must be
> simulated in C.]
>
> Can anyone tell me whether Rosetta will handle a function like this,
> including fetching and storing the globals, or will I have to write an
> x86 assembly routine? [I do not have an x86 computer and have never
> written x86 assembly.]
It depends on exactly what you're asking.
If you're asking whether Rosetta will correctly handle this inline
assembly inside a PowerPC application, the answer is yes. Once your
application is compiled, it's basically impossible to detect which
portions of the app are inline assembly and which portions came from C. As
long as your inline assembly doesn't do things that Rosetta doesn't
support (altivec, basically), Rosetta will translate it fine.
If you're asking whether Rosetta will handle this function inside a binary
that you've recompiled as an x86 binary, the answer is no. Processes on
Mac OS X are an either-or proposition; either the entire process is PPC,
or the entire process is x86, there is no mixed-mode support. If you're
compiling for x86, you need either an x86 equivalent of this function, or
a C equivalent. Of course, this is no great loss, as running the function
emulated is probably going to be slower than a native C implementation
anyway. >> Stay informed about: Inline assembly and Rosetta |
|
| Back to top |
|
 |  |
External

Since: Feb 15, 2005 Posts: 8
|
(Msg. 3) Posted: Thu Jul 21, 2005 10:03 am
Post subject: Re: Inline assembly and Rosetta [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On 2005-07-20 13:23:51 -0400, Michael McLaughlin <mpmcl DeleteThis @mitre.org> said:
> Can anyone tell me whether Rosetta will handle a function like this,
> including fetching and storing the globals, or will I have to write an
> x86 assembly routine? [I do not have an x86 computer and have never
> written x86 assembly.]
Does your code work on G3 Macs? If so, then yes, it will work under Rosetta.
--
Clark S. Cox, III
clarkcox3 DeleteThis @gmail.com >> Stay informed about: Inline assembly and Rosetta |
|
| Back to top |
|
 |  |
External

Since: Apr 14, 2004 Posts: 25
|
(Msg. 4) Posted: Thu Jul 21, 2005 4:11 pm
Post subject: Re: Inline assembly and Rosetta [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
The part of the inline assembly that concerned me most was the access of
global variables. I was/am not sure whether the indicated construction
was CodeWarrior-specific or OK in general.
Is it the latter -- I hope?
Clark S. Cox III wrote:
> On 2005-07-20 13:23:51 -0400, Michael McLaughlin <mpmcl RemoveThis @mitre.org> said:
>
>> Can anyone tell me whether Rosetta will handle a function like this,
>> including fetching and storing the globals, or will I have to write an
>> x86 assembly routine? [I do not have an x86 computer and have never
>> written x86 assembly.]
>
>
> Does your code work on G3 Macs? If so, then yes, it will work under
> Rosetta.
> >> Stay informed about: Inline assembly and Rosetta |
|
| Back to top |
|
 |  |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|