Skip to content

Instantly share code, notes, and snippets.

@mansr
Created May 19, 2012 21:12
Show Gist options
  • Save mansr/2732404 to your computer and use it in GitHub Desktop.
Save mansr/2732404 to your computer and use it in GitHub Desktop.
/* wrong output with pathcc -O1
* the return value is not truncated to 32 bits */
#include <stdio.h>
unsigned long foo(unsigned long a, unsigned b)
{
b -= a;
return b;
}
int main(void)
{
printf("%016lx\n", foo(2, 1));
return 0;
}
/* wrong output with pathcc -O3
* the loop is incorrectly vectorised with pslld,
* which is not an element-wise shift as the compiler
* appears to believe */
#include <stdio.h>
#define N 8
void print(unsigned *v)
{
int i;
for (i = 0; i < N; i++)
printf("v[%2d] = %08x\n", i, v[i]);
}
int main(void)
{
unsigned v[N];
unsigned i;
for (i = 0; i < N; i++)
v[i] = 1 << i;
print(v);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment