Index: src/runtime/lookup-asm/lookup-asm-x86-elf.S ================================================================== --- src/runtime/lookup-asm/lookup-asm-x86-elf.S +++ src/runtime/lookup-asm/lookup-asm-x86-elf.S @@ -61,12 +61,13 @@ add eax, offset _GLOBAL_OFFSET_TABLE_ lea eax, [eax+\not_found@GOTOFF] jmp eax .Ltagged_pointer_\name: + and dl, 0xF + shr dl, 1 movzx edx, dl - shr edx, 1 call get_eip add eax, offset _GLOBAL_OFFSET_TABLE_ lea eax, [eax+objc_tagged_pointer_classes@GOTOFF] Index: src/runtime/lookup-asm/lookup-asm-x86-win32.S ================================================================== --- src/runtime/lookup-asm/lookup-asm-x86-win32.S +++ src/runtime/lookup-asm/lookup-asm-x86-win32.S @@ -53,12 +53,13 @@ jz \not_found ret .Ltagged_pointer_\name: + and dl, 0xF + shr dl, 1 movzx edx, dl - shr edx, 1 mov eax, offset _objc_tagged_pointer_classes mov edx, [eax+edx*4] mov edx, [edx+32] Index: src/runtime/lookup-asm/lookup-asm-x86_64-elf.S ================================================================== --- src/runtime/lookup-asm/lookup-asm-x86_64-elf.S +++ src/runtime/lookup-asm/lookup-asm-x86_64-elf.S @@ -54,12 +54,13 @@ jz short \not_found@PLT ret .Ltagged_pointer_\name: + and dil, 0xF + shr dil, 1 movzx r8, dil - shr r8, 1 mov rax, [rip+objc_tagged_pointer_classes@GOTPCREL] mov r8, [rax+r8*8] mov r8, [r8+64] Index: src/runtime/lookup-asm/lookup-asm-x86_64-win64.S ================================================================== --- src/runtime/lookup-asm/lookup-asm-x86_64-win64.S +++ src/runtime/lookup-asm/lookup-asm-x86_64-win64.S @@ -60,12 +60,13 @@ mov rcx, r10 mov rdx, r11 jmp \not_found .Ltagged_pointer_\name: + and cl, 0xF + shr cl, 1 movzx r8, cl - shr r8, 1 mov rax, offset objc_tagged_pointer_classes mov r8, [rax+r8*8] mov r8, [r8+56] Index: src/runtime/tagged-pointer.m ================================================================== --- src/runtime/tagged-pointer.m +++ src/runtime/tagged-pointer.m @@ -17,11 +17,12 @@ #import "ObjFWRT.h" #import "private.h" -#define NUM_TAGGED_POINTER_CLASSES 0x7F +#define TAGGED_POINTER_BITS 4 +#define NUM_TAGGED_POINTER_CLASSES (1 << (TAGGED_POINTER_BITS - 1)) Class objc_tagged_pointer_classes[NUM_TAGGED_POINTER_CLASSES]; static uint_fast8_t taggedPointerClassesCount; int_fast8_t @@ -47,11 +48,11 @@ Class object_getTaggedPointerClass(id object) { uintptr_t pointer = (uintptr_t)object; - pointer &= 0x7E; + pointer &= (1 << TAGGED_POINTER_BITS) - 1; pointer >>= 1; if (pointer >= NUM_TAGGED_POINTER_CLASSES) return Nil; @@ -61,12 +62,11 @@ uintptr_t object_getTaggedPointerValue(id object) { uintptr_t pointer = (uintptr_t)object; - pointer &= ~(uintptr_t)0xFF; - pointer >>= 8; + pointer >>= TAGGED_POINTER_BITS; return pointer; } id @@ -75,13 +75,13 @@ uintptr_t pointer; if (class >= NUM_TAGGED_POINTER_CLASSES) return nil; - if (value > (UINTPTR_MAX >> 8)) + if (value > (UINTPTR_MAX >> TAGGED_POINTER_BITS)) return nil; pointer = (class << 1) | 1; - pointer |= (value << 8); + pointer |= (value << TAGGED_POINTER_BITS); return (id)pointer; }