Skip to content

Commit 20344d5

Browse files
authored
Merge pull request #2544 from Starbuck5/compile-smoothscale-intrinsics-on-neon
Compile SSE2 smoothscale intrinsics on NEON
2 parents c60d69d + bf20ea5 commit 20344d5

File tree

2 files changed

+46
-26
lines changed

2 files changed

+46
-26
lines changed

src_c/transform.c

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,42 +1226,51 @@ smoothscale_init(struct _module_state *st)
12261226
return;
12271227
}
12281228

1229-
#ifdef SCALE_MMX_SUPPORT
1229+
#if !defined(__EMSCRIPTEN__)
1230+
#if PG_ENABLE_SSE_NEON
12301231
if (SDL_HasSSE2()) {
12311232
st->filter_type = "SSE2";
12321233
st->filter_shrink_X = filter_shrink_X_SSE2;
12331234
st->filter_shrink_Y = filter_shrink_Y_SSE2;
12341235
st->filter_expand_X = filter_expand_X_SSE2;
12351236
st->filter_expand_Y = filter_expand_Y_SSE2;
1237+
return;
12361238
}
1237-
else if (SDL_HasSSE()) {
1239+
if (SDL_HasNEON()) {
1240+
st->filter_type = "NEON";
1241+
st->filter_shrink_X = filter_shrink_X_SSE2;
1242+
st->filter_shrink_Y = filter_shrink_Y_SSE2;
1243+
st->filter_expand_X = filter_expand_X_SSE2;
1244+
st->filter_expand_Y = filter_expand_Y_SSE2;
1245+
return;
1246+
}
1247+
#endif /* PG_ENABLE_SSE_NEON */
1248+
#endif /* !__EMSCRIPTEN__ */
1249+
#ifdef SCALE_MMX_SUPPORT
1250+
if (SDL_HasSSE()) {
12381251
st->filter_type = "SSE";
12391252
st->filter_shrink_X = filter_shrink_X_SSE;
12401253
st->filter_shrink_Y = filter_shrink_Y_SSE;
12411254
st->filter_expand_X = filter_expand_X_SSE;
12421255
st->filter_expand_Y = filter_expand_Y_SSE;
1256+
return;
12431257
}
1244-
else if (SDL_HasMMX()) {
1258+
if (SDL_HasMMX()) {
12451259
st->filter_type = "MMX";
12461260
st->filter_shrink_X = filter_shrink_X_MMX;
12471261
st->filter_shrink_Y = filter_shrink_Y_MMX;
12481262
st->filter_expand_X = filter_expand_X_MMX;
12491263
st->filter_expand_Y = filter_expand_Y_MMX;
1264+
return;
12501265
}
1251-
else {
1252-
st->filter_type = "GENERIC";
1253-
st->filter_shrink_X = filter_shrink_X_ONLYC;
1254-
st->filter_shrink_Y = filter_shrink_Y_ONLYC;
1255-
st->filter_expand_X = filter_expand_X_ONLYC;
1256-
st->filter_expand_Y = filter_expand_Y_ONLYC;
1257-
}
1258-
#else /* ~SCALE_MMX_SUPPORT */
1266+
#endif /* ~SCALE_MMX_SUPPORT */
1267+
1268+
/* If no accelerated options were selected, falls through to generic */
12591269
st->filter_type = "GENERIC";
12601270
st->filter_shrink_X = filter_shrink_X_ONLYC;
12611271
st->filter_shrink_Y = filter_shrink_Y_ONLYC;
12621272
st->filter_expand_X = filter_expand_X_ONLYC;
12631273
st->filter_expand_Y = filter_expand_Y_ONLYC;
1264-
#endif /* ~SCALE_MMX_SUPPORT */
12651274
}
12661275

12671276
static void
@@ -1568,14 +1577,14 @@ surf_set_smoothscale_backend(PyObject *self, PyObject *args, PyObject *kwargs)
15681577
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", keywords, &type))
15691578
return NULL;
15701579

1571-
#if defined(SCALE_MMX_SUPPORT)
15721580
if (strcmp(type, "GENERIC") == 0) {
15731581
st->filter_type = "GENERIC";
15741582
st->filter_shrink_X = filter_shrink_X_ONLYC;
15751583
st->filter_shrink_Y = filter_shrink_Y_ONLYC;
15761584
st->filter_expand_X = filter_expand_X_ONLYC;
15771585
st->filter_expand_Y = filter_expand_Y_ONLYC;
15781586
}
1587+
#if defined(SCALE_MMX_SUPPORT)
15791588
else if (strcmp(type, "MMX") == 0) {
15801589
if (!SDL_HasMMX()) {
15811590
return RAISE(PyExc_ValueError,
@@ -1598,6 +1607,15 @@ surf_set_smoothscale_backend(PyObject *self, PyObject *args, PyObject *kwargs)
15981607
st->filter_expand_X = filter_expand_X_SSE;
15991608
st->filter_expand_Y = filter_expand_Y_SSE;
16001609
}
1610+
#else
1611+
else if (strcmp(st->filter_type, "MMX") == 0 ||
1612+
strcmp(st->filter_type, "SSE") == 0) {
1613+
return PyErr_Format(PyExc_ValueError,
1614+
"%s not supported on this machine", type);
1615+
}
1616+
#endif /* ~defined(SCALE_MMX_SUPPORT) */
1617+
#if !defined(__EMSCRIPTEN__)
1618+
#if PG_ENABLE_SSE_NEON
16011619
else if (strcmp(type, "SSE2") == 0) {
16021620
if (!SDL_HasSSE2()) {
16031621
return RAISE(PyExc_ValueError,
@@ -1609,22 +1627,24 @@ surf_set_smoothscale_backend(PyObject *self, PyObject *args, PyObject *kwargs)
16091627
st->filter_expand_X = filter_expand_X_SSE2;
16101628
st->filter_expand_Y = filter_expand_Y_SSE2;
16111629
}
1612-
else {
1613-
return PyErr_Format(PyExc_ValueError, "Unknown backend type %s", type);
1614-
}
1615-
Py_RETURN_NONE;
1616-
#else /* Not an x86 processor */
1617-
if (strcmp(type, "GENERIC") != 0) {
1618-
if (strcmp(st->filter_type, "MMX") == 0 ||
1619-
strcmp(st->filter_type, "SSE") == 0 ||
1620-
strcmp(st->filter_type, "SSE2") == 0) {
1621-
return PyErr_Format(PyExc_ValueError,
1622-
"%s not supported on this machine", type);
1630+
1631+
else if (strcmp(type, "NEON") == 0) {
1632+
if (!SDL_HasNEON()) {
1633+
return RAISE(PyExc_ValueError,
1634+
"NEON not supported on this machine");
16231635
}
1636+
st->filter_type = "NEON";
1637+
st->filter_shrink_X = filter_shrink_X_SSE2;
1638+
st->filter_shrink_Y = filter_shrink_Y_SSE2;
1639+
st->filter_expand_X = filter_expand_X_SSE2;
1640+
st->filter_expand_Y = filter_expand_Y_SSE2;
1641+
}
1642+
#endif /* PG_ENABLE_SSE_NEON */
1643+
#endif /* !__EMSCRIPTEN__ */
1644+
else {
16241645
return PyErr_Format(PyExc_ValueError, "Unknown backend type %s", type);
16251646
}
16261647
Py_RETURN_NONE;
1627-
#endif /* defined(SCALE_MMX_SUPPORT) */
16281648
}
16291649

16301650
/* _get_color_move_pixels is for iterating over pixels in a Surface.

test/transform_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ def test_scale2xraw(self):
11601160

11611161
def test_get_smoothscale_backend(self):
11621162
filter_type = pygame.transform.get_smoothscale_backend()
1163-
self.assertTrue(filter_type in ["GENERIC", "MMX", "SSE", "SSE2"])
1163+
self.assertTrue(filter_type in ["GENERIC", "MMX", "SSE", "SSE2", "NEON"])
11641164
# It would be nice to test if a non-generic type corresponds to an x86
11651165
# processor. But there is no simple test for this. platform.machine()
11661166
# returns process version specific information, like 'i686'.

0 commit comments

Comments
 (0)