Skip to contentSkip to conversation

Re-implemented i586 asm AES (updated)

PATCH Andi Kleen 8 participants 9 messages Aug 6, 2004 – Aug 9, 2004 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

Andi Kleen

author
#2 lore raw
Quoted 4 lines · James Morris
Quoted 2 lines

Does it work on x86 CPUs without MMX?

Yes, Linus removed the MMX stuff.

You could use .altinstructions to patch a jump in at runtime based on CPU capabilities. Assuming MMX is really faster of course.

See arch/x86_64/lib/copy_page.S for an example.

-Andi

#3 lore raw
Quoted 2 lines · Andi Kleen

You could use .altinstructions to patch a jump in at runtime based on CPU capabilities. Assuming MMX is really faster of course.

Neat. The latter could be measured at boot.

- James

Signature · 2 lines
James Morris
<[email protected]>
#4 lore raw
Quoted 6 lines · James Morris
Quoted 2 lines · Andi Kleen

You could use .altinstructions to patch a jump in at runtime based on CPU capabilities. Assuming MMX is really faster of course.

Neat. The latter could be measured at boot.

On first use, please. Don't slow the boot down.

Signature · 1 line
dwmw2
#5 lore raw
In reply to James Morris
Quoted 6 lines · James Morris
Quoted 2 lines · Andi Kleen

You could use .altinstructions to patch a jump in at runtime based on CPU capabilities. Assuming MMX is really faster of course.

Neat. The latter could be measured at boot.

Or lazily on first usage. If it doesn't have to be done at boot time, why delay the user with it?

Jörn

Signature · 2 lines
Everything should be made as simple as possible, but not simpler.
-- Albert Einstein
#6 lore raw
In reply to Andi Kleen
Quoted 3 lines · Andi Kleen

You could use .altinstructions to patch a jump in at runtime based on CPU capabilities. Assuming MMX is really faster of course.

I seriously doubt that the MMX code could be faster.

The only MMX code in the original was saving some integer contents to a scratch MMX register rather than saving to memory. There's _no_ way that is faster, especially since in the kernel it would require us much extra work to first check that the FP context is safed. Even _without_ the extra work I simply cannot imagine that a "movd reg,mmx" is faster than a plain "movl reg,stackslot".

Linus

#7 lore raw
Quoted 6 lines · Linus Torvalds
Quoted 3 lines · Andi Kleen

You could use .altinstructions to patch a jump in at runtime based on CPU capabilities. Assuming MMX is really faster of course.

I seriously doubt that the MMX code could be faster.

For what it's worth, about a year about I tested both Gladman's MMX and non-MMX code on a Pentium 4. The non-MMX code was consistently significantly faster in every scenario I could come up with.

Signature · 3 lines
I love deadlines.
I love the whooshing noise they make as they go by.
--Douglas Adams
#8 lore raw
In reply to Linus Torvalds

i dont know anything at all about this, but wouldnt it be possible to optimize it even more, if there were a version for each cpu, like one for athlon-xp and one for p4?

Quoted 22 lines · Linus Torvalds
Quoted 3 lines · Andi Kleen

You could use .altinstructions to patch a jump in at runtime based on CPU capabilities. Assuming MMX is really faster of course.

I seriously doubt that the MMX code could be faster.

The only MMX code in the original was saving some integer contents to a scratch MMX register rather than saving to memory. There's _no_ way that is faster, especially since in the kernel it would require us much extra work to first check that the FP context is safed. Even _without_ the extra work I simply cannot imagine that a "movd reg,mmx" is faster than a plain "movl reg,stackslot".

Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

author
#9 lore raw
Quoted 3 lines · Kasper Sandberg

i dont know anything at all about this, but wouldnt it be possible to optimize it even more, if there were a version for each cpu, like one for athlon-xp and one for p4?

I also haven't looked at the code (It seems except for Linus/James everybody posting to this thread is clueless about the actual code - is that a good sign or a bad one? ;-).

But if someone wanted to write such optimized versions .altinstructions would make it easy to switch to the right version at runtime. There is no bit for Athlon-XP right now, but for AMD K8 B/C and for P3/P4. A bit for XP could be relatively easily added. You can also test for SSE2, MMX etc. which may be more generic.

-Andi

#10 lore raw
In reply to Linus Torvalds
Quoted 3 lines · Linus Torvalds

work to first check that the FP context is safed. Even _without_ the extra work I simply cannot imagine that a "movd reg,mmx" is faster than a plain "movl reg,stackslot".

p3/p-m have datapaths specifically for movd -- apparently a path for int->mmx and a separate path for mmx->int. the paths are latency 1, throughput one per clock.

however that line of x86 processors is essentially unique in this respect...

my measurement methodology is to pair a bunch of movd back and forth between (int,mmx) register pairs, then measure the avg latency per round-trip as i increase the number of pairs (i.e. to see how much parallelism is available.)

i.e. for 2 in parallel my code is this fragment repeated 100 times:

	movd %eax,%mm0
	movd %ebx,%mm1
	movd %mm0,%eax
	movd %mm1,%ebx

here's the average round-trip latency (in cycles) per movd/movd pair for various processors i have access to, and availble parallelisms:

available parallelism
1 2 3 4 5 6

p-m         2.00    1.30    1.00    1.04    1.01    1.00
p4-2        8.00    4.05    2.67    2.50    2.40    2.33
p4-3       11.02    5.50    3.67    2.75    2.40    2.33
opteron    14.67    6.00    5.33    5.00    5.00    5.00
efficeon    7.06    3.55    2.80    2.97    2.95    3.08

i'm pretty sure the gladman code was tuned on processors like p3/p-m... where movd is an improvement over using memory. actually i've been kind of puzzled why nobody ever used mmx for the XORing on a p3 -- i think the 1 cycle latency mmx plus the 1 cycle latency movd makes it all pay off fine... but this won't pay off anywhere else because of 2-cycle mmx latency, and long latency between int/mmx register files.

i've seen another totally slimy AES trick for this problem -- store %esp in a global memory location then use it as a general purpose register. there's a benchmark which does this, i consider it wholly inappropriate for general code though :)

-dean