* Re: rpcc
1999-01-12 3:55 rpcc Christoph Dworzak
@ 1999-01-12 3:20 ` Peter Petrakis
1999-01-12 4:59 ` rpcc Richard Henderson
1 sibling, 0 replies; 23+ messages in thread
From: Peter Petrakis @ 1999-01-12 3:20 UTC (permalink / raw)
To: axp-list
Do you know how to profile your code? Here's an example. Say I have a
single source file called hello.c and i want to find out what calls it
makes , how many times the calls are made, percent of time spent etc
etc. I do this at the command line.
gcc -p -o hello hello.c
The -p flag generates code sutible for the profiler and the "hello" is
the name of the binary executable. Now execute hello.
./hello
Hello World
Wow, fancy. Now to see how it spent it's time. do
gprof hello
And you'll get something like this
Flat profile:
Each sample counts as 0.000976562 seconds.
no time accumulated
% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
0.00 0.00 0.00 1 0.00 0.00 main
........
I hope this is has some use. BTW any good text on C will detail how to
do this.
I learned the from "A book on C" which you can find at amazon.com
Peter P.
Christoph Dworzak wrote:
>
> Hi
>
> With some help from this list, I'm getting better
> with axp-asm :)
>
> Now my next question is, how do I measure the speed
> of my code?
>
> My test looks like this:
>
> --------------------------------------------------------
> unsigned long c1, c2, ccm=~0UL, ccs=0, n;
>
>
> for (n=0; n<(1UL<<19); n++){
> asm volatile("rpcc %0" : "=r"(c1) : : "memory");
> core();
> asm volatile("rpcc %0" : "=r"(c2) : : "memory");
> c1 = (c1 + (c1<<32)) >> 32;
> c2 = (c2 + (c2<<32)) >> 32;
> c2 = (c2>c1) ? c2-c1 : c2+(1UL<<32)-c1;
> ccs += c2;
> if (c2<ccm) ccm = c2;
> }
> printf("\nMin=%ld Avg=%ld\n\n", ccm, ccs/n;
> --------------------------------------------------------
>
> When I run this several times, I get strange results
> (see end of my mail)
>
> Why does it take up to 50% longer sometimes? (it really
> does, checking with my wrist-watch.)
>
> Of course I know, there are some task-switches or interupts,
> but I would expect, that at least one loop out of one million
> runs uninteruptet on full speed...
>
> Has it something to do with alignment of the code in memory
> and if so, how could I place the code so it runs at full speed?
>
> Bye
> dworz
>
> --------------------------------------------------------
> [dworz@really speed]# time ./speedtest
>
> Min=6063 Avg=6552
>
> 13.85user 0.00system 0:15.11elapsed 91%CPU (0avgtext+0avgdata 0maxresident)k
> 0inputs+0outputs (69major+14minor)pagefaults 0swaps
> [dworz@really speed]# time ./speedtest
>
> Min=6065 Avg=6546
>
> 13.84user 0.00system 0:15.54elapsed 89%CPU (0avgtext+0avgdata 0maxresident)k
> 0inputs+0outputs (69major+14minor)pagefaults 0swaps
> [dworz@really speed]# time ./speedtest
>
> Min=7961 Avg=8975
>
> 18.93user 0.00system 0:20.66elapsed 91%CPU (0avgtext+0avgdata 0maxresident)k
> 0inputs+0outputs (69major+14minor)pagefaults 0swaps
> [dworz@really speed]# time ./speedtest
>
> Min=6063 Avg=6532
>
> 13.80user 0.00system 0:15.52elapsed 88%CPU (0avgtext+0avgdata 0maxresident)k
> 0inputs+0outputs (69major+14minor)pagefaults 0swaps
> [dworz@really speed]# time ./speedtest
>
> Min=7975 Avg=8970
>
> 18.92user 0.00system 0:20.66elapsed 91%CPU (0avgtext+0avgdata 0maxresident)k
> 0inputs+0outputs (69major+14minor)pagefaults 0swaps
> [dworz@really speed]# time ./speedtest
>
> Min=6062 Avg=6477
>
> 13.69user 0.00system 0:14.96elapsed 91%CPU (0avgtext+0avgdata 0maxresident)k
> 0inputs+0outputs (69major+14minor)pagefaults 0swaps
> [dworz@really speed]# time ./speedtest
>
> Min=6063 Avg=6520
>
> 13.78user 0.00system 0:15.06elapsed 91%CPU (0avgtext+0avgdata 0maxresident)k
> 0inputs+0outputs (69major+14minor)pagefaults 0swaps
> --------------------------------------------------------
>
> --
> To unsubscribe: send e-mail to axp-list-request@redhat.com with
> 'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
--
STCC DEC Alpha Resource Page
http://math.stcc.mass.edu/petrakis
PeterPan@wn.net AlphaGuy =)
"BLAM! Who the hell are you!? Name's Ash <click clock> Housewares..."
^ permalink raw reply [flat|nested] 23+ messages in thread
* rpcc
@ 1999-01-12 3:55 Christoph Dworzak
1999-01-12 3:20 ` rpcc Peter Petrakis
1999-01-12 4:59 ` rpcc Richard Henderson
0 siblings, 2 replies; 23+ messages in thread
From: Christoph Dworzak @ 1999-01-12 3:55 UTC (permalink / raw)
To: axp-list
Hi
With some help from this list, I'm getting better
with axp-asm :)
Now my next question is, how do I measure the speed
of my code?
My test looks like this:
--------------------------------------------------------
unsigned long c1, c2, ccm=~0UL, ccs=0, n;
for (n=0; n<(1UL<<19); n++){
asm volatile("rpcc %0" : "=r"(c1) : : "memory");
core();
asm volatile("rpcc %0" : "=r"(c2) : : "memory");
c1 = (c1 + (c1<<32)) >> 32;
c2 = (c2 + (c2<<32)) >> 32;
c2 = (c2>c1) ? c2-c1 : c2+(1UL<<32)-c1;
ccs += c2;
if (c2<ccm) ccm = c2;
}
printf("\nMin=%ld Avg=%ld\n\n", ccm, ccs/n;
--------------------------------------------------------
When I run this several times, I get strange results
(see end of my mail)
Why does it take up to 50% longer sometimes? (it really
does, checking with my wrist-watch.)
Of course I know, there are some task-switches or interupts,
but I would expect, that at least one loop out of one million
runs uninteruptet on full speed...
Has it something to do with alignment of the code in memory
and if so, how could I place the code so it runs at full speed?
Bye
dworz
--------------------------------------------------------
[dworz@really speed]# time ./speedtest
Min=6063 Avg=6552
13.85user 0.00system 0:15.11elapsed 91%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (69major+14minor)pagefaults 0swaps
[dworz@really speed]# time ./speedtest
Min=6065 Avg=6546
13.84user 0.00system 0:15.54elapsed 89%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (69major+14minor)pagefaults 0swaps
[dworz@really speed]# time ./speedtest
Min=7961 Avg=8975
18.93user 0.00system 0:20.66elapsed 91%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (69major+14minor)pagefaults 0swaps
[dworz@really speed]# time ./speedtest
Min=6063 Avg=6532
13.80user 0.00system 0:15.52elapsed 88%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (69major+14minor)pagefaults 0swaps
[dworz@really speed]# time ./speedtest
Min=7975 Avg=8970
18.92user 0.00system 0:20.66elapsed 91%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (69major+14minor)pagefaults 0swaps
[dworz@really speed]# time ./speedtest
Min=6062 Avg=6477
13.69user 0.00system 0:14.96elapsed 91%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (69major+14minor)pagefaults 0swaps
[dworz@really speed]# time ./speedtest
Min=6063 Avg=6520
13.78user 0.00system 0:15.06elapsed 91%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (69major+14minor)pagefaults 0swaps
--------------------------------------------------------
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: rpcc
1999-01-12 3:55 rpcc Christoph Dworzak
1999-01-12 3:20 ` rpcc Peter Petrakis
@ 1999-01-12 4:59 ` Richard Henderson
[not found] ` <rth@twiddle.net>
1 sibling, 1 reply; 23+ messages in thread
From: Richard Henderson @ 1999-01-12 4:59 UTC (permalink / raw)
To: axp-list
On Tue, Jan 12, 1999 at 03:55:00AM +0000, Christoph Dworzak wrote:
> Why does it take up to 50% longer sometimes? (it really
> does, checking with my wrist-watch.)
That really depends on the nature of `core()', but I can
throw out generalities --
(1) page faulting, though that would surely only explain a
higher average, not minimum.
(2) page colouring. this affects the efficiency of the caches.
there is no way under linux to control your page colour.
r~
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: rpcc
[not found] ` <rth@twiddle.net>
@ 1999-01-12 16:59 ` Christoph Dworzak
1999-01-12 19:27 ` rpcc Richard Henderson
1999-01-14 16:17 ` Alpha 21264 Christoph Dworzak
1999-10-24 15:04 ` patch_v2: (on Alpha) emulating missing instructions Christoph Dworzak
2 siblings, 1 reply; 23+ messages in thread
From: Christoph Dworzak @ 1999-01-12 16:59 UTC (permalink / raw)
To: axp-list
On Jan 11 Richard Henderson (rth@twiddle.net) wrote:
> On Tue, Jan 12, 1999 at 03:55:00AM +0000, Christoph Dworzak wrote:
> > Why does it take up to 50% longer sometimes? (it really
> > does, checking with my wrist-watch.)
>
> That really depends on the nature of `core()',
core() is actually core(n). It only depends on
n. no other variables. so it calculates exactly
the same for every run of my testprogram.
the core is mostly unconditional, but i had a test
to the end of the core which would skip some 300
instructions if a certain condition is true.
i took this out, so now the core has no
conditional code at all. i would expect, that
it takes the same amount of ops every time.
(calculations like "c=a+b" take up the same amount
of time, no matter what the values of a and b are.
right?)
I'm not shure, if the behavior of my program really
changed (maybe it's just that my computer was less
busy), but i hat to run my speedtest about 30 times
to get some runs which were slower. Mostly the
minimum was around 6300, but there are some runs
where the min was more than 7000...
Min=6317 Avg=6425
Min=6319 Avg=6429
Min=6316 Avg=6542
Min=6667 Avg=6926
Min=7076 Avg=7423
Min=6316 Avg=6499
Min=6321 Avg=6419
Min=6319 Avg=6425
Min=7077 Avg=7201
Min=6667 Avg=6836
> (1) page faulting, though that would surely only explain a
> higher average, not minimum.
My computer has 256MB RAM and right now it uses 200MB for
cacheing. I don't expect it to do pageing (the testprogram
is about 60kB in size and uses about 32kB for its variables).
> (2) page colouring. this affects the efficiency of the caches.
> there is no way under linux to control your page colour.
What is page colouring? Could you explain this or do you
know where I can read about it?
Thanks a lot Mr. Henderson. It's always a pleasure to learn
from people which know more than one self :)
Bye
dworz
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: rpcc
1999-01-12 16:59 ` rpcc Christoph Dworzak
@ 1999-01-12 19:27 ` Richard Henderson
1999-01-12 21:06 ` rpcc Wes Bauske
0 siblings, 1 reply; 23+ messages in thread
From: Richard Henderson @ 1999-01-12 19:27 UTC (permalink / raw)
To: axp-list
On Tue, Jan 12, 1999 at 04:59:00PM +0000, Christoph Dworzak wrote:
> > (2) page colouring. this affects the efficiency of the caches.
> > there is no way under linux to control your page colour.
>
> What is page colouring? Could you explain this or do you
> know where I can read about it?
It should be found in most operating system or system architecture
textbooks, in the location in which they talk about memory caches.
Caches work by indexing off the middle bits of an address, also
referred to as the address' `colour'. The exact range of middle bits
has to do with the cache line size on the low end, and the size of
the cache / set associativeness of the cache on the high end.
If the high bits of two addresses are different, but their colours
are the same, the two addresses alias. The set associativeness
of the cache determines how many aliases we can have in the cache
at one time.
If the physical memory for a process is all contiguous, we get the
maximal distribution of colours, and so optimal cache efficiency.
This rarely happens in practice.
What does happen is that, due to physical memory fragmentation, the
kernel uses a page from here and a page from there. On a system
that has been up a while, the colour any particular page a process
owns is effectively random.
Worst case, one could receive a set of pages all with the same colour.
In this case the process would spend a great deal of its time waiting
on main memory because cache efficiency would be abysmal. This also
rarely happens in practice.
DaveM experimented with page colouring allocator -- one that would
be more likely to give a maximal distribution of colours -- midway
through the 2.1 series. But on top of the buddy-system page allocation
system we have, that lead to serious memory fragmentation, fell over
and died in low memory situations.
Perhaps it will be revisited in the 2.3 series; who knows. It's only
a real issue for benchmarks, when one wants to have reproducible numbers,
so it's a fairly low-priority thing.
r~
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: rpcc
1999-01-12 19:27 ` rpcc Richard Henderson
@ 1999-01-12 21:06 ` Wes Bauske
1999-01-13 2:16 ` rpcc Richard Henderson
0 siblings, 1 reply; 23+ messages in thread
From: Wes Bauske @ 1999-01-12 21:06 UTC (permalink / raw)
To: axp-list
Richard Henderson wrote:
>
> On Tue, Jan 12, 1999 at 04:59:00PM +0000, Christoph Dworzak wrote:
> > > (2) page colouring. this affects the efficiency of the caches.
> > > there is no way under linux to control your page colour.
> >
> > What is page colouring? Could you explain this or do you
> > know where I can read about it?
>
> It should be found in most operating system or system architecture
> textbooks, in the location in which they talk about memory caches.
>
> Caches work by indexing off the middle bits of an address, also
> referred to as the address' `colour'. The exact range of middle bits
> has to do with the cache line size on the low end, and the size of
> the cache / set associativeness of the cache on the high end.
>
>
I agree with your description except for one point.
What I've read about other systems is that it is the
virtual address that drives your cache location, not
your physical page address. Are you saying under Linux
or in general it is the physical page address?
Wes
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: rpcc
1999-01-12 21:06 ` rpcc Wes Bauske
@ 1999-01-13 2:16 ` Richard Henderson
0 siblings, 0 replies; 23+ messages in thread
From: Richard Henderson @ 1999-01-13 2:16 UTC (permalink / raw)
To: axp-list
On Tue, Jan 12, 1999 at 09:06:54PM +0000, Wes Bauske wrote:
> I agree with your description except for one point.
> What I've read about other systems is that it is the
> virtual address that drives your cache location, not
> your physical page address. Are you saying under Linux
> or in general it is the physical page address?
Whether the virtual address or physical address is used in the
on-chip cache is an implementation specific detail. Off-chip
caches will of course always use the physical address.
The EV5 Icache is virtually tagged, but the Dcache is physically
tagged, as is the Scache.
r~
^ permalink raw reply [flat|nested] 23+ messages in thread
* Alpha 21264.
@ 1999-01-13 14:10 Andy Almond
1999-01-13 16:36 ` Jeff Sturm
0 siblings, 1 reply; 23+ messages in thread
From: Andy Almond @ 1999-01-13 14:10 UTC (permalink / raw)
To: 'axp-list@redhat.com'
Three questions relating to the 21264 CPU and 264DP motherboard.
(a) I haven't used a dual processor before, so how much performance can you expect over a single CPU machine when working on a single job using an SMP linux kernel. Can you configure the system to use both CPUs for an ordinary job, or does that require a special compilation option/re-coding?
(b) Are DEC fortran/C ev6 compilers going to be available under linux? or is DEC UNIX or NT the only way to achieve this? I assume that the performance of gcc will be relatively poor compared with DECs C compiler, as is the case for the 21164 processor.
(c) Will code already compiled for ev56 CPUs run efficiently on an ev6 CPU?
Any comments appreciated.
Dr. Andrew Almond.
University of Manchester. UK.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Alpha 21264.
1999-01-13 14:10 Alpha 21264 Andy Almond
@ 1999-01-13 16:36 ` Jeff Sturm
1999-01-14 6:50 ` Richard Henderson
0 siblings, 1 reply; 23+ messages in thread
From: Jeff Sturm @ 1999-01-13 16:36 UTC (permalink / raw)
To: Andy Almond; +Cc: 'axp-list@redhat.com'
On Wed, 13 Jan 1999, Andy Almond wrote:
> Three questions relating to the 21264 CPU and 264DP motherboard.
>
> (a) I haven't used a dual processor before, so how much performance can you expect over a single CPU machine when working on a single job using an SMP linux kernel. Can you configure the system to use both CPUs for an ordinary job, or does that require a special compilation option/re-coding?
SMP works well for parallelized tasks, however for a single process
running a single thread, one CPU will be basically idle.
To take advantage of SMP, you can run multiple processes concurrently, or
design your process for multithreading (using pthreads or similar).
> (b) Are DEC fortran/C ev6 compilers going to be available under linux? or is DEC UNIX or NT the only way to achieve this? I assume that the performance of gcc will be relatively poor compared with DECs C compiler, as is the case for the 21164 processor.
GCC does reasonably well at integer code. Most FP-intensive code relies
heavily on math libraries, which are improving on Alpha/Linux thanks to
libffm. It's still not as fast as the DEC compiler, but it isn't dismal
either.
> (c) Will code already compiled for ev56 CPUs run efficiently on an ev6 CPU?
Good question. I have heard that the ev6 can do its own instruction
scheduling. If that's true, I'd speculate that the ev6 can partly
compensate for poor instruction scheduling in the compiler, and perhaps
improve ev56 object code too. Anyone know for sure?
Jeff
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Alpha 21264.
1999-01-13 16:36 ` Jeff Sturm
@ 1999-01-14 6:50 ` Richard Henderson
0 siblings, 0 replies; 23+ messages in thread
From: Richard Henderson @ 1999-01-14 6:50 UTC (permalink / raw)
To: axp-list, Andy Almond
On Wed, Jan 13, 1999 at 11:36:29AM -0500, Jeff Sturm wrote:
> > (c) Will code already compiled for ev56 CPUs run efficiently on an ev6 CPU?
>
> Good question. I have heard that the ev6 can do its own instruction
> scheduling. If that's true...
It is. I expect ev56 binaries to run quite well on ev6. Recompiling
will still help; as I don't have access to one, I can't tell you how
much though.
> ... I'd speculate that the ev6 can partly compensate for poor
> instruction scheduling in the compiler ...
Just a data point -- gcc's alpha instruction scheduling is pretty
fair these days. Register allocation needs work though. :-P
r~
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Alpha 21264.
1999-01-14 16:17 ` Alpha 21264 Christoph Dworzak
@ 1999-01-14 15:46 ` Greg Lindahl
1999-01-14 17:27 ` Richard Henderson
1 sibling, 0 replies; 23+ messages in thread
From: Greg Lindahl @ 1999-01-14 15:46 UTC (permalink / raw)
To: axp-list
> Instruction scheduling: It does a very good job.
If anyone wants to really work on this, get "fftw" and note that egcs
1.1 gets less than 1/2 the performance of Digital Fortran on this
particular code. I don't think 1.1.1 fixes this. But I'm glad to hear
that it is getting better in general...
> About Optimizations: I use
> "-O1 -fschedule-insns2 -fexpensive-optimizations"
> This generates Code which is about 30% faster than
> any higher Optimization-Levels. Why could this be?
> What does -O2 do which -O1 doesn't do?
Ooo, this sounds interesting.
-- g
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Alpha 21264.
[not found] ` <rth@twiddle.net>
1999-01-12 16:59 ` rpcc Christoph Dworzak
@ 1999-01-14 16:17 ` Christoph Dworzak
1999-01-14 15:46 ` Greg Lindahl
1999-01-14 17:27 ` Richard Henderson
1999-10-24 15:04 ` patch_v2: (on Alpha) emulating missing instructions Christoph Dworzak
2 siblings, 2 replies; 23+ messages in thread
From: Christoph Dworzak @ 1999-01-14 16:17 UTC (permalink / raw)
To: axp-list
Hi
On Jan 13 Richard Henderson (rth@twiddle.net) wrote:
> Just a data point -- gcc's alpha instruction scheduling is pretty
> fair these days. Register allocation needs work though. :-P
I second this (trying to squeeze some more
cycles out of egcs1.1.1-generated code...)
Register allocation: Does egcs ever use $11-$15?
In my code it badly needs more registers, but it
doesn't use them.
Instruction scheduling: It does a very good job.
I noticed just one case which could be improved.
From this C-snippet:
static void s11 (
unsigned long a1, unsigned long a2,
unsigned long a3, unsigned long a4,
unsigned long a5, unsigned long a6) {
a1 ^= t[31];
a2 ^= t[ 0];
a3 ^= t[ 1];
a4 ^= t[ 2];
a5 ^= t[ 3];
a6 ^= t[ 4];
[..]
it generated this (actually it used $1 as
the index-register, but I freed that and use
$30):
ldq $3,0($30)
ldq $2,248($30)
xor $17,$3,$17
xor $16,$2,$16
ldq $3,16($30)
ldq $2,8($30)
xor $19,$3,$19
xor $18,$2,$18
ldq $3,32($30)
ldq $2,24($30)
xor $21,$3,$21
xor $20,$2,$20
Reordering helps here:
ldq $3,0($30)
ldq $2,248($30)
ldq $4,16($30)
ldq $5,8($30)
xor $17,$3,$17
xor $16,$2,$16
ldq $6,32($30)
ldq $7,24($30)
xor $19,$4,$19
xor $18,$5,$18
xor $21,$6,$21
xor $20,$7,$20
From 9 down to 6 Cycles :)
About Optimizations: I use
"-O1 -fschedule-insns2 -fexpensive-optimizations"
This generates Code which is about 30% faster than
any higher Optimization-Levels. Why could this be?
What does -O2 do which -O1 doesn't do?
Bye
dworz
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Alpha 21264.
1999-01-14 16:17 ` Alpha 21264 Christoph Dworzak
1999-01-14 15:46 ` Greg Lindahl
@ 1999-01-14 17:27 ` Richard Henderson
1 sibling, 0 replies; 23+ messages in thread
From: Richard Henderson @ 1999-01-14 17:27 UTC (permalink / raw)
To: axp-list
On Thu, Jan 14, 1999 at 04:17:00PM +0000, Christoph Dworzak wrote:
> Register allocation: Does egcs ever use $11-$15?
> In my code it badly needs more registers, but it
> doesn't use them.
Sure it uses them. Apparently it doesn't think it needs them,
for whatever reason.
> >From this C-snippet:
>
> static void s11 (
> unsigned long a1, unsigned long a2,
> unsigned long a3, unsigned long a4,
> unsigned long a5, unsigned long a6) {
Gimme a whole test case and I'll look at it.
> About Optimizations: I use
> "-O1 -fschedule-insns2 -fexpensive-optimizations"
> This generates Code which is about 30% faster than
> any higher Optimization-Levels. Why could this be?
> What does -O2 do which -O1 doesn't do?
That combination is the same as "-O2 -fno-schedule-insns".
r~
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: patch_v2: (on Alpha) emulating missing instructions
@ 1999-10-18 14:46 Robert Harley
1999-10-18 15:31 ` Phil Carmody
1999-10-21 16:23 ` patch_v3: emulating missing instructions on Alpha Luke Deller
0 siblings, 2 replies; 23+ messages in thread
From: Robert Harley @ 1999-10-18 14:46 UTC (permalink / raw)
To: axp-list
BTW, here is a fast and short way of doing minuw():
------------------------------------------------------------------------------
#define CMPBGE(a, b, c) \
asm("cmpbge %1, %2, %0" : "=r" (c) : "r" (a), "r" (b))
#define ZAP(a, b, c) \
asm("zap %1, %2, %0" : "=r" (c) : "r" (a), "r" (b))
#define ZAPNOT(a, b, c) \
asm("zapnot %1, %2, %0" : "=r" (c) : "r" (a), "r" (b))
static u64 minuw(u64 x, u64 y) {
u64 eq, ge1, ge2;
CMPBGE(x, y, ge1);
CMPBGE(0, x ^ y, eq);
ge2 = (ge1 & ~eq | eq & ge1<<1) & 0xAA;
ge2 |= ge2>>1;
ZAP(x, ge2, x);
ZAPNOT(y, ge2, y);
return x | y;
} /* end function minuw */
------------------------------------------------------------------------------
The output from gcc 2.95 looks like:
------------------------------------------------------------------------------
minuw:
cmpbge $16, $17, $1
xor $16,$17,$3
mov $31,$2
cmpbge $2, $3, $2
addq $1,$1,$4
bic $1,$2,$1
and $2,$4,$2
bis $1,$2,$1
and $1,170,$1
srl $1,1,$2
bis $1,$2,$1
zapnot $17, $1, $17
zap $16, $1, $16
bis $16,$17,$0
ret $31,($26),1
.end minuw
------------------------------------------------------------------------------
This bit:
mov $31,$2
cmpbge $2, $3, $2
would be better as:
cmpbge $31, $3, $2
Bye,
Rob.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: patch_v2: (on Alpha) emulating missing instructions
1999-10-18 14:46 patch_v2: (on Alpha) emulating missing instructions Robert Harley
@ 1999-10-18 15:31 ` Phil Carmody
1999-10-23 20:39 ` Richard Henderson
1999-10-21 16:23 ` patch_v3: emulating missing instructions on Alpha Luke Deller
1 sibling, 1 reply; 23+ messages in thread
From: Phil Carmody @ 1999-10-18 15:31 UTC (permalink / raw)
To: axp-list
On Mon, 18 Oct 1999, EXT Robert Harley wrote:
> ge2 = (ge1 & ~eq | eq & ge1<<1) & 0xAA;
For the C coders out there, an expression of the form
D = (A & M) | (B & ~M);
can be turned into
D = A ^ ((A ^ B) & M);
i.e. change (^) the bits which are different (A^B) and within (&) the mask
Now it appears that the alpha can do (B&~M) as one instruction, and
there's no need to create a temporary ~M, so this isn't a win for us.
However, as it is a win on other architectures, and isn't a loss for
us I'd thought I'd share it.
Phil
--
Phil Carmody
Not speaking for or on behalf of Nokia Telecommunications
sequal : second part of a dilogy which is identical to the first part.
^ permalink raw reply [flat|nested] 23+ messages in thread
* patch_v3: emulating missing instructions on Alpha
1999-10-18 14:46 patch_v2: (on Alpha) emulating missing instructions Robert Harley
1999-10-18 15:31 ` Phil Carmody
@ 1999-10-21 16:23 ` Luke Deller
1999-10-23 20:55 ` Richard Henderson
1 sibling, 1 reply; 23+ messages in thread
From: Luke Deller @ 1999-10-21 16:23 UTC (permalink / raw)
To: axp-list; +Cc: Daniel Paul Potts
[-- Attachment #1: Type: TEXT/PLAIN, Size: 2861 bytes --]
Thanks Robert for your optimisations and bugspotting. I've incorporated them
into our emulation code. Also I have completed the emulation of the
multimedia instructions (not just what we needed to run Civilisation CTP) by
adding emulation for:
- "pixel error"(perr)
- word/long pack to byte (pkwb,pklb) and unpack (unpkbw,unpkbl)
I've attached the new patch to this email so that some of you guys can check
it out. Is this sort of code useful to other people? Do you think it's
worth adding this to the mainstream Linux distribution?
Again, this is a patch for kernel v2.2.11 because Loki say that v2.2.12 has
problems which break Civilisation CTP. Our purpose in writing this patch
was to get CivCTP to run. It doesn't change many files though, so it will
probably work with other kernel versions.
- Luke & Daniel.
On Mon, 18 Oct 1999, Robert Harley wrote:
> BTW, here is a fast and short way of doing minuw():
>
> ------------------------------------------------------------------------------
> #define CMPBGE(a, b, c) \
> asm("cmpbge %1, %2, %0" : "=r" (c) : "r" (a), "r" (b))
> #define ZAP(a, b, c) \
> asm("zap %1, %2, %0" : "=r" (c) : "r" (a), "r" (b))
> #define ZAPNOT(a, b, c) \
> asm("zapnot %1, %2, %0" : "=r" (c) : "r" (a), "r" (b))
>
> static u64 minuw(u64 x, u64 y) {
> u64 eq, ge1, ge2;
>
> CMPBGE(x, y, ge1);
> CMPBGE(0, x ^ y, eq);
>
> ge2 = (ge1 & ~eq | eq & ge1<<1) & 0xAA;
> ge2 |= ge2>>1;
>
> ZAP(x, ge2, x);
> ZAPNOT(y, ge2, y);
>
> return x | y;
> } /* end function minuw */
> ------------------------------------------------------------------------------
>
>
> The output from gcc 2.95 looks like:
>
> ------------------------------------------------------------------------------
> minuw:
> cmpbge $16, $17, $1
> xor $16,$17,$3
> mov $31,$2
> cmpbge $2, $3, $2
> addq $1,$1,$4
> bic $1,$2,$1
> and $2,$4,$2
> bis $1,$2,$1
> and $1,170,$1
> srl $1,1,$2
> bis $1,$2,$1
> zapnot $17, $1, $17
> zap $16, $1, $16
> bis $16,$17,$0
> ret $31,($26),1
> .end minuw
> ------------------------------------------------------------------------------
>
>
> This bit:
>
> mov $31,$2
> cmpbge $2, $3, $2
>
> would be better as:
>
> cmpbge $31, $3, $2
>
>
> Bye,
> Rob.
--------------------------------------------------------------------------
Luke Deller luked@cse.unsw.edu.au
_--_|\ Computer Engineering student
/ \ School of Computer Science and Engineering ? ? ? ?
\_.--._* The University of New South Wales ~~^^~
v Sydney, NSW 2052 AUSTRALIA o o
-------------------------------------------------------ooO--(_)--Ooo------
[-- Attachment #2: linux-alpha-emu-v3-for2_2_11.patch --]
[-- Type: TEXT/PLAIN, Size: 22931 bytes --]
diff -u --recursive --new-file v2.2.11/linux/Documentation/Configure.help linux/Documentation/Configure.help
--- v2.2.11/linux/Documentation/Configure.help Tue Aug 10 05:04:57 1999
+++ linux/Documentation/Configure.help Thu Oct 21 17:58:27 1999
@@ -11588,8 +11588,22 @@
Everyone using these boards should say Y here.
See "linux/Documentation/cpqarray.txt" for the current list of
boards supported by this driver, and for further information
- on the use of this driver.
-
+ on the use of this driver.
+
+Emulation of some extended alpha instructions
+CONFIG_ALPHA_EXTINSNS
+ This emulates some instructions which are not implemented in hardware
+ on some alpha CPU's. Emulation is provided for byte/word load/store
+ instructions (in the BWX instruction set extension) and the multimedia
+ extension instructions. If you say Y here then this emulation code will
+ be included in your kernel. Any of these instructions which your
+ hardware supports will not be emulated even if you have included the
+ emulation code in your kernel. If unsure, say N.
+
+ Here is the list of emulated instructions:
+ maxuw, maxsw, minuw, minsw, maxub, maxsb, minsb, minub,
+ sexb, sexw, perr, pklb, pkwb, unpkbl, unpkbw, stb, stw, ldbu, ldwu.
+
#
# A couple of things I keep forgetting:
# capitalize: AppleTalk, Ethernet, DOS, DMA, FAT, FTP, Internet,
diff -u --recursive --new-file v2.2.11/linux/arch/alpha/config.in linux/arch/alpha/config.in
--- v2.2.11/linux/arch/alpha/config.in Sun May 23 06:41:37 1999
+++ linux/arch/alpha/config.in Fri Oct 22 02:18:51 1999
@@ -280,6 +280,7 @@
#bool 'Debug kmalloc/kfree' CONFIG_DEBUG_MALLOC
if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
tristate 'Kernel FP software completion' CONFIG_MATHEMU
+ bool 'Emulation of some extended instructions' CONFIG_ALPHA_EXTINSNS
else
define_bool CONFIG_MATHEMU y
fi
diff -u --recursive --new-file v2.2.11/linux/arch/alpha/defconfig linux/arch/alpha/defconfig
--- v2.2.11/linux/arch/alpha/defconfig Sun Jun 13 04:52:51 1999
+++ linux/arch/alpha/defconfig Tue Oct 19 01:15:28 1999
@@ -330,4 +330,5 @@
# Kernel hacking
#
CONFIG_MATHEMU=y
+# CONFIG_ALPHA_EXTINSNS is not set
# CONFIG_MAGIC_SYSRQ is not set
diff -u --recursive --new-file v2.2.11/linux/arch/alpha/kernel/entry.S linux/arch/alpha/kernel/entry.S
--- v2.2.11/linux/arch/alpha/kernel/entry.S Tue Aug 10 05:04:57 1999
+++ linux/arch/alpha/kernel/entry.S Fri Oct 22 01:43:03 1999
@@ -39,6 +39,13 @@
#define PF_PTRACED 0x00000010
/*
+ * This is used to tell if a memory address is in user land.
+ * This must be consistent with USER_DS in include/asm-alpha/uaccess.h
+ * and TASK_SIZE in include/asm-alpha/processor.h
+ */
+#define LOG2_TASKSIZE 42
+
+/*
* This defines the normal kernel pt-regs layout.
*
* regs 9-15 preserved by C code
@@ -173,10 +180,1038 @@
jsr $31,do_entArith
.end entArith
+#ifdef CONFIG_ALPHA_EXTINSNS
+/* emulation of some extended alpha instructions */
+
+/* This emulation code doesn't handle segfaults as nicely as it should ..
+ * it just faults in kernel mode (resulting in the user task being killed)
+ * rather than pretending that the fault happened in userland (which should
+ * result in a SIGSEGV being sent to the user task).
+ *
+ * The emulation code ensures that the user doesn't access kernel space by
+ * checking that the high bits of the load/store virtual address are zero.
+ */
+
+.align 3
+.ent get_user_sp
+/* gets the value of the user's stack pointer into $3 */
+get_user_sp:
+ subq $30,6*8,$30
+ stq $0,0($30)
+ stq $1,8($30)
+ stq $16,16($30)
+ mov $25,$3
+ stq $22,24($30)
+ stq $23,32($30)
+ stq $24,40($30)
+ call_pal PAL_rdusp
+ ldq $24,40($30)
+ mov $3,$25
+ ldq $23,32($30)
+ ldq $22,24($30)
+ mov $0,$3
+ ldq $16,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,6*8,$30
+ ret $31,($5)
+.end get_user_sp
+
+.align 3
+.ent put_user_sp
+/* puts the value from $3 into the user's stack pointer */
+put_user_sp:
+ subq $30,5*8,$30
+ stq $16,0($30)
+ stq $22,8($30)
+ stq $23,16($30)
+ mov $3,$16
+ stq $24,24($30)
+ mov $1,$3
+ stq $25,32($30)
+ call_pal PAL_wrusp
+ ldq $25,32($30)
+ ldq $24,24($30)
+ mov $3,$1
+ ldq $23,16($30)
+ ldq $22,8($30)
+ ldq $16,0($30)
+ addq $30,5*8,$30
+ ret $31,($5)
+.end put_user_sp
+
+/* this macro trashes $5 & index, and returns user reg val in $3. */
+/* index should be a register containing a value from 0 to 31. */
+#define get_user_reg(index) \
+ br $3,1f ;\
+1: ;\
+ s8addq index,$3,index ;\
+ lda $5,get_ureg0-1b($31) ;\
+ addq index,$5,index ;\
+ jsr $5,(index),get_ureg16
+
+/* this macro takes new user reg val in $3, and trashes $3,$5 & index. */
+/* index should be a register containing a value from 0 to 31. */
+#define put_user_reg(index) \
+ br $5,1f ;\
+1: ;\
+ s8addq index,$5,index ;\
+ lda $5,put_ureg0-1b($31) ;\
+ addq index,$5,index ;\
+ jsr $5,(index),put_ureg16
+
+/* a code table .. make sure each entry is exactly 2 instructions. */
+/* used by get_user_reg macro. */
+.align 3
+.ent get_ureg_table
+get_ureg0:
+ ldq $3,8*0($30)
+ ret $31,($5)
+get_ureg1:
+ ldq $3,8*1($30)
+ ret $31,($5)
+get_ureg2:
+ ldq $3,8*2($30)
+ ret $31,($5)
+get_ureg3:
+ ldq $3,8*3($30)
+ ret $31,($5)
+get_ureg4:
+ ldq $3,8*4($30)
+ ret $31,($5)
+get_ureg5:
+ ldq $3,8*5($30)
+ ret $31,($5)
+get_ureg6:
+ mov $6,$3
+ ret $31,($5)
+get_ureg7:
+ mov $7,$3
+ ret $31,($5)
+get_ureg8:
+ mov $8,$3
+ ret $31,($5)
+get_ureg9:
+ mov $9,$3
+ ret $31,($5)
+get_ureg10:
+ mov $10,$3
+ ret $31,($5)
+get_ureg11:
+ mov $11,$3
+ ret $31,($5)
+get_ureg12:
+ mov $12,$3
+ ret $31,($5)
+get_ureg13:
+ mov $13,$3
+ ret $31,($5)
+get_ureg14:
+ mov $14,$3
+ ret $31,($5)
+get_ureg15:
+ mov $15,$3
+ ret $31,($5)
+get_ureg16:
+ ldq $3,8*10($30)
+ ret $31,($5)
+get_ureg17:
+ ldq $3,8*11($30)
+ ret $31,($5)
+get_ureg18:
+ ldq $3,8*12($30)
+ ret $31,($5)
+get_ureg19:
+ mov $19,$3
+ ret $31,($5)
+get_ureg20:
+ mov $20,$3
+ ret $31,($5)
+get_ureg21:
+ mov $21,$3
+ ret $31,($5)
+get_ureg22:
+ mov $22,$3
+ ret $31,($5)
+get_ureg23:
+ mov $23,$3
+ ret $31,($5)
+get_ureg24:
+ mov $24,$3
+ ret $31,($5)
+get_ureg25:
+ mov $25,$3
+ ret $31,($5)
+get_ureg26:
+ mov $26,$3
+ ret $31,($5)
+get_ureg27:
+ mov $27,$3
+ ret $31,($5)
+get_ureg28:
+ mov $28,$3
+ ret $31,($5)
+get_ureg29:
+ ldq $3,9*8($30)
+ ret $31,($5)
+get_ureg30:
+ br $31,get_user_sp
+ ret $31,($5)
+get_ureg31:
+ mov $31,$3
+ ret $31,($5)
+.end get_ureg_table
+
+/* another code table .. make sure each entry is exactly 2 instructions. */
+/* used by put_user_reg macro. */
+.align 3
+.ent put_ureg_table
+put_ureg0:
+ stq $3,8*0($30)
+ ret $31,($5)
+put_ureg1:
+ stq $3,8*1($30)
+ ret $31,($5)
+put_ureg2:
+ stq $3,8*2($30)
+ ret $31,($5)
+put_ureg3:
+ stq $3,8*3($30)
+ ret $31,($5)
+put_ureg4:
+ stq $3,8*4($30)
+ ret $31,($5)
+put_ureg5:
+ stq $3,8*5($30)
+ ret $31,($5)
+put_ureg6:
+ mov $3,$6
+ ret $31,($5)
+put_ureg7:
+ mov $3,$7
+ ret $31,($5)
+put_ureg8:
+ mov $3,$8
+ ret $31,($5)
+put_ureg9:
+ mov $3,$9
+ ret $31,($5)
+put_ureg10:
+ mov $3,$10
+ ret $31,($5)
+put_ureg11:
+ mov $3,$11
+ ret $31,($5)
+put_ureg12:
+ mov $3,$12
+ ret $31,($5)
+put_ureg13:
+ mov $3,$13
+ ret $31,($5)
+put_ureg14:
+ mov $3,$14
+ ret $31,($5)
+put_ureg15:
+ mov $3,$15
+ ret $31,($5)
+put_ureg16:
+ stq $3,8*10($30)
+ ret $31,($5)
+put_ureg17:
+ stq $3,8*11($30)
+ ret $31,($5)
+put_ureg18:
+ stq $3,8*12($30)
+ ret $31,($5)
+put_ureg19:
+ mov $3,$19
+ ret $31,($5)
+put_ureg20:
+ mov $3,$20
+ ret $31,($5)
+put_ureg21:
+ mov $3,$21
+ ret $31,($5)
+put_ureg22:
+ mov $3,$22
+ ret $31,($5)
+put_ureg23:
+ mov $3,$23
+ ret $31,($5)
+put_ureg24:
+ mov $3,$24
+ ret $31,($5)
+put_ureg25:
+ mov $3,$25
+ ret $31,($5)
+put_ureg26:
+ mov $3,$26
+ ret $31,($5)
+put_ureg27:
+ mov $3,$27
+ ret $31,($5)
+put_ureg28:
+ mov $3,$28
+ ret $31,($5)
+put_ureg29:
+ stq $3,9*8($30)
+ ret $31,($5)
+put_ureg30:
+ br $31,put_user_sp
+ ret $31,($5)
+put_ureg31:
+ ret $31,($5)
+.end put_ureg_table
+
+.align 3
+.globl emul_ldwu
+.ent emul_ldwu
+/* emulating a "load word unsigned" instruction of the form:
+ * ldwu $ra,displacement($rb)
+ */
+emul_ldwu:
+ stq $3,24($30)
+ stq $4,32($30)
+ stq $5,40($30)
+
+ srl $0,21,$1
+ srl $0,16,$2
+ and $1,0x1f,$1
+ sll $0,48,$0
+ and $2,0x1f,$2
+ sra $0,48,$0 /* $0 = displacement */
+ get_user_reg($2) /* $3 = $rb */
+ addq $0,$3,$0
+ srl $0,LOG2_TASKSIZE,$5 /* if addr is not in userland, */
+ cmovne $5,$31,$0 /* then force a segfault by putting addr=0 */
+ ldq_u $3,0($0)
+ ldq_u $5,1($0)
+ extwl $3,$0,$3
+ extwh $5,$0,$5
+ or $3,$5,$3
+ put_user_reg($1) /* $ra = loaded val */
+
+ ldq $5,40($30)
+ ldq $4,32($30)
+ ldq $3,24($30)
+ ldq $2,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,7*8,$30
+ call_pal PAL_rti
+.end emul_ldwu
+
+.align 3
+.globl emul_stw
+.ent emul_stw
+emul_stw:
+/* emulating a "store word" instruction of the form:
+ * stw $ra,displacement($rb)
+ */
+ stq $3,24($30)
+ stq $4,32($30)
+ stq $5,40($30)
+
+ srl $0,21,$1
+ srl $0,16,$2
+ and $1,0x1f,$1
+ sll $0,48,$0
+ and $2,0x1f,$2
+ sra $0,48,$0 /* $0 = displacement */
+ get_user_reg($1)
+ mov $3,$1 /* $1 = $ra val */
+ get_user_reg($2) /* $3 = $rb val */
+ addq $0,$3,$0
+ srl $0,LOG2_TASKSIZE,$5 /* if addr is not in userland, */
+ cmovne $5,$31,$0 /* then force a segfault by putting addr=0 */
+ ldq_u $3,1($0)
+ ldq_u $2,0($0)
+ inswh $1,$0,$5
+ inswl $1,$0,$4
+ mskwh $3,$0,$3
+ mskwl $2,$0,$2
+ or $3,$5,$3
+ or $2,$4,$2
+ stq_u $3,1($0)
+ stq_u $2,0($0)
+
+ ldq $5,40($30)
+ ldq $4,32($30)
+ ldq $3,24($30)
+ ldq $2,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,7*8,$30
+ call_pal PAL_rti
+.end emul_stw
+
+.align 3
+.globl emul_ldbu
+.ent emul_ldbu
+/* emulating a "load byte unsigned" instruction of the form:
+ * ldbu $ra,displacement($rb)
+ */
+emul_ldbu:
+ stq $3,24($30)
+ stq $4,32($30)
+ stq $5,40($30)
+
+ srl $0,21,$1
+ srl $0,16,$2
+ and $1,0x1f,$1
+ sll $0,48,$0
+ and $2,0x1f,$2
+ sra $0,48,$0 /* $0 = displacement */
+ get_user_reg($2) /* $3 = $ra val */
+ addq $0,$3,$0
+ srl $0,LOG2_TASKSIZE,$5 /* if addr is not in userland, */
+ cmovne $5,$31,$0 /* then force a segfault by putting addr=0 */
+ ldq_u $3,0($0)
+ extbl $3,$0,$3
+ put_user_reg($1) /* $rb := loaded val */
+
+ ldq $5,40($30)
+ ldq $4,32($30)
+ ldq $3,24($30)
+ ldq $2,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,7*8,$30
+ call_pal PAL_rti
+.end emul_ldbu
+
+.align 3
+.globl emul_stb
+.ent emul_stb
+emul_stb:
+/* emulating a "store byte" instruction of the form:
+ * stb $ra,displacement($rb)
+ */
+ stq $3,24($30)
+ stq $4,32($30)
+ stq $5,40($30)
+
+ srl $0,21,$1
+ srl $0,16,$2
+ and $1,0x1f,$1
+ sll $0,48,$0
+ and $2,0x1f,$2
+ sra $0,48,$0 /* $0 = displacement */
+ get_user_reg($1)
+ mov $3,$1 /* $1 = $ra val */
+ get_user_reg($2) /* $3 = $rb val */
+ addq $0,$3,$0
+ srl $0,LOG2_TASKSIZE,$5 /* if addr is not in userland, */
+ cmovne $5,$31,$0 /* then force a segfault by putting addr=0 */
+ ldq_u $2,0($0)
+ insbl $1,$0,$3
+ mskbl $2,$0,$2
+
+ ldq $5,40($30)
+ or $2,$3,$2
+
+ ldq $3,24($30)
+ stq_u $2,0($0)
+
+ ldq $2,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,7*8,$30
+ call_pal PAL_rti
+.end emul_stb
+
+.align 3
+.globl emul_minsw_4
+.ent emul_minsw_4
+/* emulating a "vector signed word minimum" instruction of the form:
+ * minsw4 $ra,$rb,$rc
+ * or
+ * minsw4 $ra,immediate8,$rc
+ *
+ * (called by emul_mmx below)
+ */
+emul_minsw_4:
+ stq $6,48($30)
+
+ not $31,$1
+ zap $1,0x33,$1
+ srl $1,1,$5
+ xor $1,$5,$1 /* $1 = 0x8000800080008000 */
+ xor $1,$3,$6
+ xor $1,$2,$5
+
+ cmpbge $6,$5,$1
+ xor $6,$5,$5
+ cmpbge $31,$5,$4
+ addq $1,$1,$6
+ bic $1,$4,$1
+ and $4,$6,$4
+ bis $1,$4,$1
+ and $1,0xaa,$1
+ srl $1,1,$4
+ bis $1,$4,$1
+ zapnot $2,$1,$2
+ zap $3,$1,$3
+ bis $3,$2,$3
+
+ ldq $6,48($30)
+
+ put_user_reg($0)
+
+ ldq $5,40($30)
+ ldq $4,32($30)
+ ldq $3,24($30)
+ ldq $2,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,7*8,$30
+ call_pal PAL_rti
+.end emul_minsw_4
+
+.align 3
+.globl emul_minuw_4
+.ent emul_minuw_4
+/* emulating a "vector unsigned word maximum" instruction of the form:
+ * minuw4 $ra,$rb,$rc
+ * or
+ * minuw4 $ra,immediate8,$rc
+ *
+ * (called by emul_mmx below)
+ */
+emul_minuw_4:
+ stq $6,48($30)
+
+ cmpbge $3,$2,$1
+ xor $3,$2,$5
+ cmpbge $31,$5,$4
+ addq $1,$1,$6
+ bic $1,$4,$1
+ and $4,$6,$4
+ bis $1,$4,$1
+ and $1,0xaa,$1
+ srl $1,1,$4
+ bis $1,$4,$1
+ zapnot $2,$1,$2
+ zap $3,$1,$3
+ bis $3,$2,$3
+
+ ldq $6,48($30)
+
+ put_user_reg($0)
+
+ ldq $5,40($30)
+ ldq $4,32($30)
+ ldq $3,24($30)
+ ldq $2,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,7*8,$30
+ call_pal PAL_rti
+.end emul_minuw_4
+
+.align 3
+.globl emul_maxsw_4
+.ent emul_maxsw_4
+/* emulating a "vector signed word maximum" instruction of the form:
+ * maxsw4 $ra,$rb,$rc
+ * or
+ * maxsw4 $ra,immediate8,$rc
+ *
+ * (called by emul_mmx below)
+ */
+emul_maxsw_4:
+ stq $6,48($30)
+
+ not $31,$1
+ zap $1,0x33,$1
+ srl $1,1,$5
+ xor $1,$5,$1 /* $1 = 0x8000800080008000 */
+ xor $1,$3,$6
+ xor $1,$2,$5
+
+ cmpbge $6,$5,$1
+ xor $6,$5,$5
+ cmpbge $31,$5,$4
+ addq $1,$1,$6
+ bic $1,$4,$1
+ and $4,$6,$4
+ bis $1,$4,$1
+ and $1,0xaa,$1
+ srl $1,1,$4
+ bis $1,$4,$1
+ zap $2,$1,$2
+ zapnot $3,$1,$3
+ bis $3,$2,$3
+
+ ldq $6,48($30)
+
+ put_user_reg($0)
+
+ ldq $5,40($30)
+ ldq $4,32($30)
+ ldq $3,24($30)
+ ldq $2,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,7*8,$30
+ call_pal PAL_rti
+.end emul_maxsw_4
+
+.align 3
+.globl emul_maxuw_4
+.ent emul_maxuw_4
+/* emulating a "vector unsigned word maximum" instruction of the form:
+ * maxuw4 $ra,$rb,$rc
+ * or
+ * maxuw4 $ra,immediate8,$rc
+ *
+ * (called by emul_mmx below)
+ */
+emul_maxuw_4:
+ stq $6,48($30)
+
+ cmpbge $3,$2,$1
+ xor $3,$2,$5
+ cmpbge $31,$5,$4
+ addq $1,$1,$6
+ bic $1,$4,$1
+ and $4,$6,$4
+ bis $1,$4,$1
+ and $1,0xaa,$1
+ srl $1,1,$4
+ bis $1,$4,$1
+ zap $2,$1,$2
+ zapnot $3,$1,$3
+ bis $3,$2,$3
+
+ ldq $6,48($30)
+
+ put_user_reg($0)
+
+ ldq $5,40($30)
+ ldq $4,32($30)
+ ldq $3,24($30)
+ ldq $2,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,7*8,$30
+ call_pal PAL_rti
+.end emul_maxuw_4
+
+.align 3
+.globl emul_maxub_8
+.ent emul_maxub_8
+/* emulating a "vector unsigned byte maximum" instruction of the form:
+ * maxub8 $ra,$rb,$rc
+ * or
+ * maxub8 $ra,immediate8,$rc
+ */
+emul_maxub_8:
+ cmpbge $2,$3,$1
+ zap $3,$1,$3
+ zapnot $2,$1,$2
+ or $3,$2,$3
+ put_user_reg($0)
+
+ ldq $5,40($30)
+ ldq $4,32($30)
+ ldq $3,24($30)
+ ldq $2,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,7*8,$30
+ call_pal PAL_rti
+.end emul_maxub_8
+
+.align 3
+.globl emul_maxsb_8
+.ent emul_maxsb_8
+/* emulating a "vector signed byte maximum" instruction of the form:
+ * maxsb8 $ra,$rb,$rc
+ * or
+ * maxsb8 $ra,immediate8,$rc
+ *
+ * (called by emul_mmx below)
+ */
+emul_maxsb_8:
+ not $31,$1
+ zap $1,0x55,$1
+ srl $1,1,$5
+ xor $1,$5,$1 /* $1 = 0x8080808080808080 */
+ xor $3,$1,$5
+ xor $2,$1,$1
+
+ cmpbge $1,$5,$1
+ zap $3,$1,$3
+ zapnot $2,$1,$2
+ or $3,$2,$3
+ put_user_reg($0)
+
+ ldq $5,40($30)
+ ldq $4,32($30)
+ ldq $3,24($30)
+ ldq $2,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,7*8,$30
+ call_pal PAL_rti
+.end emul_maxsb_8
+
+.align 3
+.globl emul_minub_8
+.ent emul_minub_8
+/* emulating a "vector unsigned byte minimum" instruction of the form:
+ * minsb8 $ra,$rb,$rc
+ * or
+ * minsb8 $ra,immediate8,$rc
+ */
+emul_minub_8:
+ cmpbge $3,$2,$1
+ zap $3,$1,$3
+ zapnot $2,$1,$2
+ or $3,$2,$3
+ put_user_reg($0)
+
+ ldq $5,40($30)
+ ldq $4,32($30)
+ ldq $3,24($30)
+ ldq $2,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,7*8,$30
+ call_pal PAL_rti
+.end emul_minub_8
+
+.align 3
+.globl emul_minsb_8
+.ent emul_minsb_8
+/* emulating a "vector unsigned byte maximum" instruction of the form:
+ * maxsb8 $ra,$rb,$rc
+ * or
+ * maxsb8 $ra,immediate8,$rc
+ *
+ * (called by emul_mmx below)
+ */
+emul_minsb_8:
+ not $31,$1
+ zap $1,0x55,$1
+ srl $1,1,$5
+ xor $1,$5,$1 /* $1 = 0x8080808080808080 */
+ xor $3,$1,$5
+ xor $2,$1,$1
+
+ cmpbge $5,$1,$1
+ zap $3,$1,$3
+ zapnot $2,$1,$2
+ or $3,$2,$3
+ put_user_reg($0)
+
+ ldq $5,40($30)
+ ldq $4,32($30)
+ ldq $3,24($30)
+ ldq $2,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,7*8,$30
+ call_pal PAL_rti
+.end emul_minsb_8
+
+.align 3
+.globl emul_sexw
+.ent emul_sexw
+/* emulating a "word sign extend" instruction of the form:
+ * sexw $rb,$rc
+ * or
+ * sexw immediate8,$rc
+ *
+ * (called by emul_mmx below)
+ */
+emul_sexw:
+ sll $3,48,$3
+ and $0,0x1f,$1
+ sra $3,48,$3
+ put_user_reg($1)
+ ldq $5,40($30)
+ ldq $4,32($30)
+ ldq $3,24($30)
+ ldq $2,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,7*8,$30
+ call_pal PAL_rti
+.end emul_sexw
+
+.align 3
+.globl emul_sexb
+.ent emul_sexb
+/* emulating a "byte sign extend" instruction of the form:
+ * sexb $rb,$rc
+ * or
+ * sexb immediate8,$rc
+ *
+ * (called by emul_mmx below)
+ */
+emul_sexb:
+ sll $3,56,$3
+ and $0,0x1f,$1
+ sra $3,56,$3
+ put_user_reg($1)
+ ldq $5,40($30)
+ ldq $4,32($30)
+ ldq $3,24($30)
+ ldq $2,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,7*8,$30
+ call_pal PAL_rti
+.end emul_sexb
+
+.align 3
+.globl emul_perr
+.ent emul_perr
+/* emulating a "pixel error" instruction of the form:
+ * perr $ra,$rb,$rc
+ */
+emul_perr:
+ cmpbge $2,$3,$1
+ zap $3,$1,$4
+ zapnot $2,$1,$5
+ zap $2,$1,$2
+ zapnot $3,$1,$3
+ or $4,$5,$4 /* $4 = vector of max bytes */
+ or $2,$3,$3 /* $3 = vector of min bytes */
+ subq $4,$3,$3
+ put_user_reg($0)
+
+ ldq $5,40($30)
+ ldq $4,32($30)
+ ldq $3,24($30)
+ ldq $2,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,7*8,$30
+ call_pal PAL_rti
+.end emul_perr
+
+.align 3
+.globl emul_pklb
+.ent emul_pklb
+/* emulating a "pack longwords to bytes" instruction of the form:
+ * pklb $rb,$rc
+ */
+emul_pklb:
+ extbl $3,0x4,$4
+ extbl $3,0x0,$5
+ insbl $4,0x1,$4
+ and $0,0x1f,$1
+ or $4,$5,$3
+ put_user_reg($1)
+
+ ldq $5,40($30)
+ ldq $4,32($30)
+ ldq $3,24($30)
+ ldq $2,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,7*8,$30
+ call_pal PAL_rti
+.end emul_pklb
+
+.align 3
+.globl emul_pkwb
+.ent emul_pkwb
+/* emulating a "pack words to bytes" instruction of the form:
+ * pkwb $rb,$rc
+ */
+emul_pkwb:
+ extbl $3,0x6,$4
+ extbl $3,0x4,$5
+ insbl $4,0x3,$4
+ insbl $5,0x2,$5
+ extbl $3,0x2,$2
+ or $4,$5,$5
+ extbl $3,0x0,$3
+ insbl $2,0x1,$2
+ or $2,$3,$3
+ and $0,0x1f,$1
+ or $5,$3,$3
+ put_user_reg($1)
+
+ ldq $5,40($30)
+ ldq $4,32($30)
+ ldq $3,24($30)
+ ldq $2,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,7*8,$30
+ call_pal PAL_rti
+.end emul_pkwb
+
+.align 3
+.globl emul_unpkbl
+.ent emul_unpkbl
+/* emulating a "unpack bytes to longwords" instruction of the form:
+ * unpkbl $rb,$rc
+ */
+emul_unpkbl:
+ extbl $3,0x1,$4
+ extbl $3,0x0,$5
+ insbl $4,0x4,$4
+ and $0,0x1f,$1
+ or $4,$5,$3
+ put_user_reg($1)
+
+ ldq $5,40($30)
+ ldq $4,32($30)
+ ldq $3,24($30)
+ ldq $2,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,7*8,$30
+ call_pal PAL_rti
+.end emul_unpkbl
+
+.align 3
+.globl emul_unpkbw
+.ent emul_unpkbw
+/* emulating a "unpack bytes to words" instruction of the form:
+ * unpkbw $rb,$rc
+ */
+emul_unpkbw:
+ extbl $3,0x3,$4
+ extbl $3,0x2,$5
+ insbl $4,0x6,$4
+ insbl $5,0x4,$5
+ extbl $3,0x1,$2
+ or $4,$5,$5
+ extbl $3,0x0,$3
+ insbl $2,0x2,$2
+ or $2,$3,$3
+ and $0,0x1f,$1
+ or $5,$3,$3
+ put_user_reg($1)
+
+ ldq $5,40($30)
+ ldq $4,32($30)
+ ldq $3,24($30)
+ ldq $2,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,7*8,$30
+ call_pal PAL_rti
+.end emul_unpkbw
+
+.align 3
+.globl emul_mmx
+.ent emul_mmx
+/* Emulates multimedia support instructions and sign extend instructions.
+ * These instructions share a common form:
+ * <instr> $ra,$rb,$rc
+ * or
+ * <instr> $ra,immediate8,$rc
+ *
+ * (the sign extend instructions do not use $ra)
+ */
+emul_mmx:
+ stq $3,24($30)
+ stq $4,32($30)
+ stq $5,40($30)
+
+ srl $0,5,$4
+ srl $0,12,$2
+ and $4,0x3f,$4
+ blbs $2,21f
+ /* the second parameter comes from a register */
+ srl $0,16,$1
+ and $1,0x1f,$1
+ get_user_reg($1)
+21:
+ /* get the second parameter from an 8-bit immediate field (sign extd)*/
+ srl $0,13,$1
+ and $1,0xff,$1
+ cmovlbs $2,$1,$3 /* if needed, use imm field instead of $rb */
+ /* now: $0 = instruction
+ $3 = $rb val
+ $4 = operation function code */
+ cmpeq $4,0x1,$2
+ beq $4,emul_sexb
+ bne $2,emul_sexw
+ cmpeq $4,0x36,$1
+ cmpeq $4,0x37,$2
+ bne $1,emul_pkwb
+ bne $2,emul_pklb
+ cmpeq $4,0x34,$1
+ cmpeq $4,0x35,$2
+ bne $1,emul_unpkbw
+ bne $2,emul_unpkbl
+ srl $0,21,$1
+ mov $3,$2
+ and $1,0x1f,$1
+ get_user_reg($1)
+ cmpeq $4,0x3a,$1
+ cmpeq $4,0x38,$5
+ and $0,0x1f,$0
+ /* now: $0 = $rc register index
+ $2 = $rb val
+ $3 = $ra val
+ $4 = operation function code */
+ bne $1,emul_minub_8
+ bne $5,emul_minsb_8
+ cmpeq $4,0x3e,$1
+ cmpeq $4,0x3c,$5
+ bne $1,emul_maxsb_8
+ bne $5,emul_maxub_8
+ cmpeq $4,0x39,$1
+ cmpeq $4,0x3f,$5
+ bne $1,emul_minsw_4
+ bne $5,emul_maxsw_4
+ cmpeq $4,0x3b,$1
+ cmpeq $4,0x3d,$5
+ bne $1,emul_minuw_4
+ bne $5,emul_maxuw_4
+ cmpeq $4,0x31,$1
+ bne $1,emul_perr
+ ldq $5,40($30)
+ ldq $4,32($30)
+ ldq $3,24($30)
+ ldq $2,16($30)
+ ldq $1,8($30)
+ ldq $0,0($30)
+ addq $30,7*8,$30
+ br old_entIF
+.end emul_mmx
+
+#endif /* CONFIG_ALPHA_EXTINSNS */
+
.align 3
.globl entIF
.ent entIF
entIF:
+#ifdef CONFIG_ALPHA_EXTINSNS
+ subq $30,7*8,$30 /* 3 regs saved here, 3 or 4 more saved in fns */
+ stq $0,0($30)
+ ldq $0,8+7*8($30)
+ stq $1,8($30)
+ ldl $0,-4($0)
+ stq $2,16($30)
+ srl $0,26,$1
+ and $1,0x3f,$1
+ cmpeq $1,0x1c,$2
+ bne $2,emul_mmx
+ cmpeq $1,0x0a,$2
+ bne $2,emul_ldbu
+ cmpeq $1,0x0e,$2
+ bne $2,emul_stb
+ cmpeq $1,0x0c,$2
+ cmpeq $1,0x0d,$1
+ bne $2,emul_ldwu
+ bne $1,emul_stw
+ ldq $0,0($30)
+ ldq $1,8($30)
+ ldq $2,16($30)
+ addq $30,7*8,$30
+old_entIF:
+#endif /* CONFIG_ALPHA_EXTINSNS */
SAVE_ALL
lda $8,0x3fff
lda $26,ret_from_sys_call
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: patch_v2: (on Alpha) emulating missing instructions
1999-10-18 15:31 ` Phil Carmody
@ 1999-10-23 20:39 ` Richard Henderson
0 siblings, 0 replies; 23+ messages in thread
From: Richard Henderson @ 1999-10-23 20:39 UTC (permalink / raw)
To: axp-list
On Mon, Oct 18, 1999 at 04:31:25PM +0100, Phil Carmody wrote:
> D = (A & M) | (B & ~M);
> can be turned into
> D = A ^ ((A ^ B) & M);
I'll note that the former expression, given an andnot operation,
has 3 ops and a tree height of 2. The later expression has 3 ops
and a tree height of 3. I.e. the former expression takes better
advantage of instruction-level parallelism.
r~
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: patch_v3: emulating missing instructions on Alpha
1999-10-21 16:23 ` patch_v3: emulating missing instructions on Alpha Luke Deller
@ 1999-10-23 20:55 ` Richard Henderson
1999-10-24 0:28 ` Daniel Potts
1999-10-25 1:22 ` Luke Deller
0 siblings, 2 replies; 23+ messages in thread
From: Richard Henderson @ 1999-10-23 20:55 UTC (permalink / raw)
To: axp-list; +Cc: Daniel Paul Potts
On Fri, Oct 22, 1999 at 02:23:22AM +1000, Luke Deller wrote:
> + srl $0,LOG2_TASKSIZE,$5 /* if addr is not in userland, */
> + cmovne $5,$31,$0 /* then force a segfault by putting addr=0 */
> + ldq_u $3,0($0)
> + ldq_u $5,1($0)
This is not sufficient to be safe. Examine the extended
measures taken by the uaccess.h code.
I know you spent a lot of time writing this in assembly,
but I'd feel more comfortable if this were in C hanging
out with the existing opDEC code in do_entIF. There won't
be _that_ much of a speed hit doing things that way. You
get to resuse much of the entArith_User code.
DU has a defined interface through setsysinfo to turn this stuff
on and off -- use that and you don't have to conditionally
compile the code. If you don't have access to the appropriate
DU headers, I can dig them up at work later.
r~
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: patch_v3: emulating missing instructions on Alpha
1999-10-23 20:55 ` Richard Henderson
@ 1999-10-24 0:28 ` Daniel Potts
1999-10-25 1:22 ` Luke Deller
1 sibling, 0 replies; 23+ messages in thread
From: Daniel Potts @ 1999-10-24 0:28 UTC (permalink / raw)
To: Richard Henderson; +Cc: axp-list
On Sat, 23 Oct 1999, Richard Henderson wrote:
> On Fri, Oct 22, 1999 at 02:23:22AM +1000, Luke Deller wrote:
> > + srl $0,LOG2_TASKSIZE,$5 /* if addr is not in userland, */
> > + cmovne $5,$31,$0 /* then force a segfault by putting addr=0 */
> > + ldq_u $3,0($0)
> > + ldq_u $5,1($0)
>
> This is not sufficient to be safe. Examine the extended
> measures taken by the uaccess.h code.
ok
> I know you spent a lot of time writing this in assembly,
And fun.. we are meant to be completing theses.
> but I'd feel more comfortable if this were in C hanging
> out with the existing opDEC code in do_entIF. There won't
> be _that_ much of a speed hit doing things that way. You
> get to resuse much of the entArith_User code.
We did this originally, but there is a noticable speedup the way
we do it now. The main aim was to reduce the amount of loads and stores.
This is a better solution, but on something that has compiled byte
operations in, they are too frequent to go unnoticed speedwise.
> DU has a defined interface through setsysinfo to turn this stuff
> on and off -- use that and you don't have to conditionally
> compile the code. If you don't have access to the appropriate
> DU headers, I can dig them up at work later.
Thats cool.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: patch_v2: (on Alpha) emulating missing instructions
[not found] ` <rth@twiddle.net>
1999-01-12 16:59 ` rpcc Christoph Dworzak
1999-01-14 16:17 ` Alpha 21264 Christoph Dworzak
@ 1999-10-24 15:04 ` Christoph Dworzak
1999-10-25 9:47 ` Phil Carmody
2 siblings, 1 reply; 23+ messages in thread
From: Christoph Dworzak @ 1999-10-24 15:04 UTC (permalink / raw)
To: axp-list
Hi
On Oct 23 Richard Henderson (rth@twiddle.net) wrote:
> On Mon, Oct 18, 1999 at 04:31:25PM +0100, Phil Carmody wrote:
> > D = (A & M) | (B & ~M);
I used the same sequence twice to exchange bits between two
variables depending on a mask:
t = (A & M) | (B & ~M);
B = (B & M) | (A & ~M);
A = t;
> > can be turned into
> > D = A ^ ((A ^ B) & M);
>
> I'll note that the former expression, given an andnot operation,
> has 3 ops and a tree height of 2. The later expression has 3 ops
> and a tree height of 3. I.e. the former expression takes better
> advantage of instruction-level parallelism.
In my App the later is faster (4 ops instead of 6):
t = (A ^ B) & M;
A ^= t;
B ^= t;
Can it get any better?
Bye
dworz
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: patch_v3: emulating missing instructions on Alpha
1999-10-23 20:55 ` Richard Henderson
1999-10-24 0:28 ` Daniel Potts
@ 1999-10-25 1:22 ` Luke Deller
1999-10-28 23:34 ` Richard Henderson
1 sibling, 1 reply; 23+ messages in thread
From: Luke Deller @ 1999-10-25 1:22 UTC (permalink / raw)
To: axp-list; +Cc: Daniel Paul Potts
On Sat, 23 Oct 1999, Richard Henderson wrote:
> On Fri, Oct 22, 1999 at 02:23:22AM +1000, Luke Deller wrote:
> > + srl $0,LOG2_TASKSIZE,$5 /* if addr is not in userland, */
> > + cmovne $5,$31,$0 /* then force a segfault by putting addr=0 */
> > + ldq_u $3,0($0)
> > + ldq_u $5,1($0)
>
> This is not sufficient to be safe. Examine the extended
> measures taken by the uaccess.h code.
Actually I wrote this code after reading include/asm-alpha/uaccess.h ..
I must be missing something. Let me explain why I think this is safe, then
you can point out where I'm mistaken :)
First let me acknowledge that I need to put some entries in the __ex_table
section for a segfault here to be handled correctly as a user-level segfault
(resulting in a SIGSEGV being sent) rather than a kernel bug segfault
(resulting in the user process being killed). However this is not a
security hole; merely error handling that's too heavy handed (that I can
fix soon).
Now, the macro for reading from user memory in uaccess.h is:
#define get_user(x,ptr) \
__get_user_check((x),(ptr),sizeof(*(ptr)),get_fs())
and the macro __get_user_check does its security check by calling:
__access_ok((long)__gu_addr,size,segment)
which is defined as:
#define __access_ok(addr,size,segment) \
(((segment).seg & (addr | size | (addr+size))) == 0)
Now "segment" in this last line is obtained from the "get_fs()" macro
which according to comments at the top of uaccess.h should be equal
to USER_DS or KERNEL_DS:
#define KERNEL_DS ((mm_segment_t) { 0UL })
#define USER_DS ((mm_segment_t) { -0x40000000000UL })
By inspecting the code for __access_ok, I see that checking is only
performed if get_fs()==USER_DS. So the check performed for reading from
user space is:
(0xfffffc0000000000UL & (addr | size | (addr+size))) == 0
[ Strictly speaking I think the check should use (addr+size-1) rather than
(addr+size), but it's probably not worth the extra cycle ]
According to this check, userland addresses must have the most significant
22 bits equal to zero. For size==1 and size==2, I'll simplify the check
to:
(0xfffffc0000000000UL & addr) == 0
or equivalently: (addr >> 42) == 0
This is no problem for size==1; but for size==2 it allows the user to access
the byte at address 0x400000000000. However I believe that this is no
problem since the kernel seems to use only addresses from
0xfffffc0000000000 and above. Would you agree?
So can you see a hole in my understanding?
Thanks for your help,
- Luke
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: patch_v2: (on Alpha) emulating missing instructions
1999-10-24 15:04 ` patch_v2: (on Alpha) emulating missing instructions Christoph Dworzak
@ 1999-10-25 9:47 ` Phil Carmody
0 siblings, 0 replies; 23+ messages in thread
From: Phil Carmody @ 1999-10-25 9:47 UTC (permalink / raw)
To: axp-list
On Sun, 24 Oct 1999, EXT axp@amazing.ch (Christoph Dworzak) wrote:
> Hi
>
> On Oct 23 Richard Henderson (rth@twiddle.net) wrote:
> > On Mon, Oct 18, 1999 at 04:31:25PM +0100, Phil Carmody wrote:
> > > D = (A & M) | (B & ~M);
>
> I used the same sequence twice to exchange bits between two
> variables depending on a mask:
>
> t = (A & M) | (B & ~M);
> B = (B & M) | (A & ~M);
> A = t;
>
> > > can be turned into
> > > D = A ^ ((A ^ B) & M);
> >
> > I'll note that the former expression, given an andnot operation,
> > has 3 ops and a tree height of 2. The later expression has 3 ops
> > and a tree height of 3. I.e. the former expression takes better
> > advantage of instruction-level parallelism.
Accepted, yes. However, with registers coming out of your ears there
should be plenty of other things that can fill the gaps. (and OOOE
goes a long way to filling the gaps anyway).
I merely wanted people to have to tool in their toolkit, should it be
needed (as it was for Cristoph).
> In my App the later is faster (4 ops instead of 6):
>
> t = (A ^ B) & M;
> A ^= t;
> B ^= t;
>
> Can it get any better?
Yes, get a TI DSP processor (the MVP/MP will do) which can do 'insert bit
string' operations in a single processor cycle.
t=A
A=A with bits from B
B=B with bits from t
three ticks.
Phil
--
Phil Carmody
Not speaking for or on behalf of Nokia Telecommunications
Resistrance : Peaceful and passive resistance
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: patch_v3: emulating missing instructions on Alpha
1999-10-25 1:22 ` Luke Deller
@ 1999-10-28 23:34 ` Richard Henderson
0 siblings, 0 replies; 23+ messages in thread
From: Richard Henderson @ 1999-10-28 23:34 UTC (permalink / raw)
To: Luke Deller; +Cc: axp-list, Daniel Paul Potts
On Mon, Oct 25, 1999 at 11:22:03AM +1000, Luke Deller wrote:
> First let me acknowledge that I need to put some entries in the __ex_table
> section for a segfault here to be handled correctly as a user-level segfault
> (resulting in a SIGSEGV being sent) rather than a kernel bug segfault
This is mostly what I was referring to.
r~
^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~1999-10-28 23:34 UTC | newest]
Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-01-12 3:55 rpcc Christoph Dworzak
1999-01-12 3:20 ` rpcc Peter Petrakis
1999-01-12 4:59 ` rpcc Richard Henderson
[not found] ` <rth@twiddle.net>
1999-01-12 16:59 ` rpcc Christoph Dworzak
1999-01-12 19:27 ` rpcc Richard Henderson
1999-01-12 21:06 ` rpcc Wes Bauske
1999-01-13 2:16 ` rpcc Richard Henderson
1999-01-14 16:17 ` Alpha 21264 Christoph Dworzak
1999-01-14 15:46 ` Greg Lindahl
1999-01-14 17:27 ` Richard Henderson
1999-10-24 15:04 ` patch_v2: (on Alpha) emulating missing instructions Christoph Dworzak
1999-10-25 9:47 ` Phil Carmody
-- strict thread matches above, loose matches on Subject: below --
1999-01-13 14:10 Alpha 21264 Andy Almond
1999-01-13 16:36 ` Jeff Sturm
1999-01-14 6:50 ` Richard Henderson
1999-10-18 14:46 patch_v2: (on Alpha) emulating missing instructions Robert Harley
1999-10-18 15:31 ` Phil Carmody
1999-10-23 20:39 ` Richard Henderson
1999-10-21 16:23 ` patch_v3: emulating missing instructions on Alpha Luke Deller
1999-10-23 20:55 ` Richard Henderson
1999-10-24 0:28 ` Daniel Potts
1999-10-25 1:22 ` Luke Deller
1999-10-28 23:34 ` Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox