Re: Safety and legality of optimizations

Vinod.Grover@Eng.Sun.COM (Vinod Grover)
Tue, 28 Mar 1995 17:39:02 GMT

          From comp.compilers

Related articles
Re: Optimizing Across && And || bart@cs.uoregon.edu (1995-02-23)
Re: Safety and legality of optimizations cliffc@crocus.hpl.hp.com (1995-03-21)
Re: Safety and legality of optimizations Vinod.Grover@Eng.Sun.COM (1995-03-28)
Re: Safety and legality of optimizations cliffc@crocus.hpl.hp.com (1995-04-03)
Re: Safety and legality of optimizations cef@geodesic.com (Charles Fiterman) (1995-04-15)
Re: Safety and legality of optimizations Dave@OCCL-CAM.DEMON.CO.UK (Dave Lloyd) (1995-04-18)
Re: Safety and legality of optimizations cliffc@crocus.hpl.hp.com (1995-04-17)
Re: Safety and legality of optimizations jim@meiko.co.uk (1995-04-21)
Re: Safety and legality of optimizations clodius@lanl.gov (1995-04-26)
| List of all articles for this month |
Newsgroups: comp.compilers
From: Vinod.Grover@Eng.Sun.COM (Vinod Grover)
Keywords: optimize, design
Organization: Sun Microsystems Computer Corporation
References: 95-02-179 95-03-119
Date: Tue, 28 Mar 1995 17:39:02 GMT

Cliff Click <cliffc@crocus.hpl.hp.com> wrote:
>Moving I/O across a potentially infinite loop is bad.
>However, you _can_ move everything else across the loop, as long as you
>preserve all data- & control- dependences. You can even move other
>potentially infinite loops across.


This is not quite true, especially in certain system applications
where multiple threads or processes might be active. A typical case is
when spinlocks/busy-waits are used for implementing critical sections.
A critical section may contain non-I/O statements that manipulate a
shared data structure, e.g. a bounded buffer. The lock-variable
itself might be declared as volatile, but not necessarily the data
structure being manipulated in the critical section:




#define LOCKED 1
#define FREE 0
      volatile int lock;


              ...


void worker(...) {


      int old = LOCKED;
      /*
        * try to acquire the lock
        */
      do { /* potentialy infinite loop */
          while (lock == LOCKED) {}
          old = atomic_exchange(lock, old);
      } while (old == LOCKED);


      /*
        * critical section code;
        */


            ...


      /*
        * release the lock.
        */
        lock = FREE; /* assume atomic store */
              ...


}


In the above example you don't want the critical section code to be moved
out.


--Vinod Grover
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.