0

This commit says:

In amdgcn target, null pointers in global, constant, and generic address space take value 0 but null pointers in private and local address space take value -1.

How do they use those two different values of NULL?

Abyx
  • 12,345
  • 5
  • 44
  • 76
  • 2
    C standard has made all the effort to make NULL indistinguishable from integer 0 and boolean false, yet does not mention it must be 0 at the machine code level. My guess is, in those address spaces, 0 is reserved a valid address. – user3528438 Dec 12 '16 at 14:29
  • 2
    Your question is unclear. The title asks "why?" and the text asks "how?"; "How" seems to be thoroughly explained in the commit unless you meant "How can that be valid C?", which is yet another question. Please be more specific. – rici Dec 12 '16 at 16:27
  • I worked for a long time on a machine where null was 0xffffffff (ie -1). Seemed odd to me to come to a system where 0 == null. I mean 0 is a perfectly valid address, its the first byte of RAM. – pm100 Dec 13 '16 at 16:45

1 Answers1

1

As to why: I don't know this for a fact, but local/private address space pointers are almost certainly just implemented as offsets/indices in a flat physical register file/memory area. There's no virtual memory-like address remapping, just a big array. You still want to be able to access array index 0, so "invalid pointer" (invalid index) needs to be something else.

Don't forget, NULL = non-dereferenceable pointer = 0 is just a convention in regular C, too - some non-OpenCL systems also have valid memory at address 0. There's some complication in the standard regarding memset and so on, so you're probably best off reading the document yourself if you're interested in the exact specification.

I'm not sure what exactly you're asking regarding "how" - you can't sensibly convert between pointers in different OpenCL address spaces, so there's no conflict there.

pmdj
  • 22,018
  • 3
  • 52
  • 103