aboutsummaryrefslogtreecommitdiffstats
path: root/c_src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2014-04-02 23:30:25 +0200
committerLoïc Hoguin <[email protected]>2014-04-02 23:30:25 +0200
commit00114c813b6c6829dcf3b6eedc6b45803b31c808 (patch)
treec602f21f0c0eff488bf2eb8b4eb3d0aeee8d820e /c_src
parent3fca1d3a170ac311fc379b3128be411edc21b0ee (diff)
downloadesdl2-00114c813b6c6829dcf3b6eedc6b45803b31c808.tar.gz
esdl2-00114c813b6c6829dcf3b6eedc6b45803b31c808.tar.bz2
esdl2-00114c813b6c6829dcf3b6eedc6b45803b31c808.zip
Add CPU feature detection functions
Now requiring SDL 2.0.3+.
Diffstat (limited to 'c_src')
-rw-r--r--c_src/Makefile6
-rw-r--r--c_src/esdl2.h14
-rw-r--r--c_src/sdl_cpu_info.c136
3 files changed, 155 insertions, 1 deletions
diff --git a/c_src/Makefile b/c_src/Makefile
index 85cb8ce..0887c86 100644
--- a/c_src/Makefile
+++ b/c_src/Makefile
@@ -14,10 +14,14 @@
PRIV_DIR ?= ../priv
+# SDL 2.0.3 has this option enabled that causes problems with NIF functions.
+SDL2_LIBS_FILTER_OUT = -Wl,--no-undefined
+SDL2_LIBS = $(filter-out $(SDL2_LIBS_FILTER_OUT),$(shell sdl2-config --static-libs))
+
all: env.mk
mkdir -p $(PRIV_DIR)
gcc *.c -fPIC -shared -o $(PRIV_DIR)/esdl2.so -I $(ERTS_INCLUDE_DIR) \
- `sdl2-config --cflags` `sdl2-config --static-libs` -lSDL2_image
+ `sdl2-config --cflags` $(SDL2_LIBS) -lSDL2_image
env.mk:
erl -noshell -noinput -eval "file:write_file(\"env.mk\", \
diff --git a/c_src/esdl2.h b/c_src/esdl2.h
index 7af7097..7a5346d 100644
--- a/c_src/esdl2.h
+++ b/c_src/esdl2.h
@@ -113,6 +113,20 @@
F(get_clipboard_text, 0) \
F(has_clipboard_text, 0) \
F(set_clipboard_text, 1) \
+ /* sdl_cpu_info */ \
+ F(get_cpu_cache_line_size, 0) \
+ F(get_cpu_count, 0) \
+ F(get_system_ram, 0) \
+ F(has_3dnow, 0) \
+ F(has_avx, 0) \
+ F(has_altivec, 0) \
+ F(has_mmx, 0) \
+ F(has_rdtsc, 0) \
+ F(has_sse, 0) \
+ F(has_sse2, 0) \
+ F(has_sse3, 0) \
+ F(has_sse41, 0) \
+ F(has_sse42, 0) \
/* sdl_events */ \
F(poll_event, 0) \
/* sdl_filesystem */ \
diff --git a/c_src/sdl_cpu_info.c b/c_src/sdl_cpu_info.c
new file mode 100644
index 0000000..1178504
--- /dev/null
+++ b/c_src/sdl_cpu_info.c
@@ -0,0 +1,136 @@
+// Copyright (c) 2014, Loïc Hoguin <[email protected]>
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+#include "esdl2.h"
+
+// get_cpu_cache_line_size
+
+NIF_FUNCTION(get_cpu_cache_line_size)
+{
+ return enif_make_int(env, SDL_GetCPUCacheLineSize());
+}
+
+// get_cpu_count
+
+NIF_FUNCTION(get_cpu_count)
+{
+ return enif_make_int(env, SDL_GetCPUCount());
+}
+
+// get_system_ram
+
+NIF_FUNCTION(get_system_ram)
+{
+ return enif_make_int(env, SDL_GetSystemRAM());
+}
+
+// has_3dnow
+
+NIF_FUNCTION(has_3dnow)
+{
+ if (SDL_Has3DNow())
+ return atom_true;
+
+ return atom_false;
+}
+
+// has_avx
+
+NIF_FUNCTION(has_avx)
+{
+ if (SDL_HasAVX())
+ return atom_true;
+
+ return atom_false;
+}
+
+// has_altivec
+
+NIF_FUNCTION(has_altivec)
+{
+ if (SDL_HasAltiVec())
+ return atom_true;
+
+ return atom_false;
+}
+
+// has_mmx
+
+NIF_FUNCTION(has_mmx)
+{
+ if (SDL_HasMMX())
+ return atom_true;
+
+ return atom_false;
+}
+
+// has_rdtsc
+
+NIF_FUNCTION(has_rdtsc)
+{
+ if (SDL_HasRDTSC())
+ return atom_true;
+
+ return atom_false;
+}
+
+// has_sse
+
+NIF_FUNCTION(has_sse)
+{
+ if (SDL_HasSSE())
+ return atom_true;
+
+ return atom_false;
+}
+
+// has_sse2
+
+NIF_FUNCTION(has_sse2)
+{
+ if (SDL_HasSSE2())
+ return atom_true;
+
+ return atom_false;
+}
+
+// has_sse3
+
+NIF_FUNCTION(has_sse3)
+{
+ if (SDL_HasSSE3())
+ return atom_true;
+
+ return atom_false;
+}
+
+// has_sse41
+
+NIF_FUNCTION(has_sse41)
+{
+ if (SDL_HasSSE41())
+ return atom_true;
+
+ return atom_false;
+}
+
+// has_sse42
+
+NIF_FUNCTION(has_sse42)
+{
+ if (SDL_HasSSE42())
+ return atom_true;
+
+ return atom_false;
+}