Skip to contentSkip to conversation

Looking for an emulation for CMOV* instructions.

Q Ronald Wahl 15 participants 28 messages Jan 10, 2002 – Apr 12, 2002

lore
Share & tools
lore
#0 lore raw

Hallo kernel hackers,

is it possible to include an emulation for the CMOV* (and possible other i686 instructions) for processors that dont have these (k6, pentium etc.)? I think this should work like the fpu emulation. Even if its slow it will allow you to work even if you tried to install a libc for i686 on an older architecture or if you have apps that are statically linked against such a libc (rpm, e2fschk, etc.).

I found some info on this here:

http://gwenole.beauchesne.online.fr/basilisk2/

"... * uae_jit: added CMOV "emulation" for processors that don't
support them ..."

Maybe this can be of any use to hack it in the kernel?

thanx,
ron

Signature · 4 lines
/\/\  Dipl.-Inf. Ronald Wahl                /\/\        C S N         /\/\
\/\/  [email protected] \/\/  ------------------  \/\/
/\/\  http://www.tu-chemnitz.de/~row/       /\/\  network and system  /\/\
\/\/  GnuPG/PGP key available               \/\/    administration    \/\/
#1 lore raw
Quoted 3 lines

is it possible to include an emulation for the CMOV* (and possible other i686 instructions) for processors that dont have these (k6, pentium etc.)? I think this should work like the fpu emulation. Even if its slow

The kernel isnt there to fix up the fact authors can't read. Its also very hard to get emulations right. I grant that this wasn't helped by the fact the gcc x86 folks also couldnt read the pentium pro manual correctly.

If you have a static linked program install the right version. RPMv4 even knows about cmov and i686 rpms.

#2 lore raw
Quoted 7 lines · Alan Cox
Quoted 3 lines

is it possible to include an emulation for the CMOV* (and possible other i686 instructions) for processors that dont have these (k6, pentium etc.)? I think this should work like the fpu emulation. Even if its slow

The kernel isnt there to fix up the fact authors can't read. Its also very hard to get emulations right. I grant that this wasn't helped by the fact the gcc x86 folks also couldnt read the pentium pro manual correctly.

      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^       

What do you mean with this? Explain, please!

Quoted 2 lines

If you have a static linked program install the right version. RPMv4 even knows about cmov and i686 rpms.

The problem I had is the following: I make all of my linux binaries myself but I have also some older machines here that have a k6 or a pentium. For mistake I installed the wrong rpm and had a non working system. An emulation for such cases would be a _real_ feature at least more than a pinguin boot logo (if one uses the framebuffer console). I think a stable and possible self correcting [1] system should be the aim of a modern OS. Maybe I will have a look on implementing the emulation but I thought I'll find someone here who has done this already (or is willing to do so).

ron

[1] This means catching most or all errors and correct them as good as possible. Only a running system is a good system. ;-)

Signature · 4 lines
/\/\  Dipl.-Inf. Ronald Wahl                /\/\        C S N         /\/\
\/\/  [email protected] \/\/  ------------------  \/\/
/\/\  http://www.tu-chemnitz.de/~row/       /\/\  network and system  /\/\
\/\/  GnuPG/PGP key available               \/\/    administration    \/\/
#3 lore raw
Quoted 4 lines
Quoted 2 lines

hard to get emulations right. I grant that this wasn't helped by the fact the gcc x86 folks also couldnt read the pentium pro manual correctly.

      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^       

What do you mean with this? Explain, please!

gcc told to generate i686 binaries uses cmov unconditionally. The intel PPro handbook explicitly says that cmov must be checked for.

Quoted 3 lines

myself but I have also some older machines here that have a k6 or a pentium. For mistake I installed the wrong rpm and had a non working system. An emulation for such cases would be a _real_ feature at least

So you have a buggy rpm program. Get the rpm program fixed so it correctly stops you from doing that.

Alan
--
If my call is so important to you why don't you hire
some more people to answer the telephone?

