openshmem-org / specification

OpenSHMEM Application Programming Interface
http://www.openshmem.org
49 stars 32 forks source link

Char arithmetic is undefined outside of the character set #484

Open jdinan opened 2 years ago

jdinan commented 2 years ago

Problem Statement

We have character reductions in OpenSHMEM. However, the C language specification only guarantees well-defined behavior when the values correspond to characters in the basic execution character set.

C99 Section 6.2.5, Paragraph 3:

An object declared as type char is large enough to store any member of the basic execution character set. If a member of the basic execution character set is stored in a char object, its value is guaranteed to be positive. If any other character is stored in a char object, the resulting value is implementation-defined but shall be within the range of values that can be represented in that type.

Question

Should an OpenSHMEM reduction on character data provide be required to provide the implementation-defined result? For context, this was encountered recently because Power 9 treats character as unsigned whereas x86/Linux treats it as a signed type. ASCII is a 7-bit character set, so it is implementation defined what to do with the eighth bit.

Possible Solutions

  1. Specify whether OpenSHMEM libraries need to provide the C language's implementation defined behavior or can provide their own.
  2. Remove char reductions since we have uint8_t, signed char, and unsigned char.
  3. ??