mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* 387 emulator hack - mutant AAD trick - any objections?
@ 2005-05-27  7:11 cutaway
  2005-05-27  7:25 ` Mikael Pettersson
  0 siblings, 1 reply; 8+ messages in thread
From: cutaway @ 2005-05-27  7:11 UTC (permalink / raw)
  To: linux-kernel

Will there be any objections to using a quasi-documented mutation of the
x86's AAD instruction in the 387 emulator? Every CPU around has to do this
mutation correctly or a LOT of existing code will break...

The performance of storing to user space of BCD numbers in the 387 emulator
code could be improved significantly by using the mutant AAD instruction
trick (i.e. alter its implicit base from 10 to 16).  See reg_ld_str.c, in
function FPU_store_bcd()

As it stands now, the BCD digits are being decoded one at a time in a 10
iteration divide by 10 loop that makes two calls to an extended precision
division routine.

This loop could be morphed into a 5 iteration divide by 100 loop.

The remainder of a divide by 100 would be processed thus (pseudo asm code):

AL = remainder
AH = 0
AAM    /* this creates BCD nibbles in low 4 of AH and AL */
AAD (mutated with 16 as base rather than 10)

Now AL contains two packed BCD digits.   Here's a worked out example of the
transformation of data starting with an initial remainder of 35 (decimal) in
AX

1) Start with AX = 0x0023
2) Execute AAM instruction
3) Now AX = 0x0203 (unpacked BCD)
4) Execute base 16 AAD instruction
5) Now AX = 0x0023 (packed BCD)

AAM and AAD aren't cheap instructions, but compared to the cost of 2X trips
through the extended precision divide routine, they are quite a bargain.



^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: 387 emulator hack - mutant AAD trick - any objections?
@ 2005-05-27  7:44 cutaway
  2005-05-27  9:35 ` Denis Vlasenko
  0 siblings, 1 reply; 8+ messages in thread
From: cutaway @ 2005-05-27  7:44 UTC (permalink / raw)
  To: cutaway, linux-kernel

Brain fade...example should be:

1) Start with AX = 0x0023
2) Execute AAM instruction
3) Now AX = 0x0305 (unpacked BCD)
4) Execute base 16 AAD instruction
5) Now AX = 0x0035 (packed BCD)

----- Original Message ----- > 
> 1) Start with AX = 0x0023
> 2) Execute AAM instruction
> 3) Now AX = 0x0203 (unpacked BCD)
> 4) Execute base 16 AAD instruction
> 5) Now AX = 0x0023 (packed BCD)


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-05-27 13:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-27  7:11 387 emulator hack - mutant AAD trick - any objections? cutaway
2005-05-27  7:25 ` Mikael Pettersson
2005-05-27 12:17   ` Maciej W. Rozycki
2005-05-27  7:44 cutaway
2005-05-27  9:35 ` Denis Vlasenko
2005-05-27 11:43   ` cutaway
2005-05-27 12:24   ` Maciej W. Rozycki
2005-05-27 13:47     ` cutaway

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®