Please take a look. I always worry about getting the mov operands backwards :)
Details
Diff Detail
Event Timeline
LGTM
lib/Headers/Intrin.h | ||
---|---|---|
777 | I would use offset instead of addr. | |
779 | Can you add explicit size suffixes so we get better error checking here? I think you can use movb, movw, movl, and movq. | |
779 | I spent a while fooling around with multi-alternative constraints trying to get clang to produce 'movb %fs:0, %reg' for __readfsbyte(0), but I gave up. Our inline asm stuff isn't sophisticated enough to handle that. |
Addressed rnk's comments.
Chandler: can you provide a pointer to the address space technique you mentioned?
This is the address space extension for accessing TLS:
http://clang.llvm.org/docs/LanguageExtensions.html#x86-x86-64-language-extensions
That's a lot cleaner. Let's do that.
Uploading patch that uses the address_space attribute instead of inline asm.
Please take another look.
lib/Headers/Intrin.h | ||
---|---|---|
779 | We may want to move to macro-stamping these out if we add incfs*, addfs*, and __*gs*. | |
779 | __offset isn't pointer sized in x64 mode, so we'll get -Wsystem-header warnings here. The API is specified to use unsigned long, since I believe you can't address more than 2 GB off of these segments. I'm not sure what integer type we can use to cast, though... |
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.
lib/Headers/Intrin.h | ||
---|---|---|
781–796 | In MSVC, these intrinsics actually aren't available on x64. (They're not needed anyway on Windows/x64, because it uses GS for the TEB instead of FS as Windows/i386 does.) For this reason (unless you have some pressing need for FS-relative access on a non-Windows x86-64 platform), you might consider putting them inside an #ifndef __x86_64__ block. |
I would use offset instead of addr.