« September 2009 | Main | December 2009 »

November 2009 Archives

November 13, 2009

The beginning of a bigger change ?

So I try to compile some older code (10.5) on SnowLeopard and I get:
error: @defs is not supported in new abi

The offending code looks something like this

@interface Foo
{
   void   *table1_;
}
@endif

static inline BOOL   Foo_IsASpecialObject( Foo *self, id p)
{
   return( NSHashGet( ((struct { @defs( Foo) } *) self)->table1_, p) != nil);
}
If you find this a little obscure, I once wrote an article about it (look for Using inline functions instead of method calls)

These are all the solutions to this particular problem I came up with:

  1. don't use the new ABI / abandon platform
  2. pester ABI maintainer to support @defs
  3. pester ABI maintainer to support static inline between @interface and @end
  4. painstakingly create a shadow struct, that mimics the Foo class
  5. unprotect inline accessed instance variables in Foo with @public
Just ignoring the ABI and sticking to 32 bit is a dead end on Mac OS X, so it's not an option. Option #2 and #3, well call me negative but I am also not buying lottery tickets because of the bad odds. Option #4 is extremely fragile, I don't want that. So for now I will have to make the instance variables @public. SIGH!

November 15, 2009

va_list is now an array of some (opaque ?) struct... gee thanks

A little trap in the new 64 bit ABI.
void   bar( va_list args)
{
   va_list   x;  
   
   x = args;
   return( va_arg( x, int));
}
does not work anymore. It gives the error

error: array type 'va_list' (aka 'struct __va_list_tag [1]') is not assignable

I was curious if there was any "obvious" change in functionality. Here is the part of a function calling bar disassembled for three different architectures. The disassembly shows, that it's the same internally, two pointers are pushed unto the stack (put into parameter registers).

x86_64
	movq	%rbx, %rsi
	movl	%r12d, %edi
	call	_bar

i386:
	movl	-12(%ebp), %eax
	movl	%eax, 4(%esp)
	movl	8(%ebp), %eax
	movl	%eax, (%esp)
	call	_bar

ppc:
	lwz r4,76(r1)
	mr r3,r29
	bl _bar
What does work in the old and the new world is
void   bar( va_list args)
{
   va_list   *x;  
   
   x = &args;
   return( va_arg( *x, int));
}
where I incur one pointer indirection due to syntax. I am still forming an opinion on that...

November 19, 2009

A small x86_64 optimization brainteaser [with complete solution]

Can you make this code - method abc - run faster with x86_64 ?
#import <Foundation/Foundation.h>

@interface Foo : NSObject 
{
   long  a;
   long  b;
   long  c;
}

- (long) abc;

@end

@implementation Foo

- (long) abc
{
   return( self->a + self->b + self->c);
}

@end
Hint: Think about reorganization or restructuring.
Reference toolchain is stock Xcode 3.2 with default gcc 4.2 and Release setting.

The solution is in the full text.

Continue reading "A small x86_64 optimization brainteaser [with complete solution]" »

About November 2009

This page contains all entries posted to Nat!'s Web Journal in November 2009. They are listed from oldest to newest.

September 2009 is the previous archive.

December 2009 is the next archive.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 4.25