summaryrefslogtreecommitdiffstats
path: root/sys/i386/include/cpufunc.h
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2009-04-11 14:01:01 +0000
committered <ed@FreeBSD.org>2009-04-11 14:01:01 +0000
commita0f5dad6a9ddfbedadd87bc81dd972213e8212d3 (patch)
tree00aa69c55bfef2687b612052e3414a52502e861a /sys/i386/include/cpufunc.h
parent3287d737bd0b368b878c53334e63860c83828f8f (diff)
downloadFreeBSD-src-a0f5dad6a9ddfbedadd87bc81dd972213e8212d3.zip
FreeBSD-src-a0f5dad6a9ddfbedadd87bc81dd972213e8212d3.tar.gz
Simplify in/out functions (for i386 and AMD64).
Remove a hack to generate more efficient code for port numbers below 0x100, which has been obsolete for at least ten years, because GCC has an asm constraint to specify that. Submitted by: Christoph Mallon <christoph mallon gmx de>
Diffstat (limited to 'sys/i386/include/cpufunc.h')
-rw-r--r--sys/i386/include/cpufunc.h87
1 files changed, 8 insertions, 79 deletions
diff --git a/sys/i386/include/cpufunc.h b/sys/i386/include/cpufunc.h
index ad5fc4c..98eb9ac 100644
--- a/sys/i386/include/cpufunc.h
+++ b/sys/i386/include/cpufunc.h
@@ -170,70 +170,12 @@ halt(void)
__asm __volatile("hlt");
}
-#if !defined(__GNUCLIKE_BUILTIN_CONSTANT_P) || __GNUCLIKE_ASM < 3
-
-#define inb(port) inbv(port)
-#define outb(port, data) outbv(port, data)
-
-#else /* __GNUCLIKE_BUILTIN_CONSTANT_P && __GNUCLIKE_ASM >= 3 */
-
-/*
- * The following complications are to get around gcc not having a
- * constraint letter for the range 0..255. We still put "d" in the
- * constraint because "i" isn't a valid constraint when the port
- * isn't constant. This only matters for -O0 because otherwise
- * the non-working version gets optimized away.
- *
- * Use an expression-statement instead of a conditional expression
- * because gcc-2.6.0 would promote the operands of the conditional
- * and produce poor code for "if ((inb(var) & const1) == const2)".
- *
- * The unnecessary test `(port) < 0x10000' is to generate a warning if
- * the `port' has type u_short or smaller. Such types are pessimal.
- * This actually only works for signed types. The range check is
- * careful to avoid generating warnings.
- */
-#define inb(port) __extension__ ({ \
- u_char _data; \
- if (__builtin_constant_p(port) && ((port) & 0xffff) < 0x100 \
- && (port) < 0x10000) \
- _data = inbc(port); \
- else \
- _data = inbv(port); \
- _data; })
-
-#define outb(port, data) ( \
- __builtin_constant_p(port) && ((port) & 0xffff) < 0x100 \
- && (port) < 0x10000 \
- ? outbc(port, data) : outbv(port, data))
-
static __inline u_char
-inbc(u_int port)
+inb(u_int port)
{
u_char data;
- __asm __volatile("inb %1,%0" : "=a" (data) : "id" ((u_short)(port)));
- return (data);
-}
-
-static __inline void
-outbc(u_int port, u_char data)
-{
- __asm __volatile("outb %0,%1" : : "a" (data), "id" ((u_short)(port)));
-}
-
-#endif /* __GNUCLIKE_BUILTIN_CONSTANT_P && __GNUCLIKE_ASM >= 3*/
-
-static __inline u_char
-inbv(u_int port)
-{
- u_char data;
- /*
- * We use %%dx and not %1 here because i/o is done at %dx and not at
- * %edx, while gcc generates inferior code (movw instead of movl)
- * if we tell it to load (u_short) port.
- */
- __asm __volatile("inb %%dx,%0" : "=a" (data) : "d" (port));
+ __asm volatile("inb %w1, %0" : "=a" (data) : "Nd" (port));
return (data);
}
@@ -242,7 +184,7 @@ inl(u_int port)
{
u_int data;
- __asm __volatile("inl %%dx,%0" : "=a" (data) : "d" (port));
+ __asm volatile("inl %w1, %0" : "=a" (data) : "Nd" (port));
return (data);
}
@@ -284,33 +226,20 @@ inw(u_int port)
{
u_short data;
- __asm __volatile("inw %%dx,%0" : "=a" (data) : "d" (port));
+ __asm volatile("inw %w1, %0" : "=a" (data) : "Nd" (port));
return (data);
}
static __inline void
-outbv(u_int port, u_char data)
+outb(u_int port, u_char data)
{
- u_char al;
- /*
- * Use an unnecessary assignment to help gcc's register allocator.
- * This make a large difference for gcc-1.40 and a tiny difference
- * for gcc-2.6.0. For gcc-1.40, al had to be ``asm("ax")'' for
- * best results. gcc-2.6.0 can't handle this.
- */
- al = data;
- __asm __volatile("outb %0,%%dx" : : "a" (al), "d" (port));
+ __asm __volatile("outb %0, %w1" : : "a" (data), "Nd" (port));
}
static __inline void
outl(u_int port, u_int data)
{
- /*
- * outl() and outw() aren't used much so we haven't looked at
- * possible micro-optimizations such as the unnecessary
- * assignment for them.
- */
- __asm __volatile("outl %0,%%dx" : : "a" (data), "d" (port));
+ __asm volatile("outl %0, %w1" : : "a" (data), "Nd" (port));
}
static __inline void
@@ -340,7 +269,7 @@ outsl(u_int port, const void *addr, size_t cnt)
static __inline void
outw(u_int port, u_short data)
{
- __asm __volatile("outw %0,%%dx" : : "a" (data), "d" (port));
+ __asm volatile("outw %0, %w1" : : "a" (data), "Nd" (port));
}
static __inline void
OpenPOWER on IntegriCloud