public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* i387 control word...
@ 1998-10-16 22:01 Jan Hubicka
  1998-10-27  1:12 ` Jeffrey A Law
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Hubicka @ 1998-10-16 22:01 UTC (permalink / raw)
  To: egcs

Hi
I am thinking how to improve float->integer conversion at intel. Current
situation is following: conversion is done by one instruction (fist),
but you need to have set control word correctly. So pattern emits code
to set cw first and asm looks like this:

	fnstcw 4(%esp)    ; store control word
	movl 4(%esp),%edx ; 
	movb $12,%dh      ; set higher part to correct value
	movl %edx,(%esp)  ; 
	fldcw (%esp)      ; load it
	subl $4,%esp
	fistpl (%esp)     ; push the integer value
	popl %eax
	fldcw 4(%esp)     ; return back...

Problem is that this ceremony is done for EVERY truncation that makes code
very bad.
Easy solution is to assume, that CW is set correclty (it is in many cases)
and make some option (like -mfast-fp-truncation) to just ignore this code.
It should help to XaoS a lot. What do you think about it?

For cases where  this is neccesary I was thinking about different solution:
legitimize control word as global SImode reigster, make mov patterns for it
and then produce sequences like:
(set tmp_reg cw)
(set tmp_reg2 (and:SI tmp_reg 0xc00))
(set cw tmp_reg2)
(conversion)
(set cw tmp_reg)
and mark all fp oprations as they use cw. This should let optimizer be smart
about it. For example even in case loop does both calcualtion and truncation
it should just make two register containing the values and emit fldcw
instructions.. Also asm statements probably needs to be changed to implicitly
clobber control word.
Before making heoric attempts to implement this I want to ask if it
should work and if it is good way to go..... I am not sure how weell optimizer
handles such cases with hard reigsters (they don't seems to be optimized at
all) and so on...  ase I want to ask if it is worthwhile...


Honza
-- 
------------------------------------------------------------------------------
                   Have you browsed my www pages? Look at:
                       http://www.paru.cas.cz/~hubicka
      Koules-the game for Svgalib,X11 and OS/2,  Xonix-the game for X11
      czech documentation for linux index, original 2D computer art and
              funny 100 years old photos and articles are there!

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

* Re: i387 control word...
  1998-10-16 22:01 i387 control word Jan Hubicka
@ 1998-10-27  1:12 ` Jeffrey A Law
  1998-11-04 15:31   ` Joern Rennecke
  0 siblings, 1 reply; 3+ messages in thread
From: Jeffrey A Law @ 1998-10-27  1:12 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: egcs

  In message < 19981016214857.02176@horac.ta.jcu.cz >you write:
  > Hi
  > I am thinking how to improve float->integer conversion at intel. Current
  > situation is following: conversion is done by one instruction (fist),
  > but you need to have set control word correctly. So pattern emits code
  > to set cw first and asm looks like this:
  > 
  > 	fnstcw 4(%esp)    ; store control word
  > 	movl 4(%esp),%edx ; 
  > 	movb $12,%dh      ; set higher part to correct value
  > 	movl %edx,(%esp)  ; 
  > 	fldcw (%esp)      ; load it
  > 	subl $4,%esp
  > 	fistpl (%esp)     ; push the integer value
  > 	popl %eax
  > 	fldcw 4(%esp)     ; return back...
  > 
  > Problem is that this ceremony is done for EVERY truncation that makes code
  > very bad.
  > Easy solution is to assume, that CW is set correclty (it is in many cases)
  > and make some option (like -mfast-fp-truncation) to just ignore this code.
  > It should help to XaoS a lot. What do you think about it?
I think we'll be able to implement this as a lazy code motion problem too.
It ought to be fairly simple and work reliably.

Basically think about the problem at a higher level.  What are you doing?
You're trying to eliminate redundant calculations.

So, the trick is to determine what operations set the value you want,
what operations kill the value you want, then run traditional redundancy
elimination algorithms.

We're going to need to solve a similar problem for the SH in the near
future, you'll probably be able to reuse much of that code.

jeff

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

* Re: i387 control word...
  1998-10-27  1:12 ` Jeffrey A Law
@ 1998-11-04 15:31   ` Joern Rennecke
  0 siblings, 0 replies; 3+ messages in thread
From: Joern Rennecke @ 1998-11-04 15:31 UTC (permalink / raw)
  To: law; +Cc: hubicka, egcs

> We're going to need to solve a similar problem for the SH in the near
> future, you'll probably be able to reuse much of that code.

The SH problem is harder because the usage of the register in the ABIs
doesn't fit into gcc's scheme of call-used and call-saved registers.

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

end of thread, other threads:[~1998-11-04 15:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-10-16 22:01 i387 control word Jan Hubicka
1998-10-27  1:12 ` Jeffrey A Law
1998-11-04 15:31   ` Joern Rennecke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).