delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/31/17:50:44

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Possible bug/misfeature in GCC
Date: Fri, 31 Jan 1997 19:43:44 +0000
Organization: None
Distribution: world
Message-ID: <w6dv5EAwtk8yEw1j@talula.demon.co.uk>
References: <32F1A438 DOT 5509 AT rangenet DOT com>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 28
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Dan Hedlund writes:
>The following lines compile wrong with the -O3 option.
>
>unsigned char inportb (int port)
>{
>  unsigned char c;
>  asm ("inb     %%dx, %%al"
>      : "=a" (c)
>      : "d" (port));
>  return c;
>}
[...]
>GCC reads a byte from port 0 only once, and then compars that byte to 0
>in an endless loop.  Apparently GCC thinks the byte retrieved from the
>port doesn't change.

This is correct behaviour on the part of gcc. In most cases that is a
valid optimisation, since you've told it what registers you change in
your asm routine, and it has no way of knowing that you are waiting for
an external hardware event. To make the optimiser leave your function
alone, you need to add the 'volatile' keyword. Look in
djgpp\include\inlines\pc.h for an example. In fact, why don't you just
use the inportb() from that header?

/*
 *  Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
 *  Ghoti: 'gh' as in 'enough', 'o' as in 'women', and 'ti' as in 'nation'.
 */

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019