Skip to content

Commit 089dfee

Browse files
authored
[X86] Add support for MS inp functions. (#93804)
support _inp, _inpw, _inpd. These functions were removed from the Windows runtime library, but aare still supported for kernel mode development.
1 parent 1fa073a commit 089dfee

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

clang/lib/Headers/intrin.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,25 @@ static __inline__ void __DEFAULT_FN_ATTRS __stosq(unsigned __int64 *__dst,
329329
static __inline__ void __DEFAULT_FN_ATTRS __halt(void) {
330330
__asm__ volatile("hlt");
331331
}
332+
333+
static inline int _inp(unsigned short port) {
334+
int ret;
335+
__asm__ volatile("inb %w1, %b0" : "=a"(ret) : "Nd"(port));
336+
return ret;
337+
}
338+
339+
static inline unsigned short _inpw(unsigned short port) {
340+
unsigned short ret;
341+
__asm__ volatile("inw %w1, %w0" : "=a"(ret) : "Nd"(port));
342+
return ret;
343+
}
344+
345+
static inline unsigned long _inpd(unsigned short port) {
346+
unsigned long ret;
347+
__asm__ volatile("inl %w1, %k0" : "=a"(ret) : "Nd"(port));
348+
return ret;
349+
}
350+
332351
#endif
333352

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

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,31 @@ 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+
67+
int test_inp(unsigned short port) {
68+
return _inp(port);
69+
}
70+
// CHECK-LABEL: i32 @test_inp(i16 noundef
71+
// CHECK-SAME: [[PORT:%.*]])
72+
// CHECK: [[TMP0:%.*]] = tail call i32 asm sideeffect "inb ${1:w}, ${0:b}", "={ax},N{dx},~{dirflag},~{fpsr},~{flags}"(i16 [[PORT]])
73+
// CHECK-NEXT: ret i32 [[TMP0]]
74+
75+
unsigned short test_inpw(unsigned short port) {
76+
return _inpw(port);
77+
}
78+
// CHECK-LABEL: i16 @test_inpw(i16 noundef
79+
// CHECK-SAME: [[PORT:%.*]])
80+
// CHECK: [[TMP0:%.*]] = tail call i16 asm sideeffect "inw ${1:w}, ${0:w}", "={ax},N{dx},~{dirflag},~{fpsr},~{flags}"(i16 [[PORT]])
81+
// CHECK-NEXT: ret i16 [[TMP0]]
82+
83+
unsigned long test_inpd(unsigned short port) {
84+
return _inpd(port);
85+
}
86+
// CHECK-LABEL: i32 @test_inpd(i16 noundef
87+
// CHECK-SAME: [[PORT:%.*]])
88+
// CHECK: [[TMP0:%.*]] = tail call i32 asm sideeffect "inl ${1:w}, ${0:k}", "={ax},N{dx},~{dirflag},~{fpsr},~{flags}"(i16 [[PORT]])
89+
// CHECK-NEXT: ret i32 [[TMP0]]
90+
6691
#if defined(__x86_64__)
6792

6893
char test__readgsbyte(unsigned long Offset) {

0 commit comments

Comments
 (0)