An Illustrated History of objc_msgSend

index   |   Jaguar   >>

PowerPC: Cheetah and Puma

Cheetah, Puma
_objc_msgSend:                                                     
        cmplwi r3,  0         if (self == nil)                     
        beq    NIL                return zero                      
        stw    r8,  44(r1)                                         
        stw    r9,  48(r1)    save non-volatile registers          
        stw    r10, 52(r1)                                         
        lwz    r12, 0(r3)     class = self->isa                    
        lwz    r12, 32(r12)   cache = class->cache                 
        lwz    r11, 0(r12)    mask = cache->mask                   
        addi   r9,  r12, 8    buckets = cache->buckets             
        and    r12, r4,  r11  index = _cmd & mask                  
 LOOP:  slwi   r0,  r12, 2    offset = index * 4                   
        lwzx   r10, r9,  r0   method = buckets[offset]             
        cmplwi r10, 0         if (method == nil)                   
        beq    MISS               goto cache miss                  
        addi   r12, r12, 1    index++                              
        lwz    r8,  0(r10)    sel = method->sel                    
        and    r12, r12, r11  index &= mask                        
        lwz    r10, 8(r10)    imp = method->imp                    
        cmplw  r8,  r4        if (sel != _cmd)                     
        bne    LOOP               scan more                        
        mr     r12, r10       r12 = imp                            
        mtctr  r10            ctr = imp                            
        lwz    r8,  44(r1)                                         
        lwz    r9,  48(r1)    restore saved registers              
        lwz    r10, 52(r1)                                         
        li     r11, 0         set non-struct return for forwarding 
        bctr                  jump to imp                          

The PowerPC implementation in Mac OS X 10.0 was likely based on one of the other architectures supported by NeXT.

objc_msgSend was unchanged in Puma.

index   |   Jaguar   >>