#4 lore raw
Quoted 7 lines · Alan Cox
Quoted 4 lines
Quoted 2 lines

hard to get emulations right. I grant that this wasn't helped by the fact the gcc x86 folks also couldnt read the pentium pro manual correctly.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ What do you mean with this? Explain, please!

gcc told to generate i686 binaries uses cmov unconditionally. The intel PPro handbook explicitly says that cmov must be checked for.

The compiler doesn't know, where the binary runs later. Or do you mean, that it has to insert some code that checks for the existance of these instructions during program start? Ok that would be a solution, but how do you do this for libraries that are not run in itself?

Quoted 6 lines
Quoted 3 lines

myself but I have also some older machines here that have a k6 or a pentium. For mistake I installed the wrong rpm and had a non working system. An emulation for such cases would be a _real_ feature at least

So you have a buggy rpm program. Get the rpm program fixed so it correctly stops you from doing that.

Maybe, ok. But why should such a mistake prevent me from workin with the system when it could be easily catched? Ok, the emulation code may not be easy, I dunno, but the infrastructure for emulation of instructions is already there (FPU emulation). To say its the admins fault is easy but the costs of automatically catching such errors are little in respect of the benefit you get. A running system is always better than a unusable one even if it was the admins fault.

ron

Signature · 4 lines
/\/\  Dipl.-Inf. Ronald Wahl                /\/\        C S N         /\/\
\/\/  [email protected] \/\/  ------------------  \/\/
/\/\  http://www.tu-chemnitz.de/~row/       /\/\  network and system  /\/\
\/\/  GnuPG/PGP key available               \/\/    administration    \/\/
#5 lore raw
Quoted 4 lines

The compiler doesn't know, where the binary runs later. Or do you mean, that it has to insert some code that checks for the existance of these instructions during program start? Ok that would be a solution, but how do you do this for libraries that are not run in itself?

It means the compiler for -m686 shouldn't have assumed cmov was available

Quoted 5 lines
Quoted 2 lines

So you have a buggy rpm program. Get the rpm program fixed so it correctly stops you from doing that.

Maybe, ok. But why should such a mistake prevent me from workin with the system when it could be easily catched? Ok, the emulation code may not

It can be easily caught. Thats what rpm is for. If it let you install that package on a box that can run it without using --force type options its a bug.

Quoted 2 lines

be easy, I dunno, but the infrastructure for emulation of instructions is already there (FPU emulation). To say its the admins fault is easy

FPU emulation should probably have been in glibc via a fault handler but thats a historical story.

Quoted 3 lines

but the costs of automatically catching such errors are little in respect of the benefit you get. A running system is always better than a unusable one even if it was the admins fault.

Then while you are it you can make the kernel magically recover from rm -rf / or rm * in /lib...

#6 lore raw

----- Original Message -----
From: "Alan Cox" <[email protected]>
To: "Ronald Wahl" <[email protected]>
Cc: "Alan Cox" <[email protected]>; <[email protected]>
Sent: Friday, January 11, 2002 1:54 AM
Subject: Re: [Q] Looking for an emulation for CMOV* instructions.

<snip>

Quoted 3 lines

It can be easily caught. Thats what rpm is for. If it let you install that package on a box that can run it without using --force type options its a bug.

Just curious; is RPM a "standard" for most linux distros now? I have always been running RedHat so I wouldn't know.

Maybe Ronald should start a new kernel tree with patches for goofy admins ;D

#7 lore raw
Quoted 2 lines

Just curious; is RPM a "standard" for most linux distros now? I have always been running RedHat so I wouldn't know.

Most but not all. Debian has a very powerful package system that is quite different for example. I don't know if the Debian package setup protects you from installing i686 binaries on an i486, but I bet within 48 hours of this discussion it will do anyway

#8 lore raw
In reply to Alan Cox
Quoted 8 lines · Martin Eriksson

