| 1 |
/* In the source code, the vec_adds appears before the call to |
| 2 |
validate_sat(). In the .s code, the vaddubs has been moved to after |
| 3 |
the call to validate_sat(). This invalidates the meaning of checking |
| 4 |
the saturation bit. */ |
| 5 |
|
| 6 |
#include <stdio.h> |
| 7 |
#include <stdlib.h> |
| 8 |
#include <altivec.h> |
| 9 |
|
| 10 |
static int failed; |
| 11 |
|
| 12 |
void validate_sat(); |
| 13 |
void validate_u8(vector unsigned char, vector unsigned char); |
| 14 |
|
| 15 |
int |
| 16 |
main() |
| 17 |
{ |
| 18 |
vector unsigned char result_u8; |
| 19 |
vec_mtvscr(((vector unsigned short){0,0,0,0,0,0,0,0})); |
| 20 |
result_u8 = vec_adds(((vector unsigned |
| 21 |
char){0,1,2,3,0xfc,0xfd,0xfe,0xff, |
| 22 |
0,1,2,3,0xfc,0xfd,0xfe,0xff}), |
| 23 |
((vector unsigned |
| 24 |
char){0,0xf0,0xfd,0xfd,2,2,2,2,0, |
| 25 |
0xf0,0xfd,0xfd,2,2,2,2})); |
| 26 |
validate_sat(); |
| 27 |
validate_u8(result_u8, ((vector unsigned |
| 28 |
char){0,0xf1,0xff,0xff,0xfe,0xff,0xff,0xff, |
| 29 |
0,0xf1,0xff,0xff,0xfe,0xff,0xff,0xff})); |
| 30 |
if (failed) |
| 31 |
abort (); |
| 32 |
return 0; |
| 33 |
} |
| 34 |
|
| 35 |
void validate_sat() |
| 36 |
{ |
| 37 |
#ifdef __LITTLE_ENDIAN__ |
| 38 |
if (vec_any_ne(vec_splat(vec_mfvscr(), 0), ((vector unsigned short){1,1,1,1,1,1,1,1}))) |
| 39 |
#else |
| 40 |
if (vec_any_ne(vec_splat(vec_mfvscr(), 7), ((vector unsigned short){1,1,1,1,1,1,1,1}))) |
| 41 |
#endif |
| 42 |
{ |
| 43 |
union {vector unsigned short v; unsigned short s[8];} u; |
| 44 |
u.v = vec_mfvscr(); |
| 45 |
printf("error: vscr == { %d,%d,%d,%d,%d,%d,%d,%d }", |
| 46 |
u.s[0], u.s[1], u.s[2], u.s[3], |
| 47 |
u.s[4], u.s[5], u.s[6], u.s[7]); |
| 48 |
printf("expected { 1,1,1,1,1,1,1,1 }\n"); |
| 49 |
failed++; |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
void validate_u8(vector unsigned char v, vector unsigned char vx) |
| 54 |
{ |
| 55 |
union {vector unsigned char v; unsigned char x[16]; } u, ux; |
| 56 |
int i; |
| 57 |
u.v = v; |
| 58 |
ux.v = vx; |
| 59 |
for (i=0; i<16; i++) { |
| 60 |
if (u.x[i] != ux.x[i]) { |
| 61 |
printf(" error: field %d %#2.2x expected %#2.2x\n", |
| 62 |
i, u.x[i], ux.x[i]); |
| 63 |
failed++; |
| 64 |
} |
| 65 |
} |
| 66 |
} |