On Fri, Jan 16, 2015 at 11:48 AM, Joerg Sonnenberger <[email protected]>
wrote:
> Also, using functions gives better typing in terms of documentation, so it
> seems reasonable to continue to support that.
>
I agree, it would be nice if there were a better way to write these types
of wrappers, but we don't have one.
> For optimality I meant things like:
>
> unsigned char inb (unsigned short int __port)
> {
> unsigned char _v;
>
> if (__builtin_constant_p(__port) && __port < 256)
> __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"N" (__port));
> else
> __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"d" (__port));
> return _v;
> }
>
This code is still invalid and the backend will still reject this code at
-O0. Diagnosing it earlier is better.
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:
template <int __port>
unsigned char inb() {
unsigned char __v;
__asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"N" (__port));
return __v;
}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits