5 // This function could be made to do a binary search if we can
6 // manage to somehow sort the IFaceTables...
8 uintptr_t downcast(::System::_i_Object *obj,
9 const unsigned long *new_guid)
14 void unsupported_long_size();
16 if (sizeof(long) != 4 && sizeof(long) != 8)
17 unsupported_long_size();
19 IFaceTable *tbl = obj->info->concrete_IFaceTable;
20 unsigned long new_guid_first = *new_guid;
22 // This doesn't use guids_equal(), as that would eliminate the
23 // ability to cache the first word of new_guid. The compiler
24 // *might* do it anyway, but this code was written before
25 // guids_equal existed, and I don't want to risk removing an
26 // optimization by changing it now without testing how GCC
30 if (tbl->guid[0] == new_guid_first &&
31 tbl->guid[1] == new_guid[1] &&
33 (tbl->guid[2] == new_guid[2] &&
34 tbl->guid[3] == new_guid[3])))
38 if (__builtin_expect(!tbl->guid, 0))
42 uintptr_t ptr = reinterpret_cast<uintptr_t>(obj);
44 ptr += obj->info->concrete;
50 unsigned long get_pc()
52 return reinterpret_cast<unsigned long>(__builtin_return_address(0));