supernova: c++11 compile fix
[supercollider.git] / platform / mac / SuperColliderAU / AUSDK / CAVectorUnit.cpp
blob64ce5a8a050b912eb2b2fabbe0dffc3c05ffcf89
1 /* Copyright © 2007 Apple Inc. All Rights Reserved.
3 Disclaimer: IMPORTANT: This Apple software is supplied to you by
4 Apple Inc. ("Apple") in consideration of your agreement to the
5 following terms, and your use, installation, modification or
6 redistribution of this Apple software constitutes acceptance of these
7 terms. If you do not agree with these terms, please do not use,
8 install, modify or redistribute this Apple software.
10 In consideration of your agreement to abide by the following terms, and
11 subject to these terms, Apple grants you a personal, non-exclusive
12 license, under Apple's copyrights in this original Apple software (the
13 "Apple Software"), to use, reproduce, modify and redistribute the Apple
14 Software, with or without modifications, in source and/or binary forms;
15 provided that if you redistribute the Apple Software in its entirety and
16 without modifications, you must retain this notice and the following
17 text and disclaimers in all such redistributions of the Apple Software.
18 Neither the name, trademarks, service marks or logos of Apple Inc.
19 may be used to endorse or promote products derived from the Apple
20 Software without specific prior written permission from Apple. Except
21 as expressly stated in this notice, no other rights or licenses, express
22 or implied, are granted by Apple herein, including but not limited to
23 any patent rights that may be infringed by your derivative works or by
24 other works in which the Apple Software may be incorporated.
26 The Apple Software is provided by Apple on an "AS IS" basis. APPLE
27 MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
28 THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
29 FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
30 OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
32 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
33 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
36 MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
37 AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
38 STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
39 POSSIBILITY OF SUCH DAMAGE.
41 /*=============================================================================
42 CAVectorUnit.cpp
44 =============================================================================*/
46 #include "CAVectorUnit.h"
48 #if !TARGET_OS_WIN32
49 #include <sys/sysctl.h>
50 #elif HAS_IPP
51 #include "ippdefs.h"
52 #include "ippcore.h"
53 #endif
55 int CAVectorUnit::sVectorUnitType = kVecUninitialized;
57 SInt32 CAVectorUnit::CheckVectorUnit()
59 int result = kVecNone;
61 #if !TARGET_OS_WIN32
62 #if DEBUG
63 if (getenv("CA_NoVector")) {
64 fprintf(stderr, "CA_NoVector set; Vector unit optimized routines will be bypassed\n");
65 return result;
67 else
68 #endif
70 #if (TARGET_CPU_PPC || TARGET_CPU_PPC64)
71 int sels[2] = { CTL_HW, HW_VECTORUNIT };
72 int vType = 0; //0 == scalar only
73 size_t length = sizeof(vType);
74 int error = sysctl(sels, 2, &vType, &length, NULL, 0);
75 if (!error && vType > 0)
76 result = kVecAltivec;
77 #elif (TARGET_CPU_X86 || TARGET_CPU_X86_64)
78 int answer = 0;
79 size_t length = sizeof(answer);
80 int error = sysctlbyname("hw.optional.sse3", &answer, &length, NULL, 0);
81 if (!error && answer)
82 result = kVecSSE3;
83 else {
84 answer = 0;
85 length = sizeof(answer);
86 error = sysctlbyname("hw.optional.sse2", &answer, &length, NULL, 0);
87 if (!error && answer)
88 result = kVecSSE2;
90 #endif
92 #elif HAS_IPP
93 int error = ippStaticInit();
94 if(ippStsNoErr == error)
96 switch(ippGetCpuType())
98 case ippCpuP4HT2:
99 case ippCpuDS:
100 result = kVecSSE3;
101 break;
102 case ippCpuP4:
103 case ippCpuP4HT:
104 case ippCpuCentrino:
105 result = kVecSSE2;
106 break;
107 default:
108 break;
111 #endif
112 sVectorUnitType = result;
113 return result;