|
4 | 4 |
|
5 | 5 | #include "doc/system_doc.h" |
6 | 6 |
|
| 7 | +static PyObject * |
| 8 | +pg_system_get_cpu_instruction_sets(PyObject *self, PyObject *_null) |
| 9 | +{ |
| 10 | + PyObject *tmp_bool = NULL; |
| 11 | + PyObject *instruction_sets = NULL; |
| 12 | + |
| 13 | + instruction_sets = PyDict_New(); |
| 14 | + if (!instruction_sets) { |
| 15 | + goto error; |
| 16 | + } |
| 17 | + |
| 18 | +#define INSERT_INSTRUCTIONSET_INFO(name, SDL_fn_name) \ |
| 19 | + tmp_bool = PyBool_FromLong((SDL_fn_name)()); \ |
| 20 | + if (PyDict_SetItemString(instruction_sets, (name), tmp_bool)) { \ |
| 21 | + Py_DECREF(tmp_bool); \ |
| 22 | + goto error; \ |
| 23 | + } \ |
| 24 | + Py_DECREF(tmp_bool); |
| 25 | + |
| 26 | + INSERT_INSTRUCTIONSET_INFO("RDTSC", SDL_HasRDTSC); |
| 27 | + INSERT_INSTRUCTIONSET_INFO("ALTIVEC", SDL_HasAltiVec); |
| 28 | + INSERT_INSTRUCTIONSET_INFO("MMX", SDL_HasMMX); |
| 29 | + INSERT_INSTRUCTIONSET_INFO("SSE", SDL_HasSSE); |
| 30 | + INSERT_INSTRUCTIONSET_INFO("SSE2", SDL_HasSSE2); |
| 31 | + INSERT_INSTRUCTIONSET_INFO("SSE3", SDL_HasSSE3); |
| 32 | + INSERT_INSTRUCTIONSET_INFO("SSE41", SDL_HasSSE41); |
| 33 | + INSERT_INSTRUCTIONSET_INFO("SSE42", SDL_HasSSE42); |
| 34 | + INSERT_INSTRUCTIONSET_INFO("AVX", SDL_HasAVX); |
| 35 | + INSERT_INSTRUCTIONSET_INFO("AVX2", SDL_HasAVX2); |
| 36 | + INSERT_INSTRUCTIONSET_INFO("AVX512F", SDL_HasAVX512F); |
| 37 | + INSERT_INSTRUCTIONSET_INFO("NEON", SDL_HasNEON); |
| 38 | +#if SDL_VERSION_ATLEAST(2, 0, 12) |
| 39 | + INSERT_INSTRUCTIONSET_INFO("ARMSIMD", SDL_HasARMSIMD); |
| 40 | +#else |
| 41 | + if (PyDict_SetItemString(instruction_sets, "ARMSIMD", Py_False)) |
| 42 | + goto error; |
| 43 | +#endif |
| 44 | +#if SDL_VERSION_ATLEAST(2, 24, 0) |
| 45 | + INSERT_INSTRUCTIONSET_INFO("LSX", SDL_HasLSX); |
| 46 | + INSERT_INSTRUCTIONSET_INFO("LASX", SDL_HasLASX); |
| 47 | +#else |
| 48 | + if (PyDict_SetItemString(instruction_sets, "LSX", Py_False)) |
| 49 | + goto error; |
| 50 | + if (PyDict_SetItemString(instruction_sets, "LASX", Py_False)) |
| 51 | + goto error; |
| 52 | +#endif |
| 53 | + |
| 54 | +#undef INSERT_INSTRUCTIONSET_INFO |
| 55 | + |
| 56 | + return instruction_sets; |
| 57 | + |
| 58 | +error: |
| 59 | + Py_XDECREF(instruction_sets); |
| 60 | + return NULL; |
| 61 | +} |
| 62 | + |
| 63 | +static PyObject * |
| 64 | +pg_system_get_total_ram(PyObject *self, PyObject *_null) |
| 65 | +{ |
| 66 | + return PyLong_FromLong(SDL_GetSystemRAM()); |
| 67 | +} |
| 68 | + |
7 | 69 | static PyObject * |
8 | 70 | pg_system_get_pref_path(PyObject *self, PyObject *args, PyObject *kwargs) |
9 | 71 | { |
@@ -100,6 +162,10 @@ pg_system_get_pref_locales(PyObject *self, PyObject *_null) |
100 | 162 | } |
101 | 163 |
|
102 | 164 | static PyMethodDef _system_methods[] = { |
| 165 | + {"get_cpu_instruction_sets", pg_system_get_cpu_instruction_sets, |
| 166 | + METH_NOARGS, DOC_SYSTEM_GETCPUINSTRUCTIONSETS}, |
| 167 | + {"get_total_ram", pg_system_get_total_ram, METH_NOARGS, |
| 168 | + DOC_SYSTEM_GETTOTALRAM}, |
103 | 169 | {"get_pref_path", (PyCFunction)pg_system_get_pref_path, |
104 | 170 | METH_VARARGS | METH_KEYWORDS, DOC_SYSTEM_GETPREFPATH}, |
105 | 171 | {"get_pref_locales", pg_system_get_pref_locales, METH_NOARGS, |
|
0 commit comments