aboutsummaryrefslogtreecommitdiffstats
path: root/c_src/sdl_cpu_info.c
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/sdl_cpu_info.c
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/sdl_cpu_info.c')
-rw-r--r--c_src/sdl_cpu_info.c136
1 files changed, 136 insertions, 0 deletions
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;
+}