Răsfoiți Sursa

Apply @marning suggested SSE auto-detect to make builds easier on non-x86 platforms: https://github.com/mwarning/ZeroTierOne/commit/aa2fd044cb69b97eef1ea38d5fefd18543aae22a

Adam Ierymenko 10 ani în urmă
părinte
comite
a9a390a930
5 a modificat fișierele cu 12 adăugiri și 45 ștergeri
  1. 0 21
      make-freebsd.mk
  2. 0 21
      make-linux.mk
  3. 0 3
      make-mac.mk
  4. 6 0
      node/Salsa20.hpp
  5. 6 0
      selftest.cpp

+ 0 - 21
make-freebsd.mk

@@ -8,27 +8,6 @@ LIBS=
 include objects.mk
 OBJS+=osdep/BSDEthernetTap.o 
 
-# Enable SSE-optimized Salsa20 on x86 and x86_64 machines
-MACHINE=$(shell uname -m)
-ifeq ($(MACHINE),x86_64)
-	DEFS+=-DZT_SALSA20_SSE 
-endif
-ifeq ($(MACHINE),amd64)
-	DEFS+=-DZT_SALSA20_SSE 
-endif
-ifeq ($(MACHINE),i686)
-	DEFS+=-DZT_SALSA20_SSE 
-endif
-ifeq ($(MACHINE),i586)
-	DEFS+=-DZT_SALSA20_SSE 
-endif
-ifeq ($(MACHINE),i386)
-	DEFS+=-DZT_SALSA20_SSE 
-endif
-ifeq ($(MACHINE),x86)
-	DEFS+=-DZT_SALSA20_SSE 
-endif
-
 # "make official" is a shortcut for this
 ifeq ($(ZT_OFFICIAL_RELEASE),1)
 	ZT_AUTO_UPDATE=1

+ 0 - 21
make-linux.mk

@@ -9,27 +9,6 @@ LIBS=
 include objects.mk
 OBJS+=osdep/LinuxEthernetTap.o 
 
-# Enable SSE-optimized Salsa20 on x86 and x86_64 machines
-MACHINE=$(shell uname -m)
-ifeq ($(MACHINE),x86_64)
-	DEFS+=-DZT_SALSA20_SSE 
-endif
-ifeq ($(MACHINE),amd64)
-	DEFS+=-DZT_SALSA20_SSE 
-endif
-ifeq ($(MACHINE),i686)
-	DEFS+=-DZT_SALSA20_SSE 
-endif
-ifeq ($(MACHINE),i586)
-	DEFS+=-DZT_SALSA20_SSE 
-endif
-ifeq ($(MACHINE),i386)
-	DEFS+=-DZT_SALSA20_SSE 
-endif
-ifeq ($(MACHINE),x86)
-	DEFS+=-DZT_SALSA20_SSE 
-endif
-
 # "make official" is a shortcut for this
 ifeq ($(ZT_OFFICIAL_RELEASE),1)
 	ZT_AUTO_UPDATE=1

+ 0 - 3
make-mac.mk

@@ -31,9 +31,6 @@ ifeq ($(ZT_ENABLE_NETWORK_CONTROLLER),1)
 	OBJS+=controller/SqliteNetworkController.o 
 endif
 
-# Enable SSE-optimized Salsa20 -- all Intel macs support SSE2
-DEFS+=-DZT_SALSA20_SSE
-
 # Debug mode -- dump trace output, build binary with -g
 ifeq ($(ZT_DEBUG),1)
 	DEFS+=-DZT_TRACE 

+ 6 - 0
node/Salsa20.hpp

@@ -7,10 +7,16 @@
 #ifndef ZT_SALSA20_HPP
 #define ZT_SALSA20_HPP
 
+#include <stdio.h>
 #include <stdint.h>
+#include <stdlib.h>
 
 #include "Constants.hpp"
 
+#if (!defined(ZT_SALSA20_SSE)) && (defined(__SSE2__) || defined(__WINDOWS__))
+#define ZT_SALSA20_SSE 1
+#endif
+
 #ifdef ZT_SALSA20_SSE
 #include <emmintrin.h>
 #endif // ZT_SALSA20_SSE

+ 6 - 0
selftest.cpp

@@ -187,6 +187,12 @@ static int testCrypto()
 	}
 	std::cout << "PASS" << std::endl;
 
+#ifdef ZT_SALSA20_SSE
+	std::cout << "[crypto] Salsa20 SSE: ENABLED" << std::endl;
+#else
+	std::cout << "[crypto] Salsa20 SSE: DISABLED" << std::endl;
+#endif
+
 	std::cout << "[crypto] Benchmarking Salsa20/12... "; std::cout.flush();
 	{
 		unsigned char *bb = (unsigned char *)::malloc(1234567);