----- Original Message -----
From: "Alan Cox" <[email protected]>
To: "Ronald Wahl" <[email protected]>
Cc: "Alan Cox" <[email protected]>; <[email protected]>
Sent: Friday, January 11, 2002 1:54 AM
Subject: Re: [Q] Looking for an emulation for CMOV* instructions.

Quoted 8 lines

<snip>

Quoted 3 lines

It can be easily caught. Thats what rpm is for. If it let you install that package on a box that can run it without using --force type options its a bug.

Just curious; is RPM a "standard" for most linux distros now? I have always been running RedHat so I wouldn't know.

IIRC, it is a standard according to the FHS. Please let's not get started
on the RPM v. Apt debate.

Quoted 3 lines

Maybe Ronald should start a new kernel tree with patches for goofy admins ;D

You know, it's funny how people think. I'm sure that we all have had some
ideas which appear goofy to others, esp. at first blush. I think that
creativity requires that thoughts sometimes be juxtaposed in a goofy manner; usually it creates garbage, but sometimes it's like peanut butter and chocolate. :-)

That much said, a good system administrator should be able to handle this
situation without having to rely on RPM. The fact that that RedHat ships
everything defaulted to i386 (except the kernel) is just one more proof of good thinking. If you know what you're doing, then Mandrake i586 is good, but can be a rude awakening for newbies, which is Mandrake's target it would seem.

IMHO, for ordinary day to day tasks, the gains from compiling -m[4|5|6] are not worth the effort and extra administrative work.

Signature · 1 line
[email protected].
#9 lore raw
In reply to Alan Cox
Quoted 7 lines · Alan Cox
Quoted 4 lines

The compiler doesn't know, where the binary runs later. Or do you mean, that it has to insert some code that checks for the existance of these instructions during program start? Ok that would be a solution, but how do you do this for libraries that are not run in itself?

It means the compiler for -m686 shouldn't have assumed cmov was available

It's not the compiler that is responsible for it. At least in my case. The problem is that if you compile the glibc than some assembler code gets included into glibc. So the problem here is glibc and not gcc. Ok, the way to go for me now will be to make a new glibc without this instructions. But I still think it would be a step to more fault tolerance (or tolerance to goofy admins ;-) if we could have an emulation of this. If I find some time I will do this...

Quoted 6 lines
Quoted 3 lines

but the costs of automatically catching such errors are little in respect of the benefit you get. A running system is always better than a unusable one even if it was the admins fault.

Then while you are it you can make the kernel magically recover from rm -rf / or rm * in /lib...

Let the FS driver copy all modified sectors into a hidden log on the disk (fixed or dynamic in size or as a ringbuffer). Then e.g during kernel startup in case you removed most of the system you might be asked to recover from some point. Such concepts are used by software like HDD-Sheriff but one level below (disc sector level). On filesystem level it makes more sense since you may recover partially. All that will bloat the kernel but it would be possible. This case is one that has (very) high costs. Not that I want this but I want to show that there _are_ ways to do it.

ron

Signature · 4 lines
/\/\  Dipl.-Inf. Ronald Wahl                /\/\        C S N         /\/\
\/\/  [email protected] \/\/  ------------------  \/\/
/\/\  http://www.tu-chemnitz.de/~row/       /\/\  network and system  /\/\
\/\/  GnuPG/PGP key available               \/\/    administration    \/\/
#10 lore raw
In reply to Ronald Wahl
Quoted 1 line · Alan Cox

It means the compiler for -m686 shouldn't have assumed cmov was available

Eh? -march=i686 *asserts* that cmov is available.

What's the point of optimizing an IF to a cmov if I have to insert another IF to see if I can use cmov?

r~

#11 lore raw
Quoted 3 lines
Quoted 1 line

It means the compiler for -m686 shouldn't have assumed cmov was available

Eh? -march=i686 *asserts* that cmov is available.

So why is it called "i686" when the intel i686 machine definition says its optional ? Its just the naming that seems odd

