Skip to contentSkip to conversation

Enabled building of x86_64 code on Mac OS X

PATCH Applied Alexander Graf 6 participants 10 messages Jan 24, 2009 – Jan 27, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Enabled building of x86_64 code on Mac OS X

Mac OS X 10.5 supports 64-bit userspace on an x86_64 kernel and by default uses 32-bit userspace applications, so the detection for the host architecture fails.

This patch enabled building of x86_64 code on x86_64 capable CPUS with Mac OS X.

---
 configure |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)
configure +11 -1
index 3c9d832..c3fbbbe 100755
@@ -243,11 +243,21 @@ oss_lib="-lossaudio"
 Darwin)
 bsd="yes"
 darwin="yes"
+# on Leopard most of the system is 32-bit, so we have to ask the kernel it if we can run 64-bit userspace code
+is_x86_64=`sysctl -n hw.optional.x86_64`
+if [ "$is_x86_64" = "1" ]; then
+    cpu=x86_64
+fi
+if [ "$cpu" = "x86_64" ] ; then
+    OS_CFLAGS="-arch x86_64"
+    LDFLAGS="-arch x86_64"
+else
+    OS_CFLAGS="-mdynamic-no-pic"
+fi
 darwin_user="yes"
 cocoa="yes"
 audio_drv_list="coreaudio"
 audio_possible_drivers="coreaudio sdl fmod"
-OS_CFLAGS="-mdynamic-no-pic"
 OS_LDFLAGS="-framework CoreFoundation -framework IOKit"
 ;;
 SunOS)
Signature · 1 line
1.6.0.2
#1 lore raw
Quoted 7 lines · Alexander Graf

Mac OS X 10.5 supports 64-bit userspace on an x86_64 kernel and by default uses 32-bit userspace applications, so the detection for the host architecture fails.

This patch enabled building of x86_64 code on x86_64 capable CPUS with Mac OS X.

Applied. Thanks.

Out of curiousity, what are the benefits of using 64-bit apps in OS X? I guess greater memory addressability is important for QEMU.

Regards,

Anthony Liguori

#2 lore raw
Quoted 1 line

Out of curiousity, what are the benefits of using 64-bit apps in OS X?

My guess is that same as most other x86 targets: The i386 legacy mode is crippled by lack of registers, modern x86 hardware has a big fat wide memory bus, and noone's bothered implementing an ILP32 64-bit API[1], so 64-bit apps give measurably better overall performance.

Paul

[1] ILP32 APIs for 64-bit x86 do exist, but the architecture is missing a couple of features so they're a bit hairy, and AFAIK not supported by any mainstream operating systems.

#3 lore raw
Quoted 7 lines · Paul Brook
Quoted 1 line

Out of curiousity, what are the benefits of using 64-bit apps in OS X?

My guess is that same as most other x86 targets: The i386 legacy mode is crippled by lack of registers, modern x86 hardware has a big fat wide memory bus, and noone's bothered implementing an ILP32 64-bit API[1], so 64-bit apps give measurably better overall performance.

Except they use more memory and memory bandwidth (arguably filling nearly half of it with zeros most of the time :-) so worse overall performance in some cases.

-- Jamie

#4 lore raw
Quoted 9 lines · Jamie Lokier
Quoted 7 lines · Paul Brook
Quoted 1 line

Out of curiousity, what are the benefits of using 64-bit apps in OS X?

My guess is that same as most other x86 targets: The i386 legacy mode is crippled by lack of registers, modern x86 hardware has a big fat wide memory bus, and noone's bothered implementing an ILP32 64-bit API[1], so 64-bit apps give measurably better overall performance.

Quoted 3 lines

Except they use more memory and memory bandwidth (arguably filling nearly half of it with zeros most of the time :-) so worse overall performance in some cases.

I did say overall performance.

My experience with AMD hardware is that you generally get ~10% overall improvement from LP64. Intel hardware (particularly the early 64-bit cores) less so, but it's generally still a win.

I guess ILP32 long mode would probably increase that further, and avoid the odd regressions. It's an awful lot of work to implement though, especially on a target that isn't used to having lots of incompatible variants.

Paul

#5 lore raw
Quoted 5 lines · Paul Brook

I did say overall performance.
My experience with AMD hardware is that you generally get ~10% overall improvement from LP64. Intel hardware (particularly the early 64-bit cores) less so, but it's generally still a win.

I guess ILP32 long mode would probably increase that further, and avoid the odd regressions. It's an awful lot of work to implement though, especially on a target that isn't used to having lots of incompatible variants.

