Skip to content

Commit 17c3fc9

Browse files
committed
Add support for _outp{|w|d}
1 parent 0821b79 commit 17c3fc9

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

clang/lib/Headers/intrin.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,23 @@ static inline unsigned long _inpd(unsigned short port) {
348348
return ret;
349349
}
350350

351+
static inline int _outp(unsigned short port, int data) {
352+
__asm__ volatile("outb %b0, %w1" : : "a"(data), "Nd"(port) : "memory");
353+
return data;
354+
}
355+
356+
static inline unsigned short
357+
_outpw(unsigned short port, unsigned short data) {
358+
__asm__ volatile("outw %w0, %w1" : : "a"(data), "Nd"(port) : "memory");
359+
return data;
360+
}
361+
362+
static inline unsigned long _outpd(unsigned short port,
363+
unsigned long data) {
364+
__asm__ volatile("outl %k0, %w1" : : "a"(data), "Nd"(port) : "memory");
365+
return data;
366+
}
367+
351368
#endif
352369

353370
#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)

clang/test/CodeGen/X86/ms-x86-intrinsics.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ unsigned __int64 test__emulu(unsigned int a, unsigned int b) {
6363
// CHECK: [[RES:%[0-9]+]] = mul nuw i64 [[Y]], [[X]]
6464
// CHECK: ret i64 [[RES]]
6565

66-
6766
int test_inp(unsigned short port) {
6867
return _inp(port);
6968
}
@@ -88,6 +87,30 @@ unsigned long test_inpd(unsigned short port) {
8887
// CHECK: [[TMP0:%.*]] = tail call i32 asm sideeffect "inl ${1:w}, ${0:k}", "={ax},N{dx},~{dirflag},~{fpsr},~{flags}"(i16 [[PORT]])
8988
// CHECK-NEXT: ret i32 [[TMP0]]
9089

90+
int test_outp(unsigned short port, int data) {
91+
return _outp(port, data);
92+
}
93+
// CHECK-LABEL: i32 @test_outp(
94+
// CHECK-SAME: [[PORT:%.*]], i32 noundef returned [[DATA:%.*]])
95+
// CHECK-NEXT: tail call void asm sideeffect "outb ${0:b}, ${1:w}", "{ax},N{dx},~{memory},~{dirflag},~{fpsr},~{flags}"(i32 [[DATA]], i16 [[PORT]]
96+
// CHECK-NEXT: ret i32 [[DATA]]
97+
98+
unsigned short test_outpw(unsigned short port, unsigned short data) {
99+
return _outpw(port, data);
100+
}
101+
// CHECK-LABEL: i16 @test_outpw(
102+
// CHECK-SAME: [[PORT:%.*]], i16 noundef returned zeroext [[DATA:%.*]])
103+
// CHECK-NEXT: tail call void asm sideeffect "outw ${0:w}, ${1:w}", "{ax},N{dx},~{memory},~{dirflag},~{fpsr},~{flags}"(i16 [[DATA]], i16 [[PORT]])
104+
// CHECK-NEXT: ret i16 [[DATA]]
105+
106+
unsigned long test_outpd(unsigned short port, unsigned long data) {
107+
return _outpd(port, data);
108+
}
109+
// CHECK-LABEL: i32 @test_outpd(
110+
// CHECK-SAME: [[PORT:%.*]], i32 noundef returned [[DATA:%.*]])
111+
// CHECK-NEXT: tail call void asm sideeffect "outl ${0:k}, ${1:w}", "{ax},N{dx},~{memory},~{dirflag},~{fpsr},~{flags}"(i32 [[DATA]], i16 [[PORT]])
112+
// CHECK-NEXT: ret i32 [[DATA]]
113+
91114
#if defined(__x86_64__)
92115

93116
char test__readgsbyte(unsigned long Offset) {

0 commit comments

Comments
 (0)