Quoted 2 lines

What's the point of optimizing an IF to a cmov if I have to insert another IF to see if I can use cmov?

I've always wondered. Intel made the instruction optional yet there isnt an obvious way to do runtime fixups on it

#12 lore raw
Quoted 4 lines · Alan Cox

[somebody]

Quoted 1 line

Eh? -march=i686 *asserts* that cmov is available.

Quoted 8 lines

So why is it called "i686" when the intel i686 machine definition says its optional ? Its just the naming that seems odd

Quoted 2 lines

What's the point of optimizing an IF to a cmov if I have to insert another IF to see if I can use cmov?

I've always wondered. Intel made the instruction optional yet there isnt an obvious way to do runtime fixups on it

This may design-by-committee in action, or corporate rules that are hard to defy. Don't worry about it. Intel will never produce a new x86-compatible chip without cmov. Nobody else will either.

Gee, when was the last time Intel removed something from the instruction set? An old 80286 instruction comes to mind, but that was a super-CISC mess that was really specific to the implementation. Anything really useful that was ever removed?

#13 lore raw
Quoted 3 lines

that are hard to defy. Don't worry about it. Intel will never produce a new x86-compatible chip without cmov. Nobody else will either.

People already do. The C3 and C5. The fact the real world i686 definition and the compiler one differed caused much pain in the package installing department.

Alan

#14 lore raw
In reply to Richard Henderson
Quoted 5 lines · Alan Cox
Quoted 2 lines

What's the point of optimizing an IF to a cmov if I have to insert another IF to see if I can use cmov?

I've always wondered. Intel made the instruction optional yet there isnt an obvious way to do runtime fixups on it

Yes there is -- emulation! :-)

-- Jamie

#15 lore raw
Quoted 9 lines · Jamie Lokier
Quoted 5 lines · Alan Cox
Quoted 2 lines

What's the point of optimizing an IF to a cmov if I have to insert another IF to see if I can use cmov?

I've always wondered. Intel made the instruction optional yet there isnt an obvious way to do runtime fixups on it

Yes there is -- emulation! :-)

It's just as bad, probably worse! You trap on an invalid op-code. The trap-handler checks the op-code and if it's emulated, it emulates it and returns to the executing task. This takes many instruction cycles, certainly more than if(cmov) doit; else do_something_else; --which, itself, takes many more instruction cycles than cmov is supposed to reduce. It's a no-win situation. The only way to win is a compile-time choice. This means customizing for your CPU IFF it has the cmov instruction.

Cheers,
Dick Johnson

Penguin : Linux version 2.4.1 on an i686 machine (797.90 BogoMips).

I was going to compile a list of innovations that could be attributed to Microsoft. Once I realized that Ctrl-Alt-Del was handled in the BIOS, I found that there aren't any.

#16 lore raw
Quoted 11 lines · Richard B Johnson
Quoted 9 lines · Jamie Lokier
Quoted 5 lines · Alan Cox
Quoted 2 lines

What's the point of optimizing an IF to a cmov if I have to insert another IF to see if I can use cmov?

I've always wondered. Intel made the instruction optional yet there isnt an obvious way to do runtime fixups on it

Yes there is -- emulation! :-)

Quoted 8 lines

It's just as bad, probably worse! You trap on an invalid op-code. The trap-handler checks the op-code and if it's emulated, it emulates it and returns to the executing task. This takes many instruction cycles, certainly more than if(cmov) doit; else do_something_else; --which, itself, takes many more instruction cycles than cmov is supposed to reduce. It's a no-win situation. The only way to win is a compile-time choice. This means customizing for your CPU IFF it has the cmov instruction.

It is a big win in the situation where you have only a binary for i686 and want or better must execute it e.g. on a i586. This was the reason why I asked initially.

ron

