<div dir="ltr"><div><div>Some languages, such as OpenCL, has address spaces that are not part of standard C. This may mean "add some offset to the pointer [if it's not NULL]" (the offset may be in a hardware register and depend on the current thread or some such too).<br><br></div>I expect one could use this in C to support Thread Local Storage, for example. I don't know if Clang actually does that, or has some separate mechanism for solving this. In x86, the TLS is supported by using the segment register to hold the base-address into the TLS memory for a given thread, so a addrspacecast to "global" address space would then be a LEA RDX, FS:[RAX] to convert from offset RAX in TLS into a global pointer in RDX [it's a few years since I worked on x86-64 assembler, so syntax may be off].<br><br>--<br></div>Mats<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 6 October 2015 at 09:31, David Chisnall via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 6 Oct 2015, at 06:39, Hayden Livingston via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
> I was reading the LangRef for semantics of an instruction and came<br>
> across addrspacecast. I've never needed it, so I suppose I don't care<br>
> about it.<br>
<br>
</span>You use it when you have a pointer in one address space and you wish to have a pointer in another address space.<br>
<span class=""><br>
> But, why does it exist? What problem is it trying to solve?<br>
<br>
</span>Casts between address spaces may not be simple bitcasts. For example, you may have one address space that uses 32-bit integers to cover all of physical memory and 16-bit pointers in some fast scratchpad memory. It may or may not be defined to cast a 16-bit pointer to a 32-bit one (it definitely won’t be a simple sign / zero extension, but it may be a masking operation if the fast memory is mapped into the larger address space).<br>
<br>
David<br>
<div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</div></div></blockquote></div><br></div>