| 1 |
/* PR rtl-optimization/91347 */ |
| 2 |
/* Reported by John David Anglin <[email protected]> */ |
| 3 |
/* { dg-additional-options "-std=gnu17" } */ |
| 4 |
/* { dg-require-effective-target int32plus } */ |
| 5 |
|
| 6 |
typedef unsigned short __u16; |
| 7 |
typedef __signed__ int __s32; |
| 8 |
typedef unsigned int __u32; |
| 9 |
typedef __signed__ long long __s64; |
| 10 |
typedef unsigned long long __u64; |
| 11 |
typedef __u16 u16; |
| 12 |
typedef __s32 s32; |
| 13 |
typedef __u32 u32; |
| 14 |
typedef __u64 u64; |
| 15 |
typedef _Bool bool; |
| 16 |
typedef s32 int32_t; |
| 17 |
typedef u32 uint32_t; |
| 18 |
typedef u64 uint64_t; |
| 19 |
|
| 20 |
char hex_asc_upper[16]; |
| 21 |
u16 decpair[100]; |
| 22 |
|
| 23 |
static __attribute__ ((noipa)) void |
| 24 |
put_dec_full4 (char *buf, unsigned r) |
| 25 |
{ |
| 26 |
unsigned q; |
| 27 |
q = (r * 0x147b) >> 19; |
| 28 |
*((u16 *)buf) = decpair[r - 100*q]; |
| 29 |
buf += 2; |
| 30 |
*((u16 *)buf) = decpair[q]; |
| 31 |
} |
| 32 |
|
| 33 |
static __attribute__ ((noipa)) unsigned |
| 34 |
put_dec_helper4 (char *buf, unsigned x) |
| 35 |
{ |
| 36 |
uint32_t q = (x * (uint64_t)0x346DC5D7) >> 43; |
| 37 |
put_dec_full4(buf, x - q * 10000); |
| 38 |
return q; |
| 39 |
} |
| 40 |
|
| 41 |
static __attribute__ ((noipa)) char * |
| 42 |
put_dec (char *buf, unsigned long long n) |
| 43 |
{ |
| 44 |
uint32_t d3, d2, d1, q, h; |
| 45 |
d1 = ((uint32_t)n >> 16); |
| 46 |
h = (n >> 32); |
| 47 |
d2 = (h ) & 0xffff; |
| 48 |
d3 = (h >> 16); |
| 49 |
q = 656 * d3 + 7296 * d2 + 5536 * d1 + ((uint32_t)n & 0xffff); |
| 50 |
q = put_dec_helper4(buf, q); |
| 51 |
q += 7671 * d3 + 9496 * d2 + 6 * d1; |
| 52 |
q = put_dec_helper4(buf+4, q); |
| 53 |
q += 4749 * d3 + 42 * d2; |
| 54 |
q = put_dec_helper4(buf+8, q); |
| 55 |
return buf; |
| 56 |
} |
| 57 |
|
| 58 |
struct printf_spec { |
| 59 |
unsigned int type:8; |
| 60 |
signed int field_width:24; |
| 61 |
unsigned int flags:8; |
| 62 |
unsigned int base:8; |
| 63 |
signed int precision:16; |
| 64 |
} __attribute__((__packed__)); |
| 65 |
|
| 66 |
static __attribute__ ((noipa)) char * |
| 67 |
number (char *buf, char *end, unsigned long long num, struct printf_spec spec) |
| 68 |
{ |
| 69 |
|
| 70 |
char tmp[3 * sizeof(num)] __attribute__((__aligned__(2))); |
| 71 |
char sign; |
| 72 |
char locase; |
| 73 |
int need_pfx = ((spec.flags & 64) && spec.base != 10); |
| 74 |
int i; |
| 75 |
bool is_zero = num == 0LL; |
| 76 |
int field_width = spec.field_width; |
| 77 |
int precision = spec.precision; |
| 78 |
|
| 79 |
i = 0; |
| 80 |
if (num < spec.base) |
| 81 |
tmp[i++] = hex_asc_upper[num] | locase; |
| 82 |
else if (spec.base != 10) { |
| 83 |
int mask = spec.base - 1; |
| 84 |
int shift = 3; |
| 85 |
if (spec.base == 16) |
| 86 |
shift = 4; |
| 87 |
else |
| 88 |
__builtin_abort (); |
| 89 |
do { |
| 90 |
tmp[i++] = (hex_asc_upper[((unsigned char)num) & mask] | locase); |
| 91 |
num >>= shift; |
| 92 |
} while (num); |
| 93 |
} else { |
| 94 |
i = put_dec(tmp, num) - tmp; |
| 95 |
} |
| 96 |
return buf; |
| 97 |
} |
| 98 |
|
| 99 |
static __attribute__ ((noipa)) char * |
| 100 |
pointer_string (char *buf, char *end, const void *ptr, struct printf_spec spec) |
| 101 |
{ |
| 102 |
spec.base = 16; |
| 103 |
spec.flags = 0; |
| 104 |
return number(buf, end, 100, spec); |
| 105 |
} |
| 106 |
|
| 107 |
int |
| 108 |
main (void) |
| 109 |
{ |
| 110 |
struct printf_spec spec; |
| 111 |
char *s = pointer_string (0, 0, 0, spec); |
| 112 |
return 0; |
| 113 |
} |