From 35747ee3d54765a05d7594ee52fdcd564464b18f Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 2 Apr 2014 11:43:54 +0200 Subject: Rename "BLI_cpu.h" to "BLI_system.h" and add to it BLI_getpid() helper. There is not much sense to have a whole BLI file just to check SSE2 on CPUs... So idea is to rename it to more generic "BLI_system", and add to it more system-related utils, like e.g. an include helper for getpid(), which allows to hide unix/windows internals from rest of the code... Reviewers: campbellbarton Reviewed By: campbellbarton Differential Revision: https://developer.blender.org/D439 --- source/blender/blenkernel/intern/pointcache.c | 4 +- source/blender/blenlib/BLI_cpu.h | 31 -------------- source/blender/blenlib/BLI_system.h | 38 +++++++++++++++++ source/blender/blenlib/CMakeLists.txt | 4 +- source/blender/blenlib/intern/cpu.c | 59 -------------------------- source/blender/blenlib/intern/system.c | 59 ++++++++++++++++++++++++++ source/blender/blenloader/intern/writefile.c | 5 +-- source/blender/imbuf/intern/thumbs.c | 5 +-- source/blender/render/intern/source/rayshade.c | 2 +- source/blender/windowmanager/intern/wm_files.c | 5 +-- source/creator/creator.c | 9 +--- 11 files changed, 109 insertions(+), 112 deletions(-) delete mode 100644 source/blender/blenlib/BLI_cpu.h create mode 100644 source/blender/blenlib/BLI_system.h delete mode 100644 source/blender/blenlib/intern/cpu.c create mode 100644 source/blender/blenlib/intern/system.c (limited to 'source') diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 20107aa41a8..7458b4a4fa0 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -51,6 +51,8 @@ #include "BLI_threads.h" #include "BLI_math.h" #include "BLI_utildefines.h" +#include "BLI_system.h" +#include BLI_SYSTEM_PID_H #include "BLF_translation.h" @@ -100,9 +102,7 @@ /* untitled blend's need getpid for a unique name */ #ifndef WIN32 # include -# include #else -# include # include "BLI_winstuff.h" #endif diff --git a/source/blender/blenlib/BLI_cpu.h b/source/blender/blenlib/BLI_cpu.h deleted file mode 100644 index fa29162e59e..00000000000 --- a/source/blender/blenlib/BLI_cpu.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#ifndef __BLI_CPU_H__ -#define __BLI_CPU_H__ - -/** \file BLI_cpu.h - * \ingroup bli - */ - -int BLI_cpu_support_sse2(void); - -#endif - diff --git a/source/blender/blenlib/BLI_system.h b/source/blender/blenlib/BLI_system.h new file mode 100644 index 00000000000..8cdc9e4e6c5 --- /dev/null +++ b/source/blender/blenlib/BLI_system.h @@ -0,0 +1,38 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __BLI_SYSTEM_H__ +#define __BLI_SYSTEM_H__ + +/** \file BLI_system.h + * \ingroup bli + */ + +int BLI_cpu_support_sse2(void); + +/* getpid */ +#ifdef WIN32 +# define BLI_SYSTEM_PID_H +#else +# define BLI_SYSTEM_PID_H +#endif + +#endif /* __BLI_SYSTEM_H__ */ + diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index 491f988642b..205935f3d14 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -55,7 +55,6 @@ set(SRC intern/buffer.c intern/callbacks.c intern/convexhull2d.c - intern/cpu.c intern/dynlib.c intern/easing.c intern/edgehash.c @@ -97,6 +96,7 @@ set(SRC intern/string.c intern/string_cursor_utf8.c intern/string_utf8.c + intern/system.c intern/task.c intern/threads.c intern/time.c @@ -117,7 +117,6 @@ set(SRC BLI_callbacks.h BLI_compiler_attrs.h BLI_convexhull2d.h - BLI_cpu.h BLI_dlrbTree.h BLI_dynlib.h BLI_dynstr.h @@ -168,6 +167,7 @@ set(SRC BLI_string_cursor_utf8.h BLI_string_utf8.h BLI_sys_types.h + BLI_system.h BLI_task.h BLI_threads.h BLI_timecode.h diff --git a/source/blender/blenlib/intern/cpu.c b/source/blender/blenlib/intern/cpu.c deleted file mode 100644 index 784b1900785..00000000000 --- a/source/blender/blenlib/intern/cpu.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/blenlib/intern/cpu.c - * \ingroup bli - */ - - -#include "BLI_cpu.h" - -int BLI_cpu_support_sse2(void) -{ -#if defined(__x86_64__) || defined(_M_X64) - /* x86_64 always has SSE2 instructions */ - return 1; -#elif defined(__GNUC__) && defined(i386) - /* for GCC x86 we check cpuid */ - unsigned int d; - __asm__( - "pushl %%ebx\n\t" - "cpuid\n\t" - "popl %%ebx\n\t" - : "=d" (d) - : "a" (1)); - return (d & 0x04000000) != 0; -#elif (defined(_MSC_VER) && defined(_M_IX86)) - /* also check cpuid for MSVC x86 */ - unsigned int d; - __asm { - xor eax, eax - inc eax - push ebx - cpuid - pop ebx - mov d, edx - } - return (d & 0x04000000) != 0; -#else - return 0; -#endif -} - diff --git a/source/blender/blenlib/intern/system.c b/source/blender/blenlib/intern/system.c new file mode 100644 index 00000000000..e6389bc68f3 --- /dev/null +++ b/source/blender/blenlib/intern/system.c @@ -0,0 +1,59 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/blenlib/intern/system.c + * \ingroup bli + */ + + +#include "BLI_system.h" + +int BLI_cpu_support_sse2(void) +{ +#if defined(__x86_64__) || defined(_M_X64) + /* x86_64 always has SSE2 instructions */ + return 1; +#elif defined(__GNUC__) && defined(i386) + /* for GCC x86 we check cpuid */ + unsigned int d; + __asm__( + "pushl %%ebx\n\t" + "cpuid\n\t" + "popl %%ebx\n\t" + : "=d" (d) + : "a" (1)); + return (d & 0x04000000) != 0; +#elif (defined(_MSC_VER) && defined(_M_IX86)) + /* also check cpuid for MSVC x86 */ + unsigned int d; + __asm { + xor eax, eax + inc eax + push ebx + cpuid + pop ebx + mov d, edx + } + return (d & 0x04000000) != 0; +#else + return 0; +#endif +} + diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index ffd1d6d1be1..6c4fac60646 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -81,12 +81,9 @@ #include "zlib.h" -#ifndef WIN32 -# include -#else +#ifdef WIN32 # include "winsock2.h" # include -# include // for getpid # include "BLI_winstuff.h" #endif diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c index 18268043a04..843134a4289 100644 --- a/source/blender/imbuf/intern/thumbs.c +++ b/source/blender/imbuf/intern/thumbs.c @@ -39,6 +39,8 @@ #include "BLI_path_util.h" #include "BLI_fileops.h" #include "BLI_md5.h" +#include "BLI_system.h" +#include BLI_SYSTEM_PID_H #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" @@ -59,12 +61,9 @@ # endif # include /* for SHGetSpecialFolderPath, has to be done before BLI_winstuff * because 'near' is disabled through BLI_windstuff */ -# include /* getpid */ # include /* chdir */ # include "BLI_winstuff.h" # include "utfconv.h" -#else -# include #endif #define URI_MAX (FILE_MAX * 3 + 8) diff --git a/source/blender/render/intern/source/rayshade.c b/source/blender/render/intern/source/rayshade.c index 60327c7db8d..7e6fd04c3f4 100644 --- a/source/blender/render/intern/source/rayshade.c +++ b/source/blender/render/intern/source/rayshade.c @@ -41,7 +41,7 @@ #include "DNA_lamp_types.h" #include "BLI_blenlib.h" -#include "BLI_cpu.h" +#include "BLI_system.h" #include "BLI_math.h" #include "BLI_rand.h" #include "BLI_utildefines.h" diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 952fb42d607..850e4e13b75 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -46,10 +46,7 @@ # endif # include /* for SHGetSpecialFolderPath, has to be done before BLI_winstuff * because 'near' is disabled through BLI_windstuff */ -# include /* getpid */ # include "BLI_winstuff.h" -#else -# include /* getpid */ #endif #include "MEM_guardedalloc.h" @@ -60,6 +57,8 @@ #include "BLI_utildefines.h" #include "BLI_threads.h" #include "BLI_callbacks.h" +#include "BLI_system.h" +#include BLI_SYSTEM_PID_H #include "BLF_translation.h" diff --git a/source/creator/creator.c b/source/creator/creator.c index b74c64fa6b8..de320386bf8 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -40,13 +40,6 @@ # include #endif -/* crash handler */ -#ifdef WIN32 -# include /* getpid */ -#else -# include /* getpid */ -#endif - #ifdef WIN32 # include # include "utfconv.h" @@ -79,6 +72,8 @@ #include "BLI_callbacks.h" #include "BLI_blenlib.h" #include "BLI_mempool.h" +#include "BLI_system.h" +#include BLI_SYSTEM_PID_H #include "DNA_ID.h" #include "DNA_scene_types.h" -- cgit v1.2.3