Signature · 4 lines
/\/\  Dipl.-Inf. Ronald Wahl                /\/\        C S N         /\/\
\/\/  [email protected] \/\/  ------------------  \/\/
/\/\  http://www.tu-chemnitz.de/~row/       /\/\  network and system  /\/\
\/\/  GnuPG/PGP key available               \/\/    administration    \/\/
#17 lore raw
In reply to Jamie Lokier
Quoted 4 lines · Jamie Lokier
Quoted 2 lines

I've always wondered. Intel made the instruction optional yet there isnt an obvious way to do runtime fixups on it

Yes there is -- emulation! :-)

For shared libraries the dynamic linker could choose appropriate images.

Signature · 3 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +
#18 lore raw
In reply to Richard Henderson
Quoted 5 lines · Jamie Lokier
Quoted 4 lines
Quoted 2 lines

What's the point of optimizing an IF to a cmov if I have to insert another IF to see if I can use cmov?

I've always wondered. Intel made the instruction optional yet there isnt an obvious way to do runtime fixups on it

Yes there is -- emulation! :-)

Too much overhead to be of practical use..

Signature · 2 lines
| Dave Jones.        http://www.codemonkey.org.uk
| SuSE Labs
#19 lore raw
In reply to Alan Cox
Quoted 7 lines · Alan Cox
Quoted 3 lines

is it possible to include an emulation for the CMOV* (and possible other i686 instructions) for processors that dont have these (k6, pentium etc.)? I think this should work like the fpu emulation. Even if its slow

The kernel isnt there to fix up the fact authors can't read. Its also very hard to get emulations right. I grant that this wasn't helped by the fact the gcc x86 folks also couldnt read the pentium pro manual correctly.

But it shouldn't crash, if the wrong architecture is chosen. (Different problem, I know) Perfect solution would be emulate them all, but at least an simple error message (please eject CPU, and put in a XXX one) would be sufficient, IMHO.

Quoted 2 lines

If you have a static linked program install the right version. RPMv4 even knows about cmov and i686 rpms.

Hans-Peter

#20 lore raw
In reply to Alan Cox
Quoted 5 lines · Hans-Peter Jansen
Quoted 4 lines · Alan Cox
Quoted 3 lines

is it possible to include an emulation for the CMOV* (and possible other i686 instructions) for processors that dont have these (k6, pentium etc.)? I think this should work like the fpu emulation. Even if its slow

Quoted 8 lines
Quoted 3 lines

The kernel isnt there to fix up the fact authors can't read. Its also very hard to get emulations right. I grant that this wasn't helped by the fact the gcc x86 folks also couldnt read the pentium pro manual correctly.

But it shouldn't crash, if the wrong architecture is chosen. (Different problem, I know) Perfect solution would be emulate them all, but at least an simple error message (please eject CPU, and put in a XXX one) would be sufficient, IMHO.

A message occurs already: "Illegal instruction". But this is not really a help.

ron

Signature · 4 lines
/\/\  Dipl.-Inf. Ronald Wahl                /\/\        C S N         /\/\
\/\/  [email protected] \/\/  ------------------  \/\/
/\/\  http://www.tu-chemnitz.de/~row/       /\/\  network and system  /\/\
\/\/  GnuPG/PGP key available               \/\/    administration    \/\/
#21 lore raw
Quoted 2 lines

A message occurs already: "Illegal instruction". But this is not really a help.

So LD_PRELOAD a library that handles it

#22 lore raw
In reply to Ronald Wahl
Quoted 2 lines · Ronald Wahl

is it possible to include an emulation for the CMOV* (and possible other i686 instructions) for processors that dont have these (k6, pentium

Where does it stop? Perhaps we should emulate PPC and Sparc instructions in the kernel, in case the sysadmin installs wrong architecture package....

;-)

Signature · 4 lines
Alistair Riddell - BOFH
IT Manager, George Watson's College, Edinburgh
Tel: +44 131 446 6070    Fax: +44 131 452 8594
Microsoft - because god hates us
#23 lore raw
In reply to Ronald Wahl

