Ticket #254: tt254-64bit-2.patch
File tt254-64bit-2.patch, 12.9 KB (added by rurban, 13 years ago) |
---|
-
src/packfile.c
old new 148 148 PARROT_CANNOT_RETURN_NULL 149 149 static const opcode_t * directory_unpack(PARROT_INTERP, 150 150 ARGMOD(PackFile_Segment *segp), 151 ARG IN(constopcode_t *cursor))151 ARGMOD(opcode_t *cursor)) 152 152 __attribute__nonnull__(1) 153 153 __attribute__nonnull__(2) 154 154 __attribute__nonnull__(3) 155 FUNC_MODIFIES(*segp); 155 FUNC_MODIFIES(*segp) 156 FUNC_MODIFIES(*cursor); 156 157 157 158 PARROT_WARN_UNUSED_RESULT 158 159 PARROT_CAN_RETURN_NULL … … 453 454 extern int Parrot_exec_run; 454 455 #endif 455 456 456 /* TODO: This is broken on 64/32 transformations. See TT #254 */457 #define ROUND_16(val) (((val) & 0xf) ? 16 - ((val) & 0xf) : 0)458 #define ALIGN_16(st, cursor) \459 (cursor) += ROUND_16((const char *)(cursor) - (const char *)(st))/sizeof (opcode_t)460 457 /* offset not in ptr diff, but in byte */ 461 #define OFFS(cursor) ((pf) ? ((const char *)(cursor) - (const char *)(pf->src)) : 0) 458 #define OFFS(pf, cursor) ((pf) ? ((const char *)(cursor) - (const char *)(pf->src)) : 0) 459 /** 460 * Possible values for ALIGN_16 461 * 4 (32bit): 0 1 2 3 462 * 8 (64bit): 0 1 463 * e.g. reading 4 byte wordsize on 8 byte wordsize: possible ptrs end in 0 4 8 c. 464 * offs(c)/8 => 4/8 = 0 => impossible to align with 8 byte ptr. 465 * Limitation TT #254: ALIGN_16 may only be used native, e.g. in the writer, 466 * but not with 64bit reading 32bit! 467 */ 468 #define ROUND_16(val) (((val) & 0xf) ? 16 - ((val) & 0xf) : 0) 469 #define ALIGN_16(pf, cursor) \ 470 (cursor) += ROUND_16(OFFS(pf, cursor))/sizeof (opcode_t) 471 /* pad to 16 in bytes */ 472 #define PAD_16_B(size) ((size) % 16 ? 16 - (size) % 16 : 0) 462 473 463 474 #if TRACE_PACKFILE 464 475 void … … 854 865 ASSERT_ARGS(do_sub_pragmas) 855 866 PackFile_FixupTable * const ft = self->fixups; 856 867 PackFile_ConstTable * const ct = self->const_table; 857 #if TRACE_PACKFILE858 868 PackFile * const pf = self->base.pf; 859 #endif860 869 opcode_t i; 861 870 862 871 TRACE_PRINTF(("PackFile: do_sub_pragmas (action=%d)\n", action)); … … 997 1006 } 998 1007 else if (header->uuid_type == 1) { 999 1008 /* Read in the UUID. We'll put it in a NULL-terminated string, just in 1000 * case pe pole use it that way. */1009 * case people use it that way. */ 1001 1010 header->uuid_data = (unsigned char *) 1002 1011 mem_sys_allocate(header->uuid_size + 1); 1003 1012 … … 1015 1024 /* Set cursor to position after what we've read, allowing for padding to a 1016 1025 * 16 byte boundary. */ 1017 1026 header_read_length = PACKFILE_HEADER_BYTES + header->uuid_size; 1018 header_read_length += header_read_length % 16 ? 1019 16 - header_read_length % 16 : 0; 1027 header_read_length += PAD_16_B(header_read_length); 1020 1028 cursor = packed + (header_read_length / sizeof (opcode_t)); 1029 TRACE_PRINTF(("PackFile_unpack: pad=%d\n", 1030 (char *)cursor - (char *)packed)); 1021 1031 1022 1032 /* Set what transforms we need to do when reading the rest of the file. */ 1023 1033 PackFile_assign_transforms(self); … … 1445 1455 } 1446 1456 else { 1447 1457 int i; 1458 TRACE_PRINTF(("default_unpack: pre-fetch %d ops into data\n", 1459 self->size)); 1448 1460 for (i = 0; i < (int)self->size; i++) { 1449 1461 self->data[i] = PF_fetch_opcode(self->pf, &cursor); 1450 1462 TRACE_PRINTF(("default_unpack: transformed op[#%d]/%d %u\n", … … 1784 1796 ARGIN(opcode_t *cursor)) 1785 1797 { 1786 1798 ASSERT_ARGS(PackFile_Segment_pack) 1787 const size_t align = 16 / sizeof (opcode_t);1799 /*const size_t align = 16 / sizeof (opcode_t);*/ 1788 1800 PackFile_Segment_pack_func_t f = 1789 1801 self->pf->PackFuncs[self->type].pack; 1802 #if TRACE_PACKFILE 1803 PackFile * const pf = self->pf; 1804 #endif 1790 1805 1791 1806 cursor = default_pack(self, cursor); 1792 1807 1793 1808 if (f) 1794 1809 cursor = (f)(interp, self, cursor); 1795 1810 1796 if (align && (cursor - self->pf->src) % align) 1797 cursor += align - (cursor - self->pf->src) % align; 1811 TRACE_PRINTF_ALIGN(("-ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 1812 OFFS(pf, cursor), pf->src, cursor)); 1813 ALIGN_16(self->pf, cursor); 1814 /*if (align && (cursor - self->pf->src) % align) 1815 cursor += align - (cursor - self->pf->src) % align;*/ 1816 TRACE_PRINTF_ALIGN(("+ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 1817 OFFS(pf, cursor), pf->src, cursor)); 1798 1818 1799 1819 return cursor; 1800 1820 } … … 1824 1844 { 1825 1845 ASSERT_ARGS(PackFile_Segment_unpack) 1826 1846 PackFile_Segment_unpack_func_t f = self->pf->PackFuncs[self->type].unpack; 1847 int offs; 1827 1848 #if TRACE_PACKFILE 1828 1849 PackFile * const pf = self->pf; 1829 1850 #endif … … 1841 1862 return NULL; 1842 1863 } 1843 1864 1844 TRACE_PRINTF_ALIGN(("-ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 1845 OFFS(cursor), pf->src, cursor)); 1846 /* FIXME on 64bit reading 32bit */ 1847 ALIGN_16(self->pf->src, cursor); 1848 TRACE_PRINTF_ALIGN(("+ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 1849 OFFS(cursor), pf->src, cursor)); 1865 offs = OFFS(self->pf, cursor); 1866 TRACE_PRINTF_ALIGN(("-S ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 1867 offs, self->pf->src, cursor)); 1868 offs += PAD_16_B(offs); 1869 cursor = (const char *)(self->pf->src) + offs; 1870 TRACE_PRINTF_ALIGN(("+S ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 1871 offs, self->pf->src, cursor)); 1850 1872 return cursor; 1851 1873 } 1852 1874 … … 1951 1973 PARROT_WARN_UNUSED_RESULT 1952 1974 PARROT_CANNOT_RETURN_NULL 1953 1975 static const opcode_t * 1954 directory_unpack(PARROT_INTERP, ARGMOD(PackFile_Segment *segp), ARG IN(constopcode_t *cursor))1976 directory_unpack(PARROT_INTERP, ARGMOD(PackFile_Segment *segp), ARGMOD(opcode_t *cursor)) 1955 1977 { 1956 1978 ASSERT_ARGS(directory_unpack) 1957 1979 PackFile_Directory * const dir = (PackFile_Directory *) segp; 1958 1980 PackFile * const pf = dir->base.pf; 1959 1981 const opcode_t *pos; 1960 1982 size_t i; 1983 int offs; 1961 1984 1962 1985 dir->num_segments = PF_fetch_opcode(pf, &cursor); 1963 1986 TRACE_PRINTF(("directory_unpack: %ld num_segments\n", dir->num_segments)); … … 2003 2026 return 0; 2004 2027 } 2005 2028 TRACE_PRINTF_VAL(("Segment offset: new pos 0x%x " 2006 "(src=0x%x cursor=0x%x).\n", pos - pf->src, pf->src, cursor)); 2029 "(src=0x%x cursor=0x%x).\n", 2030 OFFS(pf, pos), pf->src, cursor)); 2007 2031 } 2008 2032 else 2009 2033 pos = pf->src + seg->file_offset; … … 2030 2054 seg->dir = dir; 2031 2055 } 2032 2056 2057 offs = OFFS(pf, cursor); 2033 2058 TRACE_PRINTF_ALIGN(("-ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 2034 OFFS(cursor), pf->src, cursor));2035 /* FIXME on 64bit reading 32bit */2036 ALIGN_16(pf->src, cursor);2059 offs, pf->src, cursor)); 2060 offs += PAD_16_B(offs); 2061 cursor = (const char *)(pf->src) + offs; 2037 2062 TRACE_PRINTF_ALIGN(("+ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 2038 OFFS(cursor), pf->src, cursor));2063 offs, pf->src, cursor)); 2039 2064 2040 2065 /* and now unpack contents of dir */ 2041 2066 for (i = 0; cursor && i < dir->num_segments; i++) { … … 2073 2098 else 2074 2099 delta = pos - cursor; 2075 2100 2076 TRACE_PRINTF_VAL((" delta=%d pos=0x%xcursor=0x%x\n",2101 TRACE_PRINTF_VAL((" delta=%d, pos=0x%x, cursor=0x%x\n", 2077 2102 delta, pos, cursor)); 2078 2103 2079 2104 if ((size_t)delta != tmp || dir->segments[i]->op_count != tmp) … … 2233 2258 ASSERT_ARGS(directory_pack) 2234 2259 PackFile_Directory * const dir = (PackFile_Directory *)self; 2235 2260 const size_t num_segs = dir->num_segments; 2236 const size_t align = 16/sizeof (opcode_t);2261 /*const size_t align = 16/sizeof (opcode_t);*/ 2237 2262 size_t i; 2263 PackFile * const pf = self->pf; 2238 2264 2239 2265 *cursor++ = num_segs; 2240 2266 … … 2246 2272 *cursor++ = seg->op_count; 2247 2273 } 2248 2274 2249 if (align && (cursor - self->pf->src) % align) 2250 cursor += align - (cursor - self->pf->src) % align; 2275 TRACE_PRINTF_ALIGN(("-ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 2276 OFFS(pf, cursor), pf->src, cursor)); 2277 ALIGN_16(pf, cursor); 2278 TRACE_PRINTF_ALIGN(("+ALIGN_16: offset=0x%x src=0x%x cursor=0x%x\n", 2279 OFFS(pf, cursor), pf->src, cursor)); 2280 /*if (align && (cursor - self->pf->src) % align) 2281 cursor += align - (cursor - self->pf->src) % align;*/ 2251 2282 2252 2283 /* now pack all segments into new format */ 2253 2284 for (i = 0; i < dir->num_segments; i++) { -
src/packfile/pf_items.c
old new 231 231 /* 232 232 * offset not in ptr diff, but in byte 233 233 */ 234 #define OFFS( cursor) ((pf) ? ((const char *)(cursor) - (const char *)(pf->src)) : 0)234 #define OFFS(pf, cursor) ((pf) ? ((const char *)(cursor) - (const char *)(pf->src)) : 0) 235 235 236 236 /* 237 237 * low level FLOATVAL fetch and convert functions … … 456 456 457 457 Converts IEEE 754 16-byte long double to IEEE 754 8 byte double. 458 458 459 Testedok.459 First variant ok, 2nd not ok. 460 460 461 461 =cut 462 462 … … 478 478 479 479 } 480 480 else { 481 481 /* FIXME: This codepath fails */ 482 482 int expo, i, s; 483 483 #ifdef __LCC__ 484 484 int expo2; … … 970 970 fetch_buf_le_4(u.buf, b); 971 971 #if PARROT_BIGENDIAN 972 972 # if OPCODE_T_SIZE == 8 973 return u.o >> 32;973 return (Parrot_Int4)(u.o >> 32); 974 974 # else 975 975 return (opcode_t) fetch_iv_be((INTVAL)u.o); 976 976 # endif 977 977 #else 978 978 # if OPCODE_T_SIZE == 8 979 return u.o & 0xffffffff; 979 /* without the cast we would not get a negative int, the vtable indices */ 980 return (Parrot_Int4)(u.o & 0xffffffff); 980 981 # else 981 982 return u.o; 982 983 # endif … … 1037 1038 return *(*stream)++; 1038 1039 o = (pf->fetch_op)(*((const unsigned char **)stream)); 1039 1040 TRACE_PRINTF_VAL((" PF_fetch_opcode: 0x%lx (%ld), at 0x%x\n", 1040 o, o, OFFS( *stream)));1041 o, o, OFFS(pf, *stream))); 1041 1042 *((const unsigned char **) (stream)) += pf->header->wordsize; 1042 1043 return o; 1043 1044 } … … 1107 1108 return *(*stream)++; 1108 1109 i = (pf->fetch_iv)(*((const unsigned char **)stream)); 1109 1110 TRACE_PRINTF_VAL((" PF_fetch_integer: 0x%x (%d) at 0x%x\n", i, i, 1110 OFFS( *stream)));1111 OFFS(pf, *stream))); 1111 1112 /* XXX assume sizeof (opcode_t) == sizeof (INTVAL) on the 1112 1113 * machine producing this PBC. 1113 1114 * … … 1182 1183 TRACE_PRINTF(("PF_fetch_number: Native [%d bytes]\n", 1183 1184 sizeof (FLOATVAL))); 1184 1185 memcpy(&f, (const char *)*stream, sizeof (FLOATVAL)); 1185 TRACE_PRINTF_VAL(("PF_fetch_number: %f at 0x%x\n", f, OFFS( *stream)));1186 TRACE_PRINTF_VAL(("PF_fetch_number: %f at 0x%x\n", f, OFFS(pf, *stream))); 1186 1187 (*stream) += (sizeof (FLOATVAL) + sizeof (opcode_t) - 1)/ 1187 1188 sizeof (opcode_t); 1188 1189 return f; 1189 1190 } 1190 1191 f = (FLOATVAL) 0; 1191 TRACE_PRINTF(("PF_fetch_number at 0x%x: Converting...\n", OFFS( *stream)));1192 TRACE_PRINTF(("PF_fetch_number at 0x%x: Converting...\n", OFFS(pf, *stream))); 1192 1193 /* 12->8 has a messy cast. */ 1193 1194 if (NUMVAL_SIZE == 8 && pf->header->floattype == FLOATTYPE_12) { 1194 1195 (pf->fetch_nv)((unsigned char *)&d, (const unsigned char *) *stream); … … 1309 1310 1310 1311 /* print only printable characters */ 1311 1312 TRACE_PRINTF_VAL(("PF_fetch_string(): string is '%s' at 0x%x\n", 1312 s->strstart, OFFS( *cursor)));1313 s->strstart, OFFS(pf, *cursor))); 1313 1314 1314 1315 /* s = string_make(interp, *cursor, size, 1315 1316 encoding_lookup_index(encoding), … … 1318 1319 (const char *)*cursor + size, size, wordsize)); 1319 1320 size = ROUND_UP_B(size, wordsize); 1320 1321 TRACE_PRINTF(("PF_fetch_string(): round size up to %ld.\n", size)); 1321 *((const unsigned char **) 1322 *((const unsigned char **)(cursor)) += size; 1322 1323 TRACE_PRINTF_ALIGN(("+s ROUND_UP_B: cursor=0x%x, size=%d\n", *cursor, size)); 1323 1324 return s; 1324 1325 } … … 1432 1433 TRACE_PRINTF(("PF_fetch_cstring(): size is %ld...\n", str_len)); 1433 1434 strcpy(p, (const char*) (*cursor)); 1434 1435 TRACE_PRINTF_VAL(("PF_fetch_cstring(): string is '%s' at 0x%x\n", 1435 p, OFFS( *cursor)));1436 p, OFFS(pf, *cursor))); 1436 1437 TRACE_PRINTF_ALIGN(("-s ROUND_UP_B: cursor=0x%x, size=%d, wordsize=%d (cstring)\n", 1437 1438 *cursor, str_len, wordsize)); 1438 1439 *((const unsigned char **) (cursor)) += ROUND_UP_B(str_len, wordsize); 1439 1440 TRACE_PRINTF_ALIGN(("+s ROUND_UP_B: cursor=0x%x, offset=0x%x\n", 1440 *cursor, OFFS( *cursor)));1441 *cursor, OFFS(pf, *cursor))); 1441 1442 1442 1443 return p; 1443 1444 }