<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Jan 16, 2015 at 11:48 AM, Joerg Sonnenberger <span dir="ltr"><<a href="mailto:joerg@netbsd.org" target="_blank">joerg@netbsd.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Also, using functions gives better typing in terms of documentation, so it seems reasonable to continue to support that.<br></blockquote><div><br></div><div>I agree, it would be nice if there were a better way to write these types of wrappers, but we don't have one.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
For optimality I meant things like:<br>
<br>
  unsigned char inb (unsigned short int __port)<br>
  {<br>
    unsigned char _v;<br>
<br>
    if (__builtin_constant_p(__port) && __port < 256)<br>
      __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"N" (__port));<br>
    else<br>
      __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"d" (__port));<br>
    return _v;<br>
<div class=""><div class="h5">  }<br></div></div></blockquote><div><br></div><div>This code is still invalid and the backend will still reject this code at -O0. Diagnosing it earlier is better.</div><div><br></div><div>If C had language rules for things like "this must be an ICE at compile time", then we could do something nice here, but it doesn't. C++ has such rules, and we can write this:</div><div>template <int __port></div><div>unsigned char inb() {</div><div>  unsigned char __v;<br>  __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"N" (__port));</div><div>  return __v;</div><div><div class=""><div class="h5">}</div></div></div></div></div></div>