[ardour-dev] Patch for optimization on OSX

Stéphane Letz letz at grame.fr
Mon Sep 19 05:47:17 PDT 2005


Here is a patch to use the Apple Accelerate framework (a library of  
optimized functions on both G3 and G4,G5 altivec based machines) to  
implement the CPU critical functions that were recently optimized for  
SSE on X86.

The patch will be usefull *only* on 10.4 Tiger, since some of the  
used functions are not available in older version of the Accelerate  
framework. The optimized functions will be activated only when Ardour  
runs on a Tiger system.

The following had to be added in the link phase  (I did it in the  
global SConstruct  folder but I'm not sure this is the right place...):

-framework Accelerate

It accelerate quite a bit on atltivec: Testetd on G5, at least twice  
faster on the DSP CPU part that is spend in those functions. It  
should accelerate also on G3, since even the scalar version of these  
function is much more optimized compared to standard C written code.

Stephane




-------------- next part --------------
diff -ru /Volumes/Document1/Developpement/ProjectsCVS/ArdourCVS/ardour-0.9beta30-old/libs/ardour/ardour/mix.h /Volumes/Document1/Developpement/ProjectsCVS/ArdourCVS/ardour-0.9beta30/libs/ardour/ardour/mix.h
--- /Volumes/Document1/Developpement/ProjectsCVS/ArdourCVS/ardour-0.9beta30-old/libs/ardour/ardour/mix.h	2005-09-08 21:40:55.000000000 +0200
+++ /Volumes/Document1/Developpement/ProjectsCVS/ArdourCVS/ardour-0.9beta30/libs/ardour/ardour/mix.h	2005-09-19 13:24:51.000000000 +0200
@@ -49,6 +49,18 @@
 
 #endif
 
+#if defined (__APPLE__)
+
+float veclib_compute_peak		(ARDOUR::Sample *buf, jack_nframes_t nsamples, float current);
+
+void  veclib_apply_gain_to_buffer	(ARDOUR::Sample *buf, jack_nframes_t nframes, float gain);
+
+void  veclib_mix_buffers_with_gain	(ARDOUR::Sample *dst, ARDOUR::Sample *src, jack_nframes_t nframes, float gain);
+
+void  veclib_mix_buffers_no_gain	(ARDOUR::Sample *dst, ARDOUR::Sample *src, jack_nframes_t nframes);
+
+#endif
+
 /* non-optimized functions */
 
 float compute_peak			(ARDOUR::Sample *buf, jack_nframes_t nsamples, float current);
diff -ru /Volumes/Document1/Developpement/ProjectsCVS/ArdourCVS/ardour-0.9beta30-old/libs/ardour/globals.cc /Volumes/Document1/Developpement/ProjectsCVS/ArdourCVS/ardour-0.9beta30/libs/ardour/globals.cc
--- /Volumes/Document1/Developpement/ProjectsCVS/ArdourCVS/ardour-0.9beta30-old/libs/ardour/globals.cc	2005-09-08 21:40:55.000000000 +0200
+++ /Volumes/Document1/Developpement/ProjectsCVS/ArdourCVS/ardour-0.9beta30/libs/ardour/globals.cc	2005-09-19 13:06:00.000000000 +0200
@@ -49,6 +49,10 @@
 
 #include <ardour/mix.h>
 
+#if defined (__APPLE__)
+	#include <Carbon/Carbon.h> // For Gestalt
+#endif
+	
 #include "i18n.h"
 
 ARDOUR::Configuration* ARDOUR::Config = 0;
@@ -217,13 +221,27 @@
 
 		}
 
-#else
-		Session::compute_peak 		= compute_peak;
-		Session::apply_gain_to_buffer 	= apply_gain_to_buffer;
-		Session::mix_buffers_with_gain 	= mix_buffers_with_gain;
-		Session::mix_buffers_no_gain 	= mix_buffers_no_gain;
-
-		info << "No H/W specific optimizations in use" << endmsg;
+#else if defined (__APPLE__)
+		long sysVersion = 0;
+        if (noErr != Gestalt(gestaltSystemVersion, &sysVersion))
+            sysVersion = 0;
+			
+		if (sysVersion >= 0x00001040) { // Tiger at least
+			Session::compute_peak 		= veclib_compute_peak;
+			Session::apply_gain_to_buffer 	= veclib_apply_gain_to_buffer;
+			Session::mix_buffers_with_gain 	= veclib_mix_buffers_with_gain;
+			Session::mix_buffers_no_gain 	= veclib_mix_buffers_no_gain;
+			
+			info << "Apple VecLib H/W specific optimizations in use" << endmsg;
+		} else {
+  			Session::compute_peak 		= compute_peak;
+			Session::apply_gain_to_buffer 	= apply_gain_to_buffer;
+			Session::mix_buffers_with_gain 	= mix_buffers_with_gain;
+			Session::mix_buffers_no_gain 	= mix_buffers_no_gain;
+			
+			info << "No H/W specific optimizations in use" << endmsg;
+		}
+		
 #endif
 	} else {
 
diff -ru /Volumes/Document1/Developpement/ProjectsCVS/ArdourCVS/ardour-0.9beta30-old/libs/ardour/mix.cc /Volumes/Document1/Developpement/ProjectsCVS/ArdourCVS/ardour-0.9beta30/libs/ardour/mix.cc
--- /Volumes/Document1/Developpement/ProjectsCVS/ArdourCVS/ardour-0.9beta30-old/libs/ardour/mix.cc	2005-09-07 22:19:26.000000000 +0200
+++ /Volumes/Document1/Developpement/ProjectsCVS/ArdourCVS/ardour-0.9beta30/libs/ardour/mix.cc	2005-09-19 13:37:13.000000000 +0200
@@ -114,4 +114,35 @@
 	}
 }
 		
+#if defined (__APPLE__)
+#include <Accelerate/Accelerate.h>
+
+float
+veclib_compute_peak (ARDOUR::Sample *buf, jack_nframes_t nsamples, float current) 
+{
+	vDSP_maxv(buf, 1, &current, nsamples);
+	return current;
+}	
+
+void
+veclib_apply_gain_to_buffer (ARDOUR::Sample *buf, jack_nframes_t nframes, float gain)
+{		
+	vDSP_vsmul(buf, 1, &gain, buf, 1, nframes);
+}
+
+void
+veclib_mix_buffers_with_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, jack_nframes_t nframes, float gain)
+{
+	vDSP_vsma(src, 1, &gain, dst, 1, dst, 1, nframes);
+}
+
+void
+veclib_mix_buffers_no_gain (ARDOUR::Sample *dst, ARDOUR::Sample *src, jack_nframes_t nframes)
+{
+	// It seems that a vector mult only operation does not exist...
+	float gain = 1.0f;
+	vDSP_vsma(src, 1, &gain, dst, 1, dst, 1, nframes);
+}
+
+#endif
 
-------------- next part --------------



More information about the ardour-dev-ardour.org mailing list