Skip to content

Commit

Permalink
Merge pull request surge-synthesizer#1 from kurasu/master
Browse files Browse the repository at this point in the history
updating from kurasu
  • Loading branch information
esaruoho authored Dec 14, 2018
2 parents 6ce5bb6 + 3cd6775 commit 7de625c
Show file tree
Hide file tree
Showing 17 changed files with 108 additions and 681 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,7 @@ An example of setting the environment variable `VST2SDK_DIR` would be:
```export VST2SDK_DIR=~/programming/VST_SDK_2.4```

***NOTE***: This environment variable needs to be set _before_ running `premake5 xcode4` - which generates projects / and is part of the `build-osx.sh` script.

## References

* IRC channel #surgesynth @ irc.freenode.net
46 changes: 21 additions & 25 deletions src/common/AbstractSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,37 @@
// Copyright 2005 Claes Johanson & vember|audio
//-------------------------------------------------------------------------------------------------------
#include "AbstractSynthesizer.h"
#if WINDOWS
#include <Windows.h>
#endif

#define SSE_STATE_FLAG 0x8040

#if !MAC && !__linux__
#include <CpuArchitecture.h>

int SSE_VERSION;

#include <Windows.h>
#endif
const char *SSE2ErrorText =
"This plugin requires a CPU supporting the SSE2 instruction set.";
const char *CMOVErrorText =
"This plugin requires a CPU supporting the CMOV instruction.";

void initDllGlobals()
{
#if !MAC && !__linux__ // intel macs always support SSE2
unsigned int arch = determine_support();
// detect
if (arch & ca_SSE3)
{
SSE_VERSION = 3;
}
else if (arch & ca_SSE2)
{
SSE_VERSION = 2;
}
else
initCpuArchitecture();

if (!(CpuArchitecture & CaSSE2))
{
SSE_VERSION = 0;
MessageBox(::GetActiveWindow(),
"This plugin requires a CPU supporting the SSE2 instruction set.",
#if WINDOWS
MessageBox(::GetActiveWindow(), SSE2ErrorText,
"Surge: System requirements not met", MB_OK | MB_ICONERROR);
#else
fprintf(stderr, "%s: %s", __func__, SSE2ErrorText);
#endif
}
if (!(arch & ca_CMOV))
if (!(CpuArchitecture & CaCMOV))
{
MessageBox(::GetActiveWindow(), "This plugin requires a CPU supporting the CMOV instruction.",
#if WINDOWS
MessageBox(::GetActiveWindow(), CMOVErrorText,
"Surge: System requirements not met", MB_OK | MB_ICONERROR);
}
#else
fprintf(stderr, "%s: %s", __func__, CMOVErrorText);
#endif
}
}
39 changes: 14 additions & 25 deletions src/common/CpuArchitecture.cpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,33 @@
#if !MAC
#include "CpuArchitecture.h"
#include <string.h>

unsigned int CpuArchitecture = 0;

extern "C" void __cpuid(int* CPUInfo, int InfoType);
#pragma intrinsic(__cpuid)

unsigned int determine_support()
void initCpuArchitecture()
{
unsigned int arch = 0;
#if WINDOWS
int CPUInfo[4] = {-1};
__cpuid(CPUInfo, 0);
char vendor[12];
memcpy(vendor, &CPUInfo[1], 4 * sizeof(char));
memcpy(&vendor[8], &CPUInfo[2], 4 * sizeof(char));
memcpy(&vendor[4], &CPUInfo[3], 4 * sizeof(char));
if (!CPUInfo[0])
return 0; // no additional instructions supported
return; // no additional instructions supported

__cpuid(CPUInfo, 1);
if ((1 << 15) & CPUInfo[3])
arch |= ca_CMOV;
if ((1 << 25) & CPUInfo[3])
arch |= ca_SSE;
CpuArchitecture |= CaCMOV;
if ((1 << 26) & CPUInfo[3])
arch |= ca_SSE2;
if (CPUInfo[2] & 0x1)
arch |= ca_SSE3;

// get number of extended pages
__cpuid(CPUInfo, 0x80000000);
unsigned int extendedpages = CPUInfo[0];

// determine 3DNow! support
if (!strncmp("AuthenticAMD", vendor, 12) && (extendedpages >= 0x80000001))
{
__cpuid(CPUInfo, 0x80000001);
if (((1 << 30) & CPUInfo[3]) && ((1 << 31) & CPUInfo[3]))
arch |= ca_3DNOW;
}

return arch;
CpuArchitecture |= CaSSE2;
#else
__builtin_cpu_init();
if (__builtin_cpu_supports("sse2"))
CpuArchitecture |= CaSSE2;
if (__builtin_cpu_supports("cmov"))
CpuArchitecture |= CaCMOV;
#endif
}
#endif
17 changes: 9 additions & 8 deletions src/common/CpuArchitecture.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#ifndef CPUARCHITECTURE_H
#define CPUARCHITECTURE_H

enum CpuArchitecture
{
ca_SSE = 0x1,
ca_SSE2 = 0x2,
ca_SSE3 = 0x4,
ca_3DNOW = 0x8,
ca_X64 = 0x10,
ca_PPC = 0x20,
ca_CMOV = 0x40,
CaSSE2 = 0x2,
CaCMOV = 0x40,
};

unsigned int determine_support();
extern unsigned int CpuArchitecture;

void initCpuArchitecture();

#endif // CPUARCHITECTURE_H
Loading

0 comments on commit 7de625c

Please sign in to comment.