[PATCH] Add implementations of __readfs{byte, word, dword, qword} to Intrin.h
Hans Wennborg
hans at chromium.org
Thu Jan 23 14:01:06 PST 2014
Thanks for the comments! Here's a new version with all the bells and whistles:
- volatile ptr, as per David's request
- using a macro
- casting __offset to size_t to make sure it's pointer-sized
- prefix address_space with double underscores to avoid name conflicts.
Hi rnk, whunt,
http://llvm-reviews.chandlerc.com/D2606
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D2606?vs=6611&id=6615#toc
Files:
lib/Headers/Intrin.h
Index: lib/Headers/Intrin.h
===================================================================
--- lib/Headers/Intrin.h
+++ lib/Headers/Intrin.h
@@ -101,9 +101,13 @@
unsigned long __readcr8(void);
unsigned int __readdr(unsigned int);
unsigned int __readeflags(void);
+static __inline__
unsigned char __readfsbyte(unsigned long);
+static __inline__
unsigned long __readfsdword(unsigned long);
+static __inline__
unsigned __int64 __readfsqword(unsigned long);
+static __inline__
unsigned short __readfsword(unsigned long);
unsigned __int64 __readmsr(unsigned long);
unsigned __int64 __readpmc(unsigned long);
@@ -767,6 +771,32 @@
__asm__ volatile ("" : : : "memory");
}
/*----------------------------------------------------------------------------*\
+|* readfs
+|* (Pointers in address space #257 are relative to the FS segment register.)
+\*----------------------------------------------------------------------------*/
+#define __ptr_to_addr_space(__addr_space_nbr, __type, __offset) \
+ ((volatile __type __attribute__((__address_space__(__addr_space_nbr)))*) \
+ (size_t)(__offset))
+
+static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__))
+__readfsbyte(unsigned long __offset) {
+ return *__ptr_to_addr_space(257, unsigned char, __offset);
+}
+static __inline__ unsigned long __attribute__((__always_inline__, __nodebug__))
+__readfsdword(unsigned long __offset) {
+ return *__ptr_to_addr_space(257, unsigned long, __offset);
+}
+static __inline__ unsigned __int64 __attribute__((__always_inline__, __nodebug__))
+__readfsqword(unsigned long __offset) {
+ return *__ptr_to_addr_space(257, unsigned __int64, __offset);
+}
+static __inline__ unsigned short __attribute__((__always_inline__, __nodebug__))
+__readfsword(unsigned long __offset) {
+ return *__ptr_to_addr_space(257, unsigned short, __offset);
+}
+
+#undef __ptr_to_addr_space
+/*----------------------------------------------------------------------------*\
|* Misc
\*----------------------------------------------------------------------------*/
static __inline__ void * __attribute__((__always_inline__, __nodebug__))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2606.4.patch
Type: text/x-patch
Size: 2154 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140123/cc7d5aff/attachment.bin>
More information about the cfe-commits
mailing list