[Bug libfortran/83097] Use __BYTE_ORDER__ instead of runtime test

jb at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Nov 23 10:25:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83097

--- Comment #4 from Janne Blomqvist <jb at gcc dot gnu.org> ---
Actually, I think it's for big endian we could optimize memcmp_char4. In the
example Thomas posted on the mailing list, one must also check the sign of
memcmp, not just whether it's != 0. Fixed example:

#include <stdio.h>
#include <string.h>

char a[4] = { 1, 2, 3, 4};
char b[4] = { 4, 3, 2, 1};

int main()
{
  int i, j;
  memcpy (&i, a, sizeof(i));
  memcpy (&j, b, sizeof(j));
  printf("memcmp           : ");
  if (memcmp (&i,&j,sizeof(i)) > 0)
    printf("larger\n");
  else
    printf("smaller or equal\n");

  printf("Direct comparison: ");
  if (i > j)
    printf("larger\n");
  else
    printf("smaller or equal\n");

  return 0;
}


On a little endian system this prints:

memcmp           : smaller or equal
Direct comparison: larger

Since most targets of interest for GFortran usage are little endian (x86, arm,
ppc64le) I'm not sure it's worth the bother to do the memcmp_char4
optimization.


More information about the Gcc-bugs mailing list