I expected a performance boost. Since OS X only runs on Intel CPUs, I don't think it's dramatically worth it to get a few percent CPU improvement. The reason I asked is that if we decided to drop Cocoa in favor of SDL, it would prevent the use of 64-bit.

However, as long as someone is willing to fix Cocoa, I don't think there's any harm keeping it around so it doesn't matter that much.

Regards,

Anthony Liguori

Quoted 3 lines

Paul

#6 lore raw
Quoted 12 lines · Anthony Liguori
Quoted 10 lines · Paul Brook

I did say overall performance.
My experience with AMD hardware is that you generally get ~10% overall improvement from LP64. Intel hardware (particularly the early 64-bit cores) less so, but it's generally still a win.

I guess ILP32 long mode would probably increase that further, and avoid the odd regressions. It's an awful lot of work to implement though, especially on a target that isn't used to having lots of incompatible variants.

Quoted 4 lines

I expected a performance boost. Since OS X only runs on Intel CPUs, I don't think it's dramatically worth it to get a few percent CPU improvement. The reason I asked is that if we decided to drop Cocoa in favor of SDL, it would prevent the use of 64-bit.

The extra registers should speed up things quite a bit. While that's not too much of a problem when emulating x86, which has few registers anyway, emulating a ppc or x86_64 target should be faster on an x86_64 host. I haven't done measurements though.

As for the plus in code size on x86_64 - that doesn't really apply to tcg, as that still generates 32-bit code when only 32-bit code is necessary, which still looks the same on x86_64. Plus it does simplify 64-bit operations.

I would be very surprised if the improvement of emulating x86_64 on x86 vs. x86_64 is only ~10%.

Alex

#7 lore raw
Quoted 4 lines · Alexander Graf

As for the plus in code size on x86_64 - that doesn't really apply to tcg, as that still generates 32-bit code when only 32-bit code is necessary, which still looks the same on x86_64. Plus it does simplify 64-bit operations.

TCG doesn't use the available x86_64 registers when generating code for 32-bit operations on an x86_64 host?

Quoted 2 lines

I would be very surprised if the improvement of emulating x86_64 on x86 vs. x86_64 is only ~10%.

So would I.

By the way, with KVM, can QEMU (the I/O model) be a 32-bit app while the KVM kernel module provides an x86_64 CPU?

That might be useful, if there are advantages to QEMU itself being 32-bit on MacOS X and if there's a KVM module for it.

-- Jamie

#8 lore raw
In reply to Alexander Graf
Quoted 6 lines · Alexander Graf

The extra registers should speed up things quite a bit. While that's not too much of a problem when emulating x86, which has few registers anyway, emulating a ppc or x86_64 target should be faster on an x86_64 host. I haven't done measurements though.

Quoted 7 lines

As for the plus in code size on x86_64 - that doesn't really apply to tcg, as that still generates 32-bit code when only 32-bit code is necessary, which still looks the same on x86_64. Plus it does simplify 64-bit operations.

I would be very surprised if the improvement of emulating x86_64 on x86 vs. x86_64 is only ~10%.

Here is a quick result for user mode.

x on y means running an target x on host y (the host is the same, I just forced --cpu=i386 when compiling qemu).

Host: CentOS 5.2 x86_64, E6600 (2.4GHz)
Benchmark: Spec2k gcc/integrate (compiled with gcc 4.1.2 -O2)

i386 on x86_64
gen code size 4005696/33497088
TB count 30704/524288
real 0m24.983s/user 0m24.834s

x86_64 on x86_64
gen code size 4413408/33497088
TB count 30247/524288
real 0m24.932s/user 0m24.749s

i386 on i386
gen code size 3439008/33497088
TB count 30704/524288
real 0m26.391s/user 0m26.131s

x86_64 on i386
gen code size 5715248/33497088
TB count 30254/524288
real 0m28.233s/user 0m27.985s

Laurent

#9 lore raw
In reply to Anthony Liguori

I think like all X86_64 programs, it has access to more registers than just plain i386. However, that is only on the X86 platform: the PowerPC platform has the same number of registers in both 32 and 64-bit mode.

Quoted 18 lines · Anthony Liguori
Quoted 7 lines · Alexander Graf

Mac OS X 10.5 supports 64-bit userspace on an x86_64 kernel and by default uses 32-bit userspace applications, so the detection for the host architecture fails.

This patch enabled building of x86_64 code on x86_64 capable CPUS with Mac OS X.

Applied. Thanks.

Out of curiousity, what are the benefits of using 64-bit apps in OS X? I guess greater memory addressability is important for QEMU.

Regards,

Anthony Liguori