HI!

Quoted 7 lines
Quoted 3 lines

is it possible to include an emulation for the CMOV* (and possible other i686 instructions) for processors that dont have these (k6, pentium etc.)? I think this should work like the fpu emulation. Even if its slow

The kernel isnt there to fix up the fact authors can't read. Its also very hard to get emulations right. I grant that this wasn't helped by the fact the gcc x86 folks also couldnt read the pentium pro manual correctly.

How long does it take until netscape binaries contain CMOV? We already do FPU emulation (you can do soft-float, so you do NOT need FP emulation!), so I guess this would begood freature.
Pavel

Signature · 2 lines
Philips Velo 1: 1"x4"x8", 300gram, 60, 12MB, 40bogomips, linux, mutt,
details at http://atrey.karlin.mff.cuni.cz/~pavel/velo/index.html.
#24 lore raw
In reply to Ronald Wahl

Hi!

Quoted 2 lines

The kernel isnt there to fix up the fact authors can't read. Its also very hard to get emulations right. I grant that this wasn't helped by the fact

What's so hard about CMOV?

Quoted 2 lines

If you have a static linked program install the right version. RPMv4 even knows about cmov and i686 rpms.

RPM does not help. Think new machine failed, but you still have some trash with 386 on it, so you connect your disk to it, boot from floppy, and expect it to work.
Pavel

Signature · 2 lines
Philips Velo 1: 1"x4"x8", 300gram, 60, 12MB, 40bogomips, linux, mutt,
details at http://atrey.karlin.mff.cuni.cz/~pavel/velo/index.html.
#25 lore raw
Quoted 3 lines · [email protected] said:

RPM does not help. Think new machine failed, but you still have some
trash with 386 on it, so you connect your disk to it, boot from floppy, and expect it to work.

What if my spare machine is an ARM? Should I still expect it to work?

--
dwmw2

#26 lore raw
In reply to Pavel Machek

Hi!

Quoted 5 lines
Quoted 3 lines

RPM does not help. Think new machine failed, but you still have some
trash with 386 on it, so you connect your disk to it, boot from floppy, and expect it to work.

What if my spare machine is an ARM? Should I still expect it to work?

Let's say "It is easy in 386 case and hard in ARM case". Besides, we do FPU emulation already. Way harder than CMOV emulation, and serves exactly same purpose.
Pavel

Signature · 2 lines
(about SSSCA) "I don't say this lightly.  However, I really think that the U.S.
no longer is classifiable as a democracy, but rather as a plutocracy." --hpa
#27 lore raw
In reply to Ronald Wahl
Followup to:  <[email protected]>
By author:    Pavel Machek <[email protected]>
In newsgroup: linux.dev.kernel
Quoted 7 lines

HI!

Quoted 4 lines
Quoted 3 lines

is it possible to include an emulation for the CMOV* (and possible other i686 instructions) for processors that dont have these (k6, pentium etc.)? I think this should work like the fpu emulation. Even if its slow

Quoted 8 lines
Quoted 3 lines

The kernel isnt there to fix up the fact authors can't read. Its also very hard to get emulations right. I grant that this wasn't helped by the fact the gcc x86 folks also couldnt read the pentium pro manual correctly.

How long does it take until netscape binaries contain CMOV? We already do FPU emulation (you can do soft-float, so you do NOT need FP emulation!), so I guess this would begood freature.

The difference is that the overhead of doing FP emulation is acceptable when compared to softfloat; this is not the case for CMOV unless you can somehow patch the binary on the fly.

At some point it might make sense to run "the one program" that you otherwise can't live without, but I don't think it's gotten to that stage yet. Which is, in some ways, unfortunate.

-hpa

Signature · 3 lines
<[email protected]> at work, <[email protected]> in private!
"Unix gives you enough rope to shoot yourself in the foot."
http://www.zytor.com/~hpa/puzzle.txt	<